Skip to content

fix(worker): 避免启动输入重复提交并恢复中断后的消息投递 - #1572

Merged
deepcoldy merged 5 commits into
masterfrom
fix/agy-submit-confirmation
Sep 24, 2026
Merged

deepcoldy merged 5 commits into
masterfrom
fix/agy-submit-confirmation

Conversation

@deepcoldy

@deepcoldy deepcoldy commented Sep 24, 2026 •

Copy link
Copy Markdown
Owner

修复启动 prompt 在提交回执延迟时重复注入,以及 Antigravity 中断后仍被陈旧 transcript 判为忙碌、导致后续消息持续排队的问题。提交最终未确认时保留原输入的只读回执观察,使超时告警后在终端恢复提交也能释放后续队列。

  • 共用 worker 仅对适配器明确声明 untouched / flushed_invalid 的输入重新入队;模糊的 history 超时不再触发整段重投。
  • activation 回执观察与有界告警链分开:同一 token 仅保留一个观察者,原提交回执到达后补 ACK,不重打正文或 Enter。取消、替换、worker/backend generation 变化在异步读取前后均隔离旧回执。
  • Antigravity 只有在当前权威 viewport 同时出现明确中断提示、空输入框和 ready footer 时才释放陈旧 transcript 忙碌状态。兼容 tmux ANSI/CRLF 与 PTY 清理边框后的格式;旧提示、非空草稿、busy 标记、无权威屏幕均不作为中断证据。
  • 首条消息未确认的告警明确说明后续消息正在排队,以及终端恢复或关闭会话重开的入口;普通后续输入的告警处理不变。

影响面:重试与回执观察涉及共用 worker 的 queued activation,以 Antigravity 和 TraeX 真实 worker + PTY 模拟 CLI 交叉验证;现有适配器的 recheck 读取原提交记录,不发送输入。屏幕补偿仅由 Antigravity 使用,OpenCode 原生状态检查不变。共用调用覆盖普通会话、恢复与 adopt 的 idle 检查;ZMX 不提供权威 viewport,继续保守处理。无平台专用新增依赖;本地实测 Linux,macOS 二进制由 CI 验证,sandbox 和 v3 未单独端到端验证。

实际验证:

  • bun run build:通过。
  • bun run test test/queued-activation-receipts.test.ts test/worker-agy-delivery.integration.test.ts test/antigravity-interruption.test.ts test/worker-app-runner-control-wiring.test.ts test/submit-failure-chain.test.ts test/submit-confirmation.test.ts:6 文件、68 项通过。
  • bun run test test/worker-codex-session-upgrade.test.ts:30 项通过,覆盖回执待确认期间禁止自动升级、释放后恢复。
  • 新告警文案断言加入后,bun run test test/worker-agy-delivery.integration.test.ts -t 'manual terminal submission':1 项通过;先告警、后写入 history,最终收到一次 ACK,完整输入字节未增加。
  • 将最初 3 项集成回归放到修改前的 bde5f745b:全部失败,两个 CLI 均重复写入 4 次,中断后的消息投递超时;修复版全部通过。
  • 告警后收到回执的补充用例在 754741426 的 ACK 断言处超时;补充修复后通过。
  • 相关提交确认、初始化并发、输出生命周期、OpenCode 忙碌状态等 8 个回归文件共 157 项通过(初版修复验证)。
  • 临时部署已执行 build + daemon restart,56 个受监控进程全部 online;实际停滞的 Antigravity tmux 会话恢复 ready for input。
  • 原内存队列中的那条未提交消息没有跨 daemon 重启自动补投,本 PR 不声称旧消息已进入模型。现已合并为 2efe68a59,并从 canonical/master 构建和重启;全局命令与 daemon 均已切回 canonical,56 个受监控进程全部 online。

告警文案示意(当前 i18n 字符串生成,非飞书客户端截图):

首条消息未确认的恢复指引

Closes #1571

Comment thread src/adapters/cli/antigravity.ts Fixed
@deepcoldy
deepcoldy marked this pull request as ready for review September 24, 2026 17:39
@deepcoldy

Copy link
Copy Markdown
Owner Author

补充验证发现合并前需要修正的恢复边界:启动输入在延迟确认链告警结束后,若原生 history 才出现提交回执,worker 不再发送 activation ACK,daemon 的 opening reservation 持续保留,后续消息仍排队。

