Skip to content

admin: the audit compaction is one mutex, not one process — pid-scope the staging file and state the 4,000-line bound #1191

Open

Description

@chappie-daemon

Found by: the architecture lens in review round 6 of job 032-admin-console-parity (round-6/review-architecture.md, note 3). Non-blocking there — filed so the premise is written down rather than assumed.

D2's compaction (crates/nostream-admin/src/state.rs, write_audit_lines/the rename at :703) is serialised by one mutex in one process, not by anything that stops a second process writing the same file:

  • the staging file's name is not pid-scoped, where crates/nostream-config/src/store.rs:113-115 makes it so for the settings files;
  • D2's "single-process daemon" is the unstated premise that makes this safe — a second nostreamd on the same config directory would interleave staging names and could rename a half-written file over a live one;
  • the append counter resets before the compaction runs, so a failed compaction waits another 2,000 appends before retrying;
  • the file's true bound is 4,000 lines (2,000 before the check, 2,000 more before the next).

Fix direction: pid-scope the staging name as store.rs does (cheap, and it makes the premise unnecessary rather than documented), reset the counter only after a successful rename, and state the 4,000-line bound in the code and the ADR.

Closing: Closes #N is inert on a PR targeting rewrite/main; close by hand with the merge sha.

Activity

  1. added
    rewrite
    rust
    factory
    on Nov 19, 2026
  2. chappie-daemon commented on Nov 19, 2026

    @chappie-daemon
    CollaboratorAuthor

    Measured addition (round 6 of job 032-admin-console-parity, round-6/review-performance.md): the cap on the audit file now rests on an in-process append counter (state.rs:102, :537-541), so its bound is not a property of the file:

    • a restart more often than every 2,000 appends leaves the file growing without bound, because the counter starts at zero again on every boot;
    • a compaction that keeps failing does the same, because *appends = 0 is written before the attempt, so the next attempt waits another 2,000 appends while the file keeps growing;
    • /admin/audit-log parses the whole file per panel load, so the growth is visible in that panel's latency first.

    The reviewer judged this a note rather than a finding because at one operator's append rate it is tens of lines a day; the fix is a persisted counter or a size check (metadata().len() against the byte cap) in place of the in-memory one, plus moving the reset after a successful rename.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    factoryrewriterust

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions