Repository navigation
fix: avoid duplicate agent turns for acknowledged completions - #141352
maximilliangrand wants to merge 1 commit into
Conversation
|
🦞👀 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 changes before merge. Reviewed October 7, 2026, 6:57 AM ET / 10:57 UTC (Revision 4). ClawSweeper reviewWhat this changesThe PR rechecks queued background-command completions before starting an agent turn and rebuilds the prompt and delivery policy from surviving events. Regression provenancePossible regression — suspected (reviewed change). No predecessor PR is attributed. Merge readiness⛔ Needs changes before merge - 2 items remain The fix remains necessary, but surviving cron work can inherit a consumed completion's busy-guard exemption. The proof-positive replacement also has merge conflicts, so it does not yet justify closing this branch. Priority: P2 Review scores
Verification
How this fits togetherBackground commands queue completion events that wake OpenClaw's heartbeat runner. The runner selects pending work, prepares its delivery route, and dispatches an agent turn whose successful handling consumes the selected events. flowchart TD
A[Background command finishes] --> B[Session event queue]
C[Process poll acknowledges result] --> B
B --> D[Heartbeat preparation]
D --> E[Recheck selected events]
E --> F[Skip or retry]
E --> G[Agent turn for surviving work]
G --> H[Deliver reply and consume events]
Before merge
Findings
Agent review detailsSecurityNone. PR surfaceSource +96, Tests +443. Total +539 across 6 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: Keep one heartbeat-owned revalidation path that rebuilds surviving work and retries admission whenever the completion supporting its busy exemption disappears. Do we have a high-confidence way to reproduce the issue? Yes: source and contributor before/after boundary evidence establish the preparation race. The remaining finding can be exercised with a targeted completion plus a cron event, a busy Main lane, and acknowledgement during routing; this review did not execute that scenario. Is this the best way to solve the issue? Unclear as submitted: queue-owned occurrence revalidation is the right repair, but prompt rebuilding must also invalidate admission decisions that depended on a now-consumed completion. Full review comments:
Overall correctness: patch is incorrect AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 0dc209168731. LabelsLabel changes:
Label justifications:
EvidenceWhat I checked:
Likely related people:
Rank-up movesOptional improvements that raise the rating; they are not merge blockers.
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
HistoryReview history (3 earlier review cycles)
|
8d35141 to
0c77c80
Compare
|
Rebased onto The description also states the precise preparation boundary and distinguishes this reproduction from the reporter's Windows/provider timing trace. Coalesced work retains its own event identities and delivery policy, with regression coverage for WebChat publication and route changes. The conflict resolution preserves upstream's work-started marker before preparation. After refreshing the frozen dependencies, all 95 focused acknowledgement/wake-owner tests and both core and infra-test TypeScript checks pass. The description separates this validation from the broader test run and formal review performed before the mechanical rebase. |
0c77c80 to
9b1e05f
Compare
|
This pull request has been automatically marked as stale due to inactivity. |
|
Closing due to inactivity. |
Related: #141202
What Problem This Solves
Fixes an unnecessary agent turn when a completed background command is read while heartbeat preparation is still awaiting routing. The redundant turn processes an obsolete completion notice and can repeat long-context inference.
User Impact
Already-observed completions no longer trigger this follow-up. Unobserved completions, remaining cron work, due tasks, and scheduled cadence still run. Unread events remain queued if dispatch or delivery fails.
This is a bounded fix for acknowledgement during heartbeat-owned preparation. It does not retract a turn after generic dispatch starts or close later waits inside the generic dispatcher. The reporter's live Windows/provider trace does not establish this exact ordering; the regression below reproduces it independently.
Why This Change Was Made
Revalidate the original event occurrences after heartbeat preparation and use their surviving selection for the prompt, outcome policy, and successful consumption. Same-text successor events retain their own identities.
If removing an event invalidates its delivery route, return the existing retryable
preemptedoutcome so the wake owner rebuilds routing. A consumed completion also loses its WebChat publication permission; coalesced cron work cannot inherit that permission. No grace timer, early event consumption, or additional routing owner is introduced.Thanks to @wpu911 for the report and ordering examples in #141202. Allow edits from maintainers remains enabled.
Evidence
Rebased onto
4502cad0a1f483561f11c59175e5252b20bf9c51and validated on macOS arm64 / Node 26.7.0. The mechanical conflict resolution preserves upstream's work-started marker immediately before preparation. Dependencies were refreshed withpnpm install --frozen-lockfilebefore the post-rebase checks.The runtime regression starts a real background process, observes its completion using the real process poll tool and production result-acknowledgement hook, runs the real heartbeat/reply/agent pipeline, and reads the persisted transcript. A deterministic local HTTP server supplies the provider response. A wrapper awaits the actual routing resolver and delivers the poll acknowledgement before preparation returns; no reply resolver is injected.
ebfe25f8)Replay the committed runtime regression:
Both runtime cases pass. Before the mechanical rebase, the standalone file took 4.25 seconds of test execution and 29.03 seconds command wall time including cold worker compilation. In the post-rebase four-file run, with TypeScript checking concurrently, its test execution took 11.67 seconds. This integration cost verifies real model-request dispatch and transcript creation; the existing stale-exec test file supplies the cheaper event-selection and retry controls.
Additional validation:
git diff --checkpassed.ebfe25f8: 298 tests passed and 1 Windows-only case skipped across 14 files (274 heartbeat/event tests and 24 Git worktree tests), in 190.76 seconds command wall time. Core and selected infra-test TypeScript checks, typed lint, formatting, andgit diff --checkpassed on that version.At head
9b1e05f, CI has 151 successful checks but three failed test jobs, which leave the aggregate CI gate red:Expected native command execution.The failures are outside the six changed files, but that alone does not establish that they are unrelated. An unchanged-base reproduction has not been completed. No CI rerun or test suppression was used to hide these failures. No external model, live channel, or Windows runtime result is claimed.