Skip to content

fix: cancel delegated tool waits when a turn stops - #188341

Merged
steipete merged 2 commits into
mainfrom
codex/codemode-bridge-stall
Oct 30, 2026
Merged

steipete merged 2 commits into
mainfrom
codex/codemode-bridge-stall

Conversation

@steipete

@steipete steipete commented Oct 30, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

A stopped turn could remain blocked waiting for the openclaw delegation tool because its in-process Gateway call did not receive the turn's abort signal. Placement cleanup could then replace the original cancellation error with a closed-settlement error.

User Impact

Stopping or canceling a turn now releases its delegated Gateway wait, and the original cancellation reason survives placement cleanup. Underlying execution cleanup retains its existing owner and writer custody.

Why This Change Was Made

This PR is narrowed to cancellation propagation and preservation of the original abort reason. It forwards the existing tool signal to callInProcessGatewayTool and checks an already-established lane abort before checking a placement claim that cleanup may have closed. Live execution still checks placement authority.

The watchdog is unchanged from main: its fifteen-minute quiet-tool allowance, Math.max deadline aggregation, and quiet allowance after explicit tool deadlines remain intact. The watchdog tests, documentation, and five previously failing consumer suites are unchanged.

The 224-second recovery preparation is a separate follow-up. The available timing evidence shows approximately 140 seconds in prompt preparation and 83 seconds in history preparation, with nearly identical timings in an unrelated session. It does not establish that preparation waited on the preceding turn's cleanup; this PR makes no preparation-latency claim.

Evidence

  • Rebased onto main at fdba74e2a71eaeb0fa24eca1b626f704abeb937c. Only the delegate tool, lane controller, and their two regression-test files differ from that base.
  • All eight requested test files passed: 140 tests across five shards, exit 0. This includes 54 watchdog tests, 37 logging-consumer tests, 11 admission tests, 32 lane-controller tests, and 6 delegate tests. All seven cases that failed with the discarded watchdog policy now pass without editing their consumer suites.
  • Retained red-on-base regressions: the delegated Gateway wait remained unsettled after abort while its handler was held open; placement cleanup replaced the expected original abort with the closed-settlement error. The delegation proof uses real in-process Gateway dispatch. The original production owners are unchanged between that proof base and the fetched main base.
  • Targeted oxlint, formatting, typechecking, test-line ratchet, staged whitespace check, and complete-diff whitespace check passed. Test lines: 6296346; ceiling: 6333003; no baseline or budget changes.
  • Fresh isolated Codex autoreview of the narrowed change against the fetched main base, through P1: scoped-clean, no actionable P0/P1 findings. The reviewer did not execute tests.

No live Gateway or real-model end-to-end run was used. No configuration, schema, dependency, or timeout-policy changes are included.

@clawsweeper

clawsweeper Bot commented Oct 30, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

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

ClawSweeper review complete

ClawSweeper finished reviewing this revision. The review result is being finalized.

View the workflow run.

@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation agents Agent runtime and tooling size: M labels Oct 30, 2026
@steipete
steipete marked this pull request as ready for review October 30, 2026 12:53
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 30, 2026 •

Copy link
Copy Markdown
Contributor

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-30T13:44:33.065343Z 6fb8cef New commits
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: bb4d43cb6c

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@@ -1,6 +1,6 @@
export const SESSION_WATCHDOG_WARNING_MS = 120_000;
export const SESSION_WATCHDOG_ABORT_FLOOR_MS = 5 * 60_000;
export const SESSION_WATCHDOG_QUIET_TOOL_MS = 15 * 60_000;
export const SESSION_WATCHDOG_QUIET_TOOL_MS = 3 * 60_000;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Publish existing media-tool deadlines before shortening the watchdog

