Skip to content

fix(workspace): union room participants into the JSONL reaper keep set (#2610) - #2614

Merged
vybe merged 3 commits into
devfrom
fix/2610-room-jsonl-keepset
Sep 8, 2026
Merged

vybe merged 3 commits into
devfrom
fix/2610-room-jsonl-keepset

Conversation

@dolho

@dolho dolho commented Sep 8, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #2610 (the P1): every multi-agent room went dead after ~6h.

The bug

A room stores a --resume handle per (agent, room) in enterprise_room_participants.cached_session_id (db/schema.py:641) and passes it to execute_task(resume_session_id=...) (shared_sessions/service.py:1077). The JSONL reaper built its keep set from agent_sessions and enterprise_portal_sessions only, 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:

<agent> could not respond: Execution failed with no output (exit code 1):
No conversation found with session ID: facad8e8-0f01-42a9-adef-1734c310bbeb

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_agent in 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 clears left_at (add_participant is an idempotent no-op on conflict).
  • status = 'open' — a closed room is never woken, and close_room is 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. identity is polymorphic — agent name, user id, or verified email per the sibling kind (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_parity fails when a table in db/schema.py 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 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. EXPLAIN shows an index scan on the existing idx_room_participants_identity (kind, identity) — no new index needed.

Every guard mutation-tested (each mutation applied, suite run, then restored byte-exact):

Mutation Tests killed
Remove the reaper union (the original bug) both reaper tests + the schema parity guard
Drop kind = 'agent' the polymorphic-identity test
Drop the left_at / status filter the departed-participant and closed-room tests

Targeted suites green: 869 passed across every session/portal/room/cleanup test 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_turn gives 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 (the finally that clears the indicator currently wraps a single attempt) and delta/top_seq recomputed for the cold attempt, and it must fire only on is_resume_not_found or 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.md stated the keep set as a two-source union and is corrected; learnings.md records the class.

Related to #2610

🤖 Generated with Claude Code

https://claude.ai/code/session_01CdxGmvuKuqaWJZ6pKUgaUJ

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
@dolho
dolho requested a review from vybe September 8, 2026 11:16
`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
@dolho

dolho commented Sep 8, 2026

Copy link
Copy Markdown
Contributor Author

Full unit suite: 14395 passed, 15 failed, 30 skipped in 31m37s.

All 15 failures are the pre-existing ::ffff: IPv4-mapped-address cases (test_736_a2a_outbound_edges, test_ent14_registry_url_ssrf, test_ent399_ipv6_origin, test_mcp_validator) — they fail on this box's Python 3.12 against the repo's 3.13 target and reproduce identically on clean origin/dev. None touch the reaper, rooms, or anything in this diff. CI on 3.13 is the authoritative check.

Targeted runs, for the record:

  • every session/portal/room/cleanup suite: 869 passed
  • the 14 new tests in this PR: 14 passed

Mutation results (each applied, suite run, then restored byte-exact):

Mutation Tests killed
Remove the reaper union (the original bug) both reaper tests + the schema parity guard
Drop kind = 'agent' the polymorphic-identity test
Drop the left_at / status filter the departed-participant and closed-room tests

Also pushed a follow-up commit correcting feature-flows/workspace-absorbs-session.md, which still described the keep set as "the union of both tables" — it is three now, and that section's own stated failure mode is precisely what happened to rooms.

vybe pushed a commit that referenced this pull request Sep 8, 2026
vybe pushed a commit that referenced this pull request Sep 8, 2026

@vybe vybe left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

merge-train: batch validated on train/20260908-1521 (train PR #2630 green: 27 checks).

@vybe
vybe merged commit a4046d2 into dev Sep 8, 2026
27 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants