Skip to content

fix(auto-reply): honor abortSignal in transient-HTTP retry backoff - #109805

Merged
steipete merged 3 commits into
openclaw:mainfrom
wangmiao0668000666:fix/auto-reply-transient-retry-abort
Jul 17, 2026
Merged

steipete merged 3 commits into
openclaw:mainfrom
wangmiao0668000666:fix/auto-reply-transient-retry-abort

Conversation

@wangmiao0668000666

Copy link
Copy Markdown
Contributor

What Problem This Solves

The transient-HTTP retry in handleAgentExecutionError (src/auto-reply/reply/agent-runner-error-handler.ts:405-414) waits out its backoff on a bare setTimeout(resolve, TRANSIENT_HTTP_RETRY_DELAY_MS) — 2 500 ms (TRANSIENT_HTTP_RETRY_DELAY_MS = 2_500, line 60) — that never receives the turn's AbortSignal. When a reply turn is cancelled mid-backoff (user stop, session abort, gateway/channel teardown), the error handler stays parked for the full 2 500 ms, and — worse — it then returns { kind: "retry" }, so the turn loop issues another provider attempt for a turn whose result will be discarded. Turn teardown is delayed for every auto-reply channel (telegram included) each time a transient HTTP provider error (5xx/timeout) races with a cancellation.

Sibling parity: the overload-retry branch ~30 lines above in the same function was made abort-aware by #109354 (merged 2026-07-16) — it computes retryAbortSignal = turn.replyOperation?.abortSignal ?? turn.opts?.abortSignal (line 275) and sleeps via sleepWithAbort(retryDelayMs, retryAbortSignal) inside a try/catch that maps the rejection through resolveReplyOperationAbortAction (lines 383-391). The transient-HTTP backoff was simply left behind.

Why This Change Was Made

Mirror the overload branch exactly. sleepWithAbort (src/infra/backoff.ts, re-exported from packages/retry/src/index.ts:21) and resolveReplyOperationAbortAction (line 130) are already imported/in scope in this file, and the same turn.replyOperation?.abortSignal ?? turn.opts?.abortSignal expression is what the caller already uses for runAbortSignal (agent-runner-execution.ts:260) and what the overload branch uses for its own retry sleep.

  • Before: await new Promise<void>((resolve) => { setTimeout(resolve, TRANSIENT_HTTP_RETRY_DELAY_MS); }); return { kind: "retry" };
  • After: compute retryAbortSignal (same expression as the overload branch), await sleepWithAbort(TRANSIENT_HTTP_RETRY_DELAY_MS, retryAbortSignal) inside the same try/catch → resolveReplyOperationAbortAction(sleepError) pattern (return the abort action when set, otherwise rethrow), then return { kind: "retry" } unchanged when not aborted.

No new config, no new constants, no new helpers, no behavior change when the signal is not aborted: the delay value, the single-retry budget, and the log line are untouched. Non-test LOC: +10 / -3 on one file.

This follows the same bare-setTimeout → sleepWithAbort pattern as merged #108561 (discord gateway READY backoff) and #109604 (telegram startup probe retry).

User Impact

Cancelling a reply turn (stop command, session reset, gateway shutdown, channel teardown) while a transient HTTP provider error retry is parked now unwinds the turn immediately with the abort lifecycle action (NO_REPLY for a user abort, restart copy for a restart abort) instead of waiting out the remaining backoff and firing one more doomed provider request.

Evidence

Real behavior proof — production handler, real AbortController, wall-clock

Uncommitted scratchpad/proof-transient-retry-abort.mts (not in this PR) calls the real exported handleAgentExecutionError with a transient-HTTP-shaped provider error (521 <!DOCTYPE html>…Cloudflare…), consumeTransientHttpRetry: () => true, a real AbortController wired as turn.replyOperation.abortSignal, and real wall-clock timers (no vi.mock, no fake timers). It lets the handler park in the backoff, fires abort() at ~100 ms, and measures abort-to-return.

Before (main @ e01027dd28, bare setTimeout):

Transient HTTP provider error before reply (521 <!DOCTYPE html>…). Retrying once in 2500ms.
{
  "abortToReturnMs": 2402.2,
  "totalHandlerMs": 2522.5,
  "resultKind": "retry"
}

Abort fired ~100 ms in; the handler still sat the full 2 500 ms backoff and then returned retry — i.e. the turn loop would run the provider again after cancellation.

After (this PR):

Transient HTTP provider error before reply (521 <!DOCTYPE html>…). Retrying once in 2500ms.
{
  "abortToReturnMs": 1.1,
  "totalHandlerMs": 119.2,
  "resultKind": "final",
  "payloadText": "NO_REPLY"
}

Same script, same timing: the abort interrupts the backoff in ~1 ms and the handler returns the user-abort lifecycle action.

Run with: node --import tsx scratchpad/proof-transient-retry-abort.mts (Node v24.15.0, Linux x86_64).

Regression coverage

  • New: interrupts the transient HTTP retry backoff on abort in src/auto-reply/reply/agent-runner-execution-provider-failures.test.ts — drives runAgentTurnWithFallback with a transient failover error (FailoverError reason timeout, the same isTransientHttp branch; this test harness stubs message-based isTransientHttpError to false), aborts mid-backoff, and asserts the turn resolves to the user-abort final payload with no second provider attempt (runEmbeddedAgentMock called once).
  • Existing: retries once after transient 521 HTML failure and then succeeds in agent-runner.misc.runreplyagent.test.ts locks the non-abort behavior (waits the 2 500 ms, retries once, succeeds) — unchanged.

Control-red verification

Reverting only the source hunk (keeping the new test) makes the new test hang indefinitely — the bare setTimeout parks the handler for the full backoff and nothing observes the abort; Vitest reported no output for 120 s and was terminated. Restoring the fix: pass. The wall-clock proof above shows the same contrast on the real handler (2 402 ms → 1.1 ms).

Tests & checks

  • node scripts/run-vitest.mjs run src/auto-reply/reply/agent-runner-execution-provider-failures.test.ts — 66/66 passed
  • node scripts/run-vitest.mjs run src/auto-reply/reply/agent-runner.misc.runreplyagent.test.ts — 75/75 passed
  • node scripts/run-oxlint.mjs <both files> — exit 0
  • node scripts/run-tsgo.mjs -p tsconfig.core.json — exit 0
  • node scripts/run-tsgo.mjs -p test/tsconfig/tsconfig.core.test.json — exit 0
  • git diff --check — clean

Out of scope

The overload-retry branch (already abort-aware since #109354), the overload notice delivery timeout, and TRANSIENT_HTTP_RETRY_DELAY_MS's value/retry budget are unchanged. Other bare sleeps elsewhere in the auto-reply runner were not touched.

Risk

  • User-visible behavior change? Yes — a cancelled turn now finishes promptly with the abort lifecycle action instead of sleeping out the transient retry backoff and issuing one more provider attempt. Happy-path (no abort) behavior is identical, locked by the existing 521 regression test.
  • Config/env/migration change? No.
  • Security/auth/secrets/network/tool-execution change? No.
  • Highest-risk area: an abort that is neither a user abort nor a restart abort rethrows the sleep rejection exactly like the overload branch does (same resolveReplyOperationAbortAction fall-through), preserving existing semantics.

AI-assisted; reviewed before submission.

@clawsweeper clawsweeper Bot added proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦞 diamond lobster Very strong PR readiness with only minor maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. P2 Normal backlog priority with limited blast radius. labels Jul 17, 2026
@clawsweeper

clawsweeper Bot commented Jul 17, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed July 17, 2026, 12:26 PM ET / 16:26 UTC.

Summary
This PR replaces the transient-HTTP retry timer with a shared abort-aware backoff helper and adds coverage that cancellation returns the lifecycle abort result without a second provider attempt.

PR surface: Source +9, Tests +26. Total +35 across 2 files.

Reproducibility: yes. The PR provides a real production-handler wall-clock reproduction with a real AbortController, plus a focused regression proving the aborted turn does not make a second provider attempt.

Review metrics: none identified.

Merge readiness
Overall: 🦞 diamond lobster
Proof: 🦞 diamond lobster
Patch quality: 🦞 diamond lobster
Result: ready for maintainer review.

Overall follows the weaker of proof and patch quality, so missing proof can cap an otherwise strong patch.

Risk before merge

  • [P1] The PR head is behind current main, so maintainers should confirm the current three-way merge result and exact-head required checks before landing; no concrete conflict or regression is presently shown.

Maintainer options:

  1. Decide the mitigation before merge
    Land the shared abort-aware retry wait after the behind-base merge result and exact-head checks are confirmed, retaining both the abort regression and existing non-abort retry coverage.
  2. Pause or close
    Do not merge this PR until maintainers decide whether the risk is worth taking.

Next step before merge

  • No automated repair is needed; confirm the behind-base merge result, wait for exact-head required checks, then perform normal maintainer merge review.

Security
Cleared: The diff only changes in-process retry cancellation and its test; it adds no dependency, secret, permission, workflow, artifact-download, package-resolution, or code-execution surface.

Review details

Best possible solution:

Land the shared abort-aware retry wait after the behind-base merge result and exact-head checks are confirmed, retaining both the abort regression and existing non-abort retry coverage.

Do we have a high-confidence way to reproduce the issue?

Yes. The PR provides a real production-handler wall-clock reproduction with a real AbortController, plus a focused regression proving the aborted turn does not make a second provider attempt.

Is this the best way to solve the issue?

Yes. Sharing the established abort-aware sleep and lifecycle mapping across both retry branches is narrower and more maintainable than adding another bespoke timer or cancellation path.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against 7128f6ddbb20.

Label changes

Label justifications:

  • P2: This is a bounded core runtime bug that delays cancellation and can trigger one unnecessary provider attempt, without data loss, security impact, or broad availability failure.
  • rating: 🦞 diamond lobster: Overall readiness is 🦞 diamond lobster; proof is 🦞 diamond lobster and patch quality is 🦞 diamond lobster.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (live_output): The PR body includes before-and-after live output from the real handler with a real abort signal and wall-clock timing, showing prompt abort completion and no retry result; the current-head refactor preserves that demonstrated path.
  • proof: sufficient: Contributor real behavior proof is sufficient. The PR body includes before-and-after live output from the real handler with a real abort signal and wall-clock timing, showing prompt abort completion and no retry result; the current-head refactor preserves that demonstrated path.
Evidence reviewed

PR surface:

Source +9, Tests +26. Total +35 across 2 files.

View PR surface stats
Area Files Added Removed Net
Source 1 20 11 +9
Tests 1 26 0 +26
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 2 46 11 +35

What I checked:

Likely related people:

  • steipete: Introduced the adjacent overload-retry lifecycle behavior and directly refined this PR's shared abortable-backoff implementation on the current head. (role: recent feature owner and PR refiner; confidence: high; commits: 7a45a6582759, 872b25aac384, 390cdc533fe1; files: src/auto-reply/reply/agent-runner-error-handler.ts, src/auto-reply/reply/agent-runner-execution-provider-failures.test.ts)
  • wangmiao0668000666: Authored the initial patch and previously landed the same cancellation invariant in the Discord gateway and Telegram startup retry paths, providing relevant cross-surface history beyond this PR. (role: recent abort-backoff contributor; confidence: medium; commits: 8090cb1c64ea, e01027dd28a8, 280071558710; files: extensions/discord/src/monitor/provider.lifecycle.ts, extensions/telegram/src/probe.ts, src/auto-reply/reply/agent-runner-error-handler.ts)
What the crustacean ranks mean
  • 🦀 challenger crab: rare, exceptional readiness with strong proof, clean implementation, and convincing validation.
  • 🦞 diamond lobster: very strong readiness with only minor maintainer review expected.
  • 🐚 platinum hermit: good normal PR, likely mergeable with ordinary maintainer review.
  • 🦐 gold shrimp: useful signal, but proof or patch confidence is still limited.
  • 🦪 silver shellfish: thin signal; proof, validation, or implementation needs work.
  • 🧂 unranked krab: not merge-ready because proof is missing/unusable or there are serious correctness or safety concerns.
  • 🌊 off-meta tidepool: rating does not apply to this item.

Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics.

How this review workflow works
  • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
  • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
  • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
  • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
  • Maintainers can also comment @clawsweeper review to request a fresh review only.
  • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
  • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
  • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.
Review history (2 earlier review cycles)
  • reviewed 2026-07-17T08:22:14.392Z sha c4a35d2aeb49e340131764bd6548c7eb559485a2 :: needs maintainer review before merge. :: none
  • reviewed 2026-07-17T14:56:18.371Z sha 5406b7509985044b50668632217ac2ea8d91dc66 :: needs maintainer review before merge. :: none

@wangmiao0668000666
wangmiao0668000666 force-pushed the fix/auto-reply-transient-retry-abort branch from c4a35d2 to 5406b75 Compare July 17, 2026 14:51
@wangmiao0668000666

Copy link
Copy Markdown
Contributor Author

Rebased onto current main (5406b75099). The two failing checks were unrelated to this diff (src/auto-reply/reply/agent-runner-error-handler.ts + its test):

  • check-test-types failed on scripts/openclaw-npm-postpublish-verify.ts with TS7016 for ./lib/error-format.mjs — the declaration file scripts/lib/error-format.d.mts was added on main after this branch's base (8858944), so the stale base could not resolve it.
  • build-artifacts failed the startup-memory smoke by 2.6 MB (status --json median RSS 427.6 MB vs 425 MB limit), a marginal main-side measurement.

Focused proof after rebase: node scripts/run-vitest.mjs src/auto-reply/reply/agent-runner-execution-provider-failures.test.ts — 66/66 passed locally.

@steipete steipete self-assigned this Jul 17, 2026
wangmiao0668000666 and others added 2 commits July 17, 2026 17:08
The transient-HTTP retry in handleAgentExecutionError slept its full
TRANSIENT_HTTP_RETRY_DELAY_MS (2500ms) on a bare setTimeout, ignoring the
turn abortSignal. A cancelled turn stayed parked for the whole backoff and
then returned { kind: "retry" }, issuing another provider attempt after
cancellation.

Mirror the sibling overload-retry branch (abort-aware since openclaw#109354):
sleep via sleepWithAbort with turn.replyOperation?.abortSignal ??
turn.opts?.abortSignal and map a sleep rejection through
resolveReplyOperationAbortAction, returning the abort action when set.

Co-Authored-By: Claude <[email protected]>
@steipete
steipete force-pushed the fix/auto-reply-transient-retry-abort branch from 5406b75 to 872b25a Compare July 17, 2026 16:14
@steipete

Copy link
Copy Markdown
Contributor

Maintainer review complete. This is the best fix for the retry-lifecycle boundary: transient HTTP backoff now shares the existing abort-aware wait and reply-operation abort mapping, and cancellation clears the pending timer without a second provider call.

Proof:

Ready for maintainer prepare/merge.

@steipete
steipete merged commit 4cdea67 into openclaw:main Jul 17, 2026
114 checks passed
@steipete

Copy link
Copy Markdown
Contributor

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Jul 18, 2026
…penclaw#109805)

* fix(auto-reply): honor abortSignal in transient-HTTP retry backoff

The transient-HTTP retry in handleAgentExecutionError slept its full
TRANSIENT_HTTP_RETRY_DELAY_MS (2500ms) on a bare setTimeout, ignoring the
turn abortSignal. A cancelled turn stayed parked for the whole backoff and
then returned { kind: "retry" }, issuing another provider attempt after
cancellation.

Mirror the sibling overload-retry branch (abort-aware since openclaw#109354):
sleep via sleepWithAbort with turn.replyOperation?.abortSignal ??
turn.opts?.abortSignal and map a sleep rejection through
resolveReplyOperationAbortAction, returning the abort action when set.

Co-Authored-By: Claude <[email protected]>

* refactor(auto-reply): share abortable retry backoff

* fix(auto-reply): make retry wait fallthrough explicit

---------

Co-authored-by: Claude <[email protected]>
Co-authored-by: Peter Steinberger <[email protected]>
zenglingbiao added a commit to zenglingbiao/openclaw that referenced this pull request Jul 18, 2026
Add optional signal parameter so callers can cancel the drain wait
instead of blocking until the deadline expires. On abort the function
returns the current drain state near-instantly — matching the pattern
from openclaw#109805 and openclaw#109913.
@wangmiao0668000666
wangmiao0668000666 deleted the fix/auto-reply-transient-retry-abort branch October 28, 2026 07:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

P2 Normal backlog priority with limited blast radius. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦞 diamond lobster Very strong PR readiness with only minor maintainer review expected. size: S status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants