Skip to content

refactor(ledger): deduplicate shard packing and runtime helpers - #1414

Merged
steipete merged 1 commit into
mainfrom
refactor/deslop-action-ledger
Sep 4, 2026
Merged

steipete merged 1 commit into
mainfrom
refactor/deslop-action-ledger

Conversation

@steipete

@steipete steipete commented Sep 4, 2026

Copy link
Copy Markdown
Contributor

What Problem This Solves

The action-ledger writer and importer separately implemented identical shard packing. Runtime recovery and projection failure recording also repeated existing comparisons and field conversions, while the exclusive file writer carried an unused cleanup mode and identity result.

Why This Change Was Made

Use one shard-packing implementation, the existing SHA-256 helper, and the existing producer/subject conversions. Share repeated recovery predicates and phase comparisons; remove forwarding wrappers, unreachable bookkeeping, a duplicate confidential-identifier check, and one exactly duplicated replay-conflict test. The stronger replay-conflict test remains.

The file writer still leaves cleanup to its existing publication/lock owners. Serialization, filenames, lock records and protocols, timeouts, redaction patterns, and write ordering are unchanged. The runtime test file is unchanged, including the load-tolerant lock-wait assertions and release handshake from #1412.

User Impact

Behavior-neutral; no runtime contract, config, or workflow change.

Evidence

For this behavior-neutral refactor, the behavior proof is the full pnpm run check run plus the targeted suites, supplemented by a pre/post comparison through the real local ledger writer, recovery, finalization, and importer.

pr-behavior-proof contract

  • Claim: the refactor preserves ledger behavior, durable bytes, and publication ordering.
  • Exercised surface: event persistence, interruption recovery, projection-failure recording, producer finalization, deterministic shard packing, and import bindings, plus the existing invariant tests below.
  • Scenario/fixture: deterministic synthetic review/mutation recovery, a rejected synthetic projection, and 1,025 events crossing the shard limit; import all five resulting shards into a fresh trusted root.
  • Command and environment: macOS arm64, Node 26.8.1, pnpm 11.10.0. pnpm run build:all; node scripts/run-node-tests.mjs all -- --test-name-pattern='ledger|shard|projection|producer|lock'; pnpm run check. Before and after the source edits: node /tmp/deslop-ledger-bytes.mjs, followed by cmp /tmp/deslop-ledger-before.json /tmp/deslop-ledger-after.json.
  • Observable result: all 1,061 captured durable paths and file contents, and all 1,061 publication-link targets in sequence, compare byte-for-byte identical. Five shards imported successfully. Both captures have SHA-256 45e96337e5d85fb4cda0234fb2efd04054722a4e5e5ed50e62c13a6e7d5868a4.
  • Artifact or trace: local /tmp/deslop-ledger-bytes.mjs, /tmp/deslop-ledger-before.json, /tmp/deslop-ledger-after.json, /tmp/deslop-ledger-targeted.log, and /tmp/deslop-ledger-check.log; summaries below.
  • Limits: synthetic local filesystem proof, with a fixed clock and mocked projection response. No live GitHub mutation or CrabFleet request. Random transient lock filenames are excluded from the byte capture; lock semantics are covered by the existing tests. Linux-only process tests are platform-skipped on macOS.
Preserved invariant Existing test proving it
Shard filenames, packing, immutability action-ledger.test.ts: “durable shards batch sorted events once per producer job”; “durable shard writers split deterministically within importer event and byte limits”; “a shard identity cannot be reused for a different event set”; “shard paths use the stable run partition instead of event ordering”
Causal ordering and phaseSeq action-ledger.test.ts: “durable shards preserve causal order ahead of source timestamps”; action-ledger-runtime.test.ts: “timeout recovery terminalizes the latest open mutation before its item summary”
Producer and import serialization action-ledger-runtime.test.ts: “concurrent flushes converge on one immutable shard”; “destination import transactions prevent concurrent opposing parent edges”
macOS V1/V2 transition; PID and incarnation-based reclaim action-ledger-runtime.test.ts: “producer locks reclaim fresh dead owners and never evict a live holder by age”; “macOS producer/import locks retain live V1 owners and recover dead V1 owners”; “producer/import locks reclaim current-version PID reuse and reject unknown versions”; “producer and import writers serialize the platform's lock identity version”
NoFollow symlink refusal action-ledger.test.ts: “spool and shard writes reject symlinked parent directories”; action-ledger-runtime.test.ts: “partition markers and import destinations reject symlinked parents”
Confidential identifiers and high-risk credential fields rejected before persistence action-ledger.test.ts: “identity hashing rejects values outside the canonical JSON domain”; “durable privacy guards reject raw text, local paths, secrets, and invalid digests”; action-ledger-runtime.test.ts: “workflow event scopes reject confidential identifiers before persistence or projection”
Mutation observation precedes finalization clawsweeper-action-ledger.test.ts: “apply receipts start per item and persist mutation observation before finalization”

OpenClaw Bay not affected: no dashboard changes.

Scope Added Removed Net LOC
Production 55 205 -150
Tests 0 13 -13
Docs 0 0 0

Validation summaries:

Targeted runner:
ℹ tests 633
ℹ pass 629
ℹ fail 0
ℹ cancelled 0
ℹ skipped 4
ℹ duration_ms 385417.855667

pnpm run check (exit 0):
Changed-coverage suite: 13 passed, 0 failed.
ℹ tests 4843
ℹ pass 4830
ℹ fail 0
ℹ cancelled 0
ℹ skipped 13
ℹ duration_ms 907903.758125
ℹ all files | 85.71% lines | 76.17% branches | 89.59% functions

Independent Codex autoreview: scoped-clean at P0/P1, with no accepted/actionable findings, using autoreview --mode local --base origin/main --max-priority P1. Full output: local /tmp/autoreview-deslop-ledger.md.

Validated source committed as b6c548305 without further source changes after proof or review.

@clawsweeper

clawsweeper Bot commented Sep 4, 2026

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

@steipete
steipete marked this pull request as ready for review September 4, 2026 09:16
@clawsweeper clawsweeper Bot added P3 Low-risk cleanup, docs, polish, ergonomics, or speculative feature. proof: sufficient Contributor real behavior proof is sufficient. rating: 🦞 diamond lobster Very strong PR readiness with only minor maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Sep 4, 2026
@clawsweeper

clawsweeper Bot commented Sep 4, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed September 4, 2026, 5:23 AM ET / 09:23 UTC.

ClawSweeper review

What this changes

The PR consolidates duplicate action-ledger shard packing, hashing, recovery, projection, and file-write helpers while removing redundant tests and dead helper paths.

Merge readiness

✅ Ready for maintainer review

Keep open for normal maintainer review. The introduced refactor is narrow, preserves the ledger’s canonical validation paths, and has detailed after-change durable-output evidence; no actionable regression was found.

Priority: P3
Reviewed head: b6c548305a6ca8af633ccf6df95f68cd711e4257

Review scores

Measure Result What it means
Overall readiness 🦞 diamond lobster (5/6) A focused, behavior-preserving cleanup with strong scoped durable-output evidence and no supported correctness finding.
Proof confidence 🦞 diamond lobster (5/6) Sufficient (logs): The supplied PR-body trace ties the changed production ledger writer, recovery, finalization, deterministic packing, and importer paths to an after-change local run; it reports byte-identical durable output and publication order for 1,061 captured entries, plus successful five-shard import. The stated limits are synthetic local filesystem execution with mocked projection response, not live GitHub or CrabFleet I/O.
Patch quality 🦞 diamond lobster (5/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Verified Sufficient (logs): The supplied PR-body trace ties the changed production ledger writer, recovery, finalization, deterministic packing, and importer paths to an after-change local run; it reports byte-identical durable output and publication order for 1,061 captured entries, plus successful five-shard import. The stated limits are synthetic local filesystem execution with mocked projection response, not live GitHub or CrabFleet I/O.
Evidence reviewed 5 items Complete introduced change: The verified merge-base-to-head diff changes four ledger implementation/test files; the verified test merge has the pinned main parent followed by this exact head.
Shared shard packing preserves the canonical algorithm: Both writer and importer now call the same splitter; it retains the existing byte and event-limit checks before deterministic shard output.
Privacy validation remains in the surviving helper: The removed attribute-level confidential-identifier condition was redundant because machineText still rejects confidential identifiers before accepting machine-readable attribute text.
Findings None None.
Security None None.

How this fits together

The action ledger records review and apply activity as durable local event files. Recovery and import code consume those files to resume workflows safely and optionally project outcomes to CrabFleet.

flowchart LR
  Workflow[Workflow action] --> Ledger[Action ledger writer]
  Ledger --> Spool[Durable event files]
  Spool --> Recovery[Recovery and finalization]
  Spool --> Import[Shard import validation]
  Ledger --> Projection[CrabFleet projection]
  Recovery --> Outcome[Workflow outcome]
Loading

Before merge

None.

Agent review details

Security

None.

Review metrics

Metric Value Why it matters
Code reduction production +55/-205, tests +0/-13 The four-file refactor is materially smaller while retaining the stronger duplicate-conflict coverage.
Durable-output comparison 1,061 paths/contents and 1,061 publication targets compared The supplied proof directly covers the refactor’s stated byte and publication-order preservation claim.

Technical review

Best possible solution:

Land the canonical helper consolidation while retaining the existing deterministic shard, durable-file, privacy, and recovery regression coverage.

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

Not applicable: this is a behavior-preserving refactor, and the relevant assessment is whether the after-change ledger exercise preserves durable behavior.

Is this the best way to solve the issue?

Yes: consolidating exact duplicate helpers into the existing canonical implementations reduces drift without changing the durable format or workflow contract.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against 41caa32f64b5.

Labels

Label changes:

  • add P3: This is a behavior-neutral internal cleanup with no intended user-facing contract change.
  • add proof: sufficient: Contributor real behavior proof is sufficient. The supplied PR-body trace ties the changed production ledger writer, recovery, finalization, deterministic packing, and importer paths to an after-change local run; it reports byte-identical durable output and publication order for 1,061 captured entries, plus successful five-shard import. The stated limits are synthetic local filesystem execution with mocked projection response, not live GitHub or CrabFleet I/O.
  • add rating: 🦞 diamond lobster: Overall readiness is 🦞 diamond lobster; proof is 🦞 diamond lobster and patch quality is 🦞 diamond lobster.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (logs): The supplied PR-body trace ties the changed production ledger writer, recovery, finalization, deterministic packing, and importer paths to an after-change local run; it reports byte-identical durable output and publication order for 1,061 captured entries, plus successful five-shard import. The stated limits are synthetic local filesystem execution with mocked projection response, not live GitHub or CrabFleet I/O.

Label justifications:

  • P3: This is a behavior-neutral internal cleanup with no intended user-facing contract change.
  • rating: 🦞 diamond lobster: Overall readiness is 🦞 diamond lobster; proof is 🦞 diamond lobster and patch quality is 🦞 diamond lobster.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (logs): The supplied PR-body trace ties the changed production ledger writer, recovery, finalization, deterministic packing, and importer paths to an after-change local run; it reports byte-identical durable output and publication order for 1,061 captured entries, plus successful five-shard import. The stated limits are synthetic local filesystem execution with mocked projection response, not live GitHub or CrabFleet I/O.
  • proof: sufficient: Contributor real behavior proof is sufficient. The supplied PR-body trace ties the changed production ledger writer, recovery, finalization, deterministic packing, and importer paths to an after-change local run; it reports byte-identical durable output and publication order for 1,061 captured entries, plus successful five-shard import. The stated limits are synthetic local filesystem execution with mocked projection response, not live GitHub or CrabFleet I/O.

Evidence

What I checked:

  • Complete introduced change: The verified merge-base-to-head diff changes four ledger implementation/test files; the verified test merge has the pinned main parent followed by this exact head. (src/action-ledger-runtime.ts:876, b6c548305a6c)
  • Shared shard packing preserves the canonical algorithm: Both writer and importer now call the same splitter; it retains the existing byte and event-limit checks before deterministic shard output. (src/action-ledger.ts:1570, b6c548305a6c)
  • Privacy validation remains in the surviving helper: The removed attribute-level confidential-identifier condition was redundant because machineText still rejects confidential identifiers before accepting machine-readable attribute text. (src/action-ledger.ts:2211, b6c548305a6c)
  • Existing hash helper provenance: The shared SHA-256 helper used by this refactor was introduced on main by the prior core refactor; its exact added source line remains present in this checkout. (src/content-hash.ts:3, c75901a57a96)
  • After-change behavior proof: The supplied PR body records a real local ledger writer, recovery, finalization, and importer exercise: 1,061 durable paths/contents and publication targets compared byte-for-byte with the baseline, and five shards imported successfully. (b6c548305a6c)

Likely related people:

  • Peter Steinberger: Raw commit c75901a adds src/content-hash.ts:3 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: c75901a57a96; files: src/content-hash.ts)
  • Vincent Koc: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)

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.

@steipete

steipete commented Sep 4, 2026

Copy link
Copy Markdown
Contributor Author

Landing: CI green on exact head b6c5483, ClawSweeper review reports real behavior verified (after-change local run with byte-identical durable output and publication order across 1,061 captured files) and no findings. Maintainer review confirmed the removed confidential-identifier check in attribute normalization is already enforced inside machineText, the shard packer is byte-identical to the deleted copy, and the deleted replay test duplicated an existing one. Behavior-neutral, production -150 LOC.

@steipete
steipete merged commit 934d526 into main Sep 4, 2026
21 of 23 checks passed
@steipete
steipete deleted the refactor/deslop-action-ledger branch September 4, 2026 10:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

P3 Low-risk cleanup, docs, polish, ergonomics, or speculative feature. proof: sufficient Contributor real behavior proof is sufficient. rating: 🦞 diamond lobster Very strong PR readiness with only minor 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