Skip to content

Commit eaeed67

Browse files
authored
fix: restore apply backlog throughput (#925)
1 parent 10494a0 commit eaeed67

7 files changed

Lines changed: 76 additions & 5 deletions

File tree

‎.github/actions/setup-state/action.yml‎

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,10 @@ inputs:
6464
description: Ledger/assets blob transport used by hydrate-state (git or worker). Worker mode reuses records-url and records-secret.
6565
required: false
6666
default: git
67+
hydrate-state-blobs:
68+
description: Hydrate the ledger/assets blob trees. Set false for jobs that only need canonical records and mutable state.
69+
required: false
70+
default: "true"
6771
runs:
6872
using: composite
6973
steps:
@@ -149,7 +153,7 @@ runs:
149153
key: clawsweeper-records-${{ runner.os }}-${{ steps.records-snapshot.outputs.cache-key }}
150154

151155
- name: Restore Worker blob cache
152-
if: ${{ inputs.ledger-source == 'worker' }}
156+
if: ${{ inputs.ledger-source == 'worker' && inputs.hydrate-state-blobs == 'true' }}
153157
uses: actions/cache@v6
154158
with:
155159
path: ${{ inputs.worktree-path }}/.artifacts/worker-blobs-cache
@@ -171,4 +175,15 @@ runs:
171175
CLAWSWEEPER_RECORDS_CACHE_DIR: ${{ inputs.worktree-path }}/.artifacts/worker-records-cache
172176
CLAWSWEEPER_LEDGER_SOURCE: ${{ inputs.ledger-source }}
173177
CLAWSWEEPER_BLOBS_CACHE_DIR: ${{ inputs.worktree-path }}/.artifacts/worker-blobs-cache
174-
run: node "${{ inputs.worktree-path }}/scripts/hydrate-state.ts" --state-dir "${{ inputs.state-path }}" --worktree "${{ inputs.worktree-path }}"
178+
HYDRATE_STATE_BLOBS: ${{ inputs.hydrate-state-blobs }}
179+
run: |
180+
hydrate_args=(
181+
--state-dir "${{ inputs.state-path }}"
182+
--worktree "${{ inputs.worktree-path }}"
183+
)
184+
case "$HYDRATE_STATE_BLOBS" in
185+
true) ;;
186+
false) hydrate_args+=(--skip-state-blobs) ;;
187+
*) echo "hydrate-state-blobs must be true or false" >&2; exit 2 ;;
188+
esac
189+
node "${{ inputs.worktree-path }}/scripts/hydrate-state.ts" "${hydrate_args[@]}"

‎.github/workflows/sweep.yml‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@ env:
220220
OPENROUTER_API_KEY: ${{ vars.CLAWSWEEPER_RUNNER == 'openclaw' && secrets.OPENROUTER_API_KEY || '' }}
221221

222222
concurrency:
223-
group: ${{ (github.event_name == 'schedule' && (github.event.schedule == '4/15 * * * *' || github.event.schedule == '41 * * * *' || github.event.schedule == '37 */6 * * *')) && format('clawsweeper-target-fanout-{0}', github.event.schedule || github.run_id) || github.event_name == 'repository_dispatch' && format('clawsweeper-event-{0}-{1}', github.event.client_payload.target_repo || 'openclaw/openclaw', github.event.client_payload.queue_lease_id || github.event.client_payload.item_number || github.run_id) || format('{0}-{1}', (github.event_name == 'schedule' && github.event.schedule == '13 * * * *') && 'clawsweeper-failed-review-retry' || (github.event_name == 'workflow_dispatch' && github.event.inputs.apply_existing == 'true' && github.event.inputs.apply_sync_comments_only == 'true') && format('clawsweeper-comment-sync-{0}', github.run_id) || (github.event_name == 'schedule' && github.event.schedule == '6,21,36,51 * * * *') && 'clawsweeper-comment-sync' || (github.event_name == 'workflow_dispatch' && github.event.inputs.apply_existing == 'true') && format('clawsweeper-apply-{0}', github.run_id) || (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 * * * *')) && 'clawsweeper-apply' || (github.event_name == 'workflow_dispatch' && (github.event.inputs.item_number != '' || github.event.inputs.item_numbers != '')) && format('clawsweeper-intake-exact-{0}', github.event.inputs.item_number || github.event.inputs.item_numbers) || ((github.event_name == 'workflow_dispatch' && github.event.inputs.hot_intake == 'true') || (github.event_name == 'schedule' && (github.event.schedule == '*/5 * * * *' || github.event.schedule == '2/5 * * * *'))) && 'clawsweeper-intake-v2' || ((github.event_name == 'workflow_dispatch' && github.event.inputs.audit_dashboard == 'true') || (github.event_name == 'schedule' && (github.event.schedule == '7 */6 * * *' || github.event.schedule == '12 */6 * * *' || github.event.schedule == '17 */6 * * *'))) && 'clawsweeper-audit' || 'clawsweeper-review', github.event.inputs.target_repo || github.event.client_payload.target_repo || ((github.event.schedule == '17 */6 * * *') && 'openclaw/clawsweeper' || ((github.event.schedule == '2/5 * * * *' || github.event.schedule == '22 * * * *' || github.event.schedule == '8,23,38,53 * * * *' || github.event.schedule == '12 */6 * * *') && 'openclaw/clawhub' || 'openclaw/openclaw'))) }}
223+
group: ${{ (github.event_name == 'schedule' && (github.event.schedule == '4/15 * * * *' || github.event.schedule == '41 * * * *' || github.event.schedule == '37 */6 * * *')) && format('clawsweeper-target-fanout-{0}', github.event.schedule || github.run_id) || github.event_name == 'repository_dispatch' && format('clawsweeper-event-{0}-{1}', github.event.client_payload.target_repo || 'openclaw/openclaw', github.event.client_payload.queue_lease_id || github.event.client_payload.item_number || github.run_id) || format('{0}-{1}', (github.event_name == 'schedule' && github.event.schedule == '13 * * * *') && 'clawsweeper-failed-review-retry' || (github.event_name == 'workflow_dispatch' && github.event.inputs.apply_existing == 'true' && github.event.inputs.apply_sync_comments_only == 'true') && format('clawsweeper-comment-sync-{0}', github.run_id) || (github.event_name == 'schedule' && github.event.schedule == '6,21,36,51 * * * *') && 'clawsweeper-comment-sync' || (github.event_name == 'workflow_dispatch' && github.event.inputs.apply_existing == 'true') && format('clawsweeper-apply-{0}', github.run_id) || (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 * * * *')) && 'clawsweeper-apply' || (github.event_name == 'workflow_dispatch' && (github.event.inputs.item_number != '' || github.event.inputs.item_numbers != '')) && format('clawsweeper-intake-exact-{0}', github.event.inputs.item_number || github.event.inputs.item_numbers) || (github.event_name == 'workflow_dispatch' && github.event.inputs.apply_existing != 'true') && format('clawsweeper-operator-dispatch-{0}', github.run_id) || ((github.event_name == 'workflow_dispatch' && github.event.inputs.hot_intake == 'true') || (github.event_name == 'schedule' && (github.event.schedule == '*/5 * * * *' || github.event.schedule == '2/5 * * * *'))) && 'clawsweeper-intake-v2' || ((github.event_name == 'workflow_dispatch' && github.event.inputs.audit_dashboard == 'true') || (github.event_name == 'schedule' && (github.event.schedule == '7 */6 * * *' || github.event.schedule == '12 */6 * * *' || github.event.schedule == '17 */6 * * *'))) && 'clawsweeper-audit' || 'clawsweeper-review', github.event.inputs.target_repo || github.event.client_payload.target_repo || ((github.event.schedule == '17 */6 * * *') && 'openclaw/clawsweeper' || ((github.event.schedule == '2/5 * * * *' || github.event.schedule == '22 * * * *' || github.event.schedule == '8,23,38,53 * * * *' || github.event.schedule == '12 */6 * * *') && 'openclaw/clawhub' || 'openclaw/openclaw'))) }}
224224
cancel-in-progress: false
225225

226226
jobs:
@@ -4399,6 +4399,7 @@ jobs:
43994399
records-source: ${{ vars.CLAWSWEEPER_RECORDS_SOURCE || 'worker' }}
44004400
records-url: ${{ vars.CLAWSWEEPER_EXACT_REVIEW_QUEUE_URL || 'https://clawsweeper.openclaw.ai' }}
44014401
records-secret: ${{ secrets.CLAWSWEEPER_WEBHOOK_SECRET }}
4402+
hydrate-state-blobs: "false"
44024403
token: ${{ github.token }}
44034404
persist-credentials: "false"
44044405

@@ -4616,6 +4617,7 @@ jobs:
46164617
records-source: ${{ vars.CLAWSWEEPER_RECORDS_SOURCE || 'worker' }}
46174618
records-url: ${{ vars.CLAWSWEEPER_EXACT_REVIEW_QUEUE_URL || 'https://clawsweeper.openclaw.ai' }}
46184619
records-secret: ${{ secrets.CLAWSWEEPER_WEBHOOK_SECRET }}
4620+
hydrate-state-blobs: "false"
46194621
token: ${{ steps.state-token.outputs.token }}
46204622
filter: blob:none
46214623
fetch-depth: 1
@@ -4767,6 +4769,7 @@ jobs:
47674769
records-source: ${{ vars.CLAWSWEEPER_RECORDS_SOURCE || 'worker' }}
47684770
records-url: ${{ vars.CLAWSWEEPER_EXACT_REVIEW_QUEUE_URL || 'https://clawsweeper.openclaw.ai' }}
47694771
records-secret: ${{ secrets.CLAWSWEEPER_WEBHOOK_SECRET }}
4772+
hydrate-state-blobs: "false"
47704773
token: ${{ steps.state-token.outputs.token }}
47714774

47724775
- uses: ./.github/actions/setup-pnpm

‎CHANGELOG.md‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,8 @@ checkpoint, and status-only commits are intentionally omitted.
141141

142142
### Fixed
143143

144+
- Restored close-backlog throughput by keeping apply jobs off the enormous immutable state-blob hydration path, and isolated operator-dispatched sweeps from background concurrency coalescing.
145+
144146
- Prevented exact-review cancellation storms by sparsely checking out Worker-projected state and keeping completed review-generation leases fenced through final publication.
145147
- Apply now rechecks close proposals previously blocked by protected labels, PR close-exemption labels, or locked conversations, and resumes the normal conservative close gates when the live blocker is gone instead of stranding the verdict permanently; canonical audit output is uploaded before state publication so a later tuple conflict cannot discard the close-verdict inventory.
146148
- Worker-mode hydration now cold-hydrates a slug that has no stored snapshot yet (records created canonically after the R2 seeding, e.g. a repository's first review) by replaying its journal from revision 0, bounded at 2000 records, instead of refusing cutover for the entire fleet; over-bound slugs still produce the named `snapshot_not_found` refusal (`cold_hydration_bound_exceeded`) telling the operator to trigger a snapshot, and snapshot cache key preparation excludes cold slugs instead of disabling the cache.

‎scripts/hydrate-state.ts‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ type Args = {
3232
ledgerSource?: "git" | "worker";
3333
recordsUrl?: string;
3434
recordsRepoSlugs?: string[];
35+
hydrateStateBlobs?: boolean;
3536
};
3637

3738
export async function hydrateState(
@@ -47,6 +48,7 @@ export async function hydrateState(
4748
const recordsSource = args.recordsSource ?? parseRecordsSource(env.CLAWSWEEPER_RECORDS_SOURCE);
4849
const ledgerSource =
4950
args.ledgerSource ?? parseSource(env.CLAWSWEEPER_LEDGER_SOURCE, "CLAWSWEEPER_LEDGER_SOURCE");
51+
const hydrateStateBlobs = args.hydrateStateBlobs ?? true;
5052

5153
if (!existsSync(stateRoot)) throw new Error(`State directory does not exist: ${stateRoot}`);
5254
if (!GENERATED_PATHS.some((relativePath) => existsSync(path.join(stateRoot, relativePath)))) {
@@ -71,7 +73,7 @@ export async function hydrateState(
7173

7274
let blobs: Awaited<ReturnType<typeof materializeStateBlobs>> | undefined;
7375
let ledgerFallback: { reason: string; source: "git" } | undefined;
74-
if (ledgerSource === "worker") {
76+
if (ledgerSource === "worker" && hydrateStateBlobs) {
7577
if (!webhookSecret) {
7678
throw new Error("CLAWSWEEPER_RECORDS_SECRET is required for Worker ledger hydration");
7779
}
@@ -240,6 +242,7 @@ function parseArgs(argv: string[]): Args {
240242
} else if (arg === "--ledger-source") {
241243
parsed.ledgerSource = parseSource(requiredValue(argv, ++index, arg), arg);
242244
} else if (arg === "--records-url") parsed.recordsUrl = requiredValue(argv, ++index, arg);
245+
else if (arg === "--skip-state-blobs") parsed.hydrateStateBlobs = false;
243246
else if (arg === "--records-repo-slugs") {
244247
parsed.recordsRepoSlugs = parseRepoSlugs(requiredValue(argv, ++index, arg)) ?? [];
245248
} else throw new Error(`Unknown argument: ${arg}`);

‎test/state-writer-workflow.test.ts‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,18 @@ test("worker-projected state skips the transported git trees", () => {
136136
assert.match(String((git as WorkflowStep & { if?: string }).if), /records-source != 'worker'/);
137137
assert.match(String((git as WorkflowStep & { if?: string }).if), /ledger-source != 'worker'/);
138138
assert.equal(git.with?.["sparse-checkout"], "${{ inputs.sparse-checkout }}");
139+
140+
const restoreBlobCache = (action.runs?.steps ?? []).find(
141+
(step) => step.name === "Restore Worker blob cache",
142+
) as (WorkflowStep & { if?: string }) | undefined;
143+
assert.ok(restoreBlobCache);
144+
assert.match(String(restoreBlobCache.if), /inputs\.hydrate-state-blobs == 'true'/);
145+
const hydrate = (action.runs?.steps ?? []).find(
146+
(step) => step.name === "Hydrate generated state",
147+
);
148+
assert.ok(hydrate);
149+
assert.equal(hydrate.env?.HYDRATE_STATE_BLOBS, "${{ inputs.hydrate-state-blobs }}");
150+
assert.match(hydrate.run ?? "", /--skip-state-blobs/);
139151
});
140152

141153
test("exact-review direct publication partial-clones generated state", () => {

‎test/sweep-workflow.test.ts‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1210,6 +1210,7 @@ test("apply workflow isolates proof Codex and limits mutation Codex to model-gui
12101210
);
12111211
assert.match(proofJob, /persist-credentials: false/);
12121212
assert.match(proofJob, /persist-credentials: "false"/);
1213+
assert.match(proofJob, /hydrate-state-blobs: "false"/);
12131214
assert.doesNotMatch(proofJob, /Create target write token|Create state token/);
12141215
assert.match(proofJob, /proposed-pr-close-coverage-item-numbers/);
12151216
assert.match(proofJob, /--batch-size 2/);
@@ -1265,6 +1266,7 @@ test("apply workflow isolates proof Codex and limits mutation Codex to model-gui
12651266
);
12661267
assert.match(proofPublisherJob, /path: \.clawsweeper-repair\/action-ledger-proof/);
12671268
assert.match(proofPublisherJob, /Publish apply proof action events/);
1269+
assert.match(proofPublisherJob, /hydrate-state-blobs: "false"/);
12681270
assert.doesNotMatch(proofPublisherJob, /github\.run_attempt/);
12691271

12701272
assert.match(applyJob, /needs: \[apply-proof, publish-apply-proof-action-ledger\]/);
@@ -1281,6 +1283,7 @@ test("apply workflow isolates proof Codex and limits mutation Codex to model-gui
12811283
assert.doesNotMatch(applyJob, /--codex-model|--codex-reasoning-effort/);
12821284
assert.match(applyJob, /Create target write token/);
12831285
assert.match(applyJob, /Create state token/);
1286+
assert.match(applyJob, /hydrate-state-blobs: "false"/);
12841287
assert.match(applyJob, /actions\/download-artifact@v8/);
12851288
assert.match(applyJob, /name: \$\{\{ needs\.apply-proof\.outputs\.artifact_name \}\}/);
12861289
assert.doesNotMatch(applyJob, /action-ledger-proof/);
@@ -2596,6 +2599,10 @@ test("target review queues coalesce background work without delaying exact plann
25962599
);
25972600
assert.match(concurrencyBlock, /format\('clawsweeper-comment-sync-\{0\}', github\.run_id\)/);
25982601
assert.match(concurrencyBlock, /format\('clawsweeper-apply-\{0\}', github\.run_id\)/);
2602+
assert.match(
2603+
concurrencyBlock,
2604+
/github\.event_name == 'workflow_dispatch'.*format\('clawsweeper-operator-dispatch-\{0\}', github\.run_id\)/,
2605+
);
25992606
assert.doesNotMatch(concurrencyBlock, /queue: max/);
26002607
assert.match(planHeader, /group: \$\{\{ format\('clawsweeper-planner-\{0\}'/);
26012608
assert.match(

‎test/worker-state-blobs.test.ts‎

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import assert from "node:assert/strict";
22
import { createHash, createHmac } from "node:crypto";
3-
import { mkdirSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from "node:fs";
3+
import { existsSync, mkdirSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from "node:fs";
44
import { tmpdir } from "node:os";
55
import path from "node:path";
66
import test from "node:test";
@@ -600,6 +600,35 @@ test("hydrate-state CLAWSWEEPER_LEDGER_SOURCE=worker materializes ledger/assets
600600
}
601601
});
602602

603+
test("hydrate-state can skip state blobs for record-only jobs", async () => {
604+
const fixture = createStateFixture();
605+
const target = path.join(fixture.root, "record-only-target");
606+
try {
607+
const result = await hydrateState(
608+
[
609+
"--state-dir",
610+
fixture.stateRoot,
611+
"--worktree",
612+
target,
613+
"--ledger-source",
614+
"worker",
615+
"--skip-state-blobs",
616+
],
617+
{},
618+
async () => {
619+
throw new Error("record-only hydration must not fetch state blobs");
620+
},
621+
);
622+
assert.equal(result.ledgerSource, "worker");
623+
assert.equal(result.blobs, undefined);
624+
assert.equal(readFileSync(path.join(target, "jobs", "fixture.json"), "utf8"), "{}\n");
625+
assert.equal(existsSync(path.join(target, "ledger")), false);
626+
assert.equal(existsSync(path.join(target, "assets")), false);
627+
} finally {
628+
rmSync(fixture.root, { recursive: true, force: true });
629+
}
630+
});
631+
603632
test("hydrate-state refuses the ledger cutover loudly and falls back to git", async () => {
604633
const fixture = createStateFixture();
605634
const errors: string[] = [];

0 commit comments

Comments
 (0)