Repository navigation
fix(ca): don't wake asleep agents on sleep; adopt OpenCode/Codex servers restarted after wake - #1370
Merged
Merged
Conversation
`ca sleep` flushed the disk over SSH before requesting sleep. Any SSH connection now wakes a sleeping agent, and the sleep request that follows arrives while it is starting and is refused, so the command failed and left the agent running. `ca sleep --all` did this to every sleeping agent. Read the agent's status first. A RUNNING agent is flushed and slept as before; a SLEEPING one (which includes the orchestrator's STOPPING) is reported as already asleep without connecting; any other state still sends the sleep request, but never over SSH. `--all` only acts on running agents. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
express-agent now restarts recorded listeners on the first boot after a power-off, so the OpenCode or Codex server this CLI started comes back under a new PID. The in-VM scripts only treated a listener as their own when the saved PID and start time matched, so rerunning desktop setup (or `railway code --opencode/--codex` reconnecting) failed with "Port 4096 is occupied by another process". When the saved-PID check fails and the port's listener authenticates with the saved credentials (OpenCode's server.json password, Codex's token), find it through /proc, record its process group leader and start time, and continue. Discovery does the same on a copy it never saves, and OpenCode's stop adopts before stopping. A listener that rejects the saved credentials is still refused. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes two Cloud Agent bugs:
railway ca sleepwoke agents that were already asleep and left them running, and OpenCode/Codex setup failed with "port occupied" after an agent woke.Changes
ca sleepreads the agent's status first. RUNNING: flush and sleep as before. SLEEPING (backboard also reports STOPPING as SLEEPING): print "already asleep" and send nothing. Any other state: send the sleep request without SSH.ca sleep --allonly acts on running agents.server.jsonpassword, Codex's token): they find it in/proc, record its process group leader and start time, and continue. Setup, connect, discovery (on an unsaved copy) and OpenCode's stop all do this. A listener that rejects the saved credentials is still refused.Why
syncwoke it, and the sleep request then arrived while it was starting and was refused. Thesyncstays for RUNNING agents only; since monorepo #37022 host-initiated stops sync the guest anyway.Verification
--allfiltering. The sleep tests intests/cloud_agent_lifecycle.rsnow cover the new behavior, plus--allwith nothing running.tests/opencode_desktop.py,tests/codex_server.py): a server relaunched under a new PID is adopted by setup, connect, discovery (state file unchanged) and OpenCode stop; a listener with other credentials is refused. The adopt tests fail on master. Both files pass on macOS and in a Linux container, which exercises the/proclookup. Codex's stale-PID test asserted the old refusal and is replaced by the refuse case.Related: #1369 (help text for idle sleep)
🤖 Generated with Claude Code