[vika] console keeps a stale "in progress" turn after a daemon restart mid-run
Summary
After a daemon restart that lands in the middle of a durable turn, the web console keeps showing a turn stuck at "进行中" (in progress) forever. That turn is an implicit turn: it has steps (agent.thinking / agent.tool_called / agent.tool_completed) but no agent.turn_started and no agent.turn_completed, so it never closes.
Environment
- vika
0.4.0-4a6ef611b16d(built fromfeat/vika@4a6ef61), Linux container, Lark connector,durableruntime. - Reproduced on a fresh instance: one owner DM message ("你好") arrived 15:27:54 local; I restarted the daemon 6 seconds later (to apply model/effort settings).
Evidence
Daemon log (UTC):
07:27:54 event_delivered seq=1
07:28:00 daemon_stopping reason=SIGINT <- restart mid-turn
07:28:00 durable_disconnected signal=SIGINT
07:28:18 daemon_starting
07:28:20 connector_preflight_ok
07:28:21 daemon_ready
activities rows around the restart:
id 8 07:27:55 agent.turn_started seq=1
id 9 07:28:00 agent.thinking
id 10 07:28:00 agent.tool_called toolId=call_00_JWmJc…
id 22 07:28:12 agent.turn_completed seq=1 failed ("durable stopped during an active turn")
id 26 07:28:20 agent.thinking <- replayed step, no turn boundary
id 27 07:28:20 agent.tool_called toolId=call_00_JWmJc… (same toolId as id 10)
id 28 07:28:20 agent.tool_completed toolId=call_00_JWmJc…
id 29 07:28:20 agent.thinking
id 30 07:28:20 agent.tool_called toolId=chatcmpl-tool-a960… (same as id 19)
id 31 07:28:20 agent.tool_completed toolId=chatcmpl-tool-a960…
id 32 07:28:20 agent.turn_started resumed=true
id 33 07:28:20 agent.ready
So after the restart the durable host re-emits the interrupted turn's steps (same toolIds) and then continues the run; those steps are recorded while the daemon has no open turn. The console (packages/web/public/activity.js) turns the first orphan step into an implicit turn block:
if (!open && agentRow && TURN_STEP_KINDS.has(kind)) {
// 回合开头不在已加载范围内(或旧版本没记 turn_started):补一个隐式回合
open = { …, implicit: true };
}
turnStatus() already degrades an implicit unclosed turn to "记录不全" when a later turn exists, but the last implicit turn falls through to "进行中":
if (!turn.endRow) {
if (turn.implicit && state.model?.turns.at(-1) !== turn) return { text: '记录不全', … };
return { text: '进行中', cls: 'running' };
}
Result: a phantom turn that counts up forever, and the live indicator keeps saying "思考中" while the runtime is idle.
Fix
Expose the daemon's own view of whether a turn is running and use it in the console:
packages/daemon/src/http-api.mjs: includeactiveTurns(already computed byserviceSnapshot()aswork.turnInProgress ? 1 : 0) in the/api/activityservice payload.packages/web/public/activity.js: an implicit, unclosed turn is only "进行中" whenservice.activeTurns !== 0; otherwise "记录不全". The live indicator likewise stops showing "思考中" whenactiveTurns === 0.
Backward compatible: an older daemon that does not send activeTurns keeps the previous behavior (undefined !== 0).
Not fixed here
The daemon also records replayed tool_called / tool_completed events for a turn that already finished (same toolId as before the restart, ids 26–31 above), i.e. duplicate telemetry. That is a separate daemon-side dedupe issue; this PR only stops the console from presenting such leftovers as a live turn.
Another occurrence, this time triggered by a container restart rather than a daemon restart:
container vika-src StartedAt 2026-11-04T08:08:59.99Z (16:08:59 local)
08:09:00.911Z daemon_starting
08:09:04.795Z daemon_ready
The turn for the owner's previous message (seq=2, "在吗牢底") had already completed normally at 08:01:56Z. After the container restart the durable host replayed that run's steps anyway:
08:09:04 agent.thinking <- no turn_started before it
08:09:04 agent.tool_called reply_message
08:09:04 agent.tool_completed reply_message ("Delivered reply to message_id=…")
08:09:04 agent.note 已回复。
08:09:04 agent.ready
The console opened an implicit turn for them and showed it as "进行中" with a running counter (14m+).
Two things worth noting:
- The replay is telemetry-only: no new
outboxrow was created (the delivery table still has exactly 3 rows), so the user did not get a duplicate reply. - This confirms the fix direction in #7012 (
activeTurnsfrom the daemon decides whether an implicit turn is live), and it also strengthens the case for a daemon-side dedupe of replayed events after a host resume — that part is not covered by #7012.