[GH-ISSUE #4218] [GUI] Stopped background helper keeps its In progress row after a restart #1855

Closed
opened 2026-11-04 01:54:45 +07:00 by bsakaguchi · 2 comments
Owner

Originally created by @xvcezrqpbxtpzblrt on GitHub (Oct 26, 2026).
Original GitHub issue: https://github.com/Niko1221/Strata/issues/4218

2026-11-06 核对结果:装机 0.2.11(dist)与 main@9f7d977d2 源码中已存在该修复——重启加载时 settleAgents 把仍标 working 的 helper 行标为 cancelled(agents.ts,注释含 #4218)。未做 GUI 实测。可关单;如再复现请带场景。


Area

[GUI] (the desktop app)

Desktop app, Terminal or source?

Desktop app (Windows, Linux or Mac)

What happened

I started a chat on a local model and let the agent start a background helper agent that ran a long tool call. The parent turn ended while the helper was still running; the chat header showed one running helper and the helper row said "In progress".

I pressed Stop while the helper was still running. The helper did stop: its session ends with turn/end (reason aborted, source user), and a later list_agents call returns it as [inactive]. The helper row in the chat, however, stayed "In progress" permanently, and the header kept counting one running helper. Quitting and reopening the app did not clear it.

Expected: once the helper ends, the row becomes "Cancelled" (or "Stopped") and the running count drops to zero. At the latest, a restart must not restore a "working" row for a helper that is not running.

Actual: the row stays "In progress"; its duration freezes at the last row update (48m46s in my run) although the helper ran 52m53s; the persisted browser state still has status: "working" for that row; a restart restores it unchanged.

Smallest steps or command that reproduce it

  1. Desktop app, one chat, local model.
  2. Ask the agent to start a background helper that runs a long tool (several minutes).
  3. Wait until the parent turn ends while the helper is still running. The chat header shows one running helper; the row says "In progress".
  4. Press Stop while the helper is still running.
  5. Wait for the helper to stop. The agent runtime reports it as inactive, but the row still says "In progress".
  6. Quit and reopen the app, open the same chat. The row is still "In progress" and the header still counts it.

I reproduced this once. I did not repeat it on a second run; the persisted state and the restart behaviour were consistent across the app restart I tested.

Reproduction status

Reproduced locally

Strata version

Strata 0.2.6 (desktop) · engine 0.1.50

Graphics card, memory and system

NVIDIA GeForce RTX 3080 Ti Laptop GPU, 16 GB VRAM · 64 GB RAM · Windows 11 Pro

Model, size and settings

Local model, 512K context, KV q4_0, one request slot. Pictures off. The helper used the same local model.

Logs

No log file is attached. The evidence is the UI state and the session events, with relative times:

  • T+0: helper created; row "In progress".
  • T+48m46s: last row update; the helper starts a long tool call.
  • T+52m53s: Stop; the helper session ends with turn/end reason aborted (user).
  • T+56m: list_agents returns the helper as [inactive].
  • Restart: the row is still "working"; the header still counts one running helper.

The persisted browser state for the row contains status: "working", durationMs: 2926057 and an updatedAt equal to the last row update (T+48m46s). The helper's own session log ends at T+52m53s with turn/end (aborted, user), so the helper is not running.

Code reading (inference, not a measurement)

I read the 0.2.6 tree. Line numbers may move.

  • The row is produced by the host's child projector: apps/host/server/agent/children.mjs:163-169 maps turn/end with an aborted reason to cancelled, and apps/host/server/agent/agent-bridge.mjs:578 emits the final row.
  • The frontend only merges agent frames: apps/host/src/lib/agents.ts:7-25 and apps/host/src/lib/store.ts:688 / 1785. There is no path that changes a working row when a turn ends or when the app starts.
  • loadSessions() (apps/host/src/lib/store.ts:170-187) restores agents unchanged; it only clears message.streaming.
  • finishTurn() (apps/host/server/agent/agent-bridge.mjs:471-477) closes the child follow streams. It does not emit a terminal row for a child that is still working.

So the deterministic gap is on the frontend: a persisted working row survives every restart. The terminal row was not applied in my run; I did not instrument the host to find where it was lost, so I am not claiming a specific drop point.

Suggested fix

The smallest fix is to reconcile on load: in loadSessions(), change any agents[*].status === "working" to cancelled unless the host reports that session as running. A second fix is to reconcile at the end of a run: in finishTurn(), emit a final cancelled row for every child that is still not done before closing the streams. Either one removes the permanent "In progress" row; the first also covers a crash or a closed window.

Impact

The row and the "N subagents running" count stay wrong until the browser state is cleared or the app is reinstalled. New turns and new helpers work; only the old row is stuck. Because the row is persisted, a restart does not help, which makes it look like the helper is still running.

Originally created by @xvcezrqpbxtpzblrt on GitHub (Oct 26, 2026). Original GitHub issue: https://github.com/Niko1221/Strata/issues/4218 **2026-11-06 核对结果**:装机 0.2.11(dist)与 main@9f7d977d2 源码中已存在该修复——重启加载时 settleAgents 把仍标 working 的 helper 行标为 cancelled(agents.ts,注释含 #4218)。未做 GUI 实测。可关单;如再复现请带场景。 --- ### Area [GUI] (the desktop app) ### Desktop app, Terminal or source? Desktop app (Windows, Linux or Mac) ### What happened I started a chat on a local model and let the agent start a background helper agent that ran a long tool call. The parent turn ended while the helper was still running; the chat header showed one running helper and the helper row said "In progress". I pressed Stop while the helper was still running. The helper did stop: its session ends with `turn/end` (reason `aborted`, source `user`), and a later `list_agents` call returns it as `[inactive]`. The helper row in the chat, however, stayed "In progress" permanently, and the header kept counting one running helper. Quitting and reopening the app did not clear it. Expected: once the helper ends, the row becomes "Cancelled" (or "Stopped") and the running count drops to zero. At the latest, a restart must not restore a "working" row for a helper that is not running. Actual: the row stays "In progress"; its duration freezes at the last row update (48m46s in my run) although the helper ran 52m53s; the persisted browser state still has `status: "working"` for that row; a restart restores it unchanged. ### Smallest steps or command that reproduce it 1. Desktop app, one chat, local model. 2. Ask the agent to start a background helper that runs a long tool (several minutes). 3. Wait until the parent turn ends while the helper is still running. The chat header shows one running helper; the row says "In progress". 4. Press Stop while the helper is still running. 5. Wait for the helper to stop. The agent runtime reports it as inactive, but the row still says "In progress". 6. Quit and reopen the app, open the same chat. The row is still "In progress" and the header still counts it. I reproduced this once. I did not repeat it on a second run; the persisted state and the restart behaviour were consistent across the app restart I tested. ### Reproduction status Reproduced locally ### Strata version Strata 0.2.6 (desktop) · engine 0.1.50 ### Graphics card, memory and system NVIDIA GeForce RTX 3080 Ti Laptop GPU, 16 GB VRAM · 64 GB RAM · Windows 11 Pro ### Model, size and settings Local model, 512K context, KV q4_0, one request slot. Pictures off. The helper used the same local model. ### Logs No log file is attached. The evidence is the UI state and the session events, with relative times: - T+0: helper created; row "In progress". - T+48m46s: last row update; the helper starts a long tool call. - T+52m53s: Stop; the helper session ends with `turn/end` reason `aborted` (`user`). - T+56m: `list_agents` returns the helper as `[inactive]`. - Restart: the row is still "working"; the header still counts one running helper. The persisted browser state for the row contains `status: "working"`, `durationMs: 2926057` and an `updatedAt` equal to the last row update (T+48m46s). The helper's own session log ends at T+52m53s with `turn/end` (`aborted`, `user`), so the helper is not running. ### Code reading (inference, not a measurement) I read the 0.2.6 tree. Line numbers may move. - The row is produced by the host's child projector: `apps/host/server/agent/children.mjs:163-169` maps `turn/end` with an `aborted` reason to `cancelled`, and `apps/host/server/agent/agent-bridge.mjs:578` emits the final row. - The frontend only merges agent frames: `apps/host/src/lib/agents.ts:7-25` and `apps/host/src/lib/store.ts:688` / `1785`. There is no path that changes a `working` row when a turn ends or when the app starts. - `loadSessions()` (`apps/host/src/lib/store.ts:170-187`) restores `agents` unchanged; it only clears `message.streaming`. - `finishTurn()` (`apps/host/server/agent/agent-bridge.mjs:471-477`) closes the child follow streams. It does not emit a terminal row for a child that is still `working`. So the deterministic gap is on the frontend: a persisted `working` row survives every restart. The terminal row was not applied in my run; I did not instrument the host to find where it was lost, so I am not claiming a specific drop point. ### Suggested fix The smallest fix is to reconcile on load: in `loadSessions()`, change any `agents[*].status === "working"` to `cancelled` unless the host reports that session as running. A second fix is to reconcile at the end of a run: in `finishTurn()`, emit a final `cancelled` row for every child that is still not `done` before closing the streams. Either one removes the permanent "In progress" row; the first also covers a crash or a closed window. ### Impact The row and the "N subagents running" count stay wrong until the browser state is cleared or the app is reinstalled. New turns and new helpers work; only the old row is stuck. Because the row is persisted, a restart does not help, which makes it look like the helper is still running.
Author
Owner

@xvcezrqpbxtpzblrt commented on GitHub (Oct 27, 2026):

Additional evidence and a narrower root cause (0.2.6, code reading + the same reproduced run)

I re-checked the 0.2.6 tree and the installed app. The installed host/server/agent/agent-bridge.mjs, children.mjs and profile.mjs are byte-identical to the 0.2.6 source, so this is not an old-build artifact.

In the reproduced run, the persisted row is still working; the helper's own log ends with turn/end (aborted, user) 4m7s after the row's last update. The row's durationMs is 2,926,057 ms (48m46s), while the turn ran 52m53s. A restart restores the row unchanged. Two other helpers stopped in the same app session did get a terminal row, which is consistent with a race rather than a missing status mapping.

What the code does (static analysis, not instrumented):

  • finishTurn() (agent-bridge.mjs:471-477) sets turn.finished = true and closes every child session/follow stream. It does not emit a terminal agent frame for a child that is still working.
  • fold() (agent-bridge.mjs:572) starts with if (turn.finished) return, so a child turn/end that arrives after the parent turn finished is ignored.
  • stop() (agent-bridge.mjs:1290-1308) interrupts helpers first, then cancels the parent; a 300 ms settle timer and the parent's own turn/end can finish the turn before the child's terminal event is folded.
  • The UI only merges frames (agents.ts:7-25); it has no terminal-absorbing rule. loadSessions() (store.ts:170-187) restores agents unchanged, and the rows are persisted to localStorage (store.ts:1016). runningAgents() counts status === 'working' (agents.ts:27).

So the exact drop point in this run is not proven without host instrumentation, but the class of failure is deterministic: once the terminal row is lost, nothing reconciles it, and the persisted working row survives every restart.

The load-time reconciliation needs a host snapshot, not only a per-session running flag:

The suggested "unless the host reports that session as running" check is the right direction, but the host needs to expose the live child set, not only a session-level boolean. Otherwise a webview reload while the host keeps running can still mark a live helper as cancelled, and a lost terminal frame can still leave a row working until the next reload. The load path should ask the host for the live child rows (a snapshot) and only mark rows that the host does not report as live. The same snapshot should be used after a stream gap/reconnect. A terminal row should also be emitted before the child stream is closed, and the UI merge should treat terminal states as final.

I did not instrument the host, so I am not claiming which of the three windows above fired in this run. The reproduced facts are the persisted working row, the child turn/end, and the restart behavior; the code paths are static analysis.

<!-- gh-comment-id:6435720639 --> @xvcezrqpbxtpzblrt commented on GitHub (Oct 27, 2026): **Additional evidence and a narrower root cause (0.2.6, code reading + the same reproduced run)** I re-checked the 0.2.6 tree and the installed app. The installed `host/server/agent/agent-bridge.mjs`, `children.mjs` and `profile.mjs` are byte-identical to the 0.2.6 source, so this is not an old-build artifact. In the reproduced run, the persisted row is still `working`; the helper's own log ends with `turn/end` (`aborted`, `user`) **4m7s after** the row's last update. The row's `durationMs` is 2,926,057 ms (48m46s), while the turn ran 52m53s. A restart restores the row unchanged. Two other helpers stopped in the same app session did get a terminal row, which is consistent with a race rather than a missing status mapping. **What the code does (static analysis, not instrumented):** - `finishTurn()` (`agent-bridge.mjs:471-477`) sets `turn.finished = true` and closes every child `session/follow` stream. It does not emit a terminal `agent` frame for a child that is still `working`. - `fold()` (`agent-bridge.mjs:572`) starts with `if (turn.finished) return`, so a child `turn/end` that arrives after the parent turn finished is ignored. - `stop()` (`agent-bridge.mjs:1290-1308`) interrupts helpers first, then cancels the parent; a 300 ms settle timer and the parent's own `turn/end` can finish the turn before the child's terminal event is folded. - The UI only merges frames (`agents.ts:7-25`); it has no terminal-absorbing rule. `loadSessions()` (`store.ts:170-187`) restores `agents` unchanged, and the rows are persisted to `localStorage` (`store.ts:1016`). `runningAgents()` counts `status === 'working'` (`agents.ts:27`). So the exact drop point in this run is not proven without host instrumentation, but the class of failure is deterministic: once the terminal row is lost, nothing reconciles it, and the persisted `working` row survives every restart. **The load-time reconciliation needs a host snapshot, not only a per-session running flag:** The suggested "unless the host reports that session as running" check is the right direction, but the host needs to expose the live child set, not only a session-level boolean. Otherwise a webview reload while the host keeps running can still mark a live helper as cancelled, and a lost terminal frame can still leave a row `working` until the next reload. The load path should ask the host for the live child rows (a snapshot) and only mark rows that the host does not report as live. The same snapshot should be used after a stream gap/reconnect. A terminal row should also be emitted before the child stream is closed, and the UI merge should treat terminal states as final. I did not instrument the host, so I am not claiming which of the three windows above fired in this run. The reproduced facts are the persisted `working` row, the child `turn/end`, and the restart behavior; the code paths are static analysis.
Author
Owner

@xvcezrqpbxtpzblrt commented on GitHub (Oct 30, 2026):

Still present in 0.2.8, and unchanged on main.

Not a re-test — a check that nobody fixed it by accident. Four of the files that own this were compared at tag v0.2.6 and v0.2.8 (and the installed 0.2.8 copies are byte-identical to the tag): apps/host/server/agent/children.mjs, apps/host/src/lib/agents.ts, apps/host/src/components/SubagentRow.tsx, apps/host/src/components/ChatToolbar.tsx — SHA-256 identical across both tags for all four. The v0.2.6, v0.2.7 and v0.2.8 notes never mention subagents or helper rows.

What is confirmed by reading the shipped 0.2.8, beyond what is already in this issue:

  1. The row that survives a restart is the plain localStorage copy. apps/host/src/lib/store.ts:186 loadSessions() restores agents untouched — it only clears messages[].streaming. bootOnce() reconciles time-skips, loops and tool cards (:2017, reconcileAgentTools at :2025) but has no equivalent for agents, and reconcileAgentTools only asks /api/agent/pending, which knows about approvals, not children. So a status:"working" row comes back forever. SubagentRow.tsx:20 then keeps adding now - updatedAt to its duration while the status is working, and ChatToolbar.tsx:32 counts it as running, so the header reads "N subagents running" for a helper that stopped hours ago.
  2. The host holds nothing that could correct it. Child records live in a per-turn Map (agent-bridge.mjs:568 region) that dies with the turn, and the bridge's exported surface (:1336) offers only isRunning(chatId) / pending helpers — there is no "which children are live" call for a load-time reconcile. That is the same gap my 2026-10-27 note in this issue pointed at, and 0.2.8 did not close it.
  3. Four places where a terminal row is lost. finishTurn (agent-bridge.mjs:471-473) marks the turn finished and closes the child follow streams without emitting a final row for a child still working; fold() refuses everything once the turn is finished (:572), so the child's later turn/end is discarded and the terminal mapping in children.mjs:163-169 never runs; the Stop path (:466 interrupts children, then the parent) races the 300 ms settle timer; and rows are throttled to one per 400 ms (:557) with the flush timer stopped as soon as the turn is finished (:595), so a pending working row can be the last thing ever sent. The settle loop at :744-750 (which keeps the turn open up to 8 s for a child that has not been noticed) makes the normal case arrive — which matches the observation that most helpers do get a terminal row and this one raced.
  4. One client-side rule that can drop a fix even when it arrives. apps/host/src/lib/agents.ts:12-13 discards the whole frame when its updatedAt is older than the stored row's, so a terminal row emitted after a newer working row is thrown away rather than applied. Worth checking before deciding which of the four windows matters in practice.

On the second half of the complaint — whether the assistant itself knows. It does get told, and not by polling: the harness splices a model-visible line into the parent ("Background subagent finished and will do no further work unless you send it more." / "…was stopped before it finished."), and agent-bridge.mjs:636-637 recognises exactly that text to mark a child noticed, with :750 holding the run open up to 8 s waiting for it. Two caveats I can state as code but not as observation: the parent's delegation traffic is deliberately hidden from the transcript (apps/host/server/agent/events.mjs:20 NO_CARD covers subagent, send_message, list_agents), so the person never sees that exchange; and if the parent's turn has already finished (turn.finished, checked at :452 and :572) a settlement that lands late has nowhere to render. So the misleading part is the row, not the model's knowledge — which is worth keeping in mind for the fix's scope: a client-side reconcile plus a host snapshot of live children covers it, and the terminal-state merge in updateAgent should not let a stale non-terminal frame win.

No new reproduction was run on 0.2.8 — the stuck row here is the 0.2.6 measurement already in this issue, and the list above is what the shipped 0.2.8 code does.

<!-- gh-comment-id:6533608158 --> @xvcezrqpbxtpzblrt commented on GitHub (Oct 30, 2026): Still present in 0.2.8, and unchanged on `main`. Not a re-test — a check that nobody fixed it by accident. Four of the files that own this were compared at tag `v0.2.6` and `v0.2.8` (and the installed 0.2.8 copies are byte-identical to the tag): `apps/host/server/agent/children.mjs`, `apps/host/src/lib/agents.ts`, `apps/host/src/components/SubagentRow.tsx`, `apps/host/src/components/ChatToolbar.tsx` — SHA-256 identical across both tags for all four. The v0.2.6, v0.2.7 and v0.2.8 notes never mention subagents or helper rows. What is confirmed by reading the shipped 0.2.8, beyond what is already in this issue: 1. **The row that survives a restart is the plain localStorage copy.** `apps/host/src/lib/store.ts:186` `loadSessions()` restores `agents` untouched — it only clears `messages[].streaming`. `bootOnce()` reconciles time-skips, loops and tool cards (`:2017`, `reconcileAgentTools` at `:2025`) but has no equivalent for `agents`, and `reconcileAgentTools` only asks `/api/agent/pending`, which knows about approvals, not children. So a `status:"working"` row comes back forever. `SubagentRow.tsx:20` then keeps adding `now - updatedAt` to its duration while the status is `working`, and `ChatToolbar.tsx:32` counts it as running, so the header reads "N subagents running" for a helper that stopped hours ago. 2. **The host holds nothing that could correct it.** Child records live in a per-turn Map (`agent-bridge.mjs:568` region) that dies with the turn, and the bridge's exported surface (`:1336`) offers only `isRunning(chatId)` / pending helpers — there is no "which children are live" call for a load-time reconcile. That is the same gap my 2026-10-27 note in this issue pointed at, and 0.2.8 did not close it. 3. **Four places where a terminal row is lost.** `finishTurn` (`agent-bridge.mjs:471-473`) marks the turn finished and closes the child follow streams without emitting a final row for a child still `working`; `fold()` refuses everything once the turn is finished (`:572`), so the child's later `turn/end` is discarded and the terminal mapping in `children.mjs:163-169` never runs; the Stop path (`:466` interrupts children, then the parent) races the 300 ms settle timer; and rows are throttled to one per 400 ms (`:557`) with the flush timer stopped as soon as the turn is finished (`:595`), so a pending `working` row can be the last thing ever sent. The settle loop at `:744-750` (which keeps the turn open up to 8 s for a child that has not been noticed) makes the normal case arrive — which matches the observation that most helpers do get a terminal row and this one raced. 4. **One client-side rule that can drop a fix even when it arrives.** `apps/host/src/lib/agents.ts:12-13` discards the whole frame when its `updatedAt` is older than the stored row's, so a terminal row emitted after a newer `working` row is thrown away rather than applied. Worth checking before deciding which of the four windows matters in practice. On the second half of the complaint — whether the assistant itself knows. It does get told, and not by polling: the harness splices a model-visible line into the parent ("Background subagent <id> finished and will do no further work unless you send it more." / "…was stopped before it finished."), and `agent-bridge.mjs:636-637` recognises exactly that text to mark a child `noticed`, with `:750` holding the run open up to 8 s waiting for it. Two caveats I can state as code but not as observation: the parent's delegation traffic is deliberately hidden from the transcript (`apps/host/server/agent/events.mjs:20` `NO_CARD` covers `subagent`, `send_message`, `list_agents`), so the person never sees that exchange; and if the parent's turn has already finished (`turn.finished`, checked at `:452` and `:572`) a settlement that lands late has nowhere to render. So the misleading part is the row, not the model's knowledge — which is worth keeping in mind for the fix's scope: a client-side reconcile plus a host snapshot of live children covers it, and the terminal-state merge in `updateAgent` should not let a stale non-terminal frame win. No new reproduction was run on 0.2.8 — the stuck row here is the 0.2.6 measurement already in this issue, and the list above is what the shipped 0.2.8 code does.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
Niko1221/Strata#1855
No description provided.