Skip to content

fix(compaction): forward abortSignal through delegateCompactionToRuntime bridge#93248

Closed
1052326311 wants to merge 1 commit into
openclaw:mainfrom
1052326311:fix/compaction-abort-signal-forwarding
Closed

fix(compaction): forward abortSignal through delegateCompactionToRuntime bridge#93248
1052326311 wants to merge 1 commit into
openclaw:mainfrom
1052326311:fix/compaction-abort-signal-forwarding

Conversation

@1052326311

Copy link
Copy Markdown
Contributor

Summary

When a user presses the stop button during auto-compaction, the abort signal cancels the wait but the compaction LLM call continues in-flight and writes its result to the session transcript. This causes model confusion as the model receives only a compaction summary instead of the full context.

Closes #89868

Root cause

delegateCompactionToRuntime forwarded sessionId, sessionFile, tokenBudget, currentTokenCount, force, and customInstructions to compactEmbeddedAgentSessionDirect, but not abortSignal. The runtime already accepts this field in CompactEmbeddedAgentSessionParams (src/agents/embedded-agent-runner/compact.types.ts:96), but the delegate never populated it.

The surrounding contract confirms abort propagation is expected: compactContextEngineWithSafetyTimeout already composes and passes an abort signal into context-engine compact() calls.

Fix

One-line fix: forward params.abortSignal from the delegate to the runtime compact call.

Change Type

  • Bug fix

Scope

  • Context engine / compaction

Evidence

Source-level reproduction (from ClawSweeper review, issue #89868):

  • delegate missing abortSignal: src/context-engine/delegate.ts:54
  • Runtime accepts the signal: src/agents/embedded-agent-runner/compact.types.ts:91
  • Host safety wrapper already passes abort signal elsewhere: compaction-safety-timeout.ts:163

Test coverage:

  • Added: forwards abortSignal to the compaction runtime bridge — verifies signal pass-through
  • Extended: existing delegate test now also checks abortSignal is undefined when not provided (backward compat)
Test Files  1 passed (1)
      Tests  N passed (N)

@clawsweeper review

…ime bridge

When a user presses the stop button during auto-compaction, the abort
signal cancels the wait but the compaction LLM call continues in-flight
and writes its result to the session transcript. This causes model
confusion as the model receives only a compaction summary instead of
the full context.

The bridge gap: delegateCompactionToRuntime forwarded sessionId,
sessionFile, tokenBudget, and other params, but not abortSignal. The
runtime already accepts this field in CompactEmbeddedAgentSessionParams,
but it was never populated by the delegate.

Fix: forward params.abortSignal so the runtime can properly abort
compaction when the stop button or safety timeout fires.

Closes openclaw#89868
@openclaw-barnacle openclaw-barnacle Bot added size: XS triage: needs-real-behavior-proof Candidate: external PR needs after-fix proof from a real setup. labels Jun 15, 2026
@clawsweeper

clawsweeper Bot commented Jun 15, 2026

Copy link
Copy Markdown
Contributor

Thanks for the context here. I swept through the related work, and this is now duplicate or superseded.

Close as duplicate/superseded: the same compaction abort-signal bridge fix is already owned by an older open, mergeable, maintainer-modifiable PR with successful real-behavior-proof checks, while this newer branch lacks accepted proof and currently fails lint.

Canonical path: Continue the fix through the existing canonical PR and close this duplicate branch instead of repairing two copies of the same change.

So I’m closing this here because the remaining work is already tracked in the canonical issue.

Review details

Best possible solution:

Continue the fix through the existing canonical PR and close this duplicate branch instead of repairing two copies of the same change.

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

Yes. Current main can be source-reproduced by passing an abortSignal into delegateCompactionToRuntime and observing that the mocked runtime compaction params do not receive it; the linked issue provides the real symptom logs.

Is this the best way to solve the issue?

No for this PR as the landing vehicle. Forwarding the existing abort signal is the right code fix, but the older proof-positive PR is the better canonical path for that fix.

Security review:

Security review cleared: The diff only changes context-engine source and tests, with no dependency, workflow, secret, packaging, or code-download surface.

AGENTS.md: found and applied where relevant.

What I checked:

  • Repository policy read: Read the full root AGENTS.md; no scoped AGENTS.md owns src/context-engine, and the only maintainer note present is Telegram-specific, so the root deep-review, duplicate, proof, and PR-review rules controlled this review. (AGENTS.md:1, 0314819f918a)
  • Current main bridge gap: Current main still builds the runtime compaction params without forwarding params.abortSignal, so the linked bug is real but not fixed on main. (src/context-engine/delegate.ts:55, 0314819f918a)
  • Abort signal is an existing contract: The public ContextEngine.compact() contract already documents abortSignal?: AbortSignal for cancellation before and during compaction. (src/context-engine/types.ts:352, 0314819f918a)
  • Runtime already consumes the signal: Embedded runtime compaction already passes params.abortSignal into compactWithSafetyTimeout, which cancels the active session compaction through activeSession.abortCompaction(). (src/agents/embedded-agent-runner/compact.ts:1424, 0314819f918a)
  • Caller threads abort into context-engine compaction: Overflow recovery calls compactContextEngineWithSafetyTimeout with the run-level abort signal, showing the delegate is the remaining bridge gap for delegated runtime compaction. (src/agents/embedded-agent-runner/run.ts:2164, 0314819f918a)
  • This PR duplicates the existing fix shape: The PR diff adds the same abortSignal: params.abortSignal field to delegateCompactionToRuntime and focused pass-through tests. (src/context-engine/delegate.ts:60, ec059ec320d7)

Likely related people:

  • jalehman: Authored the merged context-engine compaction delegate helper and initial tests/docs that created delegateCompactionToRuntime. (role: introduced behavior; confidence: high; commits: 7f0f8dd26802; files: src/context-engine/delegate.ts, src/context-engine/context-engine.test.ts, docs/concepts/context-engine.md)
  • steipete: Recent context-engine history and shortlog show repeated maintenance in the touched area, including the delegate runtime import boundary. (role: adjacent owner; confidence: medium; commits: 87fa88ac3d35, 27d4992eefd0; files: src/context-engine/delegate.ts, src/context-engine/context-engine.test.ts)
  • vincentkoc: Recent context-engine changes touched the same test/type surface and surrounding registry/runtime contracts. (role: recent area contributor; confidence: medium; commits: 2988203a5e52, f1b08eea54c7; files: src/context-engine/context-engine.test.ts, src/context-engine/types.ts)
  • openperf: Opened the older canonical duplicate PR with the same bridge fix and has adjacent merged context-engine registry/test work in current history. (role: canonical fix proposer; confidence: medium; commits: dbb14dfbb93e, 6aa4515798cf; files: src/context-engine/delegate.ts, src/context-engine/context-engine.test.ts, src/context-engine/registry.ts)

Codex review notes: model internal, reasoning high; reviewed against 0314819f918a.

@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. labels Jun 15, 2026
@clawsweeper

clawsweeper Bot commented Jun 15, 2026

Copy link
Copy Markdown
Contributor

ClawSweeper applied the proposed close for this PR.

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. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. size: XS status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. triage: needs-real-behavior-proof Candidate: external PR needs after-fix proof from a real setup.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug: Stop-button abort races with compaction completion, causing model confusion

1 participant