Skip to content

fix: batch canonical transcript archive migration transactions - #161900

Closed
Olli0103 wants to merge 8 commits into
openclaw:mainfrom
Olli0103:fix/archive-batch-161734
Closed

Olli0103 wants to merge 8 commits into
openclaw:mainfrom
Olli0103:fix/archive-batch-161734

Conversation

@Olli0103

@Olli0103 Olli0103 commented Sep 30, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Doctor's canonical transcript archive migration opened two immediate SQLite transactions per archive, including archives whose blobs did not need a rewrite. On installations with hundreds of historical archives, each transaction repeats maintenance and update-admission checks while Doctor has the Gateway stopped. Closes #161734.

Change

Archives are planned in bounded batches of 32. A first SQLite transaction validates and commits changed canonical blobs as unpublished, recording original publication timestamps in a small recovery journal. File repair then runs outside the SQLite write transaction. A second transaction restores publication timestamps only for verified files, advances the cursor, and removes only settled journal receipts; missing-file receipts persist until the file returns. If file repair or cursor commit fails, the rewritten rows remain unpublished. On a later run, journal recovery is independent of the caller's batch cursor and tolerates deleted, inserted, or independently rewritten archive rows without restoring stale timestamps. Directive and media migrations share the recovery key, so either owner first settles a pending published row before applying its own transform. A completed directive cursor still admits pending journal recovery, and a later transform of a pending blob carries its original timestamp forward only when the receipt matches the prior blob hash. Maintenance authority is checked at each write boundary and before atomic file publication. The two per-owner journal key names existed only on earlier unmerged heads of this PR; neither current main nor a release tag contains them, so the shared key has no deployed-key migration to perform.

Evidence

Exact head 81ee4634e87

  • ClawSweeper's in-progress-cursor finding was reproduced on c94bac23586: with an unresolved missing-copy receipt before an archives cursor and another archive still after it, Doctor returned warnings: []. The integration case failed before the fix and now verifies warning-bearing retries, then file repair, publication timestamp restoration, receipt clearance, and no warning.
  • Recovery warnings now reach the in-progress migration result. Identical warnings from journal recovery and the later batch scan are deduplicated; the existing media-migration cases caught that overlap. 48/48 focused tests across four affected files passed on this commit. Core and infra-test typechecks, changed-file type-aware lint/format, and git diff --check passed. No full local suite was run.
  • This commit changes warning propagation only. The copied-existing-Zstd production-helper trace below was measured on 70d446db3a2 and remains earlier-head evidence. Hosted CI and exact-head ClawSweeper review are pending. Published-updater → candidate Doctor validation and acceptance of the durable journal remain maintainer-owned under the existing handoff.

Earlier-head evidence on c94bac23586

  • ClawSweeper's completed-cursor missing-copy finding was reproduced on 70d446db3a2: a pending receipt survived, but Doctor returned warnings: [] while the archive file was absent. Recovery now returns a bounded missing-copy summary and path example through Doctor on every retry. After the copy returns, Doctor repairs it, restores the original publication timestamp, clears the receipt, and returns no warning.
  • The new integration case calls migrateHistoricalTranscriptDirectives with a completed cursor and a missing copy. It verifies two warning-bearing retries followed by file repair and warning clearance. The pre-fix case failed as expected. 46/46 focused tests across four affected files passed on this head; Core and infra-test typechecks, changed-file lint/format, and git diff --check passed. No full local suite was run.
  • This head changes warning propagation, not the previously proved blob rewrite or journal recovery mechanism. The copied existing-Zstd trace below was measured on 70d446db3a2 and remains earlier-head evidence. Hosted CI and exact-head ClawSweeper review are pending. Published-updater → candidate Doctor validation and acceptance of the durable journal remain maintainer-owned; the existing handoff requests both.

Earlier-head evidence on 70d446db3a2

  • The two ClawSweeper P2 cases were reproduced as failing regressions on 3b3dae004763: a complete directive cursor skipped pending recovery, and a second transform of a missing-file pending blob lost its original timestamp. Both pass on this head.
  • 45/45 focused tests across archive batching/recovery, canonical media archives, historical transcript directives, and the new complete-cursor integration test. Core and infra-test typechecks, changed-file lint/format, and git diff --check passed. No full local suite was run.
  • Exact-head production-helper trace on a disposable copy containing eight existing published Zstd archives. One archive file was removed in the copy. Two sequential transforms changed its pending canonical blob while the file stayed absent; SQLite was then closed and reopened, the stale file was repaired, and the original timestamp, blob digest, file bytes, and journal clearance were verified. No live database or serving Gateway was modified:
{"head":"70d446db3a2","copiedExistingZstdArchives":8,"twoTransformsWhileFileMissing":true,"reopenedDatabaseBeforeRecovery":true,"originalPublicationRestored":true,"blobAndFileDigestVerified":true,"journalCleared":true}
  • On the previous head, build-artifacts failed because generated extensions/workboard/openclaw.plugin.json differed from committed bytes. Both real-Gateway UI jobs stopped in prebuilt setup on a dirty checkout before running tests; a large Node shard failed a Gateway subscription assertion, while its infra-storage shard passed. These jobs do not exercise the archive migration diff. Hosted CI for this new head remains pending and is not claimed green.
  • Published-updater → candidate Doctor validation on copied existing state and explicit maintainer acceptance of the durable schema_meta journal remain open. The maintainer handoff requests both. This helper trace does not substitute for the upgrade lane.

Earlier-head evidence on 3b3dae004763

  • 43/43 focused tests passed: archive batching/recovery (15), canonical media archives (13), and historical transcript directives (15). Added regressions for cursor failure, later file-repair failure, failure in batch 2, row deletion/insertion/independent rewrite before retry, and a temporarily missing file across later batches. The missing-file case keeps its receipt until the file returns and restores the original publication timestamp. A cross-migration regression verifies that a sibling transform after a failed batch carries that timestamp forward. The three focused files took 20.22 seconds on this host; the final cross-migration case is included in the 15-test batching file.
  • The 35-archive unchanged fixture observed five immediate transactions (two per batch plus completion) and ten ownership assertions. The previous per-row structure would open 71 transactions.
  • pnpm tsgo:core, changed-file type-aware oxlint, oxfmt, and git diff --check passed. No full local suite was started for this follow-up.
  • Redacted terminal trace from the exact-head production migrateTranscriptDirectiveArchives implementation on copies of eight existing published Zstd archive records. A legacy reaction directive was injected only into each copy. Trials injected a cursor failure, file-repair failure, or a missing file after failure. They verified that rewritten rows remained unpublished with a persisted recovery journal, closed and reopened SQLite, retried, and verified each final blob digest, file byte sequence, and original publication timestamp. The missing-file trial verified that its receipt persisted through an incomplete retry, then recovered after the file returned. No live database or serving Gateway was modified:
{"head":"3b3dae004763","copiedExistingArchives":8,"injectedLegacyDirectiveArchives":8,"productionHistoricalDirectiveTransform":true,"injectedCursorFailure":true,"injectedFileFailure":false,"missingFileReceiptRetainedAndRecovered":false,"failedBatchLeftAllPublicationPending":true,"persistedRecoveryJournal":true,"reopenedDatabaseBeforeRetry":true,"retryRewrittenArchives":0,"finalBlobDigestFileAndPublicationVerified":8,"durationMs":1646}
{"head":"3b3dae004763","copiedExistingArchives":8,"injectedLegacyDirectiveArchives":8,"productionHistoricalDirectiveTransform":true,"injectedCursorFailure":false,"injectedFileFailure":true,"missingFileReceiptRetainedAndRecovered":false,"failedBatchLeftAllPublicationPending":true,"persistedRecoveryJournal":true,"reopenedDatabaseBeforeRetry":true,"retryRewrittenArchives":0,"finalBlobDigestFileAndPublicationVerified":8,"durationMs":1734}
{"head":"3b3dae004763","copiedExistingArchives":8,"injectedLegacyDirectiveArchives":8,"productionHistoricalDirectiveTransform":true,"injectedCursorFailure":false,"injectedFileFailure":false,"missingFileReceiptRetainedAndRecovered":true,"failedBatchLeftAllPublicationPending":true,"persistedRecoveryJournal":true,"reopenedDatabaseBeforeRetry":true,"retryRewrittenArchives":0,"finalBlobDigestFileAndPublicationVerified":8,"durationMs":1864}

This proves the changed migration owner and crash/retry boundaries on copied existing archive data. It is not a complete published-updater or candidate Doctor run. The upstream update-migration.yml lane is restricted to openclaw/openclaw, and this host has no Docker; that release-lane proof and acceptance of the durable schema_meta recovery contract remain explicit maintainer decisions. The earlier head passed pnpm build; on that head, pnpm check passed preflight and typechecks but repository-wide lint hit two untouched max-lines violations. The earlier full pnpm test was stopped after 4h15m and has no aggregate result. The eight-archive performance comparison from the initial head was not rerun on this one. This PR does not address the separate Codex-plugin maintenance-lease refusal.

@clawsweeper

clawsweeper Bot commented Sep 30, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

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

ClawSweeper review complete

ClawSweeper finished reviewing this revision. The review result is being finalized.

View the workflow run.

@clawsweeper clawsweeper Bot added P1 High-priority user-facing bug, regression, or broken workflow. merge-risk: 🚨 session-state 🚨 May lose, corrupt, stale, or mis-associate session, agent, or context state. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. labels Sep 30, 2026
@clawsweeper

clawsweeper Bot commented Sep 30, 2026 •

Copy link
Copy Markdown
Contributor

Thanks for the context here. I swept through the related work, and this is now duplicate or superseded.

Close this PR as superseded: the merged replacement explicitly adopted and credited its batching and recovery work, which current main retains.

Root-cause cluster
Relationship: superseded
Canonical: #165854
Summary: The merged replacement explicitly supersedes this PR and incorporates its batching and recovery foundation.

Members:

Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything.

Canonical path: Retain the released replacement and close this superseded branch with its contributor credit preserved.

So I’m closing this here because the remaining work is already tracked in the canonical issue.

Review details

Best possible solution:

Retain the released replacement and close this superseded branch with its contributor credit preserved.

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

Source inspection confirms current main uses bounded batch transactions instead of the reported per-archive structure; no target code or tests were executed.

Is this the best way to solve the issue?

The existing shared migration owner was the appropriate fix boundary, and the merged replacement already carries that solution and its recovery refinements.

Security review:

Security review cleared: The reviewed change preserves maintenance checks and archive-path containment without adding dependencies or broader authority.

AGENTS.md: found and applied where relevant.

What I checked:

  • Explicit merged replacement: fix: doctor updates recover archives without leaving gateways stopped #165854 explicitly says it supersedes this PR, credits Olli0103's archive batching and recovery foundation, closes the original report, and was merged on October 6, 2026. (292c78d743d0)
  • Current main retains batched migration: The shared migration still plans bounded batches, commits changed blobs as unpublished with recovery receipts, repairs files outside the transaction, and checkpoints publication and cursor progress together; unchanged batches avoid the rewrite transaction. (src/infra/state-migrations.transcript-directives-archives.ts:422, 27a0be4a75d9)
  • Shared recovery owner survives: Current main retains the same namespaced recovery journal, exact-hash and unpublished-row checks, bounded replay, missing-copy receipts, maintenance checks, and atomic file-publication checks. (src/infra/state-migrations.transcript-archive-publication.ts:24, 27a0be4a75d9)
  • Regression contracts retained: Current-main tests cover bounded unchanged-archive checkpointing, lease-loss rollback, failed cursor recovery, second-batch recovery, missing-file receipts, and runtime publication superseding an interrupted receipt. (src/infra/state-migrations.transcript-directives-archives.batching.test.ts:251, 27a0be4a75d9)
  • Contribution and landing provenance: The landed commit records all eight source commit subjects and includes Olli0103 as a co-author; the replacement completed and refined that work rather than leaving a separate batching implementation outstanding. (292c78d743d0)
  • Earlier handoff addressed by replacement: The maintainer-authored replacement records an accepted recovery and rollback contract plus a successful published 2026.9.8 updater to exact-candidate Doctor run on copied state; these address the two outstanding concerns in the previous review for the replacement implementation. (292c78d743d0)

Codex review notes: model internal, reasoning medium; reviewed against 27a0be4a75d9; fix evidence: release v2026.10.5-beta.1, commit 292c78d743d0.

@Olli0103

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Sep 30, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@clawsweeper clawsweeper Bot added the merge-risk: 🚨 availability 🚨 May cause crashes, hangs, restart loops, stalls, or process outages. label Sep 30, 2026
@Olli0103

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Sep 30, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@clawsweeper clawsweeper Bot added proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. and removed rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. labels Sep 30, 2026
@Olli0103

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Sep 30, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@Olli0103

Copy link
Copy Markdown
Contributor Author

Contributor-side recovery findings are addressed on 3b3dae004763. The PR body has the exact-head redacted copied-state traces; 43 focused tests, core typecheck, and changed-file lint/format passed. I did not run the full local suite again.

The remaining release proof needs a maintainer-owned lane: .github/workflows/update-migration.yml is restricted to openclaw/openclaw, this contributor identity has no upstream push permission, and Docker is unavailable on this host. Could a maintainer run or point to the published-updater → candidate Doctor upgrade receipt for this exact head on copied existing state, and decide whether the durable schema_meta recovery journal is an acceptable storage contract? I am not treating the helper trace as that upgrade proof.

@Olli0103

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Sep 30, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@clawsweeper clawsweeper Bot added merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. and removed merge-risk: 🚨 availability 🚨 May cause crashes, hangs, restart loops, stalls, or process outages. labels Sep 30, 2026
@Olli0103

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Sep 30, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@Olli0103

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Sep 30, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@clawsweeper clawsweeper Bot added status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. and removed status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. labels Sep 30, 2026
@roboclaw-bot roboclaw-bot added the clawtributors PR from a clawtributor label Oct 28, 2026
@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. and removed P1 High-priority user-facing bug, regression, or broken workflow. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. merge-risk: 🚨 session-state 🚨 May lose, corrupt, stale, or mis-associate session, agent, or context state. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. labels Oct 28, 2026
@clawsweeper

clawsweeper Bot commented Oct 28, 2026

Copy link
Copy Markdown
Contributor

ClawSweeper recorded closeout evidence for this proposed close.

@clawsweeper clawsweeper Bot closed this Oct 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

clawtributors PR from a clawtributor proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. size: XL

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Doctor archive migration repeats expensive admission checks in two transactions per unchanged archive

2 participants