Skip to content

Commit cafa0af

Browse files
fix(fanout): persist cursors in canonical store
1 parent d199482 commit cafa0af

17 files changed

Lines changed: 644 additions & 94 deletions

‎.github/workflows/proof-nudges.yml‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -205,10 +205,12 @@ jobs:
205205
fi
206206
fi
207207
if [ ${#cursor_publish_args[@]} -gt 0 ]; then
208-
pnpm run repair:publish-main -- \
208+
if ! pnpm run repair:publish-main -- \
209209
--message "chore: update proof handling cursors" \
210210
--rebase-strategy theirs \
211-
"${cursor_publish_args[@]}"
211+
"${cursor_publish_args[@]}"; then
212+
echo "::warning title=Proof cursor publish failed::Proof handling completed; continuing without the best-effort Git cursor update."
213+
fi
212214
fi
213215
214216
- uses: actions/upload-artifact@v7

‎.github/workflows/repair-conflict-self-heal.yml‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@ jobs:
126126
127127
- name: Commit conflict self-heal ledger
128128
if: ${{ always() && ((github.event_name == 'workflow_dispatch' && inputs.execute) || (github.event_name == 'schedule' && vars.CLAWSWEEPER_CONFLICT_SELF_HEAL_EXECUTE == '1')) }}
129+
continue-on-error: true
129130
env:
130131
CLAWSWEEPER_WEBHOOK_SECRET: ${{ secrets.CLAWSWEEPER_WEBHOOK_SECRET }}
131132
run: |

‎.github/workflows/repair-finalize-open-prs.yml‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ jobs:
101101
pnpm run repair:publish-result -- --skip-dashboard
102102
103103
- name: Commit finalizer ledger
104+
continue-on-error: true
104105
env:
105106
CLAWSWEEPER_WEBHOOK_SECRET: ${{ secrets.CLAWSWEEPER_WEBHOOK_SECRET }}
106107
run: |

‎.github/workflows/repair-self-heal.yml‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,7 @@ jobs:
133133
134134
- name: Commit self-heal ledger
135135
if: ${{ always() && ((github.event_name == 'workflow_dispatch' && inputs.execute) || (github.event_name == 'schedule' && vars.CLAWSWEEPER_SELF_HEAL_EXECUTE == '1')) }}
136+
continue-on-error: true
136137
env:
137138
CLAWSWEEPER_WEBHOOK_SECRET: ${{ secrets.CLAWSWEEPER_WEBHOOK_SECRET }}
138139
run: |

‎.github/workflows/spam-scanner.yml‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,7 @@ jobs:
189189
190190
- name: Commit spam scanner audit
191191
if: always()
192+
continue-on-error: true
192193
env:
193194
CLAWSWEEPER_WEBHOOK_SECRET: ${{ secrets.CLAWSWEEPER_WEBHOOK_SECRET }}
194195
run: |

‎.github/workflows/sweep.yml‎

Lines changed: 16 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -2472,20 +2472,13 @@ jobs:
24722472
filter: blob:none
24732473
fetch-depth: 0
24742474

2475-
- name: Create state token
2476-
id: state-token
2477-
uses: ./.github/actions/create-state-token
2478-
with:
2479-
client-id: ${{ env.CLAWSWEEPER_APP_CLIENT_ID }}
2480-
private-key: ${{ secrets.CLAWSWEEPER_APP_PRIVATE_KEY }}
2481-
24822475
- uses: ./.github/actions/setup-state
24832476
with:
24842477
coordinator-url: ${{ vars.CLAWSWEEPER_EXACT_REVIEW_QUEUE_URL || 'https://clawsweeper.openclaw.ai' }}
24852478
records-url: ${{ vars.CLAWSWEEPER_EXACT_REVIEW_QUEUE_URL || 'https://clawsweeper.openclaw.ai' }}
24862479
records-secret: ${{ secrets.CLAWSWEEPER_WEBHOOK_SECRET }}
2480+
hydrate-git-state: "false"
24872481
hydrate-state-blobs: "false"
2488-
token: ${{ steps.state-token.outputs.token }}
24892482

24902483
- uses: ./.github/actions/setup-pnpm
24912484
with:
@@ -2526,6 +2519,7 @@ jobs:
25262519
--repo "$GITHUB_REPOSITORY" \
25272520
--workflow sweep.yml \
25282521
--ref main \
2522+
--cursor-store-url "$REVIEW_COVERAGE_URL" \
25292523
--publish-url "$REVIEW_COVERAGE_URL"
25302524
25312525
- name: Summarize trailing weekly review coverage
@@ -2543,15 +2537,6 @@ jobs:
25432537
REVIEW_COVERAGE_URL: ${{ vars.CLAWSWEEPER_EXACT_REVIEW_QUEUE_URL || 'https://clawsweeper.openclaw.ai' }}
25442538
run: pnpm run target-fanout -- coverage --window-days 7 --publish-url "$REVIEW_COVERAGE_URL" >> "$GITHUB_STEP_SUMMARY"
25452539

2546-
- name: Publish fanout cursor
2547-
env:
2548-
CLAWSWEEPER_WEBHOOK_SECRET: ${{ secrets.CLAWSWEEPER_WEBHOOK_SECRET }}
2549-
run: |
2550-
pnpm run repair:publish-main -- \
2551-
--message "chore: update target fanout cursor" \
2552-
--path results/target-fanout-cursors \
2553-
--rebase-strategy theirs
2554-
25552540
plan:
25562541
name: Plan review candidates
25572542
if: ${{ (github.event_name != 'repository_dispatch' || github.event.action == 'clawsweeper_target_sweep') && !((github.event_name == 'workflow_dispatch' && (github.event.inputs.apply_existing == 'true' || github.event.inputs.audit_dashboard == 'true')) || (github.event_name == 'schedule' && ((github.event.schedule == '3 * * * *' || github.event.schedule == '18 * * * *' || github.event.schedule == '33 * * * *' || github.event.schedule == '48 * * * *' || github.event.schedule == '8,23,38,53 * * * *' || github.event.schedule == '6,21,36,51 * * * *') || (github.event.schedule == '7 */6 * * *' || github.event.schedule == '12 */6 * * *' || github.event.schedule == '17 */6 * * *') || (github.event.schedule == '4/15 * * * *' || github.event.schedule == '41 * * * *' || github.event.schedule == '37 */6 * * *') || github.event.schedule == '13 * * * *'))) && !(github.event_name == 'schedule' && (github.event.schedule == '2/5 * * * *' || github.event.schedule == '22 * * * *') && vars.CLAWSWEEPER_ENABLE_CLAWHUB != '1') && !(github.event_name == 'repository_dispatch' && github.event.client_payload.target_repo == 'openclaw/clawhub' && vars.CLAWSWEEPER_ENABLE_CLAWHUB != '1') }}
@@ -3630,10 +3615,12 @@ jobs:
36303615
--path "records/${target_slug}" \
36313616
--rebase-strategy normal
36323617
echo "records_published=true" >> "$GITHUB_OUTPUT"
3633-
pnpm run repair:publish-main -- \
3618+
if ! pnpm run repair:publish-main -- \
36343619
--message "chore: update sweep status" \
36353620
--path "results/sweep-status/${target_slug}.json" \
3636-
--rebase-strategy theirs
3621+
--rebase-strategy theirs; then
3622+
echo "::warning title=Sweep status publish failed::Review records are canonical; continuing without the best-effort Git dashboard update."
3623+
fi
36373624
36383625
- name: Dispatch reproducible bug implementation candidates
36393626
if: ${{ always() && !cancelled() && steps.commit-review-records.outputs.records_published == 'true' && vars.CLAWSWEEPER_AUTO_IMPLEMENT_ISSUES == '1' && needs.plan.outputs.target_repo == 'openclaw/openclaw' && vars.CLAWSWEEPER_AUTO_IMPLEMENT_REPRO_BUGS == '1' }}
@@ -3878,11 +3865,13 @@ jobs:
38783865
--message "chore: sync selected review comments" \
38793866
--path "records/${target_slug}" \
38803867
--rebase-strategy normal
3881-
pnpm run repair:publish-main -- \
3868+
if ! pnpm run repair:publish-main -- \
38823869
--message "chore: publish selected review comment status" \
38833870
--path apply-report.json \
38843871
--path "results/sweep-status/${target_slug}.json" \
3885-
--rebase-strategy theirs
3872+
--rebase-strategy theirs; then
3873+
echo "::warning title=Selected-comment bookkeeping failed::Canonical comment records are published; continuing without the best-effort Git report update."
3874+
fi
38863875
38873876
- name: Finalize selected review comment action ledger
38883877
id: finalize-selected-review-comment-action-ledger
@@ -4225,6 +4214,7 @@ jobs:
42254214
42264215
- name: Publish failed-review retry state
42274216
if: ${{ always() && vars.CLAWSWEEPER_FAILED_REVIEW_RETRY_ENABLED == '1' && hashFiles('results/failed-review-retries/openclaw-openclaw/*.json') != '' }}
4217+
continue-on-error: true
42284218
env:
42294219
CLAWSWEEPER_WEBHOOK_SECRET: ${{ secrets.CLAWSWEEPER_WEBHOOK_SECRET }}
42304220
run: |
@@ -4408,12 +4398,14 @@ jobs:
44084398
--message "chore: update sweep audit state" \
44094399
--path "records/${target_slug}" \
44104400
--rebase-strategy normal
4411-
pnpm run repair:publish-main -- \
4401+
if ! pnpm run repair:publish-main -- \
44124402
--message "chore: publish sweep audit status" \
44134403
--path README.md \
44144404
--path "results/audit/${target_slug}.json" \
44154405
--path "results/sweep-status/${target_slug}.json" \
4416-
--rebase-strategy theirs
4406+
--rebase-strategy theirs; then
4407+
echo "::warning title=Audit dashboard publish failed::Canonical reconciliation is complete; continuing without the best-effort Git dashboard update."
4408+
fi
44174409
44184410
- name: Refresh state dashboard
44194411
env:
@@ -5275,6 +5267,7 @@ jobs:
52755267
- name: Retry final apply status publication
52765268
id: retry-final-apply-status-publication
52775269
if: ${{ always() && !cancelled() && steps.primary-apply-result.outputs.succeeded == 'true' }}
5270+
continue-on-error: true
52785271
env:
52795272
CLAWSWEEPER_WEBHOOK_SECRET: ${{ secrets.CLAWSWEEPER_WEBHOOK_SECRET }}
52805273
QUEUE_URL: ${{ vars.CLAWSWEEPER_EXACT_REVIEW_QUEUE_URL || 'https://clawsweeper.openclaw.ai' }}

‎dashboard/exact-review-queue.ts‎

Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -462,6 +462,14 @@ const EXACT_REVIEW_QUEUE_ROLLBACK_CLOCK_SKEW_MS = 5 * 60 * 1000;
462462
const EXACT_REVIEW_QUEUE_LEGACY_GENERATION_PREFIX = "__clawsweeper_sql_generation:";
463463
const EXACT_REVIEW_QUEUE_STATE_KEY = "exact-review-queue";
464464
const EXACT_REVIEW_SOURCE_AUTHORITY_SEQUENCE_KEY = "exact-review-source-authority-sequence:v1";
465+
const TARGET_FANOUT_CURSOR_KEY_PREFIX = "target-fanout-cursor:v1:";
466+
type TargetFanoutMode = "hot-intake" | "normal-review" | "audit";
467+
type TargetFanoutCursor = {
468+
mode: TargetFanoutMode;
469+
nextCursor: number;
470+
revision: number;
471+
updatedAt: number;
472+
};
465473
const EXACT_REVIEW_SOURCE_AUTHORITY_RESERVATION_PREFIX =
466474
"exact-review-source-authority-reservation:v1:";
467475
const EXACT_REVIEW_SOURCE_AUTHORITY_RETRY_LIMIT = 16;
@@ -593,6 +601,13 @@ export class ExactReviewQueue {
593601
this.reviewCoverageCache = null;
594602
return json({ ok: true, accepted: true }, 202);
595603
}
604+
const targetFanoutMode = targetFanoutModeFromPath(url.pathname);
605+
if (targetFanoutMode && request.method === "GET") {
606+
return this.readTargetFanoutCursor(targetFanoutMode);
607+
}
608+
if (targetFanoutMode && request.method === "PUT") {
609+
return this.writeTargetFanoutCursor(targetFanoutMode, await request.json().catch(() => null));
610+
}
596611
if (request.method === "POST" && url.pathname === "/source-authority") {
597612
const body = objectValue(await request.json().catch(() => null));
598613
const deliveryId = String(body.delivery_id || "").trim();
@@ -2941,6 +2956,64 @@ export class ExactReviewQueue {
29412956
return new Response("not found", { status: 404 });
29422957
}
29432958

2959+
private readTargetFanoutCursor(mode: TargetFanoutMode) {
2960+
const stored = readTargetFanoutCursor(this.storage.kv.get(targetFanoutCursorKey(mode)), mode);
2961+
if (stored === "invalid") return json({ error: "fanout_cursor_store_invalid" }, 500);
2962+
return json(targetFanoutCursorJson(stored ?? emptyTargetFanoutCursor(mode)));
2963+
}
2964+
2965+
private writeTargetFanoutCursor(mode: TargetFanoutMode, value: unknown) {
2966+
const body = objectValue(value);
2967+
const nextCursor = Number(body.next_cursor);
2968+
const expectedRevision = Number(body.expected_revision);
2969+
if (
2970+
!Number.isSafeInteger(nextCursor) ||
2971+
nextCursor < 0 ||
2972+
!Number.isSafeInteger(expectedRevision) ||
2973+
expectedRevision < 0
2974+
) {
2975+
return json({ error: "invalid_fanout_cursor" }, 400);
2976+
}
2977+
try {
2978+
const result = this.storage.transactionSync(() => {
2979+
const stored = readTargetFanoutCursor(
2980+
this.storage.kv.get(targetFanoutCursorKey(mode)),
2981+
mode,
2982+
);
2983+
if (stored === "invalid") return { kind: "invalid" as const };
2984+
const current = stored ?? emptyTargetFanoutCursor(mode);
2985+
if (current.revision !== expectedRevision) {
2986+
return { kind: "conflict" as const, current };
2987+
}
2988+
if (current.revision >= Number.MAX_SAFE_INTEGER) {
2989+
return { kind: "invalid" as const };
2990+
}
2991+
const next: TargetFanoutCursor = {
2992+
mode,
2993+
nextCursor,
2994+
revision: current.revision + 1,
2995+
updatedAt: Date.now(),
2996+
};
2997+
this.storage.kv.put(targetFanoutCursorKey(mode), next);
2998+
return { kind: "written" as const, cursor: next };
2999+
});
3000+
if (result.kind === "invalid") return json({ error: "fanout_cursor_store_invalid" }, 500);
3001+
if (result.kind === "conflict") {
3002+
return json(
3003+
{
3004+
error: "fanout_cursor_revision_conflict",
3005+
current: targetFanoutCursorJson(result.current),
3006+
},
3007+
409,
3008+
);
3009+
}
3010+
return json(targetFanoutCursorJson(result.cursor), 202);
3011+
} catch (error) {
3012+
console.error(`fanout cursor write failed: ${sanitizedServerError(error)}`);
3013+
return json({ error: "fanout_cursor_store_unavailable" }, 503);
3014+
}
3015+
}
3016+
29443017
async alarm() {
29453018
await this.ready;
29463019
this.cleanupLegacyCompatibilitySync();
@@ -11989,6 +12062,52 @@ function objectValue(value) {
1198912062
return value && typeof value === "object" && !Array.isArray(value) ? value : {};
1199012063
}
1199112064

12065+
function targetFanoutModeFromPath(path: string): TargetFanoutMode | null {
12066+
const match = /^\/cursors\/(hot-intake|normal-review|audit)$/.exec(path);
12067+
return (match?.[1] as TargetFanoutMode | undefined) ?? null;
12068+
}
12069+
12070+
function targetFanoutCursorKey(mode: TargetFanoutMode): string {
12071+
return `${TARGET_FANOUT_CURSOR_KEY_PREFIX}${mode}`;
12072+
}
12073+
12074+
function emptyTargetFanoutCursor(mode: TargetFanoutMode): TargetFanoutCursor {
12075+
return { mode, nextCursor: 0, revision: 0, updatedAt: 0 };
12076+
}
12077+
12078+
function readTargetFanoutCursor(
12079+
value: unknown,
12080+
mode: TargetFanoutMode,
12081+
): TargetFanoutCursor | "invalid" | null {
12082+
if (value === undefined) return null;
12083+
const cursor = objectValue(value);
12084+
const nextCursor = Number(cursor.nextCursor);
12085+
const revision = Number(cursor.revision);
12086+
const updatedAt = Number(cursor.updatedAt);
12087+
if (
12088+
cursor.mode !== mode ||
12089+
!Number.isSafeInteger(nextCursor) ||
12090+
nextCursor < 0 ||
12091+
!Number.isSafeInteger(revision) ||
12092+
revision < 1 ||
12093+
!Number.isSafeInteger(updatedAt) ||
12094+
updatedAt < 1
12095+
) {
12096+
return "invalid";
12097+
}
12098+
return { mode, nextCursor, revision, updatedAt };
12099+
}
12100+
12101+
function targetFanoutCursorJson(cursor: TargetFanoutCursor) {
12102+
return {
12103+
ok: true,
12104+
mode: cursor.mode,
12105+
next_cursor: cursor.nextCursor,
12106+
revision: cursor.revision,
12107+
updated_at: cursor.updatedAt > 0 ? new Date(cursor.updatedAt).toISOString() : null,
12108+
};
12109+
}
12110+
1199212111
function repoName(repo) {
1199312112
return String(repo || "").split("/")[1] || "";
1199412113
}

‎dashboard/worker.ts‎

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -549,6 +549,15 @@ export default {
549549
return authenticatedExactReviewQueueRequest(request, env, "/source-authority");
550550
if (url.pathname === "/internal/review-coverage/inventory" && request.method === "POST")
551551
return authenticatedExactReviewQueueRequest(request, env, "/review-coverage/inventory");
552+
const fanoutCursorPath = /^\/internal\/state\/cursors\/(hot-intake|normal-review|audit)$/.exec(
553+
url.pathname,
554+
);
555+
if (fanoutCursorPath && (request.method === "GET" || request.method === "PUT"))
556+
return authenticatedExactReviewQueueCursorRequest(
557+
request,
558+
env,
559+
url.pathname.slice("/internal/state".length),
560+
);
552561
const canonicalRecordPath =
553562
request.method === "GET"
554563
? /^\/internal\/state\/records\/[^/]+\/(?:items|closed|plans|decision-packets)\/[1-9]\d*$/.exec(
@@ -1768,6 +1777,26 @@ async function authenticatedExactReviewQueueRead(request, env, path: string) {
17681777
);
17691778
}
17701779

1780+
async function authenticatedExactReviewQueueCursorRequest(request, env, path: string) {
1781+
const secret = stringEnv(env.CLAWSWEEPER_WEBHOOK_SECRET);
1782+
if (!secret) return json({ error: "webhook_not_configured" }, 503);
1783+
const body = await request.text();
1784+
const signature = request.headers.get("x-clawsweeper-exact-review-signature") || "";
1785+
if (!(await verifyGithubWebhookSignature({ secret, signature, bodyText: body }))) {
1786+
return json({ error: "invalid_signature" }, 401);
1787+
}
1788+
const init: RequestInit = {
1789+
method: request.method,
1790+
headers: { "content-type": "application/json" },
1791+
};
1792+
if (request.method === "PUT") init.body = body;
1793+
return exactReviewQueueRequest(
1794+
env,
1795+
path,
1796+
new Request(`https://clawsweeper-exact-review-queue${path}`, init),
1797+
);
1798+
}
1799+
17711800
async function authenticatedStateBlobRequest(request, env, operation: StateBlobOperation) {
17721801
const secret = stringEnv(env.CLAWSWEEPER_WEBHOOK_SECRET);
17731802
if (!secret) return json({ error: "webhook_not_configured" }, 503);

‎docs/scheduler.md‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,12 @@ manual workflow inputs. Scheduled fanout uses:
139139
- normal review: `41 * * * *`, 12 target repositories per cursor step
140140
- audit: `37 */6 * * *`, 12 target repositories per cursor step
141141

142+
Each mode's cursor lives in the authenticated ExactReviewQueue Durable Object,
143+
not generated Git state. Reads and writes use a monotonic revision. If the
144+
canonical cursor endpoint is unavailable, fanout warns and continues dispatch
145+
from a safe default; cursor persistence failure after dispatch never fails the
146+
productive lane.
147+
142148
Normal fanout refreshes the same signed live-open inventory consumed by
143149
`GET /api/review-coverage`, skips repositories with no open items, and visits
144150
repositories whose live count exceeds their canonical-record count before

‎docs/state-storage.md‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ operational paths that have not migrated yet.
88
| Logical paths | Canonical owner | Git state status |
99
| --- | --- | --- |
1010
| `records/**` | Durable Object record store with R2 snapshots | Never checked out or written |
11+
| fanout cursor per mode | ExactReviewQueue Durable Object KV | Never checked out or written |
1112
| `ledger/v1/**` | R2 immutable blobs | Never checked out or written |
1213
| `assets/**` | R2 mutable blobs | Never checked out or written |
1314
| `jobs/**` | `clawsweeper-state` `state` branch | Retained until its own migration |
@@ -25,6 +26,19 @@ ordinary fetch/commit/push. The former Git lease refs, atomic multi-ref pushes,
2526
shallow-history deepening, remote-head rebuilds, record reconciliation, and
2627
immutable-ledger scratch branches no longer exist.
2728

29+
Target fanout reads and updates `/internal/state/cursors/<mode>` with the same
30+
HMAC authentication as canonical record operations. Each record carries a
31+
monotonic revision so concurrent writers cannot silently overwrite one another.
32+
Cursor reads and writes are fail-open: an unavailable store emits a prominent
33+
warning, but repository dispatch continues so bookkeeping cannot block fleet
34+
coverage.
35+
36+
Git-backed reports, dashboard status, and post-dispatch cursors are best-effort
37+
after their productive side effect or canonical publication succeeds. Git
38+
publication remains mandatory where it is still the durability fence before a
39+
dispatch, notably `jobs/**` intake and comment-router claims, and in the
40+
dedicated cluster-result publisher whose failure must stay visible for retry.
41+
2842
The former state materializer is retained only as a bounded append-window
2943
compactor. It drains and acknowledges legacy projection rows so the Durable
3044
Object's receipt and capacity windows remain bounded; it does not check out,

0 commit comments

Comments
 (0)