Repository navigation
fix(doctor): repair stale session files whose header crosses a read chunk boundary - #154034
Conversation
|
🦞👀 Pull request received. I will update this pull request when review starts. ClawSweeper review completeClawSweeper finished reviewing this revision. The review result is being finalized. |
f1acab5 to
0d477e3
Compare
|
Codex review: needs real behavior proof before merge. Reviewed September 20, 2026, 5:47 PM ET / 21:47 UTC (Revision 3). ClawSweeper reviewWhat this changesDoctor reads legacy session headers across UTF-8 chunks so long headers no longer prevent stale transcript-path repair, with a regression test. Merge readiness⛔ Blocked before merge - 2 items remain This remains a useful, focused fix absent from current main and the latest release. No introduced correctness defect was found, but the required upgrade evidence remains incomplete; the PR-body assertion that checks were waived is not corroborated by maintainer discussion. Priority: P2 Review scores
Verification
How this fits togetherDoctor inspects legacy session records and transcript files before migrating conversation state. Header validation determines whether an existing transcript can replace a missing legacy path. flowchart TD
A[Legacy session record] --> B[Doctor migration]
C[Candidate transcript] --> D[Bounded UTF-8 header reader]
D --> E[Validate session identity]
B --> E
E --> F[Repair eligible transcript path]
F --> G[Normalize and persist session state]
Before merge
Agent review detailsSecurityNone. PR surfaceSource +26, Tests +35. Total +61 across 3 files. View PR surface stats
Review metricsNone. Technical reviewBest possible solution: Keep the bounded reader in the existing migration owner and demonstrate that the affected conversation remains readable after a published-updater upgrade. Do we have a high-confidence way to reproduce the issue? Yes: current main truncates valid JSON headers exceeding 8192 bytes, and the contributed fixture places a multibyte character at that boundary. Source establishes the failure mechanism; this review did not execute it. Is this the best way to solve the issue? Yes for the parsing defect: incremental UTF-8 decoding with a bounded scan preserves the existing identity and collision checks. Full migration recovery still needs the required upgrade evidence. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against af00d16e3573. LabelsLabel justifications:
EvidenceWhat I checked:
Likely related people:
Rank-up movesOptional improvements that raise the rating; they are not merge blockers.
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
HistoryReview history (2 earlier review cycles)
|
A fixed 8192-byte read window could end inside a multibyte character, and
toString("utf8") then replaced the split character with U+FFFD. The header
stopped parsing, so the stale sessionFile repair silently did nothing and the
session kept pointing at a path that no longer exists. Scan the header in
chunks with a StringDecoder and stop at the first newline instead.
0d477e3 to
48c2cc9
Compare
|
Merged via squash.
|
…nclaw#154034) Doctor could skip stale transcript-path repair when a valid session header extended past its fixed 8192-byte read window. Read the complete first line with bounded incremental UTF-8 decoding so long headers and split multibyte characters preserve the existing session identity and collision safeguards. Release-note context: restore Doctor's repair of stale session transcript paths for headers that cross a read chunk boundary. No configuration change or operator action is required. Thanks to @xydt-juyaohui for the fix. Evidence: the existing regression fails before the fix and passes afterward (8 tests passed), and the reported Windows migration-owner flow repairs both short and boundary-split headers. The approved head has green hosted CI and a scoped-clean Codex review. Published-updater-to-candidate proof and per-file timing measurements remain unrun in this landing lane. Follow-up: header parse failures still skip silently; record an explicit Doctor non-outcome in follow-up work. Co-authored-by: 琚耀辉0668001366 <[email protected]>
What Problem This Solves
Fixes:
openclaw doctor --fixsilently skips repairing a session transcript path that went stale when that session's header line is longer than one 8192-byte read chunk and a multibyte character straddles the boundary.User Impact
Affected sessions are now repaired as intended instead of being skipped, so users keep working conversation history after a Doctor migration instead of being left on a transcript path that no longer exists. No configuration change or manual action is required.
Why This Change Was Made
resolveStaleLegacySessionFile()validates a candidate transcript by reading its first line — the session header — before adopting it. It read one fixed 8192-byte window and decoded it withBuffer.toString("utf8"). When the complete JSON header extends beyond that window, the truncated JSON fails to parse and the surroundingcatchreturnsundefined, silently skipping the repair. A split multibyte character is also decoded as U+FFFD, but U+FFFD alone does not make a JSON string invalid.The fixed window is the actual defect: the reader must reach the end of the header while preserving UTF-8 character boundaries. The fix scans the header in chunks with a
StringDecoder(Node's incremental UTF-8 decoder, which carries a partial sequence into the next chunk) and stops at the first newline, keeping a character budget so an unterminated file still cannot be read without bound. The scan moved tosrc/infra/first-line-read.tsso the new behavior lives in a coherent sibling module rather than growing an over-cap file.Only the header scan changed. The existing guards (legacy file must be gone, no collision rename,
sessionIdmust be a string) and the byte-exactstatecomparison are untouched.Evidence
Real Doctor flow, before and after (primary proof)
Driven through the production entry point
migrateLegacySessions()— the same functionopenclaw doctor --fixcalls — against two identical fixtures that differ only in the header shape. The fixture is a session whose store entry points at a legacy transcript path that no longer exists, while the live copy sits in the target directory. A repaired session makes Doctor report theRepaired migrated session transcript pathschange.中starts at offset 8191 and is split by the 8192-byte chunk boundary (8197 bytes)Before the fix, only the baseline is repaired; the boundary-split header silently loses the repair:
After the fix, both header shapes are repaired:
Decode-level isolation
Scanning the same bytes directly shows the mechanism, with the old and new reads compared side by side:
Regression test
src/infra/state-migrations.legacy-session-store.test.ts—"repairs a stale session file whose header straddles the read chunk boundary". This is a real pre-fix-fails / post-fix-passes gate, not a test that mirrors the implementation:node scripts/run-vitest.mjs src/infra/state-migrations.legacy-session-store.test.tsLocal gates
oxlint -c .oxlintrc.json <changed files>->Found 0 warnings and 0 errors.(includes themax-linesrule the line-cap ratchet enforces)oxfmt --check <changed files>->All matched files use the correct format.tsc --noEmit -p tsconfig.json-> no errors reported for either changed fileEarlier CI
All shards covering this change are green:
check-lint+check-lint-core-1..5,check-test-typesandcheck-test-types-core-1,checks-windows-node-test-1..2,checks-fast-core, and 42/43checks-node-compact-large-*plus all 43checks-node-compact-small-*.Three checks remain red and none of them touch this diff:
check-test-types-core-2andchecks-node-compact-large-10fail only insrc/state/openclaw-state-db-task-identifiers.test.ts(TS2459/TypeError: bindSubagentRunRecord is not a function). That file is not in this PR and does not exist on this branch's base;upstream/mainadded it importing abindSubagentRunRecordexport thatupstream/mainitself no longer re-exports. Maintainers are already tracking it in fix(test): import the subagent run binder from its codec owner #154060, test(state): use canonical subagent codec in identifier fixture #154058, test(state): import the subagent binder from its codec #154071, and fix(ci): use the subagent codec in state migration tests #154014.resolvefailed with403 API rate limit exceeded for installation— a GitHub infrastructure limit, not a code failure.Gaps
The Doctor proof runs the real
migrateLegacySessions()entry point against a synthetic state directory on Windows; it does not exercise a published-updater upgrade against an installed release. The store normalizessessionFileout of the persisted entry shape, so the observable outcome is Doctor's repair decision and its reported change, which is what the proof asserts.Maintainer landing review
The scoped Codex autoreview is clean, and the ClawSweeper review of head
48c2cc9a31188275eceaca773c46875c0a7dc732found no introduced correctness defect. The exact-head CI gate is green according to the campaign's REST check-runs verification, superseding the earlier CI notes above; native preparation independently verifies hosted evidence.Disposition of ClawSweeper's September 20, 21:16 UTC rank-up moves:
Follow-up: header parse failures still skip silently; recording an explicit Doctor non-outcome is a named follow-up outside this patch.