Skip to content

Keep chats with background work awake, track resumed agents, show subagent approvals in sidebar - #424

Merged
frenchie4111 merged 4 commits into
mainfrom
fix/background-agent-sleep-and-resume
Nov 26, 2026
Merged

frenchie4111 merged 4 commits into
mainfrom
fix/background-agent-sleep-and-resume

Conversation

@frenchie4111

Copy link
Copy Markdown
Collaborator

Three related fixes for background work in Chat tabs.

1. Auto-sleep no longer kills chats with background work running

AutoSleepMonitor slept any idle 'waiting' chat tab, even when a background Agent or run_in_background Bash was still going. Sleeping kills the Claude process, which kills that work too. The sweep now skips any session with a running detached task. Background Bash counts too: Claude Code reports it through the same task_started / task_notification pair (task_type: "local_bash"), so Ness was already recording it.

When the process exits, tasks still marked running are set to failed. Otherwise a task that died with its process would show a spinner forever and keep the tab from ever auto-sleeping again.

2. Resumed background agents show as running again

When an agent is resumed with SendMessage, Claude Code sends a new task_started with the same task_id but with the SendMessage call's tool_use_id. Ness tracked agents by tool_use_id, so the resume created a second record and the original Agent card said "completed" for the whole resumed run. Task events are now matched back to the original record by task_id, and the resumed run's report goes on the Agent card. task_started / task_notification are now written to debug.log.

The event sequences above come from running the bundled Claude Code 2.1.327 in stream-json mode, and the new manager test replays them.

3. Subagent approval prompts in the sidebar

A blocked subagent showed only a ⚠ in the sidebar. The prompt you could act on was inside its Task card, which for a background agent is usually far up the transcript. The approval card now also appears:

  • on the agent's card in the Subagents column, even when the card is collapsed;
  • in the agent history window opened from the Agents panel.

The collapsed "subagents" chip turns amber while any subagent is waiting. A subagent's question (AskUserQuestion) points you to the chat rather than mounting a second copy of the question box, which takes focus and keeps its own draft.

Testing

  • npm run typecheck, npx electron-vite build, npx vitest run (2827 tests) all pass.
  • New tests: auto-sleep-monitor.test.ts (running agent, settled agent, resumed agent, background Bash), reducer tests for resume and exit, a manager test replaying the recorded resume sequence, and collectAgents tests for each agent's own pending calls.
  • Tested by hand in a headless Ness with its own data folder, using real background agents: approving and denying from the Subagents column and approving from the history window each reached the agent and gave the expected result (directory created or not), and both copies of the prompt cleared.

🤖 Generated with Claude Code

frenchie4111 and others added 2 commits November 25, 2026 20:03
Claude Code reports a SendMessage resume as a fresh task_started with the
same task_id but the SendMessage call's tool_use_id, so the Agent card
stayed 'completed' for the whole resumed run. Resolve task events by
task_id back to the original Agent record, and attach the resumed run's
report to that card.

Background Bash emits the same task_started/task_notification pair
(task_type local_bash), so AutoSleepMonitor now skips any session with a
running detached task. Running tasks are settled when the process exits
so a dead one can't pin a tab awake forever. Task lifecycle events are
now logged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A background agent blocked on an approval only showed a ⚠ in the
sidebar; the actionable prompt lived inside its Task card, usually far up
the transcript. collectAgents now records each agent's own pending
tool_use ids, and the Subagents column card (outside its disclosure) and
the agent peek render the same approval card the chat does. The collapsed
column's chip turns amber while any subagent is blocked. Questions
(AskUserQuestion) point back to the chat instead of mounting a second
autofocusing copy.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@frenchie4111
frenchie4111 deployed to evidence-review-auto November 26, 2026 16:39 — with GitHub Actions Active
github-actions Bot added a commit that referenced this pull request Nov 26, 2026
@github-actions

Copy link
Copy Markdown

🟡 Evidence review: partially verified

The subagent approval prompt now appears on the agent's card in the Subagents column, the collapsed chip turns amber with ⚠, and the agent history window opened from the Agents panel shows the prompt with working buttons. Before shows only a ⚠ with no controls. Auto-sleep and the SendMessage resume card were not reached: the auto-sleep setting exists in Settings, but the blocked approval keeps the tab in 'running', so the sweep never fires. Those claims rest on the unit tests in the diff.

Claim Evidence Notes
✅ A blocked subagent's approval prompt appears on its card in the Subagents column. E1, E2 After shows an inline NEEDS APPROVAL Bash card with Allow once / Allow Bash this session / Allow with edits / Always allow / Deny. Before shows only ⚠ with no controls.
✅ The collapsed 'subagents' chip turns amber with a ⚠ while a subagent waits. E1 After: amber chip with ⚠. Before: neutral chip with spinner.
✅ The approval card also appears in the agent history window opened from the Agents panel. E3 Clicking the blocked agent row in the AGENTS panel opened a history window showing the NEEDS APPROVAL Bash card with its buttons. After-only capture.
➖ A subagent's AskUserQuestion shows a pointer to the chat, not a second question box. No subagent asked a question during this session.
❔ Auto-sleep skips chats with running background tasks, and a resumed agent shows as running again on the Agent card. Routes tried: found the autoSleepMinutes setting in Settings (default 30). Reproducing needs an idle 'waiting' tab with a background task still running; the blocked approval keeps the tab in 'running', so the sweep never fires. The resume case needs a second SendMessage turn, not reached. Both rest on the unit tests.
Test plan
  • Subagent approval prompt appears on the agent card in the Subagents column (ChatAgentColumn) even when collapsed; the collapsed 'subagents' chip turns amber with ⚠ while a subagent waits: Needs a Chat tab with a background subagent that is blocked on a tool approval. Hard to produce in fixture; try a Chat tab, ask agent to run a Task/Agent in background that writes a file (needs permission), then observe Subagents column. → Before: no approval card / chip is plain. After: amber chip with ⚠ and approval card on agent card.
  • Auto-sleep skips chats with running background tasks (not verifiable without long idle time): Requires autoSleepMinutes setting and idle time; likely not testable quickly. → Tab stays awake.

E1

Before: the subagent card in the Subagents column shows only a ⚠ and no approval buttons. After: the card carries its own NEEDS APPROVAL prompt with Allow/Deny.

Before After
E1 before E1 after

E2

Subagents column reopened: after shows the agent's own NEEDS APPROVAL card with Allow/Deny inside the Subagents column; before shows the agent with only a ⚠ and no approval controls.

Before After
E2 before E2 after

E3

After: the agent history window for the blocked subagent shows the NEEDS APPROVAL Bash card with Allow/Deny buttons, opened from the Agents panel row.

after

E3 after

Model anthropic/claude-haiku-5.5 · 20 actions · 489663 reviewer tokens · $0.0596 total (reviewer $0.0517, agents in app $0.0079 over 6 calls)

  • Re-run evidence review on the latest push

Automated evidence review of 0407050a · run log + transcript

frenchie4111 and others added 2 commits November 26, 2026 11:49
- collectAgents no longer reuses a settled summary once its lifecycle
  record has moved, so a SendMessage resume shows as running with its new
  steps and pending approvals instead of the pre-resume snapshot.
- Tasks still running when the process exits settle as 'interrupted',
  not 'failed' — a sleep isn't an error.
- AutoSleepMonitor documents that background work keeps a tab awake with
  no upper bound, and logs the skip once per stretch.
- Note why the task key is resolved in both manager and reducer; narrow
  the peek's session id instead of passing ''.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The exited state event now carries a timestamp, which the reducer stamps
as completedAt on tasks it settles as interrupted. Without it the right
panel and peek kept ticking the elapsed time of a dead agent.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@frenchie4111
frenchie4111 merged commit 096b397 into main Nov 26, 2026
1 check 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.

1 participant