Skip to content

fix(native-chat): keep chats with untracked helpers during idle cleanup - #28812

Closed
brennanb2025 wants to merge 3 commits into
brennanb2025/sta-10504-overflow-rederivefrom
brennanb2025/sta-10504-idle-sweep-incomplete
Closed

brennanb2025 wants to merge 3 commits into
brennanb2025/sta-10504-overflow-rederivefrom
brennanb2025/sta-10504-idle-sweep-incomplete

Conversation

@brennanb2025

@brennanb2025 brennanb2025 commented Oct 14, 2026 •

Copy link
Copy Markdown
Contributor

ELI5

When the agent-status store fills up (it holds at most 8,192 helper records), it can refuse the record for a background helper that is still working. Native chat's 30-minute idle cleanup then sees no helper and can stop the chat's agent while that helper is mid-task.

With this change, the chat stays running while that helper works. Once the helper ends, the normal idle window applies again, and the existing Stop action still ends the agent immediately.

What Changed

The idle sweep now reads the host's existing per-session signal that child-work tracking is incomplete, and treats it as work still owed. The prerequisite fix, #28829, makes that signal exact: it remembers every refused helper until that helper is admitted, ends, or its provider session ends. No new notice, control, saved field, or wire message is added.

User-facing before and after:

  • Ordinary chats (store not full): no difference. Verified side by side below.
  • A chat whose live helper was refused by a full store, after 30 idle minutes: on main the agent is stopped under the helper; with this PR it keeps running until the helper ends or you press Stop.

Why

The sweep previously read only the child rows admitted to the status store, so a refused live helper was invisible to it. The execution host already receives the helper's identity and end event even when its display row is refused; reading that lifecycle information closes the gap with five small file changes (+12/-2) and no new state.

How this differs from the common pattern (INTENDED): the common pattern derives owed child work from one provider-reported roster of children. Here, admitted children live in the bounded display status store and the exact set of refused helpers is kept beside it by the execution host. Intended because generic ACP agents expose no helper signal and Grok exposes only bounded projections, so the exact refused-helper set is the host-owned truth under the display store's cap. Both paths settle on the child's own end event or the provider session's end. A provider-reported child-work model that gives the sweep one execution-owned source for every child is a possible later refactor; it would be a broader per-provider change than this rare case needs.

Linked Issue

STA-10504

Visual Proof

The fault state itself (8,192 tracked helpers plus 30 idle minutes) is not practical to drive live; it is covered by the real-store test described under Testing. The screenshots below prove ordinary chats did not change: hidden-window QA on a separate Mac (M4Air), with real Claude Code 2.1.301 signed in and Grok driving the app over the Chrome DevTools Protocol, comparing origin/main (de2a371) with this PR at commit 05a4c08. The later commits only merge in current main; main had rewritten the idle sweep's work check, so the same two added lines were re-applied onto main's version, and a separate review confirmed no behavior difference. Each build ran in its own throwaway home with background launch; the real agent config files hashed identically before and after.

Result: no user-visible difference caused by this PR for (a) a short prompt, (b) a long command stopped with Stop, which reads "Interrupted" and then accepts the next prompt normally, and (c) one subagent.

Scenario main This PR
Workspace before any prompt
(a) Short prompt, reply finished
(b) Long foreground command running, Stop in the composer
(b) After Stop: "Interrupted"
(b) Next prompt after Stop, back to Done
(c) One subagent finished
30 seconds later, settled and idle
Backgrounded shell command running (tray)
Backgrounded shell command ended (see note)

Notes on the differences you can see:

  • The composer's effort label reads "Opus Med" on main and "Opus Medium" on this PR. That comes from newer renderer commits on main that are not in this PR's base; this PR changes only main-process code.
  • In the last two rows, Claude moved the long command into the background tray. On this PR the driver clicked the tray's Stop while it ran ("stopped"); on main the same click arrived after the command finished ("done"). That is driver timing, not a product difference; the composer Stop rows above are the like-for-like comparison.
  • Main shows two chat tabs because the driver opened a chat twice. Reply wording and timings vary as expected for a live model.

Testing

  • Automated: a real-store test fills the host status store to 8,192 children, observes a refused Claude helper, advances the injected clock past 30 minutes, checks that the provider stays connected, then stops it from the background-task strip. Removing the new check makes it fail. The focused status-owner, idle-sweep and Claude helper tests pass on this exact stack (28/28 on M4Air).
  • Manual: hidden-window Electron QA on macOS (M4Air), main vs this PR, as shown above.
  • CI: the full PR workflow passes on the current head (473c503).

The execution host owns this check for local, folder, and SSH workspaces; no platform path or wire contract changes. Linux and Windows are covered by CI only.

Review

Three adversarial review rounds plus an architecture challenge, and one more review of the conflict resolution after main was merged in. They found that the old 512-helper overflow marker could leave a false "incomplete" signal after every helper had ended, which would have blocked idle cleanup forever, and that a proposed 24-hour expiry could instead drop a helper that was still working. Both are fixed in #28829 by tracking the exact refused helpers. No open correctness findings remain.

Agent skill upstream boundary

  • Not applicable.

Notes

Stacked on #28829 (this PR's base branch). The two commits together fix the premature idle stop and the incomplete-tracking strip that used to stay up after more than 512 refused helpers had all ended.

Checklist

  • This PR is small and focused.
  • I explained what changed and why, including the user-visible before and after.
  • Before/after screenshots attached for the ordinary flows; the fault state is covered by the automated test.
  • Self-reviewed for correctness and performance.
  • Cross-platform, SSH/remote, and compatibility impact considered.

@brennanb2025
brennanb2025 force-pushed the brennanb2025/sta-10504-idle-sweep-incomplete branch from ddd38c5 to 05a4c08 Compare October 14, 2026 22:35
@brennanb2025
brennanb2025 changed the base branch from main to brennanb2025/sta-10504-overflow-rederive October 14, 2026 22:38
@brennanb2025
brennanb2025 marked this pull request as ready for review October 16, 2026 02:03
…rederive' into brennanb2025/sta-10504-idle-sweep-incomplete

# Conflicts:
#	src/main/native-chat/agent-session-wire/structured-agent-session-conversation-lifetime.ts
#	src/main/native-chat/agent-session-wire/structured-agent-session-idle-sweep.ts
@brennanb2025

Copy link
Copy Markdown
Contributor Author

Review loop status: code review passed, CI green, QA passed

Problem. Orca's agent-status store holds at most 8,192 helper (subagent) records per host. Once it is full, it refuses records for new helpers. Native chat's idle cleanup, which stops a chat's agent after 30 quiet minutes, only looked at admitted records, so it could stop a chat's agent while a refused helper was still working. The user would see the helper's work cut off for no visible reason.

User-facing change. In that case, the chat now keeps running until the helper ends or you press Stop, and then normal idle cleanup resumes. Ordinary chats behave exactly as before; nothing new appears in the UI.

What was fixed. Idle cleanup now reads the host's existing "child tracking incomplete" signal. The base PR #28829 makes that signal exact, so it clears when the last refused helper ends. Review found two problems in earlier versions, both fixed in #28829: an old 512-helper overflow marker that stayed set after every helper ended, which would have blocked idle cleanup forever, and a proposed 24-hour expiry that could have forgotten a helper that was still working. Nothing is deferred.

What was verified.

  • Code review: three adversarial rounds plus an architecture challenge. No open correctness findings.
  • Tests: a real-store test fills the store, gets a helper refused, advances the clock past 30 minutes, and checks that the agent stays connected and Stop still ends it. It fails without the fix. 28/28 focused tests pass on this exact stack.
  • CI: the full PR workflow, including the PR checks passed gate, is green on head 473c503 (run https://github.com/stablyai/orca/actions/runs/38844681767). An earlier run kept failing in an unrelated session-search test because it had started just before this PR was retargeted onto fix(native-chat): settle refused helpers after the status store fills #28829, so every rerun tested an old main snapshot from before main fixed that test.
  • QA: hidden-window Electron QA on a separate Mac with real Claude Code 2.1.301 compared main and commit 05a4c08 for a short prompt, a long command stopped with Stop, and one subagent. No user-visible difference came from this PR. The screenshots are in the description.
  • Main merge: the commits after 05a4c08 only bring in current main. Main had rewritten the idle sweep's work check, so two files conflicted. The resolution keeps main's code and adds this PR's same two lines. The PR's diff is still the same 5 files (+12/-2). A separate review of the resolution checked that the incomplete-helper check still covers every path where idle cleanup can stop an agent. It found no behavior difference: the sweep has one retire path, and it still goes through that check first.

Not verified / remaining risks.

  • The fault state itself (8,192 helpers plus 30 idle minutes) was not reproduced live. It is covered by the real-store test.
  • Linux, Windows and SSH were checked by CI only, not by hand. The change runs on the execution host and adds no saved field or wire message, so remote hosts are unaffected apart from the fix itself.
  • Memory for remembered refused helpers grows with the number of refused helpers that have not ended yet. Session end or Stop clears it.
  • Admitted helpers and refused helpers are tracked in two places on the host. This is intended for now (explained in the description). Moving to one provider-reported list of child work is a possible later refactor.

Stacked on #28829. Merge #28829 first.

@brennanb2025

Copy link
Copy Markdown
Contributor Author

Closing: this patches the status store's size limits, which are themselves wrong. The fix is moving to the root of that store in a separate change.

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