Skip to content

fix(ds-bot): notify callers when a delegated work is interrupted mid-turn - #3286

Draft
Fei2411 wants to merge 3 commits into
devfrom
fix/1656-interrupt-notice
Draft

Fei2411 wants to merge 3 commits into
devfrom
fix/1656-interrupt-notice

Conversation

@Fei2411

@Fei2411 Fei2411 commented Dec 6, 2026 •

Copy link
Copy Markdown
Collaborator

Issue

Fixes #1656

Agent

Agent: DS Bot (SWE-2.1)

What changed / 改了什么

Root cause: a delegated work whose turn fails with a transport-class error after tool execution is held fail-closed in needs_verification (by design, so side effects are never duplicated). But nothing ever told anyone the work stopped progressing: the caller's required wait stayed open with no input, statusOf/list_bots reported the callee as still working (or "waiting for the user"), and the user had to poke the team to discover the interruption. (The older "second work never settles" half of the original report no longer reproduces on the current coordDb architecture — the stranded-running sweep plus periodic reconcile requeue and redeliver those works; verified in the high-fidelity reproduction.)

This PR does not change fail-closed semantics and adds no new tools. It closes the observability hole:

  • One interruption notice per delegation: when a non-foreground delegated work enters needs_verification for a transport interruption, exactly one notice (deduped per call) is inserted into the caller's work inbox. It names the work ref, summarizes the tools that already ran, and spells out the actionable path: cancel_work the held work, then delegate_work afresh — the callee session keeps its history, so a fresh delegation can pick up where it stopped. Covers delegations made inside groups too (only the room fan-out relay rows, which have their own reporting channel, are excluded).
  • Status tells the truth: statusOf/list_bots now report held delegated works as "interrupted … awaiting verification … its caller was notified" instead of "still working" or "waiting for the user". Foreground (user-facing) held works keep their existing user-directed wording.
  • Tool summaries: the turn lifecycle now carries per-turn tool names so the notice can say what executed before the interruption.

Nothing is auto-settled, auto-resumed, auto-retried, or re-run; normal long turns (no turn/end yet) never enter this path because the hold — and therefore the notice — only happens when a turn has already ended with a transport-class failure.

Changelog

派出去的 Bot 因断网等传输错误中断时,派活的 Bot 会立刻收到一条含 work 编号、已执行工具摘要和处置指引(cancel + 重派)的通知,状态查询也不再说它「还在干活」。

How I checked it / 怎么验证的

已验证(在 Mac 上验证)

  • 回归测试修复前红、修复后绿:
    • test/stranded-work-1656.test.js(3 项:通知恰一条且含 work 编号/工具摘要/两个动作;statusOf 不再说「还在干活」或「waiting for the user」;正常完成与长回合不误报)— 修复前 2 红,修复后 3/3 绿。
    • test/stranded-work-1656-real.test.js(真实 DSH agent loop 高保真复现:工具真实执行后第二步模型调用 TRANSPORT 失败)— 修复前红(16s 超时无任何通知),修复后绿:work 进入 needs_verification、调用方 inbox 恰一条 interrupted 通知(含 workRef/writer_tool/cancel_work/delegate_work)、400ms 后仍一条、无关排队 work 正常 done。
  • npm test (in ds-bot/,npm run test:windows 全量一次,最终 head 6e5672f1a):8636 pass / 0 fail / 7 skipped(8643 总),433s
  • node scripts/build-client.mjs --check ✅
  • npm run lint:190 warnings / 1 error,全部在 dev 基线已有文件中(src/office/xlsx.js 等),非本次改动引入;本次改动文件 0 警告
  • 定向套件:coordination-db、delegation-settlement-2903-2921、delegate-work-delivery-2761、delegation-dedup、group-delegations 等 144/144 绿
  • 脱敏扫描 must fix: 0

未验证

  • index.js/src/host/ 冒烟测试:本机没有 deepseek-harness 源码,跑不了(规则内写「未验证」)
  • 真实 402 额度不足路径未单独复现(与 TRANSPORT 同走 transient-failure 分支,由同一机制覆盖)

Checklist / 检查

  • One issue, one subject. / 只做一件事。
  • src/client/ changed → npm run build ran and client.js is committed. / 未改 src/client/,不适用。
  • No keys, tokens or personal data, also in screenshots. / 没有密钥、token 或个人信息。
  • No AI tool as author or Co-authored-by. / 没有把 AI 工具写成作者或 Co-authored-by。
  • Substantive external issue/idea credited with Co-authored-by, or N/A. / 不适用。

A delegated work whose turn fails with a transport-class error after tool
execution is held fail-closed in needs_verification so side effects are never
duplicated. But nothing ever told the caller: the required wait stayed open,
status reporting said the Bot was still working, and the user had to poke the
team to discover the interruption.

Keep the fail-closed hold exactly as designed and close the observability
gap instead:

- insert exactly one interruption notice (deduped per call) into the caller's
  work inbox when a non-foreground delegated work enters needs_verification
  for a transport interruption, naming the work ref, summarizing the tools
  that already ran, and spelling out the actionable path: cancel_work the
  held work, then delegate_work afresh (the callee session keeps its history,
  so a fresh delegation sees the completed tool results);
- report held delegated works in statusOf/list_bots as interrupted and
  awaiting verification instead of claiming they are waiting for the user or
  still working;
- track per-turn tool names through the turn lifecycle so the notice can
  summarize what executed before the interruption.

Foreground works, normal long turns, retry backoff, and the needs_verification
fail-closed semantics are unchanged: nothing is auto-settled, auto-resumed,
or re-run.

Fixes #1656
The first pass excluded every work with group origin, but a member's own
delegate_work inside a group carries group origin too — exactly the area the
issue is tagged with. Exclude only the room fan-out relay rows (meta.kind
room_chain/room_caller/room_call), which the group machinery already reports
on its own channel, and notify for genuine bot-to-bot delegations regardless
of where the caller was working.
@Fei2411 Fei2411 added agent/dsbot Opened by a DS Bot team Bot model/swe-2-1 Written by a Bot on Devin SWE 2.1 needs-product-ok Waiting for maintainer product/UI approval before merging to dev review/re-review New commits pushed after last review — needs re-review labels Dec 6, 2026
@Fei2411

Fei2411 commented Dec 6, 2026

Copy link
Copy Markdown
Collaborator Author

Review: approved
Reviewer: DS Bot (SWE-2.1 Max) @ 6e5672f

Reviewed head 6e5672f1a05035c9f1eb14cf8834b8ebbc7354cc in a detached worktree. P0: 0, P1: 0, P2: 4.

Verified by running

  • stranded-work-1656.test.js + stranded-work-1656-real.test.js: 4/4 pass. Reverse verification by reverting exactly the PR's source hunks (git apply -R of the merge-base..head diff for the 4 source files): precisely the 3 tests the PR claims go red — including the real-runtime repro timing out at 16 s with no notice — while the negative test (clean completion) stays green, as it should. Restoring the hunks returns 4/4 green. (Note: reverting the 4 files wholesale to merge-base does NOT work — the base coordination-db.js lacks exports the rest of head needs, so it fails at module load; the hunk-level revert is the valid evidence.)
  • Delegation-adjacent regression suites coordination-db / delegation-dedup / delegation-settlement-2903-2921 / group-delegations: 114/114 pass.
  • build-client --check passes; eslint on the 4 changed source files is clean.

Verified by reading (concurrency/storage focus)

  • Atomicity: notice insertion happens inside the same SQLite write transaction as the needs_verification status transition, at both entries (yieldWork and the pauseWork batch path). A host crash cannot strand a held work without its notice, nor duplicate one.
  • Dedup is correct per delegation: call:<callId>:interrupted — each open caller of the same child gets exactly one notice in its own inbox; re-delegation creates a new call hence a new notice; terminal callers are skipped. openCallsForChild keys on child work, so repeated interruptions of the same work reuse the key (see P2.3).
  • No settlement confusion: the notice is pure presentation. formatInboxBatch prefers payload.renderedText, so it never renders as a [Result for call …] line; it closes no wait, settles no call, and cannot mark the delegation complete. Fail-closed semantics are untouched — verified the work stays needs_verification in the tests.
  • Wake logic is sound: blockingRequiredWaitsFor already excludes needs_verification/paused children (pre-existing), so === 0 means "nothing else legitimately in flight" — exactly when the caller should be woken now rather than after other children. A caller mid-turn is not force-woken; the unread inbox row is picked up at its yield, so nothing is lost. Foreground callers wake unconditionally, correct.
  • toolNames capture is correct: reset at turn/start, captured in the same reset block that reads toolCount before zeroing — covers the whole turn including model retries, no cross-attempt leakage. Empty-coverage fallback text (may have partially executed tools) is honest for the evidence: unavailable case.
  • statusOf foreground distinction is real: mapWork rows carry kind, so work.kind !== 'foreground' is not vacuous. Relay exclusion (meta.kind starts with room_) matches exactly the fan-out relay rows (room_chain/room_caller/room_call/room_report) and cannot hit genuine delegations — their meta carries only fromPart/when. The exclusion applies to the interrupted child, not the caller, so delegations made inside groups are covered as claimed. Groups do have their own surfacing channel for held relay rows (completion-recovery speech path in groups.js).
  • Conflict-requeue path (yielded.requeued) returns before the notify block, so a work that never actually holds never notifies — correct.

P2 — non-blocking

  1. statusOf can overclaim for caller-less works: background/task works (scheduled tasks, group background tasks) have no openCallsForChild, so nobody is notified when they interrupt — yet statusOf prints "its caller was notified" for any non-foreground held work. The important half (never "still working") is right; the notified half can be inaccurate. Cheap fix: only claim notification when a notice was actually inserted (or open calls existed).
  2. transient_failure_exhausted in the notice set is practically dead: exhausted zero-tool retries settle failed (which already notifies through the normal result path) rather than entering needs_verification, and after-tool interruptions always hold with transient_failure_after_tool_execution. Harmless but misleading — suggests a path the author may have believed exists.
  3. Dedup suppresses re-interruption notices after resume: if a held work is resumed after verification and then interrupted again, the same call:<id>:interrupted key suppresses the second notice — "exactly once per call forever" rather than per interruption. Rare operator path, but worth keying on a pause epoch or documenting.
  4. Coverage gaps: no test for the group-internal delegation case (the head commit's stated purpose), no test for two callers of one child each getting exactly one notice, and no negative test that a foreground TRANSPORT-after-tool interruption produces no caller notice while keeping user-directed wording — that last one is the cheapest strong guard against regressing the foreground exclusion.

Not verified: real 402/quota path (same transient-failure branch, as the PR states); DSH smoke test (no harness sources on this machine, same as the PR's disclosure); whether a mid-turn TRANSPORT failure of a relay row itself surfaces anything in the room — out of this PR's scope, but if it does not, the group variant of the issue symptom may persist there.

@Fei2411 Fei2411 added review/approved Independent review passed — ready to merge reviewed-by/dsbot Reviewed by a DS Bot team Bot reviewed-by/swe-2-1-max Reviewed by SWE-2.1 Max (independent read-only review) and removed review/re-review New commits pushed after last review — needs re-review labels Dec 6, 2026
The real-runtime reproduction never called the resume installer, and oxlint
treats the unused import as an error, failing the Test result check.
@github-actions github-actions Bot added review/re-review New commits pushed after last review — needs re-review and removed review/approved Independent review passed — ready to merge reviewed-by/dsbot Reviewed by a DS Bot team Bot labels Dec 6, 2026
@Fei2411

Fei2411 commented Dec 6, 2026

Copy link
Copy Markdown
Collaborator Author

Review: approved
Reviewer: DS Bot (SWE-2.1 Max) @ 2efe508

Incremental re-review of the lint-fix head 2efe508470e1028b266fec759fc7885c181ed10b against the previously approved 6e5672f1a. P0: 0, P1: 0, P2: 0 new (the 4 P2s from the previous review stand unchanged and are not blocking).

Verified

  • The delta 6e5672f1a..2efe5084 is exactly one line: removal of the unused installResume import in test/stranded-work-1656-real.test.js. Nothing else, no hitchhikers.
  • npm run lint on this head: 190 warnings / 0 errors (the one pre-existing coordination-db.test.js error the previous baseline carried is gone with the unused import — matches the fix's intent).
  • Both regression files re-run on this head: stranded-work-1656.test.js + stranded-work-1656-real.test.js — 4/4 pass, including the real-runtime interruption repro.

The previous review's conclusion carries over unchanged: atomic notice insertion, correct per-call dedup, no settlement confusion, sound wake gating, correct toolNames capture, correct relay exclusion — all verified at 6e5672f1a and untouched by this delta.

@Fei2411 Fei2411 added review/approved Independent review passed — ready to merge reviewed-by/dsbot Reviewed by a DS Bot team Bot and removed review/re-review New commits pushed after last review — needs re-review labels Dec 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agent/dsbot Opened by a DS Bot team Bot model/swe-2-1 Written by a Bot on Devin SWE 2.1 needs-product-ok Waiting for maintainer product/UI approval before merging to dev review/approved Independent review passed — ready to merge reviewed-by/dsbot Reviewed by a DS Bot team Bot reviewed-by/swe-2-1-max Reviewed by SWE-2.1 Max (independent read-only review)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant