Skip to content

Design: tool abort signal handling and framework-level execution interruption #65223

Closed as not planned

Description

@jetd1

Context

Tools receive an AbortSignal parameter in their execute() signature but currently ignore it (typed as _signal). When a run is interrupted (abort, force-detach), the tool continues executing to natural completion, blocking the old run's cleanup and wasting resources.

Current Behavior

  • process poll --timeout 30000: 250ms tick loop continues for full duration after abort
  • sessions_send: HTTP connection to gateway hangs until timeout (callGateway has no cancel mechanism)
  • All other tools: blocked until natural return

The old run cannot complete its finally block until the tool returns, keeping the ReplyOperation alive.

Key Findings from PR A/B/C Implementation

Tool results persist in conversation history before abort check

pi-agent-core's executeToolCalls always pushes tool results to currentContext.messages before checking stopReason === "aborted" in the next loop iteration. This means:

  • New runs can see old tool results (session IDs, run IDs, file paths) in conversation history
  • Agents can theoretically resume operations by reading history — e.g., re-polling a process session ID from a previous run's tool result
  • This is an implicit "resume" mechanism that doesn't require explicit framework support

forceDetach no longer notifies global waiters

As of #65221, forceDetachEmbeddedRun no longer calls notifyEmbeddedRunEnded. Concurrent waiters (session-reset, session management) time out naturally rather than receiving a premature idle signal. This means the detached run's continued tool execution doesn't create false-idle signals for other code paths.

Tool-by-tool analysis after interrupt

Tool Process survives? New run can resume? Worth adding signal handling?
exec (start) Yes (bash registry) Yes, via session ID in history No — don't kill process
process poll N/A (no process) N/A Yes — stop 250ms tick loop
sessions_send Child run continues Orphaned (no cancel for callGateway) Known limitation
browser State persistent Yes No special handling needed
Short-lived tools Complete before abort N/A Not worth handling

Design Questions

1. Per-tool vs framework-level

Per-tool: Each tool manually checks the signal and returns early. Pros: can return meaningful partial results. Cons: every new tool needs explicit handling; easy to forget.

Framework-level (Promise.race wrapper): Wrap every tool.execute() call with a race against the abort signal at the agent-core layer. Pros: automatic coverage for all tools. Cons: tool continues running in background; no partial results; tool result in conversation history becomes "interrupted" rather than actual output.

2. Interrupt vs steer semantics

The current AbortSignal maps to interrupt semantics (kill old run, start new). For steer mode, tools need a different signal — "there is a steering message, yield back to the agent loop so it can be processed" — rather than abort.

Should tools receive a second signal/callback for steer awareness? Or should the framework race against the steering queue?

3. Partial results

When a tool is interrupted mid-execution:

  • Should the partial result (e.g., last 5 seconds of process poll output) be preserved in conversation history?
  • If using framework-level race, the real tool result is lost — only "Tool execution interrupted" appears in history
  • Note: even without explicit partial results, tool results from previous calls in the same run ARE preserved (see "Key Findings" above)

4. Resource cleanup

  • process poll: Stop tick loop, but keep underlying exec process alive (new run can resume polling)
  • sessions_send: No way to cancel callGateway HTTP call currently — connection leaks until timeout
  • exec (process start): Process should never be killed on abort — only the poll

Proposed Approach

Layered:

  1. Framework-level safety net (new): Race tool.execute() against abort signal at the agent-core wrapper level. Guarantees no tool can block the agent loop indefinitely. One change covers all tools.
  2. Per-tool optimization (opt-in): Tools that can meaningfully handle interruption check the signal themselves and return partial results. Framework race becomes a fallback.

This does not depend on PR C (abort-signal-propagation branch) — it can be built directly on top of the merged PR A + PR B codebase.

Related

Activity

  1. jetd1 commented on Apr 12, 2026

    @jetd1
    ContributorAuthor

    Added labels request: enhancement + agents. (Can't add from fork — maintainers please tag if appropriate.)

    This is a design discussion for framework-level tool abort signal handling. The prerequisite fixes are in PR #65010 (A) and #65221 (B). Would love input from anyone working on the agent runtime — cc @tyler6204 @joshavant @gumadeiras.

  2. openclaw-barnacle commented on Apr 12, 2026

    @openclaw-barnacle

    Please don’t spam-ping multiple maintainers at once. Be patient, or join our community Discord for help: https://discord.gg/clawd

  3. clawsweeper commented on Apr 27, 2026

    @clawsweeper
    Contributor

    Codex review: keeping this open for maintainer follow-up; there is still a little grit to resolve. Reviewed June 3, 2026, 1:04 AM ET / 05:04 UTC.

    Summary
    Codex review failed: codex execution failed.

    Reproducibility: unclear. The review failed before ClawSweeper could establish a reproduction path.

    Ways to help us reproduce this

    • Add a screenshot or short recording showing the behavior.
    • Add expected vs actual behavior.

    Next step
    Review did not complete, so no work-lane recommendation was made.

    Review details

    Best possible solution:

    Retry the Codex review after fixing the execution failure.

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

    Unclear. The review failed before ClawSweeper could establish a reproduction path.

    Is this the best way to solve the issue?

    Unclear. Retry the review first so ClawSweeper can evaluate the actual issue and fix direction.

    AGENTS.md: unclear because the file could not be read completely.

    Remaining risk / open question:

    • No close action taken because the review did not complete.

    Codex review notes: model gpt-5.5, reasoning high; reviewed against c0c4156b6dc9.

    Label changes

    Label changes:

    • add issue-rating: 🦪 silver shellfish: Current issue advisory state selects this label.
    • add clawsweeper:needs-info: Current issue advisory state selects this label.
    • remove P2: Current review triage priority is none.
    • remove clawsweeper:no-new-fix-pr: Current issue advisory state no longer selects this label.
    • remove clawsweeper:needs-maintainer-review: Current issue advisory state no longer selects this label.
    • remove clawsweeper:needs-product-decision: Current issue advisory state no longer selects this label.
    • remove clawsweeper:source-repro: Current issue advisory state no longer selects this label.
    • remove impact:session-state: Current review selected no impact labels.
    • remove impact:crash-loop: Current review selected no impact labels.
    • remove issue-rating: 🦞 diamond lobster: Current issue advisory state no longer selects this label.
    Evidence reviewed

    What I checked:

    • failure reason: codex execution failed.
    • codex failure detail: Codex review failed for this issue with exit 1.
    • codex stdout: Per-item Codex failure; continuing with the rest of the shard.

    Likely related people:

    • unknown: Codex failed before it could trace repository history. (role: review did not complete; confidence: low)
    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.
  4. added
    P2
    impact:crash-loop
    impact:session-state
    issue-rating: 🦞 diamond lobster
    clawsweeper:source-repro
    clawsweeper:no-new-fix-pr
    clawsweeper:needs-maintainer-review
    clawsweeper:needs-product-decision
    on May 19, 2026
  5. openclaw-barnacle commented on Jun 3, 2026

    @openclaw-barnacle

    This issue has been automatically marked as stale due to inactivity.
    Please add updates or it will be closed.

  6. added
    stale
    on Jun 3, 2026
  7. openclaw-barnacle commented on Jun 12, 2026

    @openclaw-barnacle

    Closing due to inactivity.
    If this is still an issue, please retry on the latest OpenClaw release and share updated details.
    If you are absolutely sure it still happens on the latest release, open a new issue with fresh steps to reproduce.

  8. locked as resolved and limited conversation to collaborators on Jun 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    P2clawsweeper:needs-maintainer-reviewclawsweeper:needs-product-decisionclawsweeper:no-new-fix-prclawsweeper:source-reproimpact:crash-loopimpact:session-stateissue-rating: 🦞 diamond lobsterstale

    Type

    No type

    Fields

    Priority

    None yet

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions