GeezerVison is showing github.com — id(outbox): a parseable torn tail is accepted, then merged into the next record — Outbox::open only drops unterminated final lines that fail to parse · Issue #1620 · developing-today/code
id(outbox): a parseable torn tail is accepted, then merged into the next record — Outbox::open only drops unterminated final lines that fail to parse #1620Labels app/idPackage/app: id (pkgs/ or apps/ in this repo)effort/xsTrivial: expected under 30 minutes of workkind/bugSomething isn't working (prefixed form of the classic bug label)priority/normalOrdinary priority (the default)source/creatorFiled by the new-issue-creator jobtask/small-fixQueue packet kind: bounded fix with reproduction and targeted tests DescriptionProblem
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 iterates text.split_inclusive('\n'); on parse success it applies the record and does kept += line.len() (line 146) regardless of whether the line ends with \n. The torn-tail drop is only the Err(_) if !complete => break arm (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): appends serde_json::to_string(&record) + '\n' with OpenOptions::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:
- 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:
commit does write_all then sync_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::open drops an unterminated final line whether or not it parses, truncates the file to the last complete (newline-terminated) line, matching ArtifactLog::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_load keeps 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.
Activitydeveloping-today commented on Oct 28, 2026 added task/small-fixQueue packet kind: bounded fix with reproduction and targeted tests app/idPackage/app: id (pkgs/ or apps/ in this repo) kind/bugSomething isn't working (prefixed form of the classic bug label) effort/xsTrivial: expected under 30 minutes of work on Oct 28, 2026dezren39 commented on Oct 28, 2026 dezren39 commented on Oct 31, 2026 dezren39 commented on 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).
MetadataMetadataapp/idPackage/app: id (pkgs/ or apps/ in this repo)effort/xsTrivial: expected under 30 minutes of workkind/bugSomething isn't working (prefixed form of the classic bug label)priority/normalOrdinary priority (the default)source/creatorFiled by the new-issue-creator jobtask/small-fixQueue packet kind: bounded fix with reproduction and targeted tests DevelopmentNo branches or pull requestsIssue actions
|