Skip to content

fix(auto-reply): settle active run before compacting instead of unconditional abort - #166163

Merged
steipete merged 2 commits into
openclaw:mainfrom
holny:fix/166038-compact-queue-behind-run
Oct 7, 2026
Merged

steipete merged 2 commits into
openclaw:mainfrom
holny:fix/166038-compact-queue-behind-run

Conversation

@holny

@holny holny commented Oct 6, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #166038

What Problem This Solves

Manual /compact could cancel an active turn and silently discard the user's pending answer.

User Impact

An active turn now has up to 60 seconds to finish before manual compaction cancels it. If cancellation succeeds, the status reply asks the user to resend the interrupted request, including when the following 15-second drain times out. A rejected cancellation does not produce a false resend warning. Closed invocations, revoked owners, and changed sessions cannot cancel the turn after waiting.

Why This Change Was Made

The compact command remains responsible for coordinating the active turn. It now rechecks invocation, session, and owner authority immediately before cancellation, records the cancellation result, and shares interruption guidance across returned statuses. Existing writer-fence and accepted-successor accounting remain intact. Repeated unavailable-status formatting and the equivalent context-budget fallback were simplified; production code shrank by four lines.

Original fix by @holny; maintainer cleanup addresses delayed authority, accurate interruption reporting, lifecycle regressions, documentation, and isolated proof. Contributor history is preserved, with verified human coauthor credit in the maintainer commit.

Evidence

Candidate: 388e3ee72591d74e3fdac5359a5f89bc19497553. Inspected main: de38c97c4d5f79da10ab5faee0b3d522952b4fb1; its handler still aborts before waiting. Contributor code ran only on a fresh secretless AWS lease, cbx_ee3222282fd3, through the clean-main scripts/crabbox-untrusted-bootstrap.sh, with --fresh-pr openclaw/openclaw#166163, --no-hydrate, CRABBOX_ENV_ALLOW=CI, full-SHA verification, no instance role, and no Tailscale.

  • All three compact-command files: 44 tests passed, 38.76 seconds wall time, using pnpm test src/auto-reply/reply/commands-compact.test.ts src/auto-reply/reply/commands-compact.lifecycle.test.ts src/auto-reply/reply/commands-compact-context-budget.test.ts --maxWorkers=1.
  • pnpm tsgo:core: passed, 16.16 seconds. pnpm tsgo:core:test --ci-graphs-json '["core-test-messaging"]': passed, 14.05 seconds.
  • Negative control: keeping the candidate tests and replacing only commands-compact.ts with the inspected main version made the natural-completion regression fail because abortEmbeddedAgentRun was called. Control suite: 13 failures / 29 passes, 31.92 seconds. The candidate handler was restored afterward.
  • Targeted oxfmt, core oxlint, and git diff --check: passed. Independent Codex autoreview through P2: scoped-clean, no actionable findings; published commit has the same reviewed source tree.

Real Gateway + local mock Responses provider, with isolated state and ephemeral ports: all three live cases passed. The provider held an admitted turn while a second chat.send submitted /compact; the proof observed the actual coordination boundary before releasing the held response. Both fixed-head cases used unchanged production code. The main control replaced only the production handler with the inspected main blob and rebuilt it; this is a main-handler negative control, not a claim that the entire main tree was run. The original candidate handler was restored, and the final tracked diff was empty.

Live case Pending answers delivered Compaction count / persisted summaries Wall time
Fixed: natural completion 1 1 / 1 49.28 s
Fixed: actual 60-second timeout 0, with resend guidance 1 / 1 109.27 s
Inspected main handler 0, provider socket aborted before release 1 / 1 49.25 s

Timeout evidence: pending-cancelled-before-provider-release waitMs=60109, followed by the delivered text:

⚙️ Compacted (604 → 182) • Context 182/128k (0%)
⚠️ Your in-flight request was aborted by compaction — please resend it.

Exact live commands after the trusted bootstrap:

OPENCLAW_BUILD_PRIVATE_QA=1 pnpm build qaRuntime
bash .artifacts/run-compact-live-proof.sh
PROOF_CANCEL_TIMEOUT=1 bash .artifacts/run-compact-live-proof.sh
# After substituting only the inspected main handler and rebuilding:
EXPECT_DROPPED=1 bash .artifacts/run-compact-live-proof.sh

The controller command was CRABBOX_ENV_ALLOW=CI crabbox run --provider aws --id cbx_ee3222282fd3 --fresh-pr openclaw/openclaw#166163 --no-hydrate --timing-json --script scripts/crabbox-untrusted-bootstrap.sh -- 388e3ee72591d74e3fdac5359a5f89bc19497553 bash -c "$(cat /private/tmp/oc-r4-166163/upload-live-checks.sh)", with CRABBOX_AWS_INSTANCE_PROFILE unset, launched from a clean trusted main worktree. Run IDs: run_7b1fa8c1f91336f9d7bc0d2b1c3011f2 (unit/type/full-build/initial harness run) and run_0db41cfa5ac5bb47a9593b63f4ab5910 (individual test costs and all passing live cases).

The first live attempt proved answer delivery and compaction but failed its harness assertion: status notices do not promise a replyToId. The corrected harness matches exactly one notice in the isolated conversation after the command's event cursor; pending answers still require the exact run ID and marker. No product code changed for that rerun. Full OPENCLAW_BUILD_PRIVATE_QA=1 pnpm build passed in 623.39 s; it emitted an unrelated Control UI startup-size advisory (366.1 KiB versus 364.7 KiB), with no UI changes in this PR. All Gateway processes reported confirmed shutdown and no cleanup errors.

ClawSweeper disposition

Review checklist item Resolution
1. Real behavior proof Real Gateway/QA-channel natural completion, actual timeout warning, and main-handler lost-answer control all pass; transport-specific limit below.
2. Revalidate authority before delayed abort Invocation/caller signals, bound session, and owner are rechecked after the natural wait and before cancellation. All four stale-authority cases pass.
3. Drain-timeout interruption guidance Successful cancellation's resend notice is included in the timeout reply; regression passes.
4. Two-stage lifecycle regressions Natural-wait and drain results are distinct; all lifecycle cases pass, including writer-fence and successor accounting.
5. Report interruption only on successful cancellation The boolean abort result owns the notice; accepted/rejected cancellation cases pass.
6. Expired authority security concern Same pre-effect fencing as item 2; stale authority produces no abort or compaction.
7. Final-effect merge risk Allowed cancellation and stale invocation/owner/session denial are covered at the command boundary.
8. Complete repair and proof Four code findings repaired, all module tests/types and exact-head CI green, live cases recorded above; no merge performed.

The additional Telegram Test Server request is outside this secretless contributor-code proof: it requires live channel credentials, which this execution policy prohibits. This change touches the shared command handler, not Telegram transport. The real Gateway/QA-channel proof establishes shared execution and delivered status text; it does not claim Telegram client/Test Server verification.

Size and test cost

Exact PR numstat against merge base b72a95e3f75cb6143847265fe83cc2362b57eea2:

Area / file Added Removed Net
Production: commands-compact.ts 27 31 -4
Tests: commands-compact.lifecycle.test.ts 54 5 +49
Tests: commands-compact.test.ts 24 0 +24
Docs: docs/concepts/compaction.md 5 0 +5
Total 110 36 +74

Against inspected main, the touched production owner is +29/-33, also -4. New lifecycle cases take about 2 ms each, use no real timers or sleeps, and add no production testing seams. Separate AWS commands pnpm test src/auto-reply/reply/commands-compact.test.ts --maxWorkers=1 and pnpm test src/auto-reply/reply/commands-compact.lifecycle.test.ts --maxWorkers=1 passed in 37.45 s and 12.71 s. Cold commands pay for existing compiled-worker preparation/imports; the regressions themselves add milliseconds, not process boots or delays. In exact-head CI, both files passed with one inner worker: 4.25 s and 4.61 s Vitest duration, 5.67 s and 5.80 s complete shard time. The entire CI run succeeded.

The AWS lease was released after proof. No merge was requested or performed.

…ditional abort

Manual /compact unconditionally aborted an in-flight agent run, silently
dropping the user's pending request. Wait for the run to settle
naturally (60s) before resorting to abort+drain, and tell the user when
an in-flight request was cut (openclaw#166038).
@clawsweeper

clawsweeper Bot commented Oct 6, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

ClawSweeper review complete

ClawSweeper finished reviewing this revision. The review result is being finalized.

View the workflow run.

@clawsweeper

clawsweeper Bot commented Oct 6, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed October 7, 2026, 1:05 AM ET / 05:05 UTC (Revision 4).

ClawSweeper review

What this changes

Manual /compact waits for an active answer before cancelling it, rechecks authority before cancellation, and reports successful interruptions, with lifecycle regressions and documentation.

Merge readiness

✅ Ready for maintainer review

Keep open as a useful, well-proven fix. Current main retains the reported failure, all earlier actionable findings are addressed, and the supplied Gateway evidence satisfies the previous proof request.

Priority: P1
Reviewed head: 388e3ee72591d74e3fdac5359a5f89bc19497553

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused, correct repair with strong production-boundary evidence, resolved prior findings, and successful exact-head CI.
Proof confidence 🦞 diamond lobster (5/6) Sufficient (live_output): Exact-head evidence exercises the production compact handler through real Gateway chat.send in secretless isolation: natural completion delivers the pending answer, actual timeout cancellation delivers resend guidance, and a main-handler control loses the answer. Lifecycle regressions supplement this with stale-authority denial before cancellation. Telegram client verification is not claimed; no stored-data contract changes are introduced.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Verified Sufficient (live_output): Exact-head evidence exercises the production compact handler through real Gateway chat.send in secretless isolation: natural completion delivers the pending answer, actual timeout cancellation delivers resend guidance, and a main-handler control loses the answer. Lifecycle regressions supplement this with stale-authority denial before cancellation. Telegram client verification is not claimed; no stored-data contract changes are introduced.
Evidence reviewed 8 items Pinned introduced change: Reviewed the merge-base-to-head delta: only the shared compact handler, two test modules, and compaction documentation are introduced changes. Endpoint drift and the stale test merge were not treated as PR-owned changes.
Still necessary on current main: Fetched main still calls cancellation before its 15-second drain and does not attach interruption guidance. No merged replacement fixing the central behavior was established.
Reported release retains the failure: The GitHub contents API confirms that v2026.9.8 also immediately aborts the active turn before draining.
Findings None None.
Security None None.

How this fits together

OpenClaw’s shared chat-command handler coordinates manual compaction with the active agent turn. It receives authorized commands and session state, then produces a compaction result and a user-facing status reply.

flowchart TD
  A[Authorized compact command] --> B[Current session and authority]
  B --> C[Wait for active answer]
  C --> D{Turn settled?}
  D -->|Yes| F[Compact conversation]
  D -->|No| E[Recheck authority and cancel]
  E --> F
  F --> G[Status and interruption guidance]
Loading

Before merge

None.

Agent review details

Security

None.

PR surface

Source -4, Tests +73, Docs +5. Total +74 across 4 files.

View PR surface stats
Area Files Added Removed Net
Source 1 27 31 -4
Tests 2 78 5 +73
Docs 1 5 0 +5
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 4 110 36 +74

Review metrics

Metric Value Why it matters
Focused test cost Local wall time: 37.45 s and 12.71 s; CI shard time: 5.67 s and 5.80 s The supplied measurements resolve the prior test-cost request; new lifecycle cases use mocked settlement without real waits or new process boots.

Root-cause cluster

Relationship: fixed_by_candidate
Canonical: #166038
Summary: This PR is the explicit candidate fix for the open manual-compaction lost-answer issue.

Members:

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

Technical review

Best possible solution:

Preserve natural answer completion where possible and make every successful compaction-driven interruption visible without replaying completed actions.

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

Yes, from source: send /compact during an active embedded turn; current main immediately cancels it without interruption guidance. The supplied main-handler negative control corroborates this, but this read-only reviewer did not execute current main.

Is this the best way to solve the issue?

Yes. The existing command owner handles bounded settlement and accurate cancellation reporting while retaining session and writer fencing, avoiding automatic replay of side effects.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against 9a94a2356a4f.

Labels

Label changes:

  • add proof: sufficient: Contributor real behavior proof is sufficient. Exact-head evidence exercises the production compact handler through real Gateway chat.send in secretless isolation: natural completion delivers the pending answer, actual timeout cancellation delivers resend guidance, and a main-handler control loses the answer. Lifecycle regressions supplement this with stale-authority denial before cancellation. Telegram client verification is not claimed; no stored-data contract changes are introduced.
  • add rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🦞 diamond lobster and patch quality is 🐚 platinum hermit.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (live_output): Exact-head evidence exercises the production compact handler through real Gateway chat.send in secretless isolation: natural completion delivers the pending answer, actual timeout cancellation delivers resend guidance, and a main-handler control loses the answer. Lifecycle regressions supplement this with stale-authority denial before cancellation. Telegram client verification is not claimed; no stored-data contract changes are introduced.
  • remove rating: 🦪 silver shellfish: Current PR rating is rating: 🐚 platinum hermit, so this older rating label is no longer current.
  • remove status: 📣 needs proof: Current PR status label is status: 👀 ready for maintainer look.

Label justifications:

  • P1: The PR addresses a current-release workflow that silently loses an active answer when the user requests manual compaction.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🦞 diamond lobster and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (live_output): Exact-head evidence exercises the production compact handler through real Gateway chat.send in secretless isolation: natural completion delivers the pending answer, actual timeout cancellation delivers resend guidance, and a main-handler control loses the answer. Lifecycle regressions supplement this with stale-authority denial before cancellation. Telegram client verification is not claimed; no stored-data contract changes are introduced.
  • proof: sufficient: Contributor real behavior proof is sufficient. Exact-head evidence exercises the production compact handler through real Gateway chat.send in secretless isolation: natural completion delivers the pending answer, actual timeout cancellation delivers resend guidance, and a main-handler control loses the answer. Lifecycle regressions supplement this with stale-authority denial before cancellation. Telegram client verification is not claimed; no stored-data contract changes are introduced.
  • proof: telegram-e2e: This PR needs Telegram Test Server proof with the repository E2E skill. The changed /compact timing and resend reply are observable in Telegram; supplied Gateway proof establishes shared behavior without claiming Test Server client verification.

Evidence

What I checked:

  • Pinned introduced change: Reviewed the merge-base-to-head delta: only the shared compact handler, two test modules, and compaction documentation are introduced changes. Endpoint drift and the stale test merge were not treated as PR-owned changes. (src/auto-reply/reply/commands-compact.ts:258, 388e3ee72591)
  • Still necessary on current main: Fetched main still calls cancellation before its 15-second drain and does not attach interruption guidance. No merged replacement fixing the central behavior was established. (src/auto-reply/reply/commands-compact.ts:263, 9a94a2356a4f)
  • Reported release retains the failure: The GitHub contents API confirms that v2026.9.8 also immediately aborts the active turn before draining. (src/auto-reply/reply/commands-compact.ts:272, fc23bc864e45)
  • Earlier findings resolved: The handler rechecks invocation, caller, session, and owner immediately after waiting and before cancellation; the abort boolean controls resend guidance, including drain-timeout responses. Lifecycle tests cover all four stale-authority cases, accepted/rejected cancellation, writer fences, and accepted successors. (src/auto-reply/reply/commands-compact.lifecycle.test.ts:59, 388e3ee72591)
  • After-fix production-boundary evidence: The captured PR body reports exact-head execution in secretless AWS isolation using a real Gateway and local Responses server. A held active turn completed with one delivered answer and one persisted summary; an actual 60-second timeout recorded waitMs=60109 and delivered resend guidance. Replacing only the production handler with inspected main dropped the answer and aborted the provider socket. These observations exercise the changed coordination owner; they do not claim Telegram client verification. Source snapshot identity: a10020adea211515345519c2fbc95e28f42ca7dd558f832003734003c747601b. (388e3ee72591)
  • Exact-head CI and prior rank-up coverage: GitHub confirms CI run 37570998057 succeeded for the reviewed head. The captured body supplies both requested focused-suite wall times and CI seconds, plus 44 passing focused tests and a failing main-handler negative control. This reviewer inspected evidence and did not execute contributor code. (388e3ee72591)

Likely related people:

  • steipete: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)
  • VACInc: 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 (3 earlier review cycles)
  • reviewed 2026-10-06T15:10:15.381Z sha fae8d06 :: needs real behavior proof before merge. :: [P1] Revalidate command authority before the delayed abort | [P2] Include the interruption notice when draining times out | [P2] Update the lifecycle regressions for the two-stage wait
  • reviewed 2026-10-06T15:17:40.733Z sha fae8d06 :: needs real behavior proof before merge. :: [P1] Revalidate command authority before the delayed abort | [P2] Include interruption guidance when draining times out | [P2] Update lifecycle regressions for the two-stage wait | [P2] Report interruption only when cancellation succeeds
  • reviewed 2026-10-07T04:26:43.048Z sha 388e3ee :: needs real behavior proof before merge. :: none

@clawsweeper clawsweeper Bot added P1 High-priority user-facing bug, regression, or broken workflow. merge-risk: 🚨 message-delivery 🚨 May drop, duplicate, misroute, suppress, or wrongly target messages. merge-risk: 🚨 security-boundary 🚨 May affect sandboxing, authorization, credentials, or sensitive data. proof: telegram-e2e This PR needs Telegram Test Server proof with the repository E2E skill. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. labels Oct 6, 2026
Wait for active turns before cancellation; revalidate invocation, session and owner authority at the effect boundary. Report only successful interruptions on every returned status and retain lifecycle fencing.

Original fix by @holny; maintainer cleanup covers delayed authority, interruption reporting, and lifecycle proof.

Co-authored-by: holny <[email protected]>
@openclaw-barnacle openclaw-barnacle Bot added the docs Improvements or additions to documentation label Oct 7, 2026
@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 merge-risk: 🚨 message-delivery 🚨 May drop, duplicate, misroute, suppress, or wrongly target messages. merge-risk: 🚨 security-boundary 🚨 May affect sandboxing, authorization, credentials, or sensitive data. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. labels Oct 7, 2026
@steipete
steipete merged commit fb78b85 into openclaw:main Oct 7, 2026
136 checks passed
@steipete

steipete commented Oct 7, 2026

Copy link
Copy Markdown
Contributor

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 8, 2026
…ditional abort (openclaw#166163)

* fix(auto-reply): settle active run before compacting instead of unconditional abort

Manual /compact unconditionally aborted an in-flight agent run, silently
dropping the user's pending request. Wait for the run to settle
naturally (60s) before resorting to abort+drain, and tell the user when
an in-flight request was cut (openclaw#166038).

* fix(auto-reply): preserve active requests during manual compaction

Wait for active turns before cancellation; revalidate invocation, session and owner authority at the effect boundary. Report only successful interruptions on every returned status and retain lifecycle fencing.

Original fix by @holny; maintainer cleanup covers delayed authority, interruption reporting, and lifecycle proof.

Co-authored-by: holny <[email protected]>

---------

Co-authored-by: Peter Steinberger <[email protected]>
Co-authored-by: holny <[email protected]>
github-actions Bot pushed a commit to clawhaven/openclaw that referenced this pull request Oct 16, 2026
…ditional abort (openclaw#166163)

* fix(auto-reply): settle active run before compacting instead of unconditional abort

Manual /compact unconditionally aborted an in-flight agent run, silently
dropping the user's pending request. Wait for the run to settle
naturally (60s) before resorting to abort+drain, and tell the user when
an in-flight request was cut (openclaw#166038).

* fix(auto-reply): preserve active requests during manual compaction

Wait for active turns before cancellation; revalidate invocation, session and owner authority at the effect boundary. Report only successful interruptions on every returned status and retain lifecycle fencing.

Original fix by @holny; maintainer cleanup covers delayed authority, interruption reporting, and lifecycle proof.

Co-authored-by: holny <[email protected]>

---------

Co-authored-by: Peter Steinberger <[email protected]>
Co-authored-by: holny <[email protected]>
(cherry picked from commit fb78b85)
wheakerd pushed a commit to wheakerd/clawdbot that referenced this pull request Oct 22, 2026
Adapt openclaw#166163 to the extended-stable command lifecycle.

Co-authored-by: RomneyDa <[email protected]>
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 P1 High-priority user-facing bug, regression, or broken workflow. proof: sufficient ClawSweeper judged the real behavior proof convincing. proof: telegram-e2e This PR needs Telegram Test Server proof with the repository E2E skill. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: S 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]: Manual /compact aborts the in-flight turn and silently drops the user's pending request

2 participants