Skip to content

fix(core,client): keep sessions busy until their background work reports back - #60500

Open
kitlangton wants to merge 1 commit into
t902-job-toolsfrom
t902-session-jobs
Open

kitlangton wants to merge 1 commit into
t902-job-toolsfrom
t902-session-jobs

Conversation

@kitlangton

@kitlangton kitlangton commented Oct 30, 2026 •

Copy link
Copy Markdown
Contributor

A session that moved a tool to the background now stays busy until that tool reports back and its turn finishes, instead of showing idle in between.
The server owns the busy state and reports it with the existing session.status event. Sessions with no background work go idle exactly as before. Stacked on #60497.

🔍 Origin: reported in #51810 and #56660

❌ Before

  1. A session moves a slow tool to the background and its turn ends.
  2. ❌ The active-session list and the app mark it idle, then running again when the tool's notice wakes it.
  3. ❌ The "done" sound plays at the first idle, before the work is done.

✅ After

  1. The server counts a session busy while it drains or while it owns backgrounded work that will report back and wake it.
  2. It publishes session.status (busy / idle) only when that changes, routed by session so moves never misroute it. GET /api/session/active reports the same thing, so clients hydrate one value on reconnect.
  3. ✅ The app, the client store and the mini TUI follow session.status; the done sound waits for idle. Older servers keep the old behavior.
  4. Stop also cancels the session's own backgrounded work.
- busy = a turn is draining
+ busy = a turn is draining || backgrounded work will still wake the session
+ busy changes -> session.status { busy | idle }   (existing event, now emitted)
  job finishes -> its notice wakes the session -> released only after the wake (no idle blip)
  shell({ background: true }) -> detached, never holds the session (dev servers)
+ interrupt (no resume) -> also cancels held jobs

📊 Proof

Case Before After
Turn ends while a backgrounded tool runs ❌ idle, then running ✅ busy until its wake's turn ends
A foreground tool finishes mid-turn ✅ busy ✅ busy
Background dev server (shell with background: true) idle ✅ idle
Reconnect after the work ended while offline — ✅ idle
Stop ❌ job keeps running ✅ job cancelled, idle

New tests in core (status sequence with a slow notice, Stop, held/detached jobs, bus routing across a move), server (active list), client store and mini TUI.

👀 Read: packages/core/src/job.ts, holds/waking: a held job keeps counting until its notice has woken the session, so the session never blips idle in between. packages/core/src/session/execution.ts, refreshStatus. The rest is routine.

⚠️ Trade-off: #51810 and #56660 asked for explicit background shells to count. This PR keeps them out so a dev server can't hold a session forever. A shell that auto-backgrounds after its yield_after still counts until it finishes (Stop cancels it).

Checks run
  • core: bun test test/job.test.ts test/session-execution.test.ts test/bus-session-routing.test.ts test/session-run-coordinator.test.ts test/bus.test.ts test/tool-job.test.ts test/tool-auto-background.test.ts test/session-shell.test.ts test/tool-subagent.test.ts pass. In test/tool-shell.test.ts, the 2 "conditional substitutions" tests fail on the base branch too.
  • server: bun test test/session-active-jobs.test.ts passes
  • client: bun test test/solid-data.test.ts passes
  • tui: bun test test/mini/stream-v2.transport.test.ts passes
  • bun run typecheck in schema, core, protocol, server, client, tui, app: no errors
  • Regenerated OpenAPI and clients

@kitlangton
kitlangton force-pushed the t902-session-jobs branch 2 times, most recently from bce1433 to 59a7878 Compare October 30, 2026 06:42
@kitlangton
kitlangton force-pushed the t902-session-jobs branch 3 times, most recently from d2f2c92 to 4cf993e Compare November 3, 2026 20:03
@kitlangton kitlangton changed the title feat(server,client): expose session jobs and keep sessions busy while jobs run fix(core,client): keep sessions busy until their background jobs finish Nov 3, 2026
@kitlangton kitlangton changed the title fix(core,client): keep sessions busy until their background jobs finish fix(core,client): keep sessions busy until their background work reports back Nov 3, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant