Skip to content

fix: prevent apply cursor livelock - #1129

Merged
steipete merged 10 commits into
mainfrom
steipete/apply-cursor-livelock
Aug 12, 2026
Merged

steipete merged 10 commits into
mainfrom
steipete/apply-cursor-livelock

Conversation

@steipete

@steipete steipete commented Aug 11, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Fix the ongoing openclaw/openclaw apply/comment-sync cursor livelock without raising its 300-second runtime budget.

Production run https://github.com/openclaw/clawsweeper/actions/runs/31544381133 selected 39 urgency-ranked records before the only numeric frontier record. It terminally evaluated 25 records, yielded at the runtime budget, and printed Comment sync made no cursor progress; the durable cursor therefore stayed at #105854 and every later cycle selected the same window.

The selector still reserves its first slot for the numeric frontier, which helps non-apply consumers. The load-bearing guarantee now lives in the TypeScript apply loop: with an active comment-sync cursor, it computes the smallest selected item number strictly greater than the cursor and executes that record first regardless of incoming item_numbers position. If no selected number is greater, it wraps to the smallest selected number, matching the existing cycle bookkeeping. Cursor completion follows the trusted terminal execution trace rather than the shell list order, so downstream sort operations cannot recreate the starvation.

The branch also removes the redundant placeholder sweep attempted before apply-lease acquisition. Those deletes were correctly rejected locally with apply mutation lease is not held; the lease reaper then removed the expired placeholders through its authorized path. Post-publication placeholder cleanup remains intact.

Behavior proof

  • Claim: the apply loop executes a terminal numeric frontier first and advances the durable comment-sync cursor even when later urgent work is budget-clipped; clipping the frontier itself does not advance.
  • Exercised surface: the real apply-decisions loop, comment-sync-batch selector, complete_comment_sync_batch, cursor writer, canonical closed-record fallback, and wrap/cycle regression seams.
  • Scenario: the exact 40 item numbers and cursor/frontier from run 31544381133, plus adversarial ascending input [87267,95788,97566,105342,105870] with frontier #105870 last.
  • Command/environment: docs/proof/apply-cursor-livelock/run-proof.sh on Node 24.19.0, pnpm 11.10.0, jq 1.8.2; synthetic filesystem records, no GitHub credentials or mutation.
  • Observable result: the adversarial apply report and trace both recorded #105870 first and persisted cursor #105870 with every lower urgent record unexamined; the clipped-frontier replay persisted #105854 with cursor_count=0; five focused apply/selector/completion/wrap probes passed.
  • Artifact: docs/proof/apply-cursor-livelock/fixture-result.json, behavior contract/report, container provenance, and the scripted reproduction in the same directory.
  • Limits: the fixture proves apply-loop ordering and cursor-completion semantics, not production GitHub latency. It does not claim urgent records no longer require later repair.

Finding disposition

  • Coordinator P1: accepted in substance. Shell normalization can reorder item_numbers; the loop-level numeric comparison is now the authoritative guarantee.
  • Pre-commit P1 on find() ordering: accepted. The loop now uses an explicit numeric minimum, with forward, wrap, ascending, and unsorted coverage.
  • Pre-commit P1 on clipped-frontier trace reconstruction: rejected after source verification. Apply removes an interrupted current item before writing the trusted trace; an empty terminal prefix returns with zero progress before wrap-cycle state can be persisted. The invariant is documented inline and covered by the runtime-yield continuation test.

Validation

  • pnpm run check: 3,336 tests; 3,327 passed, 9 skipped, 0 failed; coverage thresholds passed.
  • Focused suite: 243 passed, 0 failed.
  • Scripted behavior proof: 5 passed, 0 failed; PROOF_RC=0.
  • Pre-commit and committed-branch Codex autoreviews: clean, no accepted/actionable P0/P1 findings.
  • Crabbox container proof: passed on committed code/proof head 2ebe882831f99d9f22dd6f696f48d2a4e80f3195 through configured provider=aws, lease cbx_a9f86ad7a357 (quick-prawn-5920), run run_61dcc42eb8d2, inside node:24-bookworm; 5/5 focused tests passed, exit 0, and lease cleanup is confirmed. Receipt commit 695d7beaca437fe03d1da003c4a69838c043602a changes documentation only and was included in the same push.
  • jq 1.8.2 trust root: the downloaded jq-linux-amd64 binary matched repository-pinned SHA-256 b1c22172dd303f3be49e935aa56aa48a8b7a46e0bc838b4997d3bb451495870f before installation.

Scope

No runtime-budget increase, cursor schema change, close-policy change, CHANGELOG.md, or CLAUDE.md change.

OpenClaw Bay is unaffected: this changes internal apply-lane ordering and removes a redundant pre-lease cleanup attempt; no lifecycle publication or observer-only dashboard contract changes.

@clawsweeper

