Skip to content

Commit 9c7445b

Browse files
authored
fix(apply): frontier-first execution ends the comment-sync cursor livelock (#1129)
The openclaw/openclaw apply/comment-sync lane livelocked for hours: the batch selector ranked urgent (pre-cursor) repairs first, the 300-second runtime budget expired before any numeric-frontier record executed, urgent items cannot advance the cursor by design, so "no cursor progress" reloaded the identical batch every cycle -- cursor pinned at #105854 while each run re-verified the same items at live GitHub latency (run 31544381133: budget stop at 25/40, closed=0/0, three lease-blocked placeholder deletions per pass). Two-layer fix. The selector now emits the first frontier record ahead of urgent repairs; and -- the load-bearing guarantee, per review -- the apply loop itself executes the frontier record first by contract, chosen as min(item > cursor) with wrap to min(item), independent of the order item_numbers arrive in (the cycle-trim path re-sorts the list ascending on some branches, which would otherwise bury the frontier item behind lower-numbered urgent work). The premature placeholder sweep that burned budget before lease acquisition every pass is removed; lease reaping and post-publication cleanup remain. Proof: a fixture reproducing the production batch shows old logic yields no cursor progress and new logic advances past terminal-evaluated records while holding at clipped ones; the adversarial test delivers the frontier item sorted last and the loop still executes it first and advances the cursor despite a clipped tail. Verified in a Docker-backed Crabbox container with committed receipt.
1 parent 83dddd6 commit 9c7445b

16 files changed

Lines changed: 1070 additions & 31 deletions

‎.github/workflows/sweep.yml‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5952,6 +5952,7 @@ jobs:
59525952
if [ "$sync_comments_only" = "true" ]; then
59535953
sync_comments_arg=(--sync-comments-only)
59545954
fi
5955+
prepare_comment_sync_cursor_arg
59555956
min_age_minutes_arg=()
59565957
if [ -n "$min_age_minutes" ]; then
59575958
min_age_minutes_arg=(--min-age-minutes "$min_age_minutes")
@@ -6052,6 +6053,7 @@ jobs:
60526053
--processed-limit "$comment_sync_processed_limit" \
60536054
--max-runtime-ms 300000 \
60546055
--cursor-trace ".artifacts/comment-sync-trace-$checkpoint.json" \
6056+
"${comment_sync_cursor_arg[@]}" \
60556057
--comment-sync-min-age-days "$comment_sync_min_age_days" \
60566058
"${item_numbers_arg[@]}" \
60576059
"${sync_comments_arg[@]}"
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
# Apply cursor livelock proof
2+
3+
## Claim
4+
5+
The automatic `openclaw/openclaw` apply loop always executes its numeric cursor frontier before
6+
opportunistic urgent repairs, regardless of the order in which `item_numbers` arrives. The loop
7+
chooses the smallest number strictly greater than the active cursor and wraps to the smallest
8+
selected number only when no greater number exists. Per-pass-terminal outcomes can therefore
9+
advance the durable cursor, while a runtime yield on the frontier itself leaves the cursor
10+
unchanged for a truthful retry.
11+
12+
This fixes the livelock observed in production run
13+
https://github.com/openclaw/clawsweeper/actions/runs/31544381133. That run selected 39 urgency-ranked
14+
records before frontier `#105870`, exhausted its 300-second budget at urgent record `#85937`, and
15+
never reached the only record that could advance cursor `#105854`.
16+
17+
## Controlled scenario and fixture
18+
19+
`run-proof.mjs` uses the exact 40-number selection from the production run and a synthetic action
20+
mix matching its terminal classes: durable comment sync, changed-since-review, stale-sync skip,
21+
kept-open, an already-closed canonical record, and a runtime-clipped record.
22+
23+
The selector, apply loop, and cursor-completion helper are exercised four ways:
24+
25+
1. The old urgency-first order examines the terminal urgent prefix but not frontier `#105870`; it
26+
reports `cursor_count=0` and leaves the cursor at `#105854`.
27+
2. The new batch selector places `#105870` first. After that frontier and the same terminal urgent
28+
prefix complete, a yield at `#85937` advances the cursor exactly to `#105870`.
29+
3. A yield on the first frontier records no examined item and leaves the cursor at `#105854`.
30+
4. An ascending-sorted request places `#105870` last after four lower urgent records. The apply
31+
loop nevertheless examines `#105870` first, and completion consumes that trusted execution
32+
trace to persist `#105870` while every other record remains unexamined.
33+
34+
The proof also runs the repository's focused wrap/cycle tests. The selector reorder remains useful
35+
for non-apply consumers, but the TypeScript apply-loop selection is the load-bearing guarantee.
36+
The implementation does not change `cycle_start_after_number`, `cycle_wrapped`, their reset rules,
37+
or the special automatic-policy branch.
38+
39+
## Run
40+
41+
```bash
42+
docs/proof/apply-cursor-livelock/run-proof.sh
43+
```
44+
45+
The container entrypoint additionally installs jq 1.8.2 only after verifying the
46+
repository-pinned official release digest:
47+
48+
```bash
49+
docs/proof/apply-cursor-livelock/container-proof.sh
50+
```
51+
52+
## Result
53+
54+
`fixture-result.json` is the committed machine-readable fixture result. `behavior-report.json`
55+
records the source-blind behavior validation.
56+
57+
The final committed-head proof ran `2ebe882831f99d9f22dd6f696f48d2a4e80f3195`
58+
inside `node:24-bookworm` through Crabbox `provider=aws`, lease `cbx_a9f86ad7a357`
59+
(`quick-prawn-5920`), run `run_61dcc42eb8d2`. jq 1.8.2 was installed only after its
60+
`jq-linux-amd64` digest matched the repository-pinned value. All five focused fixture/wrap tests
61+
passed, Crabbox exited 0, and the lease stopped automatically. `container-provenance.json` records
62+
the complete receipt and the earlier proof-harness attempts.
63+
64+
## Limits and Bay impact
65+
66+
The fixture reproduces the cursor ownership and runtime-yield boundary without GitHub credentials
67+
or production mutation. It does not reproduce the live API latency or claim that urgent records no
68+
longer require later repair.
69+
70+
OpenClaw Bay is unaffected. This changes only internal apply-lane batch execution order and removes
71+
a redundant pre-lease cleanup attempt; it does not change lifecycle publication or the
72+
observer-only dashboard contract.
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
# Apply cursor livelock behavior contract
2+
3+
## User-visible goal
4+
5+
A scheduled comment-sync pass makes durable cursor progress whenever its numeric frontier completes,
6+
without skipping a frontier clipped by the runtime budget.
7+
8+
## Target
9+
10+
- Type: CLI fixture
11+
- Access: `docs/proof/apply-cursor-livelock/run-proof.sh`
12+
- Allowed fixtures: synthetic records using the public item numbers and outcome classes from run
13+
`31544381133`
14+
- Credentials: none
15+
16+
## User tasks
17+
18+
1. Replay the production urgency-first ordering through the cursor completion command.
19+
2. Replay the same outcomes through the current batch selector and completion command.
20+
3. Pass an ascending-sorted request with the numeric frontier last through the real apply loop,
21+
stop after its first examined record, and complete the cursor from the trusted trace.
22+
4. Clip the current batch at its first frontier and inspect the persisted cursor.
23+
5. Run the focused wrap/cycle regression probes.
24+
25+
## Expected observable behavior
26+
27+
- The old ordering reports zero cursor progress and persists `#105854`.
28+
- The current selector places frontier `#105870` first and the completed-frontier replay persists
29+
`#105870` even though later urgent work is clipped.
30+
- The apply loop executes `#105870` first when ascending input places it last, and cursor completion
31+
still persists `#105870` while every lower urgent record remains unexamined.
32+
- A clipped frontier reports zero progress and persists `#105854`.
33+
- Wrapped selection and cycle bookkeeping probes pass unchanged.
34+
- No GitHub API or credential is used.
35+
36+
## Anti-cheat probes
37+
38+
- Use the same completion helper for old and current orderings; vary only selected execution order.
39+
- Remove the frontier from the examined trace and require the cursor to remain unchanged.
40+
- Include terminal outcomes other than comment sync: kept-open, changed-since-review, stale-sync
41+
skip, and already-closed reconciliation.
42+
- Assert the current selector's reported `next_cursor` is the executed first item.
43+
- Assert the apply trace, rather than incoming list position, determines the completed prefix.
44+
45+
## Evidence required
46+
47+
- `fixture-result.json`
48+
- Focused test output with zero failures
49+
- Fresh-PR container provider, lease, head, jq checksum, and exit status
50+
51+
## Out of scope
52+
53+
Live GitHub latency, production mutation, budget increases, dashboard rendering, and OpenClaw Bay.
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
{
2+
"overall_behavior": "satisfies_contract",
3+
"overall_confidence": 0.98,
4+
"target": {
5+
"type": "CLI fixture",
6+
"access": "docs/proof/apply-cursor-livelock/run-proof.sh"
7+
},
8+
"checks": [
9+
{
10+
"contract_clause": "User task 1: replay the production urgency-first ordering",
11+
"status": "pass",
12+
"severity": null,
13+
"evidence": "The isolated CLI run reported old_order.persisted_cursor=105854, cursor_advance_count=0, and next_cursor=null.",
14+
"reproduction_steps": [
15+
"Run run-proof.sh from an isolated directory containing only the behavior contract",
16+
"Read old_order in the emitted JSON"
17+
],
18+
"confidence": 0.99
19+
},
20+
{
21+
"contract_clause": "User task 2: replay the current ordering",
22+
"status": "pass",
23+
"severity": null,
24+
"evidence": "The selector emitted first_item=105870 and selector_next_cursor=105870; completion persisted 105870 with cursor_advance_count=1.",
25+
"reproduction_steps": [
26+
"Read current_order in the emitted JSON",
27+
"Verify first_item, selector_next_cursor, and persisted_cursor are all 105870"
28+
],
29+
"confidence": 0.99
30+
},
31+
{
32+
"contract_clause": "User task 3: execute adversarial ascending input",
33+
"status": "pass",
34+
"severity": null,
35+
"evidence": "The ascending input placed 105870 at index 4, while the apply report and trusted trace both recorded 105870 first; completion persisted 105870 with cursor_advance_count=1.",
36+
"reproduction_steps": [
37+
"Read adversarial_order in the emitted JSON",
38+
"Verify frontier_input_index=4, first_executed=105870, examined_item_numbers[0]=105870, and completion.persisted_cursor=105870"
39+
],
40+
"confidence": 0.99
41+
},
42+
{
43+
"contract_clause": "User task 4: clip the first frontier",
44+
"status": "pass",
45+
"severity": null,
46+
"evidence": "The clipped_frontier result persisted 105854 with cursor_advance_count=0 and next_cursor=null.",
47+
"reproduction_steps": [
48+
"Read clipped_frontier in the emitted JSON",
49+
"Verify no examined frontier was claimed"
50+
],
51+
"confidence": 0.99
52+
},
53+
{
54+
"contract_clause": "User task 5: preserve wrap and cycle behavior",
55+
"status": "pass",
56+
"severity": null,
57+
"evidence": "The isolated command ran five focused probes covering the apply loop, selector, completion, and wrapped cursor behavior with zero failures.",
58+
"reproduction_steps": [
59+
"Read the Node test summary emitted by run-proof.sh",
60+
"Verify tests=5, pass=5, fail=0"
61+
],
62+
"confidence": 0.97
63+
}
64+
],
65+
"anti_cheat_probes": [
66+
{
67+
"probe": "Use one completion command for old and current selected orders",
68+
"result": "Only order changed: the old replay stayed at 105854 and the current replay advanced to 105870."
69+
},
70+
{
71+
"probe": "Remove the frontier from the examined trace",
72+
"result": "The cursor remained at 105854 instead of falsely advancing."
73+
},
74+
{
75+
"probe": "Sort incoming item numbers with the frontier last",
76+
"result": "The TypeScript apply loop executed 105870 first and the trace-ordered completion advanced to 105870."
77+
},
78+
{
79+
"probe": "Include multiple per-pass-terminal outcome classes",
80+
"result": "The fixture included comment-synced, changed-since-review, stale-sync-skip, kept-open, and canonical closed-record completion."
81+
},
82+
{
83+
"probe": "Run without GitHub credentials",
84+
"result": "The proof completed from synthetic filesystem records and made no GitHub API request."
85+
}
86+
],
87+
"blockers": []
88+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#!/usr/bin/env bash
2+
set -euo pipefail
3+
4+
proof_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
5+
repo_root="$(cd "$proof_dir/../../.." && pwd)"
6+
jq_version="1.8.2"
7+
jq_asset="jq-linux-amd64"
8+
jq_sha256="b1c22172dd303f3be49e935aa56aa48a8b7a46e0bc838b4997d3bb451495870f"
9+
tool_dir="$(mktemp -d /tmp/apply-cursor-proof-tools.XXXXXX)"
10+
trap 'rm -rf "$tool_dir"' EXIT
11+
12+
curl --fail --silent --show-error --location \
13+
"https://github.com/jqlang/jq/releases/download/jq-${jq_version}/${jq_asset}" \
14+
--output "$tool_dir/jq"
15+
actual="$(sha256sum "$tool_dir/jq" | awk '{ print $1 }')"
16+
test "$actual" = "$jq_sha256"
17+
install -m 0755 "$tool_dir/jq" /usr/local/bin/jq
18+
export PATH="/usr/local/bin:$PATH"
19+
git config --global --add safe.directory "$repo_root"
20+
21+
echo "JQ_ASSET=$jq_asset"
22+
echo "JQ_SHA256=$actual"
23+
echo "JQ_CHECKSUM_VERIFIED=true"
24+
echo "JQ_INSTALL_PATH=/usr/local/bin/jq"
25+
"$proof_dir/run-proof.sh"
Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
{
2+
"schema": "clawsweeper-real-boundary-proof-provenance/v1",
3+
"claim": "The committed apply-cursor livelock fix passes its production-shaped fixture, adversarial apply-loop scenario, and wrap/cycle probes inside node:24-bookworm.",
4+
"pull_request": "https://github.com/openclaw/clawsweeper/pull/1129",
5+
"reviewed_head": "2ebe882831f99d9f22dd6f696f48d2a4e80f3195",
6+
"crabbox": {
7+
"cli_version": "0.38.3-5-g2a79805d",
8+
"provider": "aws",
9+
"lease_id": "cbx_a9f86ad7a357",
10+
"slug": "quick-prawn-5920",
11+
"run_id": "run_61dcc42eb8d2",
12+
"machine_type": "c7a.8xlarge",
13+
"checkout": "clean committed worktree raw-sync, --no-hydrate",
14+
"sync_ms": 20819,
15+
"command_ms": 24276,
16+
"total_ms": 46687,
17+
"exit_code": 0,
18+
"run_status": "succeeded",
19+
"lease_stopped": true
20+
},
21+
"container": {
22+
"image": "node:24-bookworm",
23+
"engine": "Docker 29.7.1",
24+
"node": "v24.18.1",
25+
"pnpm": "11.10.0",
26+
"corepack": "enabled",
27+
"jq": "jq-1.8.2",
28+
"jq_asset": "jq-linux-amd64",
29+
"jq_sha256": "b1c22172dd303f3be49e935aa56aa48a8b7a46e0bc838b4997d3bb451495870f",
30+
"jq_checksum_source": "Repository-pinned jq_sha256 in container-proof.sh, sourced from the official jq 1.8.2 release manifest",
31+
"jq_checksum_verified": true,
32+
"jq_install_path": "/usr/local/bin/jq"
33+
},
34+
"result": {
35+
"command": "docker run --rm -e APPLY_CURSOR_PROOF_HEAD=2ebe882831f99d9f22dd6f696f48d2a4e80f3195 -v $PWD:/workspace -w /workspace node:24-bookworm bash docs/proof/apply-cursor-livelock/container-proof.sh",
36+
"fixture_assertions": {
37+
"old_order_livelocks": true,
38+
"current_order_advances_terminal_frontier": true,
39+
"clipped_frontier_blocks": true,
40+
"apply_loop_executes_frontier_first": true,
41+
"adversarial_order_advances_terminal_frontier": true
42+
},
43+
"tests": 5,
44+
"passed": 5,
45+
"failed": 0,
46+
"cancelled": 0,
47+
"skipped": 0,
48+
"proof_rc": 0
49+
},
50+
"prior_runs": [
51+
{
52+
"run_id": "run_f29c14106b53",
53+
"lease_id": "cbx_e7d5148b9beb",
54+
"reviewed_head": "07e0a7764cc39a014eea119db12e1fb82806f998",
55+
"reason": "Raw sync intentionally omitted linked-worktree Git metadata required by the original proof wrapper.",
56+
"product_tests_started": false,
57+
"lease_released": true
58+
},
59+
{
60+
"run_id": "run_fdaf84682c9e",
61+
"lease_id": "cbx_e0ec212513fc",
62+
"reviewed_head": "54db6da068abec31758a09e8fc1217626b26c2e5",
63+
"reason": "The adversarial synthetic record allowed an incidental GitHub probe; the final fixture forces the credential-free path.",
64+
"fixture_started": true,
65+
"lease_released": true
66+
},
67+
{
68+
"run_id": "run_5af9ddacd3db",
69+
"lease_id": "cbx_32c86f65b7c1",
70+
"reviewed_head": "8225b9d13e774d766ec75c224b3960a81cc0ebdc",
71+
"reason": "The Docker-mounted linked ownership required an explicit Git safe.directory.",
72+
"product_tests_started": false,
73+
"lease_released": true
74+
},
75+
{
76+
"run_id": "run_28f54a2542a6",
77+
"lease_id": "cbx_32c86f65b7c1",
78+
"reason": "A no-sync reuse targeted the lease default checkout instead of the fresh PR checkout.",
79+
"product_tests_started": false,
80+
"lease_released": true
81+
},
82+
{
83+
"run_id": "run_b0bd5a3ab475",
84+
"lease_id": "cbx_32c86f65b7c1",
85+
"reviewed_head": "8225b9d13e774d766ec75c224b3960a81cc0ebdc",
86+
"reason": "The fixture's nested login shell reset PATH before resolving the checksum-verified jq binary.",
87+
"fixture_started": true,
88+
"lease_released": true
89+
},
90+
{
91+
"run_id": "run_1b6a7eb1c3b3",
92+
"lease_id": "cbx_c61a1e135fc9",
93+
"reviewed_head": "33badc338a04f4bb30c2a09ad2c701f7c60e4fe6",
94+
"reason": "Two wrap/helper tests launched their own login shells and could not resolve jq from a temporary directory.",
95+
"fixture_assertions_passed": true,
96+
"lease_released": true
97+
},
98+
{
99+
"run_id": "run_1623fae6fdec",
100+
"lease_id": "cbx_b2223e33b8a4",
101+
"reviewed_head": "c87bd96db0bc34a0f7dcad95067973fe1853951a",
102+
"result": "succeeded",
103+
"reason_superseded": "A fresh ClawSweeper review requested a repository-controlled checksum trust root.",
104+
"tests_passed": 4,
105+
"lease_released": true
106+
}
107+
],
108+
"limits": [
109+
"Synthetic filesystem records; no GitHub API calls or credentials were present in the container.",
110+
"The run proves selector/completion and wrap/cycle behavior, not production GitHub latency.",
111+
"The receipt commit changes documentation only; reviewed_head is the exact committed code and proof-harness head exercised by Crabbox."
112+
]
113+
}

0 commit comments

Comments
 (0)