For synchronous media generation, this now stops healthy work after three minutes, even when its provider timeout allows longer. For example, music-generate-tool.ts defaults to a 300,000 ms timeout, and media-generate-background-shared.ts:shouldDetachMediaGenerationTask explicitly keeps cron runs without a durable continuation synchronous. That path awaits generation in media-generate-background.ts, but never registers its provider deadline with the tool watchdog, so it receives this new 180,000 ms cutoff instead. Previously, a generation completing between three and five minutes could finish normally; now its requesting turn is cancelled before the result arrives. Register the existing execution-owner deadlines for these bundled callers as part of this policy change.

AGENTS.md reference: AGENTS.md:L52-L52

Useful? React with 👍 / 👎.

@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. P2 Normal backlog priority with limited blast radius. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. and removed clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. labels Oct 30, 2026
@clawsweeper

clawsweeper Bot commented Oct 30, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs changes before merge.

What this changes

This PR forwards delegation cancellation, shortens silent-tool deadlines, and preserves cancellation errors after placement cleanup.

Example: A user presses Stop while an openclaw delegation handler remains pending.

  • Before: The requesting tool keeps waiting for the handler.
  • After: The tool wait rejects promptly with the cancellation reason.

Review scores

Measure Result What it means
Overall readiness 🦪 silver shellfish (2/6) Focused boundary regressions support the useful cancellation repair, but the media regression and diff-caused CI failures block merging.
Proof confidence 🦐 gold shrimp (3/6) This maintainer-authored PR is outside the ordinary contributor proof gate; supplied evidence exercises the real in-process Gateway dispatcher with a held test handler, plus controller regressions, and explicitly claims no live Gateway or model run.
Patch quality 🦪 silver shellfish (2/6) 2 actionable review findings remain.

Product

Kind: Bug fix · Worth it: Yes · Fix scope: Complete
User problem: Stopping delegated setup or repair can leave the requesting turn waiting, and silent tool calls take too long to stop.
Reason: The maintainer-authored direction addresses a concrete cancellation failure without adding configuration or another recovery owner.

Merge readiness

⛔ Needs changes before merge - 2 items remain

Keep this PR open: the cancellation fix is useful, but the shorter watchdog interrupts healthy synchronous media generation, and existing watchdog consumer tests fail.

Priority: P2
Reviewed head: bb4d43cb6c4a89a7f0bc282d6aeda7fa9230a662

Before merge

  • Publish synchronous media deadlines before shortening the watchdog (P2) - A cron music_generate call without a durable continuation remains synchronous in shouldDetachMediaGenerationTask and runMediaGenerationTask. Music generation permits 300,000 ms, but this path never registers that deadline with diagnostic tool liveness. A healthy generation finishing at 240,000 ms therefore changes from successful completion to a stalled turn at 180,000 ms. Publish the existing execution-owner deadline through the shared synchronous media boundary before applying this cutoff, covering the affected media callers.
  • Migrate existing watchdog consumer tests to the new deadline contract (P2) - The shared policy changes leave existing consumer suites asserting the removed fifteen-minute allowance. Exact-head CI fails in diagnostic-stuck-session-exec-deadline.test.ts, diagnostic-stuck-session-recovery.integration.test.ts, diagnostic-controller-recovery.integration.test.ts, diagnostic-backend-liveness.test.ts, and reply-turn-admission.waiting.test.ts. For example, the exec preparation test still expects an enforced deadline plus 900,000 ms. Update these cases to exercise the intended cutoff, overlapping tools, and registered waits without retaining obsolete expectations or deleting their distinct coverage.

Findings

  • [P2] Publish synchronous media deadlines before shortening the watchdog — src/sessions/session-controller.watchdog-state.ts:3
  • [P2] Migrate existing watchdog consumer tests to the new deadline contract — src/sessions/session-controller.watchdog.ts:628

Tests

  • Missing end-to-end proof: No shipped Gateway and agent scenario demonstrates cancellation and watchdog expiry after the fix; the body explicitly limits validation to focused tests and an in-process handler.
Agent review details

How this fits together

Agent tool calls enter the in-process Gateway and system agent; the session controller observes progress, requests cancellation, and retains writer custody until cleanup settles.

flowchart LR
A[Requesting agent] --> B[OpenClaw delegation tool]
B --> C[In-process Gateway]
C --> D[System agent]
D --> C
E[Session watchdog] --> F[Lane cancellation and cleanup]
F --> B
Loading

Technical review

Best possible solution:

Keep the existing cancellation owners, publish synchronous media execution deadlines before shortening the shared watchdog, and migrate its consumer tests.

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

Source confirms delegation omitted the Gateway abort signal and placement validation could mask cancellation; supplied regressions report red-before and green-after results, but no execution was performed during this review.

Is this the best way to solve the issue?

The cancellation and error-ordering changes reuse the right owners, but the shared timeout change needs existing media deadlines registered and affected consumer coverage migrated.

Full review comments:

  • [P2] Publish synchronous media deadlines before shortening the watchdog — src/sessions/session-controller.watchdog-state.ts:3
    A cron music_generate call without a durable continuation remains synchronous in shouldDetachMediaGenerationTask and runMediaGenerationTask. Music generation permits 300,000 ms, but this path never registers that deadline with diagnostic tool liveness. A healthy generation finishing at 240,000 ms therefore changes from successful completion to a stalled turn at 180,000 ms. Publish the existing execution-owner deadline through the shared synchronous media boundary before applying this cutoff, covering the affected media callers.
    Confidence: 0.99
  • [P2] Migrate existing watchdog consumer tests to the new deadline contract — src/sessions/session-controller.watchdog.ts:628
    The shared policy changes leave existing consumer suites asserting the removed fifteen-minute allowance. Exact-head CI fails in diagnostic-stuck-session-exec-deadline.test.ts, diagnostic-stuck-session-recovery.integration.test.ts, diagnostic-controller-recovery.integration.test.ts, diagnostic-backend-liveness.test.ts, and reply-turn-admission.waiting.test.ts. For example, the exec preparation test still expects an enforced deadline plus 900,000 ms. Update these cases to exercise the intended cutoff, overlapping tools, and registered waits without retaining obsolete expectations or deleting their distinct coverage.
    Confidence: 1

Overall correctness: patch is incorrect
Overall confidence: 0.98

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against 5ed4aa230f89.

Provenance checked

Testing

Proof path: in-process harness.

Security

None.

Evidence

Acceptance criteria:

  • pnpm test src/agents/tools/media-generate-background.test.ts src/sessions/session-controller.watchdog.test.ts --maxWorkers=1
  • pnpm test src/logging/diagnostic-stuck-session-exec-deadline.test.ts src/logging/diagnostic-stuck-session-recovery.integration.test.ts src/logging/diagnostic-controller-recovery.integration.test.ts src/logging/diagnostic-backend-liveness.test.ts src/auto-reply/reply/reply-turn-admission.waiting.test.ts --maxWorkers=1
  • pnpm test src/agents/tools/openclaw-delegate-tool.test.ts src/agents/embedded-agent-runner/run/lane-controller.test.ts --maxWorkers=1
  • git diff --check

What I checked:

PR surface

Source +5, Tests 0, Docs +3. Total +8 across 8 files. Added test files: 0.

View PR surface stats
Area Files Added Removed Net
Source 4 24 19 +5
Tests 3 79 79 0
Docs 1 4 1 +3
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 8 107 99 +8

Labels

Label changes:

  • add P2: Useful cancellation repair with a concrete regression affecting synchronous long-running media tools.
  • add rating: 🦪 silver shellfish: Overall readiness is 🦪 silver shellfish; proof is 🦐 gold shrimp and patch quality is 🦪 silver shellfish.
  • add status: ⏳ waiting on author: ClawSweeper has contributor-facing work open and is waiting for author action.

Label justifications:

  • P2: Useful cancellation repair with a concrete regression affecting synchronous long-running media tools.
  • rating: 🦪 silver shellfish: Overall readiness is 🦪 silver shellfish; proof is 🦐 gold shrimp and patch quality is 🦪 silver shellfish.
  • status: ⏳ waiting on author: ClawSweeper has contributor-facing work open and is waiting for author action.

Rating scale

6/6 🦀 challenger crab · 5/6 🦞 diamond lobster · 4/6 🐚 platinum hermit · 3/6 🦐 gold shrimp · 2/6 🦪 silver shellfish · 1/6 🧂 unranked krab. Overall follows the weaker of proof and patch quality; ✨ marks media proof (a screenshot, video, or linked artifact) that directly shows the changed behavior.

Workflow

ClawSweeper edits this one comment on every review. Comment @clawsweeper re-review for a fresh review only. Repair and merge execution lanes are retired.

Reviewed October 30, 2026, 9:11 AM ET / 13:11 UTC.

Forward turn cancellation to delegated Gateway waits, honor active tool deadlines without the quiet-tool extension, and preserve the original abort reason after placement cleanup. Silent tools without an owned deadline now stop after three minutes; registered waits and raw writer custody remain owned by the existing controller.
Restore the existing watchdog policy and documentation from main. Keep turn-abort propagation into delegated Gateway waits and preservation of the original cancellation reason after placement cleanup. Recovery preparation latency remains a separate follow-up.
@steipete
steipete force-pushed the codex/codemode-bridge-stall branch from bb4d43c to 6fb8cef Compare October 30, 2026 13:42
@openclaw-barnacle openclaw-barnacle Bot added size: S and removed docs Improvements or additions to documentation size: M labels Oct 30, 2026
@steipete steipete changed the title fix: stop stalled system-agent tool calls promptly fix: cancel delegated tool waits when a turn stops Oct 30, 2026
@steipete
steipete merged commit cd963a2 into main Oct 30, 2026
122 of 125 checks passed
@steipete
steipete deleted the codex/codemode-bridge-stall branch October 30, 2026 14:10
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 31, 2026
…w#188341)

The openclaw delegate tool now forwards the turn's abort signal into its in-process Gateway wait, so stopping a turn (user stop or watchdog) ends a blocked delegated call instead of leaving it waiting. The embedded lane controller preserves the original abort reason when cleanup has already closed the placement claim, instead of reporting "session placement turn settlement is closed".

Watchdog policy is unchanged. The ~224 s recovery preparation (about 140 s prompt and 83 s history preparation) is a separate follow-up.
github-actions Bot pushed a commit to clawhaven/openclaw that referenced this pull request Nov 23, 2026
…w#188341)

The openclaw delegate tool now forwards the turn's abort signal into its in-process Gateway wait, so stopping a turn (user stop or watchdog) ends a blocked delegated call instead of leaving it waiting. The embedded lane controller preserves the original abort reason when cleanup has already closed the placement claim, instead of reporting "session placement turn settlement is closed".

Watchdog policy is unchanged. The ~224 s recovery preparation (about 140 s prompt and 83 s history preparation) is a separate follow-up.

(cherry picked from commit cd963a2)
Co-authored-by: RomneyDa <[email protected]>
(cherry picked from commit 64eee00d56cd8ba199c35668c72e36f4b81d989c)
github-actions Bot pushed a commit to clawhaven/openclaw that referenced this pull request Nov 23, 2026
Source commits: cd963a2 (openclaw#188341), 90d82c2 (openclaw#188203), 65602ab (openclaw#188148).

Release adaptation: formatting and import ordering only after bounded conflict resolution; no behavior changes or additional source hunks.

Co-authored-by: RomneyDa <[email protected]>
(cherry picked from commit 217f1dc819fe353d5a4ee38f0c14ef84c97d6aab)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling P2 Normal backlog priority with limited blast radius. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. size: S status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant