Skip to content

fix(state): bound record export reconstruction - #1253

Merged
vincentkoc merged 2 commits into
mainfrom
fix/bounded-record-export
Aug 27, 2026
Merged

vincentkoc merged 2 commits into
mainfrom
fix/bounded-record-export

Conversation

@vincentkoc

@vincentkoc vincentkoc commented Aug 27, 2026 •

Copy link
Copy Markdown
Member

What Problem This Solves

Resolves a problem where a signed records export could select a large page and reconstruct every candidate before enforcing the serialized response limit, allowing reconstruction work to grow with the requested page.

Why This Change Was Made

ExactReviewDirectPublicationStore now owns metadata-first export selection. It joins authoritative canonical/backfill byte metadata, validates it fail-closed, and applies explicit source-byte and record-work budgets before reconstructing content while preserving the existing serialized response bound and deterministic cursor semantics.

No schema, retry, CPU, snapshot, R2, or public request-shape changes are included.

User Impact

Operators can paginate record exports with bounded per-response reconstruction work. Oversized first records still make cursor progress, and repeated pages retain exact record ordering with no gaps or duplicates.

OpenClaw Bay Impact

Bay is unaffected. The change is limited to the signed internal record-export route and its durable-object store; no Bay query, status, telemetry, or dashboard contract changes.

Documentation Impact

No documentation update is required. The internal route shape and existing export contract remain unchanged; this patch hardens implementation limits only.

Release-note context: no changelog entry is needed because this is internal operational hardening with no user-facing API or configuration change.

Evidence

Real Behavior Proof

  • Claim: a signed /internal/state/records/export call cannot reconstruct more than the configured source-byte and record-work budgets, advances its cursor, and repeated calls materialize the exact fixture.
  • Surface: real local Worker route plus SQLite-backed ExactReviewQueue durable object.
  • Scenario: mixed inline/chunked canonical and backfill records crossing both limits, plus an oversized first serialized record.
  • Command: RECORD_EXPORT_PROOF_PATH="$PWD/.artifacts/bounded-record-export/worker-do-proof.json" node --test --test-concurrency=1 test/record-export-bounds.test.ts
  • Observable: pages reconstructed 50/6/1/1 records with source bytes 51200/1605120/1600000/1600000; every page remained within the 50-record and 2 MiB source budgets. The oversized first record returned alone, advanced to cursor 1, and the final path/digest manifest matched exactly.
  • Artifact: redacted local trace .artifacts/bounded-record-export/worker-do-proof.json.
  • Limits: controlled local fixture only; no production Cloudflare CPU claim.

Verification

  • Focused route/request suite: 115/115 passed.
  • Behavior proof suite: 4/4 passed.
  • Canonical commit export regression: 1/1 passed.
  • Dashboard TypeScript build: passed.
  • Changed-file lint and formatting: passed.
  • git diff --check: passed.
  • Pre-commit autoreview: clean.
  • Committed-range autoreview against origin/main: clean.
  • Repo-native committed-range review: patch correct, security cleared, proof sufficient, no findings.
  • pnpm run check: static checks, docs, formatting, builds, lint, and coverage suites ran; the command exited nonzero on nine unrelated host/toolchain fixtures: one tmux window-lifecycle failure, seven target-validation failures resolving fixture [email protected] or @pnpm/[email protected] from the isolated package mirror, and one Git-hook callback assertion. The changed export suites remain green.

Finding Disposition

Added route-level regression coverage for the two metadata branches missing from the original proof: a historical items record whose authoritative content exists only in the backfill table, and a canonical tombstone with no backing content row. The test proves exact content/digest/revision/deletion output, cursor order, one backfill reconstruction for the live record, and zero reconstruction for the tombstone. No production or harness change was needed.

Root Cause And Ownership

The export owner applied only a post-reconstruction serialized byte limit. Candidate selection lacked authoritative logical byte metadata and a bounded reconstruction-work decision, so the route could perform unbounded content reads before deciding where to stop.

The canonical fix keeps selection in ExactReviewDirectPublicationStore, uses the existing export index plus canonical/backfill metadata tables, and passes queue-owned hard limits explicitly.

LOC

  • Production: +63/-9, net +54.
  • Tests and test support: +505/-0.
  • Follow-up test commit: +93/-8, net +85.

Rebase Repair Verification

  • Frozen base: 4a6f9ecb165edc400996fb3bb58c1a56d6133bd2.
  • Current signed head: c58a8339ca860f72c541322599abda67b73d0ecf.
  • Root cause: current main sanitizes rejected ExactReviewQueue calls into JSON HTTP 500 responses at the Worker boundary; the rebased invalid-metadata test still expected a direct rejection.
  • Repair: test-only assertions now verify status 500, application/json; charset=utf-8, a string error, and the affected record identity. No production or harness code changed.
  • Red baseline: record-export behavior proof 3/4; invalid-metadata coverage failed on the new Worker response contract.
  • Green proof: record-export behavior proof 4/4; paired record-export and Durable Object error suite 8/8; route/request/canonical matrix 115/115; canonical export regression 1/1.
  • Proof artifact: .artifacts/bounded-record-export/rebased-worker-do-proof.json records page counts 50/6/1/1, cursor progress, oversized-first progress, and exact manifest parity.
  • Formatting and git diff --check: passed. Pre-amend and committed-range reviews: clean.
  • pnpm run check: static checks, builds, formatting, and lint passed; the full suite reached 3,734/3,752 passing with 9 skipped and the same 9 unrelated host/tooling failures already documented: one tmux proof fixture, seven isolated pnpm-mirror fixtures, and one signing-callback fixture.
  • LOC: production remains +63/-9; tests and test support are +521/-0. This repair adds +26/-10 in test/record-export-bounds.test.ts only.
  • OpenClaw Bay remains unaffected.

@vincentkoc vincentkoc self-assigned this Aug 27, 2026
@clawsweeper

clawsweeper Bot commented Aug 27, 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 P2 Normal priority bug or improvement with limited blast radius. 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. labels Aug 27, 2026
@clawsweeper

clawsweeper Bot commented Aug 27, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed August 26, 2026, 10:27 PM ET / August 27, 2026, 02:27 UTC.

ClawSweeper review

What this changes

The PR selects export rows by authoritative byte metadata before reconstructing content, caps each response at 50 reconstructed records and 2 MiB of source content, and adds route-level regression coverage.

Merge readiness

⚠️ Ready for maintainer review - 1 item remains

Keep open for maintainer judgment: this is a MEMBER-authored PR, which repository policy treats as non-closeable. Source review finds the metadata-first cap preserves the existing cursor-based export flow and adds focused coverage without a concrete patch defect.

Priority: P2
Reviewed head: c58a8339ca860f72c541322599abda67b73d0ecf

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) The patch is focused, source-supported, and accompanied by targeted route coverage; it awaits normal maintainer review.
Proof confidence 🌊 off-meta tidepool Not applicable: The external-contributor proof gate does not apply to this MEMBER-authored PR; its body nevertheless records a signed Worker/Durable Object route trace and bounded-page results.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: The external-contributor proof gate does not apply to this MEMBER-authored PR; its body nevertheless records a signed Worker/Durable Object route trace and bounded-page results.
Evidence reviewed 5 items Baseline behavior: Current main's export implementation reconstructs every row selected by the requested page before applying its serialized-response byte cap.
Bounded selection: The PR head joins canonical/backfill byte metadata, validates it, selects within record and source-byte budgets, then reconstructs only selected rows.
Cursor compatibility: The repository hydration client follows nextCursor until null and rejects a non-advancing cursor, so shortened bounded pages remain consumable.
Findings None None.
Security None None.

Live Verification

Command: node --test --test-concurrency=1 test/record-export-bounds.test.ts

Result: FAIL (failed) — step 1 run node --test --test-concurrency=1 test/record-export-bounds.test.ts: previous terminal command was still running after 30 seconds: "node --test --test-concurrency=1 test/record-export-bounds.test.ts"

node:internal/modules/esm/resolve:271
    throw new ERR_MODULE_NOT_FOUND(
          ^

Error [ERR_MODULE_NOT_FOUND]: Cannot find module '/tmp/clawsweeper-live-proof-1253-uzNvRq/target/dist/repair/canonical-record-baseline.js' imported from /tmp/cl
awsweeper-live-proof-1253-uzNvRq/target/test/dashboard-worker-harness.ts
    at finalizeResolution (node:internal/modules/esm/resolve:271:11)
    at moduleResolve (node:internal/modules/esm/resolve:865:10)
    at defaultResolve (node:internal/modules/esm/resolve:992:11)
    at #cachedDefaultResolve (node:internal/modules/esm/loader:701:20)
    at #resolveAndMaybeBlockOnLoaderThread (node:internal/modules/esm/loader:721:38)
    at ModuleLoader.resolveSync (node:internal/modules/esm/loader:759:56)
    at #resolve (node:internal/modules/esm/loader:683:17)
    at ModuleLoader.getOrCreateModuleJob (node:internal/modules/esm/loader:603:35)
    at ModuleJob.syncLink (node:internal/modules/esm/module_job:163:33)
    at ModuleJob.link (node:internal/modules/esm/module_job:253:17) {
  code: 'ERR_MODULE_NOT_FOUND',
  url: 'file:///tmp/clawsweeper-live-proof-1253-uzNvRq/target/dist/repair/canonical-record-baseline.js'
}

Node.js v24.19.0
✖ test/record-export-bounds.test.ts (175.083888ms)
ℹ tests 1
ℹ suites 0
ℹ pass 0
ℹ fail 1
ℹ cancelled 0
ℹ skipped 0
ℹ todo 0
ℹ duration_ms 180.112158

✖ failing tests:

test at test/record-export-bounds.test.ts:1:1
✖ test/record-export-bounds.test.ts (175.083888ms)
  'test failed'

Assertions:

  • FAIL expect_output: pass

How this fits together

The signed internal state-export route reads canonical review records from the Worker Durable Object and returns paginated content to the state hydration client. This change inserts budgeted metadata selection before content reconstruction while retaining the existing response cursor.

flowchart LR
A[Signed export request] --> B[Export index]
B --> C[Canonical or backfill metadata]
C --> D[Source-byte and record budget]
D --> E[Content reconstruction]
E --> F[Cursor-based export response]
Loading

Before merge

  • Complete next step (P2) - This MEMBER-authored PR requires routine maintainer review; no discrete automated repair is identified.
Agent review details

Security

None.

Review metrics

Metric Value Why it matters
Production and test delta production +63/-9; tests +521/-0 The small production hardening is accompanied by targeted route and metadata-branch coverage.

Technical review

Best possible solution:

Retain metadata-first selection in the direct-publication store so every export page has bounded reconstruction work while the existing nextCursor pagination contract continues to deliver the full journal.

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

Yes, source-reproducible: current main reconstructs rows before testing the response-size boundary, while the PR's focused route fixture exercises the capped selection and cursor progression.

Is this the best way to solve the issue?

Yes. Selecting validated authoritative byte metadata before reading content is the narrowest way to bound reconstruction while preserving the established nextCursor protocol.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against 4a6f9ecb165e.

Labels

Label changes:

  • remove proof: sufficient: Current real behavior proof status is not_applicable, not sufficient.

Label justifications:

  • P2: This is bounded operational hardening for an internal export path with limited operator-facing blast radius.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🌊 off-meta tidepool and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: The external-contributor proof gate does not apply to this MEMBER-authored PR; its body nevertheless records a signed Worker/Durable Object route trace and bounded-page results.

Evidence

What I checked:

Likely related people:

  • Yuval Dinodia: Authored the current-main dashboard queue normalization commit; the locally available history establishes adjacent ownership but not a complete earlier export-feature trail. (role: recent adjacent contributor; confidence: low; commits: 4a6f9ecb165e; files: dashboard/exact-review-queue.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 (3 earlier review cycles)
  • reviewed 2026-08-27T01:02:07.896Z sha 876309d :: needs maintainer review before merge. :: none
  • reviewed 2026-08-27T01:20:33.926Z sha d261ede :: needs maintainer review before merge. :: none
  • reviewed 2026-08-27T01:36:54.606Z sha d261ede :: needs maintainer review before merge. :: none

@clawsweeper clawsweeper Bot removed the proof: sufficient Contributor real behavior proof is sufficient. label Aug 27, 2026
@vincentkoc
vincentkoc marked this pull request as ready for review August 27, 2026 01:33
@clawsweeper clawsweeper Bot added the proof: sufficient Contributor real behavior proof is sufficient. label Aug 27, 2026
@vincentkoc
vincentkoc force-pushed the fix/bounded-record-export branch from d261ede to c58a833 Compare August 27, 2026 02:22
@clawsweeper clawsweeper Bot removed the proof: sufficient Contributor real behavior proof is sufficient. label Aug 27, 2026
@vincentkoc
vincentkoc merged commit 387cf82 into main Aug 27, 2026
13 checks passed
@vincentkoc
vincentkoc deleted the fix/bounded-record-export branch August 27, 2026 03:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

P2 Normal priority bug or improvement with limited blast radius. 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