Repository navigation
Description
Problem
Outbox::open (pkgs/id/src/envelope_outbox.rs:130) only drops a torn final line when it fails to parse. A crash that cuts an append after the record's closing } but before its \n leaves a parseable unterminated final line — and open accepts it as a committed record. The next commit() then appends the following record directly onto that same line, producing one line containing two JSON objects; on the next open that line is complete (newline-terminated) and corrupt, so open errors out and the envelope outbox is bricked until a human edits the file by hand.
Evidence (verified this run on main 1658679c)
src/envelope_outbox.rs:141-157: the replay loop iteratestext.split_inclusive('\n'); on parse success it applies the record and doeskept += line.len()(line 146) regardless of whether the line ends with\n. The torn-tail drop is only theErr(_) if !complete => breakarm (line 148). If the unterminated fragment parses,kept == text.len(), so no truncation happens and the file keeps its missing trailing newline.src/envelope_outbox.rs:278-289(commit): appendsserde_json::to_string(&record) + '\n'withOpenOptions::append— no leading newline is written, so the next record is concatenated onto the unterminated line.- Sibling stores treat any unterminated final line as torn, parseable or not, because an append that never got its newline was never durably committed:
src/artifact.rs:565-583(ArtifactLog::open): "A final line cut short by a crash was never synced, so it is dropped and the file is truncated to the last complete line" — implemented asrfind('\n')truncation before parsing.src/directory.rs:512-526(the id(directory): a torn final line in directory.jsonl bricks the directory — Directory::replay refuses the crash-torn tail that ArtifactLog (loaded in the same open) drops and truncates #1521 fix): drops the torn final fragment "parseable or not", warns, and truncates.
- The existing test
a_torn_last_line_is_dropped_and_not_mixed_into_the_next_record(src/envelope_outbox.rs:523) covers only an unparseable fragment ({"op":"queued","target"). The parseable-fragment case — its exact title scenario, "not mixed into the next record" — is untested and currently fails by construction: fragment{"op":"queued",...}+ appended record ={"op":...}{"op":...}\n, which no longer parses as a single record (demonstrated with a JSON parse of the concatenated line this run). - Accepting the fragment also breaks the durability contract:
commitdoeswrite_allthensync_data(line 285-288); a crash between the data write and the sync can leave exactly this parseable-but-unterminated tail for a record that was never acknowledged.
Why it matters
The outbox is the durable delivery queue for envelopes/artifacts. One unlucky crash turns it into a file that loads once (silently accepting an unacknowledged record), then permanently fails to load after the next enqueue/withdraw/record — with a "line N is corrupt" error that gives no hint the real cause was a torn tail two restarts earlier.
Related but distinct: #1499 (petnames) and #1522 (groups) cite the Outbox as the correct sibling for refusing torn tails; neither covers this parseable-unterminated acceptance in the Outbox itself. #1521 (directory, closed) established the "drop parseable or not" policy this issue asks the Outbox to match.
Acceptance criteria
-
Outbox::opendrops an unterminated final line whether or not it parses, truncates the file to the last complete (newline-terminated) line, matchingArtifactLog::open/ directory replay semantics. - After such a recovery, a subsequent
commit()appends cleanly: reopening the outbox succeeds and contains exactly the pre-crash complete records plus the new one. - A corrupt complete (newline-terminated) line still fails the load (existing test
a_corrupt_complete_line_stops_the_loadkeeps passing). - New regression test: final line is a complete JSON record missing only its trailing
\n; open drops it (the record's envelope is not present), the file is truncated, a following enqueue round-trips through a reopen. - Existing outbox tests pass, including
a_torn_last_line_is_dropped_and_not_mixed_into_the_next_record.
Activity
developing-today commentedon Oct 28, 2026
CODE-644
dezren39 commentedon Oct 28, 2026
🤖 Agent note · filed
new-issue-creator-code-a)new-issue-creator-code-a, run 2026-10-28T08:05Z1658679cthatOutbox::open(pkgs/id/src/envelope_outbox.rs:141-157) accepts a parseable unterminated final line (kept += line.len()on parse success, torn-drop only on parse error), so the nextcommit()append merges two records onto one line and bricks the outbox on the following open — unlike ArtifactLog (artifact.rs:565-583) and directory replay (id(directory): a torn final line in directory.jsonl bricks the directory — Directory::replay refuses the crash-torn tail that ArtifactLog (loaded in the same open) drops and truncates #1521), which drop any unterminated tail parseable or not. Dedup: id: a torn final line in petnames.jsonl bricks the whole world — Petnames::open refuses the crash-torn tail that FileJournal and Outbox drop and truncate #1499/id(groups): a torn final line in groups.jsonl bricks every group command — GroupLog::open refuses the crash-torn tail that FileJournal and Outbox drop and truncate #1522 cite the Outbox as the correct sibling for unparseable tails; neither covers this variant.Outbox::open, plus a regression test with a complete-JSON-but-unterminated final line; queued for the repo worker via arepo-task/v1packet.repo-health-code-pilotthis run56 remaining items
dezren39 commentedon Oct 31, 2026
🤖 Agent note · parked
dezren39 commentedon Oct 31, 2026
agent-note:v1 — task 1737 resumed by lane E. Verdict on PR #2877 @ 7fe044a: Codex review clean (no findings). id-check run 41159335501: test shards 0 and 3 pass; rustfmt-check log does NOT name envelope_outbox.rs (only pre-existing main debt: tag.rs, peers.rs, event_store/sync.rs, web/mod.rs, world_store.rs, world_ssh.rs, groups/tests.rs); test-shard-1 FAILED as infra — job died mid-compile after 5m21s (02:32:45–02:38:06Z) with no test output. Change verified directly on the exact head in the laptop worktree: cargo test envelope_outbox 9/9 pass, incl. the new a_parseable_torn_last_line_is_also_dropped. Prior head passed shards 0-3 in CI; this head differs only by a rustfmt wrap in the same file. Other red legs (biome, web-fmt, test-web-unit, clippy, treefmt, cargo-fmt) are pre-existing on clean main. Merging under the standing rule (unrelated infra failures + change verified sound).
Merge pull request #2877 from developing-today/queue/1737-1620-outbox…
fix(id/petname): drop a parseable torn final line in Petnames::open (#…
fix(id/petname): drop a parseable torn final line in Petnames::open (#…