Repository navigation
store: an append after one that was cut short starts on a line of its own - #261
connorburgess wants to merge 5 commits into
Conversation
… own Symptom: an append to a session's events file that was cut short (a full disk, a file-size limit, the process killed mid-write) leaves a line with no end. After a restart the store wrote the next event straight onto it. The event was accepted and shown live, but the next restart dropped it with the cut line: a whole event lost, nothing logged, and the outbox source's offset already past it. Cause: `EventFiles.append` (server/store/files.ts) appended at the size the store last recorded, without looking at the file's last byte, and `readLines` skips a line that does not parse while counting its bytes. The recorded offsets came from that size too, so a write that failed part-way left them off from the real end of the file and `readAt` returned the wrong event or none. Fix: `append` opens the file once, takes the offsets from its real end (fstat), reads the last byte and begins with a newline when it is not one, in the same write. The cut line ends there and only its event is lost. The `size` argument stays on `EventLog` for MemoryLog. This is the fix core made for its outbox in spacesheep-dev/sessionpipe@87441b9 (spacesheep-dev/sessionpipe#202). Since the store's storage figure adds what each append returns less the size it knew, a file boot counted that holds no event yet (a first append cut short) now gives its new session that size, so its bytes are not counted twice; forgetting that session takes all of them off. Signed-off-by: Connor Burgess <connorburgesscodes@gmail.com>
This comment has been minimized.
This comment has been minimized.
Symptom: a session whose harness or id holds a character outside [A-Za-z0-9_.-], or is longer than 160 characters, still had its cut first line counted twice in storageBytes after a restart, and its unreadSizes entry was never cleared. Cause: boot keyed unreadSizes by the folder and file name, which went through safeName, while entry() looked it up by the raw harness and id. Fix: key unreadSizes by the session's file name on both sides (unreadKey). safeName moves to log.ts, which has no Node in it, so the store's core can use it and still bundle for the browser; files.ts re-exports it. Signed-off-by: Connor Burgess <connorburgesscodes@gmail.com>
|
Minor item from the round on 9590e9b, " |
|
@graphide-review review |
|
TL;DR
This review covers the pushes since EventFiles.append now opens the file once, fstat's its real size for offsets, and writes a leading newline in the same write when the last byte is not one. A line cut short by a failed write then costs only its own event, not the next one. In StoreCore, sizes of files that boot finds with no valid line are kept under No findings sure enough to post from reading the change. Merge confidence 5 of 5 Where to read first
1 earlier finding no longer carried
Tests and reachReach: no graph yet, so this review could not trace what the change reaches. Stages: 115 s
|
Signed-off-by: Connor Burgess <connorburgesscodes@gmail.com>
Signed-off-by: Connor Burgess <connorburgesscodes@gmail.com>
|
The truncated event-log append and storage-accounting fix still applies to SessionPipe GUI v0.8.18. Merged current Added the previously deferred Unreleased changelog entry. Validation on this head, macOS / Node 22.23.2:
GitHub CI run 47453784782 for head The phone job failed Keep the failed run visible: a maintainer needs to rerun/investigate the phone job and aggregate gate before merging. The upstream job-rerun API rejects this account with HTTP 403 for insufficient repository permissions. Also checked the combined source/test changes from all 19 refreshed PRs on the same main: no source conflicts; typecheck, lint and build passed; all 252 unit-test files passed (3,439 tests, two skipped). This was a local integration check, separate from the individual PR run above. Release-note entries may still need combining as PRs land. |
Signed-off-by: Connor Burgess <connorburgesscodes@gmail.com>
|
Merged current CI run 47497344424 for head The earlier run 47453784782 on Locally on |
Updated against v0.8.19 / main
e8bfe999on 2026-12-05. Current validation and refresh details.What
An event that arrives after an append to the session's file was cut short is now kept. Before this, it was accepted and shown live, then lost at the next restart with no log line.
Why
An append cut short leaves a line with no end. A full disk, a file-size limit or a process killed mid-write can each do this.
EventFiles.append(server/store/files.ts) wrote the next event straight onto that line.readLinesskips a line that does not parse but still counts its bytes, so at the next boot the whole event went with the cut one.The outbox source's offset had already moved past that event, so nothing sends it again. Example: a session with seqs 0 and 1, a cut seq 2, then
turn.ended(3) andsession.ended(4) after a restart. After one more restart it reads as [0, 1, 4]; seq 3 is gone.The offsets that
appendrecorded came from the size the store last saw (entry.size), not from the file. After an append that failed part-way, they no longer match the bytes on disk, andreadAtreturns the wrong event or none.The change, in
EventFiles.append:This follows core's fix for its outbox, spacesheep-dev/sessionpipe@87441b9 ("outbox: an append after one that was cut short starts on a line of its own", spacesheep-dev/sessionpipe#202).
Two more points:
server/store/core.ts. Without this, those bytes would be counted twice. Forgetting the session takes them all off; on main they stayed in the figure.That size is kept by the session's file name, the harness and id after
safeName(unreadKey), because a file with no whole line has no event to give the real harness and id, only its folder and file name. So a harness or id with a character outside[A-Za-z0-9_.-], or longer than 160 characters, finds it too.safeNamemoves toserver/store/log.ts, which has no Node in it, so the core can use it and still bundles for the browser (server/store/browser.test.ts);files.tsre-exports it.EventLog.appendkeeps itssizeargument, becauseMemoryLogsums from it.EventFilesno longer relies on it.If a cut stops right before the line's newline, the line is valid JSON and this change ends it. That event is then read at the next boot, where it is deduplicated by seq like any other line.
An entry is now included under Unreleased in
CHANGELOG.md. Other open PRs also add release notes; those entries may need combining as the PRs land.Original proof (before the v0.8.18 refresh)
New tests in
server/store/files.test.ts:readAtof the new lines.appendis given a stale size and still returns the file's real size, andreadAtreturns the right event.Storewith two restarts reads seqs [0, 1, 3, 4], and its storage figure matches the file's size.forget.my harnessand an id with a colon, a space, a slash and more than 160 characters.On the branch:
Test 6 fails on 9590e9b (this PR's first commit, before
unreadKey): the cut line's 40 bytes are counted twice.On origin/main (4ab6eae), with the same test file, 1, 2, 4 and 5 fail. Test 3 is the guard and passes on both.
Test 5 fails on main at its last step: the storage figure is still 40 after
forget.Checks on the branch head (066bc4a), macOS, Node 22:
npm run typecheckandnpm run lintpass (lint: warnings only, the same 135 as on main).npm test:That one is
server/control/remote.parity.test.ts, which this change does not touch. It hits its 15 s timeout the same way in a full run on unmodified origin/main (4ab6eae):Run on its own, it passes on both: 11/11 on main, and together with the new file 16/16 on 9590e9b.
Checklist
git commit -s).npm run typecheck && npm run lint && npm testpass (see above); no UI change, so nonpm run test:e2e.// SPDX-License-Identifier: Apache-2.0.shared/*.CHANGELOG.md.