Skip to content

fix(reply): let preflight compaction use compaction timeout#95590

Closed
yu-xin-c wants to merge 3 commits into
openclaw:mainfrom
yu-xin-c:codex/95553-preflight-compaction-timeout
Closed

fix(reply): let preflight compaction use compaction timeout#95590
yu-xin-c wants to merge 3 commits into
openclaw:mainfrom
yu-xin-c:codex/95553-preflight-compaction-timeout

Conversation

@yu-xin-c

@yu-xin-c yu-xin-c commented Jun 21, 2026

Copy link
Copy Markdown
Contributor

What Problem This Solves

Fixes #95553. Required preflight compaction could inherit the outer reply-operation abort signal, so a short reply lifecycle timeout could cancel compaction before the configured compaction timeout had a chance to govern the required preflight work.

Why This Change Was Made

This keeps required preflight compaction bounded by the compaction layer while still preserving real cancellation. ReplyOperation exposes an explicit cancellation signal for user stop and restart cancellation, and required preflight compaction now receives a scoped preflight abort signal that:

  • ignores upstream lifecycle TimeoutError aborts so the compaction timeout owns slow required compaction;
  • preserves upstream non-timeout aborts such as chat/RPC/user/restart cancellation;
  • preserves explicit stop/restart cancellation even if the lifecycle timeout has already aborted the main reply signal.

The patch is intentionally narrow: normal reply runs still use the existing operation abort signal, while required preflight compaction uses the filtered signal because it already has its own safety timeout.

User Impact

When a reply needs preflight compaction, users should see compaction complete or fail according to compaction.timeoutSeconds, instead of being prematurely canceled by the reply lifecycle timeout path. If the user explicitly stops the run, an RPC abort arrives, or the run is restarted, the preflight compaction still cancels promptly instead of waiting for the compaction timeout.

This PR is split out from #95563 to keep the P1 behavior fix reviewable on its own.

Evidence

  • node scripts/run-vitest.mjs src/auto-reply/reply/agent-runner-memory.test.ts src/auto-reply/reply/reply-run-registry.test.ts src/agents/embedded-agent-runner.compaction-safety-timeout.test.ts passed after rebasing onto origin/main: 2 auto-reply files / 68 tests and 1 agents file / 22 tests.
  • corepack pnpm tsgo:core passed after rebasing onto origin/main.
  • git diff --check passed.
  • 2026-06-24 redacted production preflight proof: node --import tsx invoked the production runPreflightCompactionIfNeeded path with a real ReplyOperation, a slow compaction seam, a simulated lifecycle TimeoutError, and a real abortByUser() explicit cancellation. Redacted terminal output:
OpenClaw preflight compaction cancellation proof
paths redacted; no credentials or channel identifiers used
  notice=start
SCENARIO lifecycle-timeout-ignored
  preflight-start phase=preflight_compacting
  compact-signal-initially-aborted=false
  lifecycle-timeout-aborted-at-ms=261
  compact-signal-after-lifecycle-timeout=false
  slow-compaction-finished-at-ms=440
  compact-signal-at-finish=false
  compaction-count-incremented=true
  notice=end
  preflight-result=completed
  operation-phase-after=preflight_compacting
  notice=start
SCENARIO explicit-user-abort-cancels
  preflight-start phase=preflight_compacting
  compact-signal-initially-aborted=false
  explicit-user-abort-called-at-ms=83
  compact-signal-after-explicit-abort=true
  compact-signal-reason-name=AbortError
  explicit-abort-observed-at-ms=83
  notice=incomplete
  preflight-result=threw-AbortError
  operation-phase-after=aborted

Known remaining proof gap: I still have not added logs from the reporter's exact slow vLLM/Qwen backend. The new proof above exercises the production preflight entry and reply cancellation contract with a slow compaction seam, plus focused regression tests and typecheck.

@openclaw-barnacle openclaw-barnacle Bot added size: XS triage: needs-pr-context Candidate: external PR body lacks required problem context or evidence. labels Jun 21, 2026
@clawsweeper

clawsweeper Bot commented Jun 21, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed June 24, 2026, 8:31 AM ET / 12:31 UTC.

Summary
The PR adds a scoped preflight compaction abort signal and an explicit reply cancellation signal so required budget/preflight compaction ignores lifecycle TimeoutError while still honoring explicit and non-timeout cancellation, with regression tests.

PR surface: Source +64, Tests +194. Total +258 across 4 files.

Reproducibility: yes. at source level: origin/main and v2026.6.10 still pass replyOperation.abortSignal into required preflight compaction, and compactWithSafetyTimeout races external aborts before the configured timeout. I did not run the reporter's exact slow vLLM/Qwen backend.

Review metrics: 1 noteworthy metric.

  • Reply Cancellation Surface: 1 optional signal added, 1 preflight signal source changed. The PR changes which abort events can interrupt required preflight compaction, so maintainers should verify timeout ownership and explicit cancellation before merge.

Root-cause cluster
Relationship: fixed_by_candidate
Canonical: #95553
Summary: The canonical remaining work is the preflight/budget compaction reply-abort timeout bug; this PR is an active candidate fix for the cancellation contract, while config-gate and partial-progress work overlap but do not replace it.

Members:

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

Merge readiness
Overall: 🐚 platinum hermit
Proof: 🐚 platinum hermit
Patch quality: 🐚 platinum hermit
Result: ready for maintainer review.

Overall follows the weaker of proof and patch quality, so missing proof can cap an otherwise strong patch.

Rank-up moves:

  • [P2] Maintainers should choose whether this filtered-signal branch is the canonical cancellation fix before landing.

Risk before merge

  • [P2] Required preflight compaction runs while session context is near overflow, so a wrong cancellation contract could leave session state locked or stale until the configured compaction timeout.
  • [P1] The new terminal proof exercises the production preflight entry with a slow seam, but it still does not reproduce the reporter's exact slow vLLM/Qwen deployment.
  • [P1] Several open candidates target the same canonical bug or its config escape hatch, so maintainers still need to choose the final cancellation/config path before landing one branch.

Maintainer options:

  1. Make This The Cancellation Fix (recommended)
    Maintainers can accept this filtered-signal contract as the canonical fix if they agree lifecycle TimeoutError should be ignored only for required preflight compaction while explicit and non-timeout aborts still cancel.
  2. Request Full Slow-Backend Proof
    Maintainers can require an additional redacted run from the reporter's slow backend before merge if the production-path seam proof is not enough for this availability-sensitive path.
  3. Resolve Competing Branches
    After choosing the cancellation contract, close or retarget the overlapping abort-signal PRs and handle the config-gate PR as a separate product/config question.

Next step before merge

  • [P2] Maintainer review is needed to choose the canonical cancellation/config path and accept the session-state merge risk; no narrow automated repair is identified.

Security
Cleared: The diff changes TypeScript abort-signal plumbing and tests only; it adds no dependency, workflow, package, credential, network, or secret-handling surface.

Review details

Best possible solution:

Land one canonical cancellation-signal fix with this filtered-signal contract after maintainer review, and keep the optional preflight config gate as a separate decision.

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

Yes at source level: origin/main and v2026.6.10 still pass replyOperation.abortSignal into required preflight compaction, and compactWithSafetyTimeout races external aborts before the configured timeout. I did not run the reporter's exact slow vLLM/Qwen backend.

Is this the best way to solve the issue?

Yes, the revised filtered-signal shape is the best fix I found for this PR's scope: it ignores only lifecycle TimeoutError while preserving explicit and upstream non-timeout cancellation. The optional preflight config gate should remain a separate maintainer decision.

AGENTS.md: found and applied where relevant.

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

Label changes

Label justifications:

  • P1: The PR targets a large-session compaction regression that can block agent turns and hold session work in active deployments.
  • merge-risk: 🚨 session-state: Required preflight compaction operates on near-overflow transcript context, and incorrect cancellation can leave session context stale or locked longer than intended.
  • merge-risk: 🚨 availability: If cancellation is wrong, slow preflight compaction can keep a session unavailable until the configured compaction timeout.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🐚 platinum hermit and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (terminal): The PR body now includes redacted terminal output from a production-path node run showing lifecycle timeout ignored and explicit user abort canceling the preflight signal after the fix.
  • proof: sufficient: Contributor real behavior proof is sufficient. The PR body now includes redacted terminal output from a production-path node run showing lifecycle timeout ignored and explicit user abort canceling the preflight signal after the fix.
Evidence reviewed

PR surface:

Source +64, Tests +194. Total +258 across 4 files.

View PR surface stats
Area Files Added Removed Net
Source 2 101 37 +64
Tests 2 196 2 +194
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 4 297 39 +258

What I checked:

Likely related people:

  • jared596: Authored the merged PR that expanded runPreflightCompactionIfNeeded around transcript estimates, which is central to the affected preflight path. (role: preflight compaction feature contributor; confidence: high; commits: c6d8318d07f5; files: src/auto-reply/reply/agent-runner-memory.ts, src/auto-reply/reply/agent-runner.ts)
  • ArthurNie: Authored the merged fix that forced preflight compaction before oversized agent turns, directly adjacent to this required-preflight behavior. (role: preflight hard-gate contributor; confidence: high; commits: 9d54285b0d4a; files: src/auto-reply/reply/agent-runner-memory.ts)
  • dutifulbob: Authored the merged reply lifecycle unification across stop, rotation, and restart, which is the cancellation contract this PR changes. (role: reply lifecycle contributor; confidence: high; commits: 3f6840230b86; files: src/auto-reply/reply/reply-run-registry.ts)
  • wangmiao0668000666: Authored the merged compaction timeout default change that preserved explicit timeoutSeconds, which this PR tries to let preflight compaction honor. (role: timeout contract contributor; confidence: high; commits: bb6e47729cf8; files: src/agents/embedded-agent-runner/compaction-safety-timeout.ts, docs/gateway/config-agents.md, src/config/schema.help.ts)
What the crustacean ranks mean
  • 🦀 challenger crab: rare, exceptional readiness with strong proof, clean implementation, and convincing validation.
  • 🦞 diamond lobster: very strong readiness with only minor maintainer review expected.
  • 🐚 platinum hermit: good normal PR, likely mergeable with ordinary maintainer review.
  • 🦐 gold shrimp: useful signal, but proof or patch confidence is still limited.
  • 🦪 silver shellfish: thin signal; proof, validation, or implementation needs work.
  • 🧂 unranked krab: not merge-ready because proof is missing/unusable or there are serious correctness or safety concerns.
  • 🌊 off-meta tidepool: rating does not apply to this item.

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.

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.

@openclaw-barnacle openclaw-barnacle Bot removed the triage: needs-pr-context Candidate: external PR body lacks required problem context or evidence. label Jun 21, 2026
@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. P1 High-priority user-facing bug, regression, or broken workflow. merge-risk: 🚨 session-state 🚨 May lose, corrupt, stale, or mis-associate session, agent, or context state. merge-risk: 🚨 availability 🚨 May cause crashes, hangs, restart loops, stalls, or process outages. labels Jun 21, 2026
wangmiao0668000666 added a commit to wangmiao0668000666/openclaw that referenced this pull request Jun 22, 2026
…law#95553)

Adds a user-facing config gate to disable preflight (budget-triggered)
compaction. When compaction.preflight.enabled === false, the pre-turn
threshold check in runPreflightCompactionIfNeeded short-circuits to the
existing session entry, so subsequent turns fall through to overflow
recovery (which already honors compaction.timeoutSeconds with a 15min
budget).

The check is '=== false' against the literal value, so an unset key
preserves the existing default-on behavior — the fix is strictly
additive and does not change shipped behavior for any current user.

This complements the four open PRs (openclaw#95561, openclaw#95563, openclaw#95580, openclaw#95590)
that are all working on the abortSignal source for the preflight
path. None of those PRs addresses the user-facing config dimension
that the issue explicitly requests.

Changes:
- src/config/types.agent-defaults.ts: new AgentCompactionPreflightConfig
  type with optional enabled boolean
- src/config/zod-schema.agent-defaults.ts: zod schema with strict mode
- src/config/schema.help.ts + schema.labels.ts: help text + label
- src/auto-reply/reply/agent-runner-memory.ts: 6-line early return in
  runPreflightCompactionIfNeeded, placed after isHeartbeat/isCli and
  before codex runtime so the gate is the only OpenClaw-specific path
  affected
- src/auto-reply/reply/agent-runner-memory.test.ts: 1 new test
  (skips preflight compaction when enabled === false) using the
  same test fixture pattern as adjacent tests
- scripts/repro/issue-95553-preflight-disabled-gate.mts: standalone
  real-environment proof that exercises the production gate

Refs openclaw#95553
@yu-xin-c
yu-xin-c force-pushed the codex/95553-preflight-compaction-timeout branch from 2e201ff to 7aa7246 Compare June 22, 2026 13:07
@yu-xin-c

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Jun 22, 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: the existing ClawSweeper review comment will be edited in place when the review finishes.

@yu-xin-c
yu-xin-c force-pushed the codex/95553-preflight-compaction-timeout branch from 7aa7246 to 0607489 Compare June 23, 2026 15:01
@yu-xin-c yu-xin-c changed the title [codex] fix(reply): let preflight compaction use compaction timeout fix(reply): let preflight compaction use compaction timeout Jun 23, 2026
@yu-xin-c

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Jun 23, 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: the existing ClawSweeper review comment will be edited in place when the review finishes.

@yu-xin-c

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@clawsweeper clawsweeper Bot added proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. and removed 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. labels Jun 24, 2026
@yu-xin-c
yu-xin-c marked this pull request as ready for review June 24, 2026 13:07
@openclaw-barnacle

Copy link
Copy Markdown

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

@openclaw-barnacle openclaw-barnacle Bot added the stale Marked as stale due to inactivity label Jul 11, 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

merge-risk: 🚨 availability 🚨 May cause crashes, hangs, restart loops, stalls, or process outages. merge-risk: 🚨 session-state 🚨 May lose, corrupt, stale, or mis-associate session, agent, or context state. P1 High-priority user-facing bug, regression, or broken workflow. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: M stale Marked as stale due to inactivity status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug: preflight (budget-triggered) compaction hard-capped at ~60s, ignores compaction.timeoutSeconds

1 participant