[vika] durable runtime records agent.turn_started twice per turn, leaving a permanently "in progress" turn in the console
Summary
With the durable runtime, one inbound message makes the web console show two turn blocks: the first contains the input but never completes (it keeps counting "in progress" for minutes/hours), while the real work happens in the second block.
Environment
- vika
0.4.0-e5921f58617b(built fromfeat/vika@e5921f5), Linux container, Lark connector,agents[0].model = "durable". - Console at
:3737; one owner DM message produced the situation below.
Symptom
A single DM message (seq=62, a merged-forward) plus its follow-up input (seq=63) produced:
| console block | input | output | state |
|---|---|---|---|
| #92 | merge_forward + steered text | none | "in progress" for 17+ minutes, never closes |
| #93 | not recorded | thinking / tools / reply | completed in 1m38s |
Evidence (activities table)
07:45:22 | seq=62 | agent.turn_started | {"runtime":"durable","input":"[chat=...] Merged and Forwarded Message"}
07:45:22 | seq=63 | agent.steered | {"runtime":"durable","input":"[chat=...] <p>...</p>"}
07:45:22 | seq=null| agent.turn_started | {"runtime":"durable","resumed":false}
07:47:00 | seq=63 | agent.turn_completed | {"inboundSeqs":[62,63],"durationMs":97873,...}
Every durable turn on this instance records two agent.turn_started rows in the same second (checked across 15+ consecutive turns, all pairs).
Root cause
packages/daemon/src/durable.mjs writes agent.turn_started in two places for the same turn:
_writeBatch()- when the daemon submits the input batch (this record carries the input text andinboundSeqs);case 'turn_start'- when the host echoesturn_startfromdurable-host.mjs(beginTurn()and the resume path).
packages/web/public/activity.js opens a new turn block on every agent.turn_started and closes the current block on agent.turn_completed. With two starts and one completion, the submit-side block is left open forever, so the console shows a permanently "in progress" turn.
Proposed fix
Only write the host-side record when the turn was resumed from storage (activeItems.length === 0), i.e. the case that genuinely has no submit-side record (daemon restart while a run was in flight). Fixed by #6873.
Additional observation (separate from this fix)
The Lark "merged forward" message arrived as two connector events with two different message_ids (a merge_forward placeholder and a text message carrying the forwarded content). vika ingesting both into one turn is reasonable, but that turn's context reached 1.57M input tokens - maybe worth checking whether merge-forward content should be truncated or attached more carefully.
Update: opened as PR #6873 (from a fresh fork of volcengine/OpenViking). The patch below is kept as a fallback.
Attaching the fix as a patch instead of opening a PR: the reporter account has no write access to this repository, and GitHub requires an external PR to come from a fork, so a same-repo branch/PR is not possible from here.
The patch applies on e5921f5 (feat/vika) and was verified with the bundled Node 24:
git checkout feat/vika
git am 0001-fix-vika-record-one-turn-start-per-durable-turn.patch
node --test packages/daemon/test/durable.test.mjs # 19/19 pass
From d4c058f594c7704b785db0ea719cb3dce00abaeb Mon Sep 17 00:00:00 2001
From: zrwangems <[email protected]>
Date: Sun, 1 Nov 2026 16:13:02 +0800
Subject: [PATCH] fix(vika): record one turn start per durable turn
The durable runtime recorded agent.turn_started twice for one turn: once when
the daemon submitted the input batch, and again when the host echoed
turn_start. The console opens a turn block on each start and closes it on
turn_completed, so the submit-side block never closed and stayed "in
progress" forever.
Only write the host-side start when the turn was resumed from storage (no
local inbound items) - the case that has no submit-side record.
---
vika/packages/daemon/src/durable.mjs | 14 +++++++++++---
vika/packages/daemon/test/durable.test.mjs | 20 ++++++++++++++++++++
2 files changed, 31 insertions(+), 3 deletions(-)
diff --git a/vika/packages/daemon/src/durable.mjs b/vika/packages/daemon/src/durable.mjs
index dc30fca..4c7d865 100644
--- a/vika/packages/daemon/src/durable.mjs
+++ b/vika/packages/daemon/src/durable.mjs
@@ -516,6 +516,12 @@ export class DurableAgent {
}
case 'turn_start': {
this.modelWorking = true;
+ // The submit side already opened this turn with its own
+ // agent.turn_started record, which carries the input. Recording the
+ // host's echo too would open a second turn that never completes in the
+ // activity log. Only a turn resumed from storage (daemon restart) has
+ // no local record and needs this one.
+ const resumed = this.activeItems.length === 0;
if (!this.turnActive) {
// A run resumed from storage after a daemon restart has no local
// inbound items but is still an active turn.
@@ -528,9 +534,11 @@ export class DurableAgent {
epoch: this.cognitionEpoch,
});
}
- this._recordActivity('agent.turn_started', {
- metadata: { runtime: DURABLE_RUNTIME.id, resumed: this.activeItems.length === 0 },
- });
+ if (resumed) {
+ this._recordActivity('agent.turn_started', {
+ metadata: { runtime: DURABLE_RUNTIME.id, resumed: true },
+ });
+ }
return;
}
case 'note':
diff --git a/vika/packages/daemon/test/durable.test.mjs b/vika/packages/daemon/test/durable.test.mjs
index 652ebf1..3bce055 100644
--- a/vika/packages/daemon/test/durable.test.mjs
+++ b/vika/packages/daemon/test/durable.test.mjs
@@ -207,6 +207,26 @@ describe('DurableAgent host protocol', () => {
assert.equal(completed.metadata.inputTokens, 12);
assert.equal(completed.metadata.cachedInputTokens, 2);
assert.equal(completed.metadata.costUsd, 0.01);
+ // The submit side opens the turn; the host's turn_start must not open a
+ // second, never-completed turn in the activity log.
+ const started = store.activities.filter((activity) => activity.kind === 'agent.turn_started');
+ assert.equal(started.length, 1);
+ assert.ok(!started[0].metadata.resumed);
+ await agent.stop();
+ });
+
+ it('keeps one start record for a turn resumed from storage', async () => {
+ const { agent, children, store } = fakeHarness();
+ await agent.start();
+ const child = children[0];
+ // A daemon that reconnects to a run already in flight has no local inbound
+ // items, so the host's turn_start is the only start record it can write.
+ child.feed({ type: 'turn_start', turn: 1 });
+ const started = store.activities.filter((activity) => activity.kind === 'agent.turn_started');
+ assert.equal(started.length, 1);
+ assert.equal(started[0].metadata.resumed, true);
+ child.feed({ type: 'settled', status: 'done', turn: 1 });
+ await waitFor(() => !agent.turnActive);
await agent.stop();
});
--
2.56.0.windows.2