Skip to content

pm-stack(external-comms): quarantine malformed pusher outbox lines (#6154) - #6199

Merged
dezren39 merged 2 commits into
mainfrom
queue/10006-6154-quarantine-malformed-outbox
Nov 5, 2026
Merged

dezren39 merged 2 commits into
mainfrom
queue/10006-6154-quarantine-malformed-outbox

Conversation

@dezren39

@dezren39 dezren39 commented Nov 5, 2026 •

Copy link
Copy Markdown
Member

Fixes #6154

Problem

record-external-send push silently dropped outbox lines it could not parse (do_push: except: continue). The line never reached pending, so the outbox rewrite deleted it permanently — while pusher-health.json and stdout could still report a clean drain (last_drain_ok_at set, pending: 0, last_error: null). The outbox is the fallback copy of a send record; a torn/corrupt line (crash mid-append, disk-full truncation, operator edit) vanished with an affirmative success report, against this module's own NEVER SILENT rule.

Change

  • Malformed lines (JSON-decode failures, and valid JSON that is not an object) are appended verbatim to quarantine.jsonl in the state dir — exact raw line + _quarantined_at + _reason, fsync'd — before the outbox rewrite removes them. If the quarantine write itself fails, the raw line stays in the outbox for the next run.
  • pusher-health.json gains last_run_quarantined, total_quarantined, last_quarantine_at, last_quarantine_reason, and last_lossy_drain_at; a run that quarantined a line clears last_drain_ok_at instead of claiming a clean drain.
  • The stdout summary reports "quarantined": <count> (counts only, never record contents).
  • Valid records are untouched: insert / ignore-duplicates / _attempts/_last_error retry bookkeeping exactly as before.

Tests (laptop, real script, isolated state dir, loopback-refused DB)

New pm-stack/external-comms/test_push_quarantine.py — 4/4 pass:

  • torn-only: line recoverable verbatim from quarantine.jsonl, health counts it, no last_drain_ok_at
  • mixed valid+torn: valid line stays pending with retry bookkeeping, torn line quarantined
  • valid-only control: no quarantine, counts 0
  • non-object JSON line ([1, 2]): quarantined with reason not a JSON object

Plus a manual mixed probe: stdout quarantined: 1, health total_quarantined: 1 with reason, outbox keeps only the valid record with _attempts: 1.

Queue: task 10006 (repo-health-code-pilot), lane code-y.


Autofix with [code]smith
Open in [code]smith · Need help on this PR? Tag @codesmith-bot with what you need.

do_push silently dropped outbox lines it could not parse: the line
never reached pending, the outbox rewrite deleted it, and health
could still report a clean drain — destroying the only fallback
copy of a send record (issue #6154).

- Unparseable / non-object lines are appended verbatim to
  quarantine.jsonl in the state dir (raw line + timestamp + reason,
  fsync) before the outbox rewrite removes them; if the quarantine
  write fails the raw line stays in the outbox.
- pusher-health.json gains last_run_quarantined, total_quarantined,
  last_quarantine_at/reason and last_lossy_drain_at; a run that
  quarantined a line clears last_drain_ok_at instead of claiming a
  clean drain. The stdout summary reports the quarantined count
  (never record contents).
- Valid records keep their insert / ignore-duplicates / retry
  bookkeeping exactly as before.
- test_push_quarantine.py pins torn-only, mixed valid+torn,
  valid-only control and non-object cases against the real script
  with an isolated state dir and a loopback-refused DB.

Fixes #6154
@dezren39
dezren39 requested a review from a team as a code owner November 5, 2026 10:55
@coderabbitai

coderabbitai Bot commented Nov 5, 2026 •

Copy link
Copy Markdown

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 27 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

Learn how review limits work.

Review configuration:

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: b35eba0d-b051-41c7-9c6a-6ab858b2015f
Commits

Reviewing files that changed from the base of the PR and between 6d9d1c8 and b1326b9.

Files selected for processing: 2

  • pm-stack/external-comms/record-external-send
  • pm-stack/external-comms/test_push_quarantine.py
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 5, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-05T11:03:17.629862Z b1326b9 New commits
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 41c84f53f3

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +177 to +180
with open(QUARANTINE, "a") as f:
f.write(json.dumps(entry) + "\n")
f.flush()
os.fsync(f.fileno())

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Recover partial quarantine appends before retrying

If a quarantine append fails after writing a prefix (for example, when the disk fills), that prefix remains in quarantine.jsonl while the original line stays pending. Once space is available, the next run appends a complete entry directly after the unterminated prefix, counts it as successfully quarantined, and removes the original from the outbox. The resulting line is invalid JSON, so ordinary JSONL recovery cannot recover that record. Roll back failed appends to their starting offset, or repair an incomplete trailing entry before appending another record.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in the follow-up commit (quarantine rollback): quarantine_line now records the starting offset of quarantine.jsonl before appending and, on any append failure (write/flush/fsync), truncates the file back to that offset before re-raising — so no unterminated prefix can merge with the next entry, and the caller keeps the raw line in the outbox (pending_raw) for the next run. Pinned by QuarantineRollbackCase.test_failed_append_rolls_back_to_starting_offset, which simulates an fsync failure mid-append, asserts the file is byte-identical afterwards, and asserts the next successful append parses as a clean JSONL entry. — task 10006, lane code-y

Comment on lines +55 to +56
def test_torn_only_is_quarantined_and_not_a_clean_drain(self):
summary, health, quarantine, outbox = self.run_push([TORN])

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Add generated coverage for the quarantine invariant

The new parser/quarantine behavior has a meaningful conservation invariant—each nonblank input must remain pending or survive verbatim in quarantine—but this suite exercises only four hand-written examples. Root AGENTS.md explicitly requires property tests for parser invariants and states that example-based tests do not replace them. Add generated malformed/non-object lines and mixed batches that assert preservation and the corresponding pending/quarantine counts.

AGENTS.md reference: AGENTS.md:L41-L45

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in the follow-up commit: added GeneratedConservationCase.test_generated_mixed_batches_preserve_every_line — a seeded generated test (120 mixed lines: valid records, truncated-JSON prefixes, non-object JSON values, garbage) whose oracle is exactly the conservation invariant you name: every nonblank input line ends the run pending in the outbox or preserved verbatim in quarantine, with summary/health counts matching (quarantined + pending == total lines, total_quarantined == generated malformed count, valid ids each pending once with retry bookkeeping). 6/6 tests pass on the laptop. — task 10006, lane code-y

…ated conservation tests

Codex review on PR #6199, both findings fixed:
- P2: a quarantine append failing mid-write left an unterminated
  prefix in quarantine.jsonl; the next entry merged with it into an
  invalid JSON line and the record became unrecoverable despite
  counting as quarantined. quarantine_line now records the starting
  offset and truncates back to it on any append failure before
  re-raising (the raw line stays in the outbox via pending_raw).
- P1: the suite was example-only. Added a generated conservation
  test (seeded, 120 mixed lines: valid, truncated-JSON, non-object
  JSON, garbage) whose oracle is the invariant that every nonblank
  line ends the run pending or verbatim in quarantine, with counts
  to match; plus a rollback test that simulates an fsync failure
  mid-append. 6/6 tests pass on the laptop.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

pm-stack(external-comms): pusher silently drops unparseable outbox lines — a spilled send record vanishes while the pusher reports a clean drain

1 participant