clawsweeper Bot commented Aug 11, 2026

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

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

@clawsweeper clawsweeper Bot added merge-risk: 🚨 automation 🚨 Merging this PR could break CI, automerge, proof capture, label sync, or automation. P1 Urgent regression or broken agent/channel workflow affecting real users now. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. labels Aug 11, 2026
@clawsweeper

clawsweeper Bot commented Aug 11, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed August 11, 2026, 8:47 PM ET / August 12, 2026, 00:47 UTC.

ClawSweeper review

What this changes

This PR prioritizes the numeric comment-sync frontier in the apply loop, checkpoints it from execution trace order, and removes pre-lease placeholder cleanup.

Merge readiness

⚠️ Ready for maintainer review - 2 items remain

Keep this PR open for normal landing review: its cursor-livelock repair is not on current main, the prior frontier-ordering concern is addressed, and this review found no actionable patch defect.

Priority: P1
Reviewed head: 695d7beaca437fe03d1da003c4a69838c043602a

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) Strong production-shaped proof and focused regression coverage support a correct, narrowly scoped automation repair.
Proof confidence 🦞 diamond lobster (5/6) ✨ media proof bonus Sufficient (linked_artifact): The committed Crabbox receipt records a 5/5 after-fix run in node:24-bookworm through provider aws (lease cbx_a9f86ad7a357); the final PR commit only updates proof documentation.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Verified Sufficient (linked_artifact): The committed Crabbox receipt records a 5/5 after-fix run in node:24-bookworm through provider aws (lease cbx_a9f86ad7a357); the final PR commit only updates proof documentation.
Evidence reviewed 6 items Apply-loop frontier ordering: The apply command derives the smallest selected number greater than the active cursor, or the smallest selected number after wrap, and sorts that frontier ahead of all other requested records.
Trace-aware cursor completion: Cursor completion now evaluates the trusted execution prefix before unexamined selected records, so shell normalization cannot erase the frontier-first execution evidence.
Selector and workflow propagation: The batch selector reserves its first slot for the regular numeric frontier, and the scheduled workflow passes the persisted cursor to the apply command.
Findings None None.
Security None None.

How this fits together

The scheduled apply lane selects reviewed records, updates durable GitHub review comments, and stores a cursor so later runs resume the batch. This change controls which selected record runs first and how completed execution advances that cursor.

flowchart LR
A[Scheduled apply run] --> B[Comment-sync batch]
B --> C[Numeric cursor frontier]
C --> D[Apply execution order]
D --> E[Trusted execution trace]
E --> F[Durable cursor checkpoint]
D --> G[GitHub comment synchronization]
Loading

Before merge

  • Resolve merge risk (P1) - A regression in the new ordering or trace interpretation could repeat a scheduled comment-sync window or checkpoint past a record, so this remains an automation-sensitive merge.
  • Complete next step (P2) - No repair-lane action is needed because this review found no concrete, mechanical blocker on the current branch.
Agent review details

Security

None.

Review metrics

Metric Value Why it matters
Code and regression coverage production +63/-21; tests +228/-10 The runtime ordering change is accompanied by focused coverage of selection, execution trace, completion, and wrap behavior.
Proof material 8 proof files, +779 lines The PR preserves a behavior contract, machine-readable result, and Crabbox provenance for a production-derived automation failure.

Merge-risk options

Maintainer options:

  1. Merge with the proven cursor boundary (recommended)
    Accept the bounded automation risk because the current code has focused selector, apply-loop, completion, and wrap/cycle proof for the failure mode.

Technical review

Best possible solution:

Land the narrow frontier-first ordering with its trace-based checkpoint semantics and retain the focused fixture as regression coverage.

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

Yes: the committed fixture replays the production-derived 40-item ordering and an ascending request that places the frontier last, exercising the real apply command and completion helper.

Is this the best way to solve the issue?

Yes: making the apply loop independently select the numeric frontier is the narrowest reliable defense because shell preparation can reorder item numbers before execution.

AGENTS.md: found and applied where relevant.

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

Labels

Label changes:

  • add proof: sufficient: Contributor real behavior proof is sufficient. The committed Crabbox receipt records a 5/5 after-fix run in node:24-bookworm through provider aws (lease cbx_a9f86ad7a357); the final PR commit only updates proof documentation.
  • 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 (linked_artifact): The committed Crabbox receipt records a 5/5 after-fix run in node:24-bookworm through provider aws (lease cbx_a9f86ad7a357); the final PR commit only updates proof documentation.
  • remove status: 📣 needs proof: Current PR status label is status: 👀 ready for maintainer look.
  • remove rating: 🦪 silver shellfish: Current PR rating is rating: 🐚 platinum hermit, so this older rating label is no longer current.

