Skip to content

fix(plugins): abort hook ctx.abortSignal on hook timeout expiry - #116522

Closed
sloptop-the-terrible wants to merge 2 commits into
openclaw:mainfrom
sloptop-the-terrible:fix/hook-timeout-kill-child
Closed

sloptop-the-terrible wants to merge 2 commits into
openclaw:mainfrom
sloptop-the-terrible:fix/hook-timeout-kill-child

Conversation

@sloptop-the-terrible

Copy link
Copy Markdown
Contributor

What Problem This Solves

A plugin hook that runs past its timeoutMs budget keeps executing after the runner gives up on it. The timeout only raced the handler's promise (Promise.race([promise, timeout])); it never signaled the handler itself, and ctx.abortSignal — documented as the signal that aborts when the owning tool call is cancelled — was never touched by hook-timeout expiry. A plugin that spawns a child process or other owned work inside a hook has no cancellation notice, so that work (and any child processes) outlives the released Gateway hook lane and accumulates across turns (#115450).

Why This Change Was Made

Introduced one invokeHookHandler helper used by every hook-dispatch path (void hooks, modifying hooks, claiming hooks, reply_payload_sending, skill_proposal_evaluate). For a timed-out call it builds a per-invocation deadline AbortController, composes it with any caller-supplied ctx.abortSignal via AbortSignal.any (already used elsewhere in the codebase, e.g. src/gateway/worker-environments/inference-runtime.ts) so a handler observes both its own timeout and the owning tool call's cancellation through the same signal, and aborts the deadline exactly when the timer fires. This replaces the previous withHookTimeout(promise, timeoutMs) shape, which constructed the handler's promise before the timeout existed and had no way to reach into it.

Docs (docs/plugins/hooks.md) and the PluginHookToolContext.abortSignal doc comment updated to state the new contract: hook timeout expiry now aborts the signal, so plugins that own long-running work must honor it (they no longer need their own separate cancellation lifecycle for the timeout case specifically).

User Impact

Plugin authors who honor ctx.abortSignal in exec/spawn-style hook work now get a real cancellation signal when their hook exceeds its timeout budget, instead of the runner silently walking away while the work keeps running unbounded.

Evidence

  • All five hook-dispatch call sites (dispatchVoidHooks, modifying-hook dispatch, claiming-hook dispatch x2, reply_payload_sending, skill_proposal_evaluate) now route through the single invokeHookHandler, so the behavior change is uniform rather than path-specific.
  • AbortSignal.any is already relied on for signal composition in this codebase (worker-turn-admission.ts, workspace-sync.ts, worker-turn-launcher.ts), confirming it's within the supported Node/lib target here.

Fixes #115450

@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation size: S labels Jul 30, 2026
@sloptop-the-terrible
sloptop-the-terrible marked this pull request as ready for review July 30, 2026 18:53
@clawsweeper clawsweeper Bot added rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. P2 Normal backlog priority with limited blast radius. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. labels Jul 30, 2026
@clawsweeper

clawsweeper Bot commented Jul 30, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs real behavior proof before merge. Reviewed August 17, 2026, 12:25 PM ET / 16:25 UTC.

ClawSweeper review

What this changes

The PR changes plugin hook invocation so a hook deadline supplies a cooperative abort signal to asynchronous handlers and updates hook documentation and context types.

Merge readiness

⛔ Blocked before merge - 15 items remain

Keep open: current main still has the documented no-cancellation timeout behavior, so the requested capability remains useful. This branch has a timeout-ordering security defect, incomplete public context typing, and stale exact-context tests; it also needs a maintainer decision on the expanded plugin SDK contract and exact-head real-behavior proof.

Priority: P1
Reviewed head: 39d66252492031581953883c915f694df21cd12e
Owner decision: Required. See Decision needed.

Review scores

Measure Result What it means
Overall readiness 🦪 silver shellfish (2/6) The patch has a coherent owner boundary but retains blocking timeout and contract defects, with only harness proof.
Proof confidence 🦪 silver shellfish (2/6) Needs real behavior proof before merge: The posted real-timer trace exercises a test hook runner on an earlier head, not an installed plugin through an ephemeral Gateway on the current head. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.
Patch quality 🦪 silver shellfish (2/6) Security review found an item that needs attention.

Verification

Check Result Evidence
Real behavior Needs proof Needs real behavior proof before merge: The posted real-timer trace exercises a test hook runner on an earlier head, not an installed plugin through an ephemeral Gateway on the current head. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.
Evidence reviewed 7 items Current main lacks deadline cancellation: Current main creates the handler promise before racing it against a rejecting timer; the handler receives no timeout-owned signal.
Current public contract is narrower: The shipped source documents tool-context abort as owning-tool cancellation only and explicitly excludes hook-timeout expiry.
Patch can lose the timeout race: The new timer aborts the deadline before rejecting the timeout promise; an abort listener can resolve its handler synchronously, allowing that handler result to win Promise.race.
Findings 4 actionable findings [P1] Settle the timeout before aborting the handler
[P1] Declare the deadline signal on pairing contexts
[P2] Remove the nonexistent deadline signal from synchronous persistence
Security Needs attention Timeout-aware policy hooks can resolve successfully: The timer broadcasts abort before settling its rejection, allowing an abort-aware handler to resolve and win the race instead of preserving timeout failure for tool and install policy hooks.

How this fits together

Gateway and agent events invoke registered plugin hooks through the hook runner. The runner applies per-hook deadlines, passes hook context to plugins, and then returns policy decisions, delivery changes, or observation results to the originating workflow.

flowchart LR
  A[Gateway or agent event] --> B[Plugin hook runner]
  B --> C[Per-hook deadline]
  C --> D[Plugin handler context]
  D --> E[Cooperative plugin work]
  C --> F[Policy or delivery outcome]
  F --> G[Originating workflow]
Loading

Decision needed

Question Recommendation
Should OpenClaw guarantee a timeout-triggered cooperative abort signal across all asynchronous plugin hook contexts, replacing the current documented no-timeout-cancellation contract? Adopt uniform cooperative cancellation: Accept the new SDK direction after the concrete timeout, typing, test, and real-proof blockers are repaired.

Why: This PR expands a public plugin SDK contract rather than only repairing an established behavior, and the desired lifetime/compatibility guarantee needs maintainer intent.

Before merge

  • Add real behavior proof - Needs real behavior proof before merge: The posted real-timer trace exercises a test hook runner on an earlier head, not an installed plugin through an ephemeral Gateway on the current head. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.
  • Settle the timeout before aborting the handler (P1) - Abort listeners run synchronously. A handler that resolves from ctx.abortSignal can settle before this timeout promise rejects, so Promise.race may accept its result rather than enforce the timeout; that can turn fail-closed policy hooks into a pass.
  • Declare the deadline signal on pairing contexts (P1) - channel_pairing_requested uses the new timed runner and has a two-second default, but its handler context still has no abortSignal property. Plugin authors therefore cannot type-check or use the cancellation behavior this change supplies at runtime.
  • Remove the nonexistent deadline signal from synchronous persistence (P2) - tool_result_persist calls the synchronous runner directly and never receives a hook timeout or the new invocation wrapper. This added public field promises cancellation that cannot occur.
  • Update exact context assertions for the new signal (P2) - Default-timed hooks now receive a spread context with abortSignal, while existing tests still require the original context object (for example hooks.correlation and pairing challenge coverage). The unchanged expectations will fail and leave the new behavior untested.
  • Resolve security concern: Timeout-aware policy hooks can resolve successfully - The timer broadcasts abort before settling its rejection, allowing an abort-aware handler to resolve and win the race instead of preserving timeout failure for tool and install policy hooks.
  • Resolve merge risk (P1) - Aborting before rejecting the deadline can turn a timed-out before_tool_call or before_install policy handler into a successful result, weakening its fail-closed boundary.
  • Resolve merge risk (P1) - This is an additive but public plugin hook-context contract change; maintainers need to accept its uniform cancellation semantics before external plugins rely on it.
  • Resolve merge risk (P1) - The bug-fix diff adds runtime/type code without committed regression coverage, and current exact-context assertions are left inconsistent with the new runtime shape.
  • Resolve merge risk (P1) - GitHub reports the branch behind main, so the repaired branch needs an exact-head rebase, CI, and proof refresh before merge.
  • Complete next step (P2) - A maintainer must first accept the public cooperative-cancellation contract; the contributor then needs concrete code repairs and real exact-head proof.
  • Improve patch quality - Make deadline failure win before publishing abort and add a regression where an abort listener resolves the handler.
  • Improve patch quality - Align only asynchronous hook-context types, including pairing, and update exact-context tests.
  • Improve patch quality - Post redacted exact-head installed-plugin plus ephemeral-Gateway evidence showing timeout abort and resulting handler cleanup.
  • Resolve maintainer decision - Resolve the maintainer decision shown above before merge.

