Repository navigation
fix(auto-reply): settle active run before compacting instead of unconditional abort - #166163
Conversation
…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).
|
🦞👀 Pull request received. I will update this pull request when review starts. ClawSweeper review completeClawSweeper finished reviewing this revision. The review result is being finalized. |
|
Codex review: needs maintainer review before merge. Reviewed October 7, 2026, 1:05 AM ET / 05:05 UTC (Revision 4). ClawSweeper reviewWhat this changesManual /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 Review scores
Verification
How this fits togetherOpenClaw’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]
Before mergeNone. Agent review detailsSecurityNone. PR surfaceSource -4, Tests +73, Docs +5. Total +74 across 4 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. Technical reviewBest 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. LabelsLabel changes:
Label justifications:
EvidenceWhat I checked:
Likely related people:
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
HistoryReview history (3 earlier review cycles)
|
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]>
|
Merged via squash.
|
…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]>
…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)
Adapt openclaw#166163 to the extended-stable command lifecycle. Co-authored-by: RomneyDa <[email protected]>
Fixes #166038
What Problem This Solves
Manual
/compactcould 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-mainscripts/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.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.commands-compact.tswith the inspected main version made the natural-completion regression fail becauseabortEmbeddedAgentRunwas called. Control suite: 13 failures / 29 passes, 31.92 seconds. The candidate handler was restored afterward.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.sendsubmitted/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.Timeout evidence:
pending-cancelled-before-provider-release waitMs=60109, followed by the delivered text: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.shThe 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)", withCRABBOX_AWS_INSTANCE_PROFILEunset, launched from a clean trusted main worktree. Run IDs:run_7b1fa8c1f91336f9d7bc0d2b1c3011f2(unit/type/full-build/initial harness run) andrun_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. FullOPENCLAW_BUILD_PRIVATE_QA=1 pnpm buildpassed 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
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:commands-compact.tscommands-compact.lifecycle.test.tscommands-compact.test.tsdocs/concepts/compaction.mdAgainst 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=1andpnpm test src/auto-reply/reply/commands-compact.lifecycle.test.ts --maxWorkers=1passed 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.