Repository navigation
Fix #1978: a workspace runs while it has an open terminal, not while it has a map slot - #1980
Merged
Merged
Conversation
…ot while it has a map slot Every "running" (the address book, the naming and ambiguity rules, the resolvers' workspace lookup, the reply footer, the name route) was "has a key in Tower's terminal map". Many routes get-or-create that key: getInstances(), behind /health, /api/workspaces and /api/status, stores an entry for every known workspace on disk, empty or not. So stopped workspaces were listed as running, made shared directory names ambiguous, and held mail that a stopped workspace with no key refuses. - runningWorkspaces() in the shared naming module is the one definition: a workspace runs while it has at least one terminal. Tower feeds it its open terminals (runningWorkspacePaths(): on the map, session exists and has not exited); afx whoami feeds it the terminal_sessions rows. - A send to a registered agent in a stopped workspace, by an address that names the workspace, is refused as not running, whatever slot the map holds. Own-workspace sends still hold, and mail already held is untouched. - /api/send and /api/address-book wait for the startup reconcile (bounded), so a workspace whose terminals are still being adopted after a restart is not refused or listed as not running.
…space - Address book: a stopped workspace with an empty slot is listed not running with no agents, takes no part in ambiguity, and a send to its registered architect is refused as not running, the same answer as with no slot. A workspace whose terminals have all exited is not running; one whose terminal is reconnecting still is. - Registry resolver: an empty slot is refused, not held. Its fixture treated an empty slot as a running workspace, which is this bug; it now gives each workspace a terminal. - Route: a send that arrives before the startup reconcile settles waits for it. - e2e on a test Tower: the empty-slot case end to end, including afx whoami agreeing with the listing, held mail staying held and listed by afx inbox, and being offered to the terminal when the workspace starts. - Mocks gain getTerminalManager / a session status; one route test removed every session on the Tower to simulate one dead recipient and now removes only that one.
… route waits, docs - The address book carries `running` on each listed workspace instead of inferring it from a slot lookup, and fails loudly if a running workspace has no slot. - runningWorkspacePaths() stops at the first open terminal of each workspace. - PUT /api/workspaces/:path/address-name waits for the startup reconcile, as /api/send and /api/address-book do, since its answer reads which workspaces are running. - The afx skill (all four copies) and resources/commands/agent-farm.md (ours and the skeleton's) say that an address naming a stopped workspace is refused. Shipped-skill hashes regenerated.
waleedkadous
added a commit
that referenced
this pull request
Nov 25, 2026
waleedkadous
added a commit
that referenced
this pull request
Nov 25, 2026
waleedkadous
added a commit
that referenced
this pull request
Nov 25, 2026
…the Cockpit and PR #1980
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 #1978
Problem
afx workspace listcalled stopped workspaces running. On the installed Tower (3.3.8) it listed 53 workspaces: 46 marked running, only 12 with a live agent. The other 34 stopped workspaces were printed with their registered architects and builders as addresses markedno live terminal.The same wrong "running" caused three more problems:
no-live-pty, while a stopped workspace with no map slot was refused.afx whoamicould disagree with Tower about addresses.Root cause
Everything that asked "is this workspace running?" asked "does it have a key in Tower's terminal map?". That covered the address book, the naming and ambiguity rules, the resolvers' workspace lookup, the reply footer and the name route. But that key is get-or-create, and many routes create it.
This is proved, not inferred.
getInstances()sits behind/health,/api/workspaces,/api/statusand/api/workspaces/:path/status. It callsgetTerminalsForWorkspace()for every known workspace that exists on disk and is not a temp dir or a worktree. That function then stores its rebuilt entry whether or not the entry holds a terminal. The 46 "running" were exactly the 53 known minus the 7 thatgetInstancesskips (6 missing directories and one temp dir). Per-workspace reads (GET /workspace/<p>/api/state,/api/overview) leave empty slots the same way.Fix
One definition of running:
runningWorkspaces()inutils/workspace-address.ts, the naming module Tower and the CLI already share. A workspace is running while it has at least one terminal.runningWorkspacePaths(): ids on the map whose session exists and has not exited. The address book, the naming and ambiguity rules, the resolvers, the reply footer and the name route all use it.afx whoamifeeds it theterminal_sessionsrows, so whoami still does not need Tower.Decisions (agreed with the architect before building):
no-live-ptyas before, and the naming rules do not flip during a reconnect.Workspace '<name>' (<path>) is not running.This applies tows:architect,ws:architect:<name>andws:<builder>. A stopped workspace with no slot already got this answer; now it is the answer whether or not a slot exists. It matches the listing, which shows a stopped workspace with no agents.afx inbox, and is offered to the agent's terminal when the workspace starts. The refusal applies to new sends only; nothing already accepted is dropped or refused after the fact./api/sendand/api/address-booknow wait for the reconcile before resolving, bounded at 10 s (CODEV_STARTUP_READY_TIMEOUT_MS) as the dashboard's reads already are. So a workspace that is coming back is neither refused nor listed as not running. The refusal text tells nobody to start anything. Only if the reconcile runs past the cap does a send go ahead against the partial map. A named-workspace send to a workspace not yet adopted then gets "is not running", which is what it gets today.Known remainder, not changed here: the ~15 routes that get-or-create a map slot still do. Making them use a non-creating lookup is a separate change: they mix reads with writes, and a stopped workspace's file tabs live in that slot. "Running" no longer depends on it.
Known gap between whoami and Tower: whoami reads Tower's
terminal_sessionsrows, while Tower counts its open in-memory sessions. The two agree except when Tower keeps a row for a shellper it cannot reconnect to yet: its process is alive, but the reconnect failed, so the row is kept and retried on the next reconcile pass (tower-terminals.ts, Bugfix #1686). In that transient state whoami counts the workspace as running and Tower does not. Closing it would mean whoami asking Tower, or recording adoption in the database; both are larger than this fix. The architect accepted this gap before I built.Small adjacent changes:
.claude,.codexand both skeleton copies) andresources/commands/agent-farm.md(ours and the skeleton's) now say that an address naming a stopped workspace is refused. Shipped-skill hashes regenerated.Testing
Regression tests, checked against the pre-fix source and build: 9 unit tests and 4 e2e cases fail without the fix; all pass with it.
spec-1940-address-book.test.ts, a stopped workspace with an empty slot:spec-1313-registry-resolve.test.ts: an empty slot is refused, not held.tower-routes.test.ts: a send that arrives before the startup reconcile settles waits for it and is delivered.workspace-address.test.ts:runningWorkspaces().cross-workspace-addressing.e2e.test.ts, on a test Tower with its own port and database: a stopped, registered workspace with an empty slot (left by a dashboard-styleGET …/api/state) that shares the runningcodev-cloud's directory name.afx workspace listshows it not running, with no agents.afx whoamigives the same address the listing prints.afx inbox.codev-cloud's name, the name is refused as ambiguous, whoami and the listing disagree, and the send is held.Fixtures that encoded the bug, now corrected:
spec-1313-registry-resolvetreated an empty slot as a running workspace ("the resolver only cares that the key exists").getTerminalManagerand a sessionstatus.Full suite: passed under porch's
testscheck (202 s), and the build check passed too.Live verification (issue step 5): not done. It needs this build on a Tower with many workspaces. The only one is the live Tower on port 4100, and that means an install plus a Tower restart, which is the owner's call. A test Tower on a copy of
global.dbwould reconcile the live shellpers and take over their connections, so I did not do that. After an install, check withafx workspace list --json: the count ofrunningworkspaces should equal the count of workspaces with aliveagent. That was 46 vs 12 before.Windows: on-demand workflow dispatched on this branch: https://github.com/cluesmith/codev/actions/runs/45502107634