Repository navigation
fix(workspace): union room participants into the JSONL reaper keep set (#2610) - #2614
Conversation
Multi-agent rooms went dead after ~6h. A room stores a `--resume` handle per (agent, room) in `enterprise_room_participants.cached_session_id` and passes it to `execute_task(resume_session_id=...)`, but the reaper's keep set was built from `agent_sessions` and `enterprise_portal_sessions` only. Every room handle was therefore an orphan by construction: kept until the 1h age guard, deleted on the next 6h sweep. The next mention of any agent in the room then failed with `No conversation found with session ID: <uuid>`. Reported from production as "the 3-agent room is dead, the 1-agent chat from the same day is fine" — the single-agent chat was a Workspace thread, and its ids were in the keep set. Same class as ent#358 one surface over, which that fix's own comment predicted. `shared_sessions.db.list_active_claude_session_ids` mirrors `_wake_agent`'s early returns rather than returning every stored handle, and the two must move together: `left_at IS NULL` and room `status = 'open'` are both permanent (`close_room` is a one-way CAS; `add_participant` is a no-op that never clears `left_at`), so those handles can never resume, and keeping them would trade this bug for an unbounded leak — every room eventually expires and closes. The `kind = 'agent'` filter is load-bearing, not decoration: `identity` is polymorphic (ent#443), so without it a human participant whose username equals an agent name would inject a handle into that agent's keep set. The union is read in its own try/except that ABORTS the sweep on failure, matching the ent#358 half: skipping a cycle costs disk, reaping against a partial keep set costs users their conversations. Two shipped occurrences means the mechanism is the defect, so the guard is anchored on the SCHEMA, not on the reaper: `test_2610_resume_surface_parity` fails when a table gains a resume-handle column that no keep-set accessor covers. A test asserting only "the reaper calls three accessors" would pass on the very next occurrence, because the new surface simply would not be in it. Verified on both backends: the unit suite on SQLite, and the accessor's exact SQL against a live PostgreSQL, which returns only the open room's agent handle (excluding a sibling agent, a `user`-kind row with the same identity, and a closed room). Each guard mutation-tested — removing the union kills the two reaper tests and the parity guard; dropping `kind='agent'` or the `left_at`/`status` filter each kills exactly its own test. The second half of the report — rooms lack the inline cold retry the other two resumable surfaces have, so a dead handle is user-visible — is split to #2613: it needs the working-state lifecycle restructured and `delta`/`top_seq` recomputed for the cold attempt, which does not belong in a P1 fix. Related to #2610 Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_01CdxGmvuKuqaWJZ6pKUgaUJ
`workspace-absorbs-session.md` still described the keep set as "the union of both tables". #2610 made it three, and the section's own warning — a live JSONL deleted an hour after it was written, no error anywhere — is exactly what happened to rooms. Point at the guard so the next resume surface is caught by CI rather than by a user reporting an agent that forgot. Related to #2610 Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_01CdxGmvuKuqaWJZ6pKUgaUJ
|
Full unit suite: All 15 failures are the pre-existing Targeted runs, for the record:
Mutation results (each applied, suite run, then restored byte-exact):
Also pushed a follow-up commit correcting |
… append collision, both entries kept)
Fixes #2610 (the P1): every multi-agent room went dead after ~6h.
The bug
A room stores a
--resumehandle per (agent, room) inenterprise_room_participants.cached_session_id(db/schema.py:641) and passes it toexecute_task(resume_session_id=...)(shared_sessions/service.py:1077). The JSONL reaper built its keep set fromagent_sessionsandenterprise_portal_sessionsonly, so every room handle was an orphan by construction: kept until the 1h age guard, deleted on the next 6h sweep. The next mention of any agent in the room then failed with:Reported from production as "the 3-agent room is dead, the 1-agent chat from the same day is fine" — the single-agent chat was a Workspace thread, and its ids were in the keep set. Same class as ent#358 one surface over, which that fix's own comment predicted: "omitting the Workspace half deletes live session files an hour after they are written and every thread goes cold with no error anywhere."
The fix
shared_sessions.db.list_active_claude_session_ids(agent_name), unioned into_sweep_agentin its own try/except that aborts the sweep on failure — the ent#358 rule, because skipping a cycle costs disk while reaping against a partial keep set costs users their conversations.The predicate deliberately mirrors
_wake_agent's early returns rather than returning every stored handle, and the two must move together:left_at IS NULL— a departed participant is never woken, and nothing clearsleft_at(add_participantis an idempotent no-op on conflict).status = 'open'— a closed room is never woken, andclose_roomis a one-way CAS.Both are permanent, so those handles can never resume. Keeping them anyway would trade this bug for an unbounded leak: rooms expire, so every room eventually closes, and a status-blind keep set would pin every JSONL they ever wrote.
kind = 'agent'is load-bearing, not decoration.identityis polymorphic — agent name, user id, or verified email per the siblingkind(the ent#443 rule) — so without it a human participant whose username equals an agent name would inject a handle into that agent's keep set.Why the guard is anchored on the schema
Two shipped occurrences of one shape means the mechanism is the defect, not the two authors: the writer of a resume handle and the reader of the keep set live in different modules with no link, so adding a surface costs nothing at the time and silently breaks under the next sweep.
So
test_2610_resume_surface_parityfails when a table indb/schema.pygains a resume-handle column that no keep-set accessor covers. A test asserting only "the reaper calls three accessors" would pass on the very next occurrence of this bug, because the new surface simply would not be in it — the same reason a keep set assembled from a hardcoded list of sources is a denylist wearing an allowlist's clothes.Verification
Both backends. The unit suite runs on SQLite; the accessor's exact SQL was also run against a live PostgreSQL, returning only the open room's agent handle and excluding a sibling agent, a
user-kind row with the same identity, and a closed room.EXPLAINshows an index scan on the existingidx_room_participants_identity (kind, identity)— no new index needed.Every guard mutation-tested (each mutation applied, suite run, then restored byte-exact):
kind = 'agent'left_at/statusfilterTargeted suites green: 869 passed across every
session/portal/room/cleanuptest file, plus the 12 new tests. The full unit suite is still running locally and its result will be posted as a comment; CI is the authoritative gate (the local box runs Python 3.12 against a 3.13 target and carries ~18 unrelated pre-existing failures).Scope
The report's second half — rooms lack the inline cold retry that
session_turn_service.run_resumable_turngives the other two surfaces, so a dead handle is a user-visible failure — is split to #2613 rather than bundled. It needs the working-state lifecycle restructured (thefinallythat clears the indicator currently wraps a single attempt) anddelta/top_seqrecomputed for the cold attempt, and it must fire only onis_resume_not_foundor every failing agent doubles its spend. That does not belong in a P1 fix. After this PR a room handle no longer dies from reaping; #2613 covers the remaining causes (container recreate, manual reset).Docs:
architecture/execution.mdstated the keep set as a two-source union and is corrected;learnings.mdrecords the class.Related to #2610
🤖 Generated with Claude Code
https://claude.ai/code/session_01CdxGmvuKuqaWJZ6pKUgaUJ