Skip to content

Commit 3f3c9cf

Browse files
authored
feat(state): Worker-backed record hydration with R2 snapshots and journal deltas (state-repo retirement, phase 2) (#874)
canonical records now export via snapshot+journal (per-repo gzip snapshot streamed to R2 via multipart with keep-two pruning and authenticated trigger/latest/range endpoints — 32MiB range proxying since R2 bindings cannot presign; measured: 603MB/34,459-file openclaw-openclaw tree → 124.9MiB snapshot, typical deltas 44-87KiB); hydrate-state gains CLAWSWEEPER_RECORDS_SOURCE=worker mode (Actions-cached snapshot + since-revision deltas, byte-identical on-disk layout, loud fail-closed git fallback when the snapshot store is unavailable); cursor-resumable git→canon backfill workflow (workflow_dispatch per repo); tree-based parity verifier as the cutover gate. Defaults stay git; R2 bucket provisioning (clawsweeper-state-snapshots) is the one pending manual step.
1 parent 439f425 commit 3f3c9cf

17 files changed

Lines changed: 3058 additions & 33 deletions

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

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,22 @@ inputs:
4444
description: Durable state-writer scheduling class
4545
required: false
4646
default: ordinary
47+
records-source:
48+
description: Record transport used by hydrate-state (git or worker).
49+
required: false
50+
default: git
51+
records-url:
52+
description: Worker base URL used when records-source is worker.
53+
required: false
54+
default: https://clawsweeper.openclaw.ai
55+
records-repo-slugs:
56+
description: Optional comma/newline-separated record repository slugs; defaults to state checkout directories.
57+
required: false
58+
default: ""
59+
records-secret:
60+
description: HMAC secret used only when records-source is worker.
61+
required: false
62+
default: ""
4763
runs:
4864
using: composite
4965
steps:
@@ -85,8 +101,31 @@ runs:
85101
with:
86102
node-version: ${{ inputs.node-version }}
87103

104+
- name: Resolve Worker record snapshot cache key
105+
id: records-snapshot
106+
if: ${{ inputs.records-source == 'worker' }}
107+
shell: bash
108+
env:
109+
CLAWSWEEPER_STATE_DIR: ${{ inputs.state-path }}
110+
CLAWSWEEPER_RECORDS_URL: ${{ inputs.records-url }}
111+
CLAWSWEEPER_RECORDS_REPO_SLUGS: ${{ inputs.records-repo-slugs }}
112+
CLAWSWEEPER_RECORDS_SECRET: ${{ inputs.records-secret }}
113+
run: node "${{ inputs.worktree-path }}/scripts/prepare-worker-record-cache.ts"
114+
115+
- name: Restore Worker record snapshot
116+
if: ${{ inputs.records-source == 'worker' && steps.records-snapshot.outputs.available == 'true' }}
117+
uses: actions/cache@v6
118+
with:
119+
path: ${{ inputs.worktree-path }}/.artifacts/worker-records-cache
120+
key: clawsweeper-records-${{ runner.os }}-${{ steps.records-snapshot.outputs.cache-key }}
121+
88122
- name: Hydrate generated state
89123
shell: bash
90124
env:
91125
CLAWSWEEPER_STATE_DIR: ${{ inputs.state-path }}
126+
CLAWSWEEPER_RECORDS_SOURCE: ${{ inputs.records-source }}
127+
CLAWSWEEPER_RECORDS_URL: ${{ inputs.records-url }}
128+
CLAWSWEEPER_RECORDS_REPO_SLUGS: ${{ inputs.records-repo-slugs }}
129+
CLAWSWEEPER_RECORDS_SECRET: ${{ inputs.records-secret }}
130+
CLAWSWEEPER_RECORDS_CACHE_DIR: ${{ inputs.worktree-path }}/.artifacts/worker-records-cache
92131
run: node "${{ inputs.worktree-path }}/scripts/hydrate-state.ts" --state-dir "${{ inputs.state-path }}" --worktree "${{ inputs.worktree-path }}"
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
name: Backfill Worker records
2+
3+
on:
4+
workflow_dispatch:
5+
inputs:
6+
target_repo:
7+
description: Repository whose state records should be seeded (owner/name).
8+
required: true
9+
type: string
10+
default: openclaw/openclaw
11+
cursor:
12+
description: Zero-based batch cursor from a prior interrupted run.
13+
required: false
14+
type: number
15+
default: 0
16+
max_batches:
17+
description: Optional bounded batch count; 0 processes the remaining batches.
18+
required: false
19+
type: number
20+
default: 0
21+
22+
concurrency:
23+
group: backfill-worker-records-${{ inputs.target_repo }}
24+
cancel-in-progress: false
25+
26+
permissions:
27+
contents: read
28+
29+
env:
30+
CLAWSWEEPER_APP_CLIENT_ID: Iv23liOECG0slfuhz093
31+
32+
jobs:
33+
backfill:
34+
runs-on: ubuntu-latest
35+
timeout-minutes: 30
36+
steps:
37+
- uses: actions/checkout@v7
38+
with:
39+
ref: main
40+
filter: blob:none
41+
fetch-depth: 1
42+
persist-credentials: false
43+
44+
- name: Resolve target record slug
45+
id: target
46+
env:
47+
TARGET_REPO: ${{ inputs.target_repo }}
48+
run: |
49+
if ! [[ "$TARGET_REPO" =~ ^[A-Za-z0-9_.-]+/[A-Za-z0-9_.-]+$ ]]; then
50+
echo "target_repo must be owner/name" >&2
51+
exit 2
52+
fi
53+
echo "slug=${TARGET_REPO//\//-}" >> "$GITHUB_OUTPUT"
54+
55+
- name: Create state token
56+
id: state-token
57+
uses: ./.github/actions/create-state-token
58+
with:
59+
client-id: ${{ env.CLAWSWEEPER_APP_CLIENT_ID }}
60+
private-key: ${{ secrets.CLAWSWEEPER_APP_PRIVATE_KEY }}
61+
62+
- uses: ./.github/actions/setup-state
63+
with:
64+
token: ${{ steps.state-token.outputs.token }}
65+
fetch-depth: 1
66+
sparse-checkout: records/${{ steps.target.outputs.slug }}
67+
persist-credentials: "false"
68+
records-source: git
69+
coordinator-enabled: ${{ vars.CLAWSWEEPER_STATE_COORDINATOR_ENABLED || 'false' }}
70+
coordinator-url: ${{ vars.CLAWSWEEPER_EXACT_REVIEW_QUEUE_URL || 'https://clawsweeper.openclaw.ai' }}
71+
72+
- name: Seed revision-zero Worker records
73+
env:
74+
CLAWSWEEPER_WEBHOOK_SECRET: ${{ secrets.CLAWSWEEPER_WEBHOOK_SECRET }}
75+
CLAWSWEEPER_RECORDS_URL: ${{ vars.CLAWSWEEPER_EXACT_REVIEW_QUEUE_URL || 'https://clawsweeper.openclaw.ai' }}
76+
BACKFILL_CURSOR: ${{ inputs.cursor }}
77+
BACKFILL_MAX_BATCHES: ${{ inputs.max_batches }}
78+
TARGET_SLUG: ${{ steps.target.outputs.slug }}
79+
run: |
80+
args=(--state-dir clawsweeper-state --repo-slug "$TARGET_SLUG" --cursor "$BACKFILL_CURSOR")
81+
if (( BACKFILL_MAX_BATCHES > 0 )); then
82+
args+=(--max-batches "$BACKFILL_MAX_BATCHES")
83+
fi
84+
node scripts/backfill-worker-records.ts "${args[@]}"

0 commit comments

Comments
 (0)