Skip to content

fix(replies): aborted reply turns stall when delivery settlement starts after cancellation - #126582

Merged
steipete merged 1 commit into
mainfrom
codex/autoqa-157-preaborted-ledger
Aug 20, 2026
Merged

steipete merged 1 commit into
mainfrom
codex/autoqa-157-preaborted-ledger

Conversation

@steipete

Copy link
Copy Markdown
Contributor
Additional instructions

MUST: Keep Allow edits from maintainers enabled for this PR so maintainers can help update the branch when needed.

Closes #126581

What Problem This Solves

Fixes an issue where aborted reply turns with a stalled delivery would remain in finalization for up to 30 seconds when cancellation happened before reply-turn settlement began.

Why This Change Was Made

Abort events are not replayed to listeners registered after cancellation. Check the existing abort state at the reply-turn ledger owner before allocating its deadline or listener and immediately return the same aborted result that the old path eventually produced after its 30-second timeout. The canonical dispatcher idle waiter already uses this owner-boundary pattern.

The finalizer runs core fallback and exposes channel recovery eligibility only for a settled result, so returning the existing aborted result sooner cannot widen fallback, replay, visibility, recipient delivery, or double-send. The outer dispatcher continues to drain deliveries and run its existing cleanup lifecycle unchanged.

User Impact

Cancelled reply turns finish their own settlement promptly instead of waiting on the 30-second deadline. Operators get faster finalization and idle cleanup with no change to cancellation outcomes, fallback policy, replay ownership, configuration, protocol, persistence, or plugin contracts.

Evidence

  • Authentic owner-boundary regression uses the real reply dispatcher and a genuinely stalled delivery, aborts before settlement, and races settlement against an already-resolved pending sentinel without advancing the 30-second deadline. Before: Expected: "aborted"; Received: "pending". After: the owner suite passes all 15 tests and preserves after-registration abort coverage.
  • Focused owner, ACP cancellation, canonical idle-waiter, Telegram fallback, and Feishu broadcast/replay proof: node scripts/run-vitest.mjs src/auto-reply/reply/dispatch-from-config.turn-ledger.test.ts src/auto-reply/reply/dispatch-from-config.test.ts src/auto-reply/reply/dispatch-from-config.acp-abort.test.ts src/auto-reply/reply/reply-flow.test.ts extensions/telegram/src/bot-message-dispatch.fallback-topic-media.test.ts extensions/feishu/src/bot.broadcast.test.ts — 454 tests passed across six files and three Vitest shards.
  • Actual changed gate: node scripts/check-changed.mjs -- src/auto-reply/reply/dispatch-from-config.turn-ledger.ts src/auto-reply/reply/dispatch-from-config.turn-ledger.test.ts — passed all core/coreTests format, production/test typecheck, lint, architecture, schema, storage, dependency, import-cycle, and ownership guards.
  • Targeted formatting and git diff --check pass. Production LOC: +3/-0; tests: +23/-0. The production growth is the necessary early owner precheck before deadline/listener allocation; removing the existing post-race check or hiding the guard would weaken cancellation ordering or clarity.
  • Fresh P1 Codex-backed structured autoreview: no accepted/actionable findings. Separate independent read-only adversarial review: no findings; fallback, replay, double-send, visibility, operation cleanup, and outer dispatcher-drain invariants verified directly.
  • Direct authenticated Telegram/Feishu live traffic is not applicable: this is a deterministic provider-independent settlement-ordering defect proved with the real dispatcher plus existing channel-boundary tests; no channel transport or external API behavior changed.
  • Regression provenance: fix(reply): report settled delivery outcomes once #124773 (eb38d5e4863a66d881c3fc1aa785ff53898088e7). Risk: low; existing outcome and all downstream contracts unchanged.
  • AI-assisted: yes

@clawsweeper

clawsweeper Bot commented Aug 20, 2026

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

@steipete

Copy link
Copy Markdown
Contributor Author

Land-ready proof for #126581 at head 1c67d07faba342b7118d00118f359388fb8c7c03:

  • Root cause: reply-turn settlement registered its abort listener after an already-fired signal, so a genuinely stalled delivery kept finalization pending until the existing 30-second deadline. The owner now checks signal.aborted before allocating the deadline/listener and immediately returns the exact same existing aborted outcome.
  • Before-fix regression: the real-dispatcher, stalled-delivery boundary test failed with Expected: "aborted"; Received: "pending" without advancing the deadline. After repair, the same owner test and existing after-registration cancellation test both pass.
  • Focused proof: node scripts/run-vitest.mjs src/auto-reply/reply/dispatch-from-config.turn-ledger.test.ts src/auto-reply/reply/dispatch-from-config.test.ts src/auto-reply/reply/dispatch-from-config.acp-abort.test.ts src/auto-reply/reply/reply-flow.test.ts extensions/telegram/src/bot-message-dispatch.fallback-topic-media.test.ts extensions/feishu/src/bot.broadcast.test.ts — 454 tests passed across six files: core/ACP/idle 425, Feishu broadcast/replay 16, Telegram fallback 13.
  • Actual changed gate: node scripts/check-changed.mjs -- src/auto-reply/reply/dispatch-from-config.turn-ledger.ts src/auto-reply/reply/dispatch-from-config.turn-ledger.test.ts — passed core/coreTests formatting, production and test typechecks, changed-file lint, zero runtime import cycles, schema/storage, dependency, and ownership guards. One infrastructure-only retry used the already-cached exact repository-pinned pnpm version after the host's separate launcher referenced a missing managed binary.
  • Formatting and git diff --check: passed. Production LOC +3/-0; tests +23/-0. Fresh P1 Codex-backed autoreview: clean. Separate independent read-only adversarial review: no findings.
  • Invariant proof: core fallback and channel recovery eligibility both require settled; faster aborted cannot widen fallback, replay, delivery visibility, or double-send. Outer dispatcher draining, settled receipts, durable custody, dedupe ownership, and operation cleanup remain unchanged.
  • Exact-head hosted CI/Testbox evidence: run 32344459758, completed success for the full head above; node scripts/watch-pr-ci.mjs 126582 1c67d07faba342b7118d00118f359388fb8c7c03 finished GREEN.
  • Native exact-head review artifacts validate as READY FOR /prepare-pr, zero findings. Latest ClawSweeper comment reports an in-progress review; no findings or Rank-up moves: have been published, so there are no actionable moves to apply or skip.
  • Proof gap: no live authenticated Telegram/Feishu traffic was needed for this provider-independent internal settlement-ordering defect; authentic real-dispatcher proof and both representative channel-boundary suites are green.

AI-assisted: yes.

@steipete
steipete merged commit 4d6c40a into main Aug 20, 2026
288 checks passed
@steipete
steipete deleted the codex/autoqa-157-preaborted-ledger branch August 20, 2026 07:44
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via squash.

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

Labels

maintainer Maintainer-authored PR size: XS

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: aborted reply turns can stall for 30 seconds when delivery settlement starts after cancellation

1 participant