Skip to content

fix(doctor): preserve large media migration timestamps - #132099

Merged
sjf-oa merged 4 commits into
mainfrom
sjf/fix-media-migration-unsafe-created-at
Aug 29, 2026
Merged

sjf-oa merged 4 commits into
mainfrom
sjf/fix-media-migration-unsafe-created-at

Conversation

@sjf-oa

@sjf-oa sjf-oa commented Aug 28, 2026 •

Copy link
Copy Markdown
Contributor

Why

Doctor must migrate persisted databases containing valid SQLite integers even when aggregate timestamp fingerprints exceed JavaScript's safe integer range. Without preserving the aggregate exactly, doctor --fix exits before committing the schema migration.

Failure scenario

During a schema 16 to 18 media-persistence migration, Doctor reads SUM(created_at) as part of its before/after source-drift fingerprint. A database with enough valid timestamp rows can produce an aggregate larger than Number.MAX_SAFE_INTEGER. Node SQLite then throws before the migration transaction can commit:

RangeError: Value is too large to be represented as a JavaScript number: 26433743215323619

The individual timestamps remain valid SQLite integers; only their aggregate exceeds JavaScript's safe integer range.

What changed

  • return the SUM(created_at) migration fingerprint as SQLite text
  • compare the exact text value before and after migration
  • leave the remaining bounded count fingerprints unchanged

Validation

  • oxfmt --check src/infra/state-migrations.media-persistence.ts
  • no tests added

@clawsweeper

clawsweeper Bot commented Aug 28, 2026

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

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

@openclaw-barnacle openclaw-barnacle Bot added size: XS maintainer Maintainer-authored PR labels Aug 28, 2026
@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. 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. labels Aug 28, 2026
@clawsweeper

clawsweeper Bot commented Aug 28, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed August 28, 2026, 6:16 PM ET / 22:16 UTC.

ClawSweeper review

What this changes

The PR reads the media-migration aggregate timestamp fingerprint as exact SQLite text and adds a regression test for valid rows whose sum exceeds JavaScript’s safe integer range.

Regression provenance

Possible regression — probable (reproduction; reviewed change). No predecessor PR is attributed.

Merge readiness

⚠️ Ready for maintainer review - 1 item remains

Keep open for standard maintainer review: the requested regression coverage is now present and the narrow repair is source-proven, but it is not on current main or in the latest stable release.

Priority: P2
Reviewed head: 58e25e9d790b0d041e45126edcfa8399f1f0132e

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused owner-bound fix with a regression test now addresses the prior review finding.
Proof confidence 🌊 off-meta tidepool Not applicable: This maintainer PR is exempt from the external-contributor proof gate; the focused regression fixture is supplemental validation of the migration boundary.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: This maintainer PR is exempt from the external-contributor proof gate; the focused regression fixture is supplemental validation of the migration boundary.
Evidence reviewed 7 items Introduced repair: The PR converts only the potentially unsafe aggregate to SQLite text and continues to compare it exactly as part of the transcript source-drift fingerprint.
Regression coverage: The new fixture creates two individually safe timestamps whose aggregate exceeds Number.MAX_SAFE_INTEGER, then verifies no warning, schema advancement, and canonical media output.
Node SQLite contract: The production SQLite loader uses node:sqlite; an in-memory query with the fixture values reproduced the RangeError for raw SUM and returned the exact decimal string when cast to TEXT.
Findings None None.
Security None None.

How this fits together

Doctor migrates legacy agent SQLite databases into the current media-persistence format. It compares a source fingerprint before rewriting media metadata so concurrent database changes prevent a partial migration.

flowchart LR
A[Legacy agent database] --> B[Doctor media migration]
B --> C[Read source fingerprint]
C --> D[Rewrite media metadata]
D --> E[Compare source fingerprint]
E --> F[Commit schema migration]
E --> G[Warn on source change]
Loading

Before merge

  • Complete next step (P2) - No repair lane is needed: the prior regression-test finding is addressed and this maintainer PR awaits normal exact-head CI and review.
Agent review details

Security

None.

PR surface

Source -5, Tests +43. Total +38 across 2 files.

View PR surface stats
Area Files Added Removed Net
Source 1 7 12 -5
Tests 1 43 0 +43
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 2 50 12 +38

Review metrics

Metric Value Why it matters
Production vs test LOC production -5, tests +43 The fix removes the explicit numeric fingerprint type while adding focused migration-boundary coverage.

Stored data model

Persistent data-model change detected: serialized state: src/infra/state-migrations.media-persistence.ts. Confirm migration or upgrade compatibility proof before merge.

Technical review

Best possible solution:

Land the owner-bound exact-text fingerprint repair once the exact-head required checks complete.

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

Yes. The direct node:sqlite query reproduces the unsafe numeric materialization, and the added fixture supplies the equivalent migration path with a safe post-fix result.

Is this the best way to solve the issue?

Yes. The repair is at the fingerprint-producing query, preserves exact drift comparison, and leaves bounded numeric fingerprints unchanged.

AGENTS.md: found and applied where relevant.

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

Labels

Label changes:

  • add rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🌊 off-meta tidepool and patch quality is 🐚 platinum hermit.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: This maintainer PR is exempt from the external-contributor proof gate; the focused regression fixture is supplemental validation of the migration boundary.
  • remove rating: 🦐 gold shrimp: Current PR rating is rating: 🐚 platinum hermit, so this older rating label is no longer current.
  • remove status: ⏳ waiting on author: Current PR status label is status: 👀 ready for maintainer look.

Label justifications:

  • P2: This fixes a bounded Doctor migration failure for valid persisted databases with unusually large timestamp aggregates.
  • 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: This maintainer PR is exempt from the external-contributor proof gate; the focused regression fixture is supplemental validation of the migration boundary.

Evidence

What I checked:

Likely related people:

  • Peter Steinberger: Introduced the Doctor-owned canonical persisted-media cutover that contains the affected fingerprint. (role: original media-migration owner; confidence: high; commits: 367ff3cea190; files: src/infra/state-migrations.media-persistence.ts)
  • Ahmad Shawwal: Recently hardened the same migration’s scan behavior and is closely connected to its operational constraints. (role: recent media-migration contributor; confidence: high; commits: ba7c8ece0cc9; files: src/infra/state-migrations.media-persistence.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 (2 earlier review cycles)
  • reviewed 2026-08-28T21:06:20.306Z sha fdbf4e6 :: found issues before merge. :: [P2] Add an unsafe timestamp-aggregate regression test
  • reviewed 2026-08-28T21:30:06.151Z sha b9cc77f :: found issues before merge. :: [P2] Add an unsafe timestamp-aggregate regression test

@sjf sjf self-assigned this Aug 28, 2026
@sjf
sjf force-pushed the sjf/fix-media-migration-unsafe-created-at branch from b9cc77f to 9cbd128 Compare August 28, 2026 22:00
@sjf
sjf force-pushed the sjf/fix-media-migration-unsafe-created-at branch from 9cbd128 to 58e25e9 Compare August 28, 2026 22:08
@clawsweeper clawsweeper Bot added 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. and removed 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. labels Aug 28, 2026
@sjf-oa
sjf-oa merged commit 139e38b into main Aug 29, 2026
242 checks passed
@sjf-oa
sjf-oa deleted the sjf/fix-media-migration-unsafe-created-at branch August 29, 2026 06:59
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Aug 30, 2026
* fix(doctor): preserve large media migration timestamps

* fix(ci): keep media migration fingerprint compact

* chore: restore source newline

* test(doctor): cover unsafe media timestamp aggregates

---------

Co-authored-by: Sarah Fortune <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

maintainer Maintainer-authored PR P2 Normal backlog priority with limited blast radius. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: S 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.

2 participants