Repository navigation
Replies: 1 comment
|
Confirmed on current master (d743267). I reproduced your sequence as a test and it fails the same way: the first turn/end queues steer as a microtask, the agent goes idle with the item still in nextStep, and only one model request is made. The window is in packages/core/agent-loop/src/agent.ts. turn() appends turn/end in its finally, then reads inbox.hasPending and returns false. kick resumes one microtask later and commits idle. A steer queued by a turn/end observer runs between those two points, so wakeDriver sees a running phase and records nothing. Fix, pushed to my fork: https://github.com/Mide69/deepseek-harness/tree/fix/agent-loop-steer-idle-race It is your first suggestion, narrowed. The running phase gets a settling flag that turn() sets when it finds the inbox empty and is about to return. wakeDriver latches wakeRequested for a waking send that arrives in that state, using the same latch it already uses for maintenance and aborted activities, and kick already replays that latch after idle if the inbox still has input. I tried latching every waking send during a running phase first, and 7 existing tests failed. A turn that errors or is cancelled keeps later steering until an explicit wake on purpose, and an unconditional latch wakes the agent for that input the moment the driver exits. Setting the flag only on the normal completion path keeps that behavior. Your second suggestion, re-checking the inbox before idle, would have the same problem for inject, which queues next-step input without a wake. New test in contract-regressions.spec.ts: a session/event observer queues steer as a microtask on the first turn/end. It fails without the change (1 request) and passes with it (2 requests, empty nextStep). The full agent-loop suite passes (450 tests), agent.ts stays at 100% coverage, and typecheck and lint are clean. I did not run the snapshot suites, since the change only affects a send that lands in this window. |
Uh oh!
There was an error while loading. Please reload this page.
First observed on 0.1.5-rc.2 and re-verified on 0.1.6-alpha.1, 0.1.6-alpha.2 and 0.2.1-alpha.2.
On 0.1.5-rc.2, Agent.steer splices into next-step and calls wakeDriver (packages/core/agent-loop/src/agent.ts:128-142). When the phase is running, wakeDriver returns without setting wakeRequested unless maintenance or wake-after-abort applies (:188-196). At turn completion, turn() appends turn/end and returns false after observing no pending inbox item (:336-344); kick's await continuation then changes the phase to idle (:225-235). A promise reaction queued by the synchronous turn/end event can call steer after the hasPending decision but before kick's idle continuation. The message is durably spliced, wakeDriver sees running and returns, and the Agent settles idle with the item pending until a later wake.
The same code path is present on @deepseek-ai/dsh-agent-loop 0.2.1-alpha.2 (lib/index.js): steer calls send(input, "next-step", true) (:809-811, :800-806); wakeDriver returns while the phase is running and sets wakeRequested only for maintenance or wake-after-abort (:854-858); turn() appends turn/end in a finally (:1027-1035) and then reads
if (!this.inbox.hasPending) return false(:1037); kick's finally changes the phase to idle (:893-898), and re-wakes only if wakeRequested was set (:898).Deterministic reproduction: create a real AgentLoop Agent with a fake adapter; on its first turn/end, queueMicrotask(() => agent.steer(message)). After agent.whenIdle(), status is idle, inbox.nextStep contains the message, and only one turn exists. Repeat with the steer behind one setImmediate: the Agent consumes it in a second turn. We run this against 0.1.5-rc.2, 0.1.6-alpha.1 and 0.1.6-alpha.2 (script: antst/sessionbus-dsh .github/scripts/prove-agent-steer-boundary.mjs). The reproduction script lives at sessionbus/sessionbus-dsh .github/scripts/prove-agent-steer-boundary.mjs.
Callers can hit this because promise-queued delivery is common: the Sessionbus kit queues worker delivery with queueMicrotask and peer delivery with Promise.resolve().then. Ordinary macrotask callers cannot interleave here. Suggested fix: have wakeDriver latch a wake request during a running phase, or make kick re-check the inbox before committing idle. Our plugin does not re-steer or replay; it moves its own admission one setImmediate hop past the microtask drain.
All reactions