Label justifications:

  • P1: The reported livelock can prevent scheduled durable review-comment synchronization from making progress.
  • merge-risk: 🚨 automation: The patch changes scheduled workflow argument propagation and durable cursor checkpoint ordering.
  • 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 (linked_artifact): The committed Crabbox receipt records a 5/5 after-fix run in node:24-bookworm through provider aws (lease cbx_a9f86ad7a357); the final PR commit only updates proof documentation.
  • proof: sufficient: Contributor real behavior proof is sufficient. The committed Crabbox receipt records a 5/5 after-fix run in node:24-bookworm through provider aws (lease cbx_a9f86ad7a357); the final PR commit only updates proof documentation.

Evidence

What I checked:

  • Apply-loop frontier ordering: The apply command derives the smallest selected number greater than the active cursor, or the smallest selected number after wrap, and sorts that frontier ahead of all other requested records. (src/clawsweeper-apply-decision-workflow.ts:251, 695d7beaca43)
  • Trace-aware cursor completion: Cursor completion now evaluates the trusted execution prefix before unexamined selected records, so shell normalization cannot erase the frontier-first execution evidence. (scripts/apply-workflow-helpers.sh:252, 695d7beaca43)
  • Selector and workflow propagation: The batch selector reserves its first slot for the regular numeric frontier, and the scheduled workflow passes the persisted cursor to the apply command. (src/repair/workflow-utils.ts:2002, 695d7beaca43)
  • Current-head behavior proof: The committed Crabbox receipt records a successful 5/5 production-shaped fixture and focused probes on code head 2ebe882; the subsequent PR-head change is documentation-only proof material. (docs/proof/apply-cursor-livelock/container-provenance.json:1, 695d7beaca43)
  • Current-main check: Neither the PR head nor its order-independent repair commit is an ancestor of current main, so the central fix is still needed. (83dddd63e750)
  • Feature-history routing: Blame attributes the current cursor-preparation and completion helper to the repository-introduction commit, while later main history includes dedicated apply publication work. (scripts/apply-workflow-helpers.sh:111, 22c7ddcc3051)

Likely related people:

  • steipete: Current-main history includes a recent workflow-helper refactor, and the proposed repair is concentrated in that automation path. (role: recent workflow-helper contributor; confidence: high; commits: 59904fe97f88; files: scripts/apply-workflow-helpers.sh)
  • Martin Cleary: Commit e10a866 substantially maintained apply publication and lease/label behavior in the central apply workflow. (role: recent apply-path contributor; confidence: high; commits: e10a866ba75f; files: src/clawsweeper-apply-decision-workflow.ts, test/review-comment-rendering.test.ts)
  • Dallin Romney: Blame ties the current comment-sync cursor preparation and completion path to commit 22c7ddc. (role: cursor-helper provenance contributor; confidence: medium; commits: 22c7ddcc3051; files: scripts/apply-workflow-helpers.sh, src/repair/workflow-utils.ts)

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 (4 earlier review cycles)
  • reviewed 2026-08-11T23:26:04.519Z sha 8225b9d :: needs real behavior proof before merge. :: none
  • reviewed 2026-08-11T23:51:21.495Z sha 33badc3 :: needs real behavior proof before merge. :: [P1] Checkpoint the completed frontier despite an urgent tail | [P2] Anchor jq verification to a repository-controlled digest
  • reviewed 2026-08-11T23:58:40.553Z sha c87bd96 :: needs real behavior proof before merge. :: [P2] Pin jq verification to an independent trust root
  • reviewed 2026-08-12T00:09:07.737Z sha 20f0e39 :: needs real behavior proof before merge. :: [P1] Preserve the frontier-first order through batch preparation

@clawsweeper clawsweeper Bot added merge-risk: 🚨 security-boundary 🚨 Merging this PR could weaken sandboxing, authorization, credentials, or sensitive data. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. and removed rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. labels Aug 11, 2026
@clawsweeper clawsweeper Bot added rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. and removed rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. labels Aug 11, 2026
@clawsweeper clawsweeper Bot removed the merge-risk: 🚨 security-boundary 🚨 Merging this PR could weaken sandboxing, authorization, credentials, or sensitive data. label Aug 12, 2026
@steipete
steipete requested a review from a team as a code owner August 12, 2026 00:43
@steipete

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Aug 12, 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: when the review finishes, ClawSweeper will create the durable review comment if needed or update the existing comment in place.

Re-review progress:

@clawsweeper clawsweeper Bot added proof: sufficient Contributor real behavior proof is sufficient. 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 status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. labels Aug 12, 2026
@steipete
steipete merged commit 9c7445b into main Aug 12, 2026
22 checks passed
@steipete
steipete deleted the steipete/apply-cursor-livelock branch August 12, 2026 00:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

merge-risk: 🚨 automation 🚨 Merging this PR could break CI, automerge, proof capture, label sync, or automation. P1 Urgent regression or broken agent/channel workflow affecting real users now. proof: sufficient Contributor real behavior proof is sufficient. 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.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant