Repository navigation
fix(plugins): abort hook ctx.abortSignal on hook timeout expiry - #116522
sloptop-the-terrible wants to merge 2 commits into
Conversation
|
Codex review: needs real behavior proof before merge. Reviewed August 17, 2026, 12:25 PM ET / 16:25 UTC. ClawSweeper reviewWhat this changesThe 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 Review scores
Verification
How this fits togetherGateway 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]
Decision needed
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
Findings
Agent review detailsSecurityNeeds attention: The abort-before-reject ordering can weaken fail-closed plugin policy timeout handling. PR surfaceSource +45, Docs +1. Total +46 across 5 files. View PR surface stats
Review metrics
Root-cause clusterRelationship: Members:
Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything. Merge-risk optionsMaintainer options:
Technical reviewBest 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:
Overall correctness: patch is incorrect AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning high; reviewed against 49af98c12bb4. LabelsLabel justifications:
EvidenceSecurity concerns:
What I checked:
Likely related people:
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
HistoryReview history (7 earlier review cycles)
|
b0d91cb to
4ffacac
Compare
|
Repro'd the exact thing this PR fixes — Setup: registered a real 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: Before this PR (parent commit
After this PR (head
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 ( 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 |
|
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. |
4ffacac to
fef404a
Compare
|
Rebased onto latest @clawsweeper re-review |
|
🦞🧹 I asked ClawSweeper to review this item again. Re-review progress:
|
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.
af21432 to
39d6625
Compare
|
This assigned pull request has been automatically marked as stale after being open for 27 days. |
|
Closing due to inactivity. |
What Problem This Solves
A plugin hook that runs past its
timeoutMsbudget 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, andctx.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
invokeHookHandlerhelper 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 deadlineAbortController, composes it with any caller-suppliedctx.abortSignalviaAbortSignal.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 previouswithHookTimeout(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 thePluginHookToolContext.abortSignaldoc 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.abortSignalinexec/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
dispatchVoidHooks, modifying-hook dispatch, claiming-hook dispatch x2,reply_payload_sending,skill_proposal_evaluate) now route through the singleinvokeHookHandler, so the behavior change is uniform rather than path-specific.AbortSignal.anyis 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