Findings

  • [P1] Settle the timeout before aborting the handler — src/plugins/hooks.ts:656-657
  • [P1] Declare the deadline signal on pairing contexts — src/plugins/hooks.ts:664
  • [P2] Remove the nonexistent deadline signal from synchronous persistence — src/plugins/hook-types.ts:725-726
  • [high] Timeout-aware policy hooks can resolve successfully — src/plugins/hooks.ts:656
Agent review details

Security

Needs attention: The abort-before-reject ordering can weaken fail-closed plugin policy timeout handling.

PR surface

Source +45, Docs +1. Total +46 across 5 files.

View PR surface stats
Area Files Added Removed Net
Source 4 97 52 +45
Tests 0 0 0 0
Docs 1 10 9 +1
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 5 107 61 +46

Review metrics

Metric Value Why it matters
Production versus test delta runtime/types +97/-52; tests +0/-0; docs +10/-9 The fix adds 45 net runtime/type lines without committed regression coverage.
Public hook-context contract 9 context fields added, 1 existing field semantics changed Plugin authors receive a new cancellation capability across multiple hook families, so consistency and upgrade semantics matter.

Root-cause cluster

Relationship: fixed_by_candidate
Canonical: #115450
Summary: This PR is a candidate cooperative-cancellation fix for the canonical hook-lifetime report, but does not itself prove descendant cleanup.

Members:

Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything.

Merge-risk options

Maintainer options:

  1. Repair and prove the timeout contract (recommended)
    Make timeout rejection terminal before abort notification, cover every asynchronous context including pairing, remove the synchronous persistence field, update affected tests, and add exact-head Gateway proof.

Technical review

Best possible solution:

Adopt a single documented cooperative-cancellation contract for every asynchronous hook context only if maintainers want that SDK surface, then make expiry terminal before notifying handlers, align every applicable type, remove the synchronous-context claim, and prove the repaired exact head through an installed plugin and ephemeral Gateway.

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

No executed current-head reproduction was run in this read-only review, but source inspection gives a high-confidence path: a handler that resolves from its abort listener can beat the timeout rejection.

Is this the best way to solve the issue?

No. Centralizing invocation at the hook runner is the right owner boundary, but expiry must be terminal before cancellation is broadcast and every advertised asynchronous context must match runtime behavior.

Full review comments:

  • [P1] Settle the timeout before aborting the handler — src/plugins/hooks.ts:656-657
    Abort listeners run synchronously. A handler that resolves from ctx.abortSignal can settle before this timeout promise rejects, so Promise.race may accept its result rather than enforce the timeout; that can turn fail-closed policy hooks into a pass.
    Confidence: 0.99
  • [P1] Declare the deadline signal on pairing contexts — src/plugins/hooks.ts:664
    channel_pairing_requested uses the new timed runner and has a two-second default, but its handler context still has no abortSignal property. Plugin authors therefore cannot type-check or use the cancellation behavior this change supplies at runtime.
    Confidence: 0.98
  • [P2] Remove the nonexistent deadline signal from synchronous persistence — src/plugins/hook-types.ts:725-726
    tool_result_persist calls the synchronous runner directly and never receives a hook timeout or the new invocation wrapper. This added public field promises cancellation that cannot occur.
    Confidence: 0.99
  • [P2] Update exact context assertions for the new signal — src/plugins/hooks.ts:664
    Default-timed hooks now receive a spread context with abortSignal, while existing tests still require the original context object (for example hooks.correlation and pairing challenge coverage). The unchanged expectations will fail and leave the new behavior untested.
    Confidence: 0.97

Overall correctness: patch is incorrect
Overall confidence: 0.98

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against 49af98c12bb4.

Labels

Label justifications:

  • P1: The timeout ordering can weaken fail-closed plugin policy hooks when a cancellation-aware handler resolves on abort.
  • merge-risk: 🚨 compatibility: The PR changes public plugin hook-context behavior and types that external plugins may consume.
  • merge-risk: 🚨 security-boundary: A timeout in before_tool_call or before_install can incorrectly resolve successfully instead of enforcing the existing fail-closed timeout path.
  • rating: 🦪 silver shellfish: Overall readiness is 🦪 silver shellfish; proof is 🦪 silver shellfish and patch quality is 🦪 silver shellfish.
  • status: 📣 needs proof: The PR needs real behavior proof before ClawSweeper can clear the contributor ask. Needs real behavior proof before merge: The posted real-timer trace exercises a test hook runner on an earlier head, not an installed plugin through an ephemeral Gateway on the current head. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.

Evidence

Security concerns:

  • [high] Timeout-aware policy hooks can resolve successfully — src/plugins/hooks.ts:656
    The timer broadcasts abort before settling its rejection, allowing an abort-aware handler to resolve and win the race instead of preserving timeout failure for tool and install policy hooks.
    Confidence: 0.99

What I checked:

  • Current main lacks deadline cancellation: Current main creates the handler promise before racing it against a rejecting timer; the handler receives no timeout-owned signal. (src/plugins/hooks.ts:620, 49af98c12bb4)
  • Current public contract is narrower: The shipped source documents tool-context abort as owning-tool cancellation only and explicitly excludes hook-timeout expiry. (src/plugins/hook-types.ts:664, 49af98c12bb4)
  • Patch can lose the timeout race: The new timer aborts the deadline before rejecting the timeout promise; an abort listener can resolve its handler synchronously, allowing that handler result to win Promise.race. (src/plugins/hooks.ts:656, 39d662524920)
  • Pairing context remains untyped: The generic runner now adds the signal for all timed hooks, but channel_pairing_requested has a default timeout while its handler context still omits abortSignal. (src/plugins/hook-types.ts:203, 39d662524920)
  • Existing assertions are not updated: Several current tests assert that handlers receive the original context object, but the patch passes a spread context with a per-invocation signal and changes no test files. (src/plugins/hooks.correlation.test.ts:40, 39d662524920)
  • History routing: Blame assigns the current-main timeout helper to a shallow-boundary commit, while available history identifies the earlier tool-cancellation hook contract as relevant area work; the shallow checkout cannot prove original semantic authorship. (src/plugins/hooks.ts:636, 1df264d3f510)

Likely related people:

  • vincentkoc: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)
  • steipete: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)

Rating scale

Score Internal tier Crab rank Meaning
6/6 S 🦀 challenger crab Exceptional readiness
5/6 A 🦞 diamond lobster Very strong readiness
4/6 B 🐚 platinum hermit Good normal PR; ordinary maintainer review
3/6 C 🦐 gold shrimp Useful, but confidence is limited
2/6 D 🦪 silver shellfish Proof or implementation needs work
1/6 F 🧂 unranked krab Not merge-ready
N/A NA 🌊 off-meta tidepool Rating does not apply

Overall follows the weaker of proof and patch quality.
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.

Workflow

  • 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.

History

Review history (7 earlier review cycles)
  • reviewed 2026-07-30T19:02:08.991Z sha 23916e79b6d53e3d297451ad067376cfdf1662e7 :: needs real behavior proof before merge. :: [P1] Expose the timeout signal on every affected hook context
  • reviewed 2026-07-30T20:13:34.063Z sha 56889c01a5ffb2518b105d118f45ea88bc97f4c9 :: needs real behavior proof before merge. :: [P1] Do not close the child-cleanup report with cooperative abort alone
  • reviewed 2026-07-30T20:34:02.832Z sha 4ffacaceb13f0acf3f5e22a9e50579bf6f2a3e4a :: needs real behavior proof before merge. :: [P1] Do not present cooperative abort as child-process cleanup
  • reviewed 2026-08-03T01:08:25.615Z sha 4ffacaceb13f0acf3f5e22a9e50579bf6f2a3e4a :: needs real behavior proof before merge. :: none
  • reviewed 2026-08-04T20:29:58.385Z sha 4ffacaceb13f0acf3f5e22a9e50579bf6f2a3e4a :: needs real behavior proof before merge. :: [P1] Settle the timeout before notifying the handler | [P1] Expose the deadline signal on pairing hook contexts
  • reviewed 2026-08-07T15:41:52.710Z sha fef404aaaa768249988738cc2698e2401c814547 :: needs real behavior proof before merge. :: [P1] Settle the timeout before notifying the handler | [P1] Expose the deadline signal on pairing hook contexts | [P2] Remove the signal from the synchronous persist context
  • reviewed 2026-08-08T00:41:14.704Z sha af214320d5bb38ac5523269bf4c98b2e5149ddf6 :: needs real behavior proof before merge. :: [P1] Settle the timeout before notifying the handler | [P1] Expose deadline cancellation on pairing hook contexts | [P2] Remove the timeout signal from synchronous persist context

@clawsweeper clawsweeper Bot added the merge-risk: 🚨 availability 🚨 May cause crashes, hangs, restart loops, stalls, or process outages. label Jul 30, 2026
@sloptop-the-terrible
sloptop-the-terrible force-pushed the fix/hook-timeout-kill-child branch 2 times, most recently from b0d91cb to 4ffacac Compare July 30, 2026 20:29
@sloptop-the-terrible

Copy link
Copy Markdown
Contributor Author

Repro'd the exact thing this PR fixes — ctx.abortSignal actually firing on hook-timeout expiry — through the real createHookRunner -> invokeHookHandler path (real setTimeout, no mocked timers, no reimplementation of the timeout logic).

Setup: registered a real before_agent_run hook via addTestHook/createHookRunner with timeoutMs: 200. The handler ignores the timeout race entirely and only resolves when it observes an 'abort' event on ctx.abortSignal (the same cooperative-cancellation pattern a plugin would use to kill an owned child process). Waited 700ms of real time, then checked whether the signal object existed and had fired.

Test file (removed after capturing output, not part of this comment's diff):

const handler = async (_event, ctx) => {
  sawAbortSignal = ctx.abortSignal;
  await new Promise((resolve) => {
    if (!ctx.abortSignal) { resolve(); return; }
    ctx.abortSignal.addEventListener("abort", () => {
      abortObserved = true;
      abortObservedAtMs = Date.now() - start;
      resolve();
    }, { once: true });
    // deliberately never resolves on the timeout race itself
  });
};
addTestHook({ registry, pluginId: "plugin-repro", hookName: "before_agent_run", handler, timeoutMs: 200 });
const runner = createHookRunner(registry, { logger });
const runPromise = runner.runBeforeAgentRun({}, TEST_PLUGIN_AGENT_CTX).catch(...);
await new Promise((r) => setTimeout(r, 700));

Run command: TMPDIR=/tmp node scripts/run-vitest.mjs src/plugins/pr116522-repro.test.ts --reporter=verbose

Before this PR (parent commit bf8da2537c, i.e. src/plugins/hooks.ts + hook-types.ts reverted to pre-PR state via git checkout bf8da2537c -- src/plugins/hooks.ts src/plugins/hook-*.types.ts docs/plugins/hooks.md):

PR116522_REPRO_RESULT {"ctxHadAbortSignalProperty":false,"abortEventObserved":false}

 × abortSignal observably fires when a before_agent_run hook overruns its timeout 708ms
   → expected undefined to be defined
AssertionError: expected undefined to be defined
 ❯ expect(sawAbortSignal).toBeDefined();

ctx.abortSignal was undefined the whole time — the handler had zero signal to observe past timeout expiry, exactly the pre-fix gap described in the PR (#115450).

After this PR (head 4ffacaceb1):

PR116522_REPRO_RESULT {"ctxHadAbortSignalProperty":true,"abortSignalAbortedFlag":true,"abortEventObserved":true,"abortObservedAtMs":202,"runRejection":"[hooks] before_agent_run handler from plugin-repro failed: timed out after 200ms"}

 ✓ abortSignal observably fires when a before_agent_run hook overruns its timeout 705ms

ctx.abortSignal was present, its 'abort' event fired ~202ms in (right at the configured 200ms budget), and .aborted flipped to true — all through the real invokeHookHandler/AbortSignal.any composition path, not a mock of it. (The runRejection in the output is before_agent_run's existing fail-closed timeout behavior — unrelated to what's being tested here, just surfaced for completeness.)

This confirms the PR does what it claims: real cooperative-cancellation signal delivery on hook timeout, through the actual hook-invocation code, for both an existing hook-context type (before_agent_run) and by extension the other dispatch paths invokeHookHandler covers.

Scope note, not addressed by this repro or asked to be: this only proves the signal fires. It says nothing about child-process lifecycle for handlers that don't check ctx.abortSignal — a plugin that spawns a child and never wires it to the signal still leaks that process past the released hook lane. That gap is explicitly out of scope here and already documented as a known limitation in the PR's own commit message and docs/plugins/hooks.md (cooperative cancellation, not preemptive termination) — no fix attempted for it.

@sloptop-the-terrible

sloptop-the-terrible commented Aug 2, 2026 •

Copy link
Copy Markdown
Contributor Author

I've been running this locally and hook timeouts now actually surface as aborts instead of hanging the runner. If maintainers prefer different semantics, happy to adjust.

@clawsweeper clawsweeper Bot added rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. merge-risk: 🚨 security-boundary 🚨 May affect sandboxing, authorization, credentials, or sensitive data. and removed rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. merge-risk: 🚨 availability 🚨 May cause crashes, hangs, restart loops, stalls, or process outages. labels Aug 3, 2026
@sloptop-the-terrible
sloptop-the-terrible force-pushed the fix/hook-timeout-kill-child branch from 4ffacac to fef404a Compare August 7, 2026 15:00
@sloptop-the-terrible

Copy link
Copy Markdown
Contributor Author

Rebased onto latest main to clear the conflict; no other changes.

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Aug 7, 2026 •

Copy link
Copy Markdown
Contributor

🦞🧹
ClawSweeper re-review requested.

I asked ClawSweeper to review this item again.
Action: item re-review queued (workflow sweep.yml, event repository_dispatch).
Result: when the review finishes, ClawSweeper will create the durable review comment if needed or update the existing comment in place.

Re-review progress:

@clawsweeper clawsweeper Bot added rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. P1 High-priority user-facing bug, regression, or broken workflow. and removed rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. P2 Normal backlog priority with limited blast radius. labels Aug 7, 2026
A timed-out hook handler kept running after the runner stopped awaiting it:
the timeout only raced the promise, it never signaled the handler itself,
and ctx.abortSignal (documented as the tool call's own cancellation signal)
was never touched by hook-timeout expiry. Plugins that spawn child
processes or other owned work had no way to observe the timeout and leaked
that work past the released hook lane (openclaw#115450).

Route every hook invocation through one invokeHookHandler helper that
builds a deadline AbortController per call, composes it with any
caller-supplied ctx.abortSignal via AbortSignal.any so both cancellation
sources reach the handler, and aborts the deadline when the timer fires.
Docs and the ctx.abortSignal doc comment updated to match.
…t runner can abort

ClawSweeper review on openclaw#115450 found the runtime/type gap: invokeHookHandler
composes and aborts a deadline signal into ctx for every hook dispatch path
(void, modifying, claiming, reply_payload_sending, skill_proposal_evaluate),
but only PluginHookToolContext's type declared abortSignal. A plugin
handling before_agent_run (or any other affected hook) had no way to
type-check against the cancellation this PR requires, even though the
runtime already supplied it.

Add abortSignal?: AbortSignal to every hook context type dispatched through
a timeout-supporting path: PluginHookAgentContext (covers
PluginHookResolveExecEnvContext), PluginHookBeforeDispatchContext,
PluginHookToolResultPersistContext, PluginHookSessionContext,
PluginHookSubagentContext, PluginHookGatewayContext (covers
PluginHookCronReconciledContext), PluginHookBeforeInstallContext,
PluginHookSkillContext, and PluginHookMessageContext (covers
PluginHookInboundClaimContext and PluginHookReplyPayloadSendingContext).
PluginHookReplyDispatchContext already declared it.
@sloptop-the-terrible
sloptop-the-terrible force-pushed the fix/hook-timeout-kill-child branch from af21432 to 39d6625 Compare August 17, 2026 16:14
@clawsweeper clawsweeper Bot added rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. and removed rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. labels Aug 17, 2026
@openclaw-barnacle

Copy link
Copy Markdown

This assigned pull request has been automatically marked as stale after being open for 27 days.
Please add updates or it will be closed.

@openclaw-barnacle openclaw-barnacle Bot added the stale Marked as stale due to inactivity label Sep 18, 2026
@openclaw-barnacle

Copy link
Copy Markdown

Closing due to inactivity.
If you believe this PR should be revived, post in #clawtributors on Discord to talk to a maintainer.
That channel is the escape hatch for high-quality PRs that get auto-closed.

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

Labels

docs Improvements or additions to documentation merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. merge-risk: 🚨 security-boundary 🚨 May affect sandboxing, authorization, credentials, or sensitive data. P1 High-priority user-facing bug, regression, or broken workflow. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. size: S stale Marked as stale due to inactivity status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Hook timeout releases lane but leaves hook child processes alive

2 participants