实际 worker 复现(当前 754741426):等待 user_notify 后写入同一输入的 history 回执,再等待 25 秒,未收到 queued_activation_submitted;测试在 ACK 断言处超时。日志显示两次 20 秒 recheck 后告警,之后没有新的确认。/restart 又被 activation ownership guard 拒绝,不能将其描述为恢复路径。

计划保留禁止模糊重投的约束,补上告警后只读观察原始提交回执的收尾,以及对应代际隔离回归;完成后再更新验证与合并结论。

@deepcoldy

Copy link
Copy Markdown
Owner Author

Review conclusion — HEAD 754741426a6d8396fe3f9c77dac758d935d539ef (base bde5f745b)

Status: do not merge yet — one blocker (regression vs base). Reviewed from an independent checkout; no code changed, not merged, not restarted.

Verified facts

  • The new test/worker-agy-delivery.integration.test.ts is sensitive to both root causes: copied onto bde5f745b it fails all 3 (slow activation written 4×, interrupted follow-up permanently stuck); on 754741426 all 3 pass (Bun 1.4.0).
  • test/antigravity-interruption.test.ts 11/11, test/worker-app-runner-control-wiring.test.ts 15/15; related regression batch 372/372.
  • The change introduces a regression base did not have. Injecting a transient drop of the first submit Enter (subsequent Enter works): base self-heals and emits queued_activation_submitted in ~7.5s; HEAD emits only user_notify and still has no ACK after 40s. Independently reproduced.

Why this is a blocker (not merely a documented recovery limit)

Root cause is src/worker.ts:12993-12999: requeueUnsubmittedQueuedActivation(item) is now gated on codexAppSafeNonSubmission (submissionDisposition === 'untouched' | 'flushed_invalid'). But the antigravity writeInput submitted:false paths (src/adapters/cli/antigravity.ts:354, :358, :380) set no disposition for the two genuinely droppable paths — the final Enter and the history-receipt timeout (:380 returns {submitted:false, recheck}). Consequences:

  1. A transiently dropped Enter — the real entry point that "duplicate re-submit" used to mask — now has no automatic recovery at all.
  2. scheduleSubmitFailureNotify's deferred chain ends at the warning; there is no read-only recheck after the warning. If the user presses Enter in the Web terminal, or history lands later, no queued_activation_submitted is ever sent (onConfirmed is wired only into the suppress-confirmed branch).
  3. Blast radius: the daemon keeps queuedActivationPending set, so hasQueuedActivationAdmissionGate (src/core/worker-pool.ts:10934, src/daemon.ts:24308) stays true → all later inbound turns are appended via admitQueuedActivationTail and never delivered. hasProtectedSessionMutationOwnership (src/core/session-mutation-guard.ts:40) rejects /restart (src/core/command-handler.ts:2612); only closing the session escapes. This weds the whole session, not just the one message, and is distinct from the stated no-replay-across-restart limitation.
  4. It also contradicts the production submit_unconfirmed wording ("inspect the terminal, then resend"): resending only queues behind the still-held gate and cannot recover the head.

Required before merge

The direction (retry only on explicit untouched/flushed_invalid) is right, but the tail is incomplete: after the warning there must be a read-only receipt observation / recheck that emits the ACK once confirmation arrives (or the final-Enter timeout path must carry a disposition), instead of telling the user to resend.

Evidence needed in the fix: a test where the warning fires first and the history receipt lands afterwards still yields queued_activation_submitted, without reintroducing duplicate writes, and without breaking the delayed-activation case (single write + delayed ACK).

@deepcoldy

Copy link
Copy Markdown
Owner Author

已在 efb33dfd5106e3f2138f997e1e3057c8290101f9 修正告警后的回执收尾:

  • activation 的只读回执观察与有界告警链分开;告警后仍检查原始提交记录,收到确认只补 ACK,不重打正文或 Enter。
  • 同一 token 只有一个观察者;取消、替换、worker/backend generation 变化均在异步读取前后检查所有权,旧回执不能释放新 head。
  • 首条消息告警明确说明后续消息正在排队,以及终端恢复/关闭会话重开的入口。
  • 影响共用 worker 的未确认 activation;普通非 activation 输入仍走原有有界告警链。复核现有适配器的 recheck 均读取提交记录,不发送输入;无新平台依赖。

验证:bun run build 通过。bun run test test/queued-activation-receipts.test.ts test/worker-agy-delivery.integration.test.ts test/antigravity-interruption.test.ts test/worker-app-runner-control-wiring.test.ts test/submit-failure-chain.test.ts test/submit-confirmation.test.ts:6 文件、68 项通过。随后单独重跑含新告警文案断言的告警后恢复用例:1 项通过;最终 ACK 恢复时完整输入字节未增加。

下图为当前 i18n 字符串生成的文案示意,不是飞书客户端截图:

首条消息未确认的恢复指引

@deepcoldy

Copy link
Copy Markdown
Owner Author

CI 补充修正:Codex 自动升级测试通过抽取 worker 函数建立独立 VM,缺少新增的 queuedActivationReceipts 依赖,导致 ReferenceError。c6c1c247f 仅补齐测试夹具,并增加“有未确认 activation 回执时禁止升级、释放后恢复升级”的行为验证,生产代码未变。

bun run test test/worker-codex-session-upgrade.test.ts:30 项通过。最新 CI 已重新触发。

@deepcoldy

Copy link
Copy Markdown
Owner Author

Re-review — HEAD c6c1c247f6 (production == efb33dfd5106; base bde5f745b)

Previous blocker is fixed. No blocking issues in this increment — mergeable. Reviewed from an independent checkout; no code changed, not merged, not restarted.

Verified

  • ACK after the warning, with no re-typed input: the new manual case in test/worker-agy-delivery.integration.test.ts passes on this HEAD (4/4, together with the original delayed single-write + delayed-ACK case and the interrupted follow-up case). Copying that new test onto the previous HEAD 754741426 fails the manual case (3 passed / 1 failed), confirming it targets exactly the prior defect. It asserts worker.input() is byte-identical before and after.
  • Cancellation / async generation isolation has teeth: test/queued-activation-receipts.test.ts covers an awaited old receipt not acknowledging after cancel/clear/generation/replacement, and a replacement observer not being cancelled by the old one. The observer is cleared in both spawnCli (src/worker.ts:13723) and restartCliProcess (:18071), and isCurrent() re-checks generation/backend/cliRestartInProgress before and after each read.
  • Upgrade isolation: test/worker-codex-session-upgrade.test.ts 30/30, covering "no auto-upgrade while a receipt is observed; resumes once released".
  • Related regression 599/599 (12 files); final batch 66/66 (5 files); bun run build passes.
  • Boundary checks: the observer is armed only when !result.failureReason && result.recheck (src/worker.ts:13020), so hard failures still go through submit_impossible without a pointless observer; acknowledgeQueuedActivation cancels the observer before sending IPC (:12140), so no duplicate ACK. The new copy distinguishes "keep observing the receipt / resending only queues / close the session to escape" from the legacy submit_unconfirmed wording.

Verdict

The previous blocker — head retained with followers waiting when no receipt ever arrives — is now covered by the read-only observer: once the original receipt lands, the ACK is sent without user resend and without re-typing the body or Enter. The remaining "in-memory queue is not replayed across restarts" is a pre-existing fail-closed limit unrelated to this PR, and the new copy states the terminal recovery path and the close-session escape hatch.

Mergeable. Reviewed commit c6c1c247f6 (production increment equivalent to efb33dfd5).

@deepcoldy
deepcoldy merged commit 2efe68a into master Sep 24, 2026
14 checks passed
@deepcoldy

Copy link
Copy Markdown
Owner Author

已合并并部署:

  • 合并提交:2efe68a59b8c3b2b20644d509fbbbf5a5d561b1c;最终审查提交 c6c1c247f6086cbae36b3671790c33e9869af0fc 的全部 CI 通过,包含三个测试分片、Bun 全量测试、三种平台二进制及 CodeQL。
  • canonical /root/iserver/botmux 已快进到 master 的合并提交,工作目录干净。
  • 已在 canonical 执行 bun run switch:here && bun run daemon:restart,全部成功;runtime build id 为 705535119391。
  • 全局命令已指向 canonical 的 dist/cli.js,相关 daemon 实际运行 canonical 的 dist/index-daemon.js;56 个受监控进程全部 online。
  • 关联问题 fix(worker): 排查启动输入重复提交与中断后消息滞留 #1571 已关闭。未发布版本或推送 tag。

@github-actions

Copy link
Copy Markdown

🚀 Released in v3.30.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix(worker): 排查启动输入重复提交与中断后消息滞留

2 participants