Skip to content

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 #1620

Closed

Description

@dezren39

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 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.

Activity

  1. developing-today commented on Oct 28, 2026

    @developing-today
    Contributor
  2. added
    source/creatorFiled by the new-issue-creator job
    task/small-fixQueue packet kind: bounded fix with reproduction and targeted tests
    priority/normalOrdinary priority (the default)
    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, 2026
  3. dezren39 commented on Oct 28, 2026

    @dezren39
    MemberAuthor

    🤖 Agent note · filed

  4. added
    work/assignedQueue worker lifecycle state
    queue/claimedQueue worker lifecycle state
    and removed on Oct 28, 2026
  5. 56 remaining items

  6. added
    queue/parkedQueue task is parked (waiting on CI, time, or an event)
    status/parkedDeliberately paused with a recorded resume condition
    on Oct 31, 2026
  7. dezren39 commented on Oct 31, 2026

    @dezren39
    MemberAuthor

    🤖 Agent note · parked

  8. added
    queue/claimedQueue worker lifecycle state
    and removed
    status/parkedDeliberately paused with a recorded resume condition
    queue/parkedQueue task is parked (waiting on CI, time, or an event)
    on Oct 31, 2026
  9. dezren39 commented on Oct 31, 2026

    @dezren39
    MemberAuthor

    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).

  10. added a commit that references this issue on Oct 31, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

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

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions