Skip to content

fix(backup): preserve text after embedded NUL characters - #138327

Merged
obviyus merged 1 commit into
mainfrom
codex/issue-138306
Sep 4, 2026
Merged

obviyus merged 1 commit into
mainfrom
codex/issue-138306

Conversation

@obviyus

@obviyus obviyus commented Sep 4, 2026 •

Copy link
Copy Markdown
Collaborator

Closes #138306. Reported by @ced-cm. Related: #134213.

What Problem This Solves

Git backups on Node 22.23.2 could silently lose text after an embedded NUL character. Distinct keys could collapse, and verification could miss a truncated single key.

Why This Change Was Made

The shared backup serializer escapes database text before the native driver reads it, then decodes it before redaction and serialization. Row order and the existing backup format stay unchanged.

User Impact

New backups preserve complete text, including Unicode and embedded NUL characters. Recreate damaged backups from an intact source database; missing bytes cannot be recovered from old backups. No migration or new setting is required.

Evidence

Real backup git create, verify, and restore commands reproduced truncation before the fix and restored complete keys afterward. Tests covered ordinary, distinct NUL-containing, Unicode, and single-key cases, plus unchanged backups. All 34 focused codec, backup, and command tests passed.

AI-assisted.

Keep Git backups lossless on supported Node versions by escaping TEXT before native reads. Preserve the existing JSONL format and source row ordering. Reported by @ced-cm in #138306.
@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.

@openclaw-barnacle openclaw-barnacle Bot added size: S maintainer Maintainer-authored PR labels Sep 4, 2026

@sylvesterkaczmarek sylvesterkaczmarek left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The driver-boundary fix is the right shape: escaping TEXT inside SQLite before node:sqlite converts it avoids trying to reconstruct bytes after the lossy boundary. Keeping row ordering on the original source columns is important as well, otherwise escaping could preserve text while still perturbing digest order. I’d keep the ANY/dynamic-typing NUL case as permanent coverage, since SQLite affinity means declared TEXT columns are not the only place this can surface. The shared create/verify serializer makes this a coherent repair.

@obviyus

obviyus commented Sep 4, 2026

Copy link
Copy Markdown
Collaborator Author

Exact-head preparation is complete at 93ce30428b4b2e49a560bec25aaea1e19be4605c.

  • Real Node 22.23.2 CLI red on current main: two NUL-bearing keys collapse and verification fails; one affected key loses its suffix while verification still passes.
  • Real CLI green: all four ASCII/NUL/Unicode/single-key scenarios preserve complete keys and values through create, verify, restore, and fresh-process public-SDK readback. Unchanged repeats create no new commit.
  • 34 focused tests passed. The new regression failed before the production repair.
  • Focused lint, formatting, max-lines, environment-count, and assertion-safety checks passed.
  • Fresh independent exact-head review passed after receiving the complete CLI artifacts. An earlier diff-only review lacked that proof; its finding was resolved by supplying the missing evidence, without changing the product patch.

Commands:

pnpm build
pnpm build qaRuntime
node scripts/run-vitest.mjs src/snapshot/git-backup-codec.test.ts src/snapshot/git-backup.test.ts src/commands/backup-git.test.ts
node scripts/run-oxlint.mjs --tsconfig config/tsconfig/oxlint.core.json src/snapshot/git-backup-codec.test.ts src/snapshot/git-backup-codec.ts

The first build belongs to the pinned main baseline; the runtime build belongs to the exact candidate. CLI and focused regression runs used the supported Node 22.23.2 runtime in an isolated secretless Linux container.

The repair stays in the serializer, removes direct lossy TEXT reads, and adds nine production lines. The backup format, redaction policy, schema, stored keys, and scope are unchanged. Existing damaged artifacts still need replacement from intact source data.

CI passed: https://github.com/openclaw/openclaw/actions/runs/33884122180

Latest ClawSweeper disposition: exact-head review started; no findings or rank-up moves have been published. The independent exact-head review and required CI are green. The contributor review's request to retain the ANY/dynamic-type case is satisfied by the committed regression test.

@obviyus
obviyus merged commit a036c70 into main Sep 4, 2026
149 checks passed
@obviyus
obviyus deleted the codex/issue-138306 branch September 4, 2026 14:43
@obviyus

obviyus commented Sep 4, 2026

Copy link
Copy Markdown
Collaborator Author

Thanks @ced-cm for the report!

Landed in a036c70ee75d. #138306 is closed.

Proof: Real backup CLI create, verify, restore, and fresh-process plugin-state readback passed on Node 22.23.2 for ordinary, NUL-colliding, Unicode, and single-key inputs. Unchanged repeats produced no new commit.

  • Bug: Successful backups silently dropped text after NUL; colliding keys prevented restore, while a single truncated key could pass verification.
  • Fix: The serializer preserves complete TEXT before native conversion, with the existing format, redaction, and source ordering unchanged.
Before After
Keys and values lost NUL suffixes Full keys and values round-trip
Colliding keys failed verification Create, verify, and restore pass
Single-key loss went undetected The suffix survives restore

The regression failed before the fix. All 34 focused tests, fresh exact-head independent review, and required CI passed. Reporter credit and Ayaan co-author attribution are retained in the merge commit.

vincentkoc added a commit that referenced this pull request Sep 4, 2026
…9-prep

* commit '407a8f453c0f0306af1ddc0aafa8697c1d49a9e7': (312 commits)
  perf(ui): coalesce automation event refreshes (#138065)
  fix: reject incomplete Skill Workshop directory reads (#138082)
  test(ui): decouple rendering checks from generated wording (#138283)
  perf: avoid temporary entries in bounded JSON traversal (#138017)
  fix(irc): render complete messages before splitting (#138328)
  perf: prepare worker trajectory payloads only for recorded events (#138086)
  fix(mcp): paginated listings no longer time out after a forward clock step (#137206)
  fix(codex): page native transcripts and bound UI previews (#136282)
  feat(gateway): apply more settings without restarting (#138112)
  fix(docs): preserve mirrored ClawHub maturity links (#138241)
  fix(test): own UI animation and legacy database setup (#138296)
  fix(tts): preserve literal directives in Markdown code (#138319)
  fix: load chat widgets behind authenticated gateways (#138074)
  chore(ui): cover native approval finalization (#137259)
  fix(cron): cancel conditions before main-session handoff (#138313)
  fix(backup): preserve text after embedded NUL characters (#138327)
  fix(android): align composer control sheets (#137442)
  fix(ci): wait for replacement PR runs instead of stale failures (#138307)
  fix(sessions): keep Gateway responsive with long transcripts (#138094)
  fix(computer): map window inputs to delivered image coordinates (#138271)
  ...

# Conflicts:
#	scripts/release-check.ts
#	test/release-check.test.ts
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Sep 5, 2026
…8327)

Preserve complete SQLite TEXT in Git backups on supported Node versions.
Escape TEXT before native reads, decode before redaction, and keep ordering
on source columns. The existing JSONL format and restore path stay unchanged.

Reported by @ced-cm in openclaw#138306. Fixes openclaw#138306.

Verified real backup create, verify, restore, fresh-process SDK readback,
and unchanged-create behavior on Node 22.23.2. Focused regression coverage
includes NUL and Unicode keys, source ordering, and all SQLite storage classes.

Co-authored-by: Ayaan Zaidi <[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 size: S

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Git backup silently produces an unrestorable dump — node:sqlite truncates TEXT at embedded NUL, collapsing distinct primary keys

2 participants