Skip to content

fix(provision): corrupt-journal undo quarantine, honestly scoped (U10 U5 follow-up) - #54

Merged
jarodtaylor merged 3 commits into
mainfrom
fix/u5-cross-project-undo-quarantine
Jul 22, 2026
Merged

jarodtaylor merged 3 commits into
mainfrom
fix/u5-cross-project-undo-quarantine

Conversation

@jarodtaylor

@jarodtaylor jarodtaylor commented Jul 22, 2026 •

Copy link
Copy Markdown
Owner

U10 U5 follow-up — corrupt-journal undo quarantine (best-effort, honestly scoped)

Follow-up to #52, from a CodeRabbit/Copilot comment about batch grouping on an untrusted undo journal.

What this does

  • groupBatches quarantines a batchId that appears under two different canonical project roots (drops the whole batch, not just conflicting rows), and newestBatchForProject selects only from that validated grouping. Best-effort defense-in-depth against a corrupted journal.
  • Adds a filesystem-level regression + a readBatches quarantine test.

Threat-model scope (application of decision #45 — flagged for veto, not a new decision)

The Codex gate escalated this into a full adversarial-journal-integrity surface (duplicate entry-ids redirecting undo, self-declared projectRoot not constraining targetPath, quarantined-newest fallback, ABA-under-quarantine). All of it requires writing semantically-valid malicious entries into the 0700 data dir — i.e. an attacker who already owns the user's home dir and can rewrite the real configs directly. That is decision #45's explicit attacker-owns-HOME, out-of-scope boundary.

On any legitimate journal none of it can occur, by construction: each apply() stamps a fresh randomUUID batchId under one ingress-canonicalized root, entry ids are per-write randomUUIDs, and targetPath = posix.join(projectRoot, PortableRelPath) is a contained descendant. So the quarantine is a no-op on real journals — the fix's real content is correcting over-claiming comments (#52 and an earlier version of this branch read as "fail-closed cross-project safety" they don't fully deliver) to say honestly: corruption-tolerance defense-in-depth, not a security boundary.

Full journal-integrity hardening is deferred to #53, triggered only if the threat model ever expands to a hostile/shared data dir. The Codex gate approved this framing.

622 tests green, tsc clean.

Summary by CodeRabbit

  • Bug Fixes
    • Strengthened handling of corrupted or conflicting journal batches by quarantining any batch IDs that appear under multiple canonical project roots.
    • Updated newest-batch selection to rely only on validated (non-quarantined) grouped batches, improving correctness for project lookups.
    • Prevented undo operations from reversing or deleting files when journal corruption causes cross-location batch ID conflicts.
  • Tests
    • Added a new “corrupt-journal quarantine” test suite covering newest-batch recency behavior, quarantining reused batch IDs, and safe undo/no-op behavior.

…nother project (U10 U5 follow-up)

The PR #52 Copilot fold trimmed conflicting rows from a batch but the post-PR
gate caught it was incomplete: newestBatchForProject still resolved a batchId
from the raw journal, so a corrupted project-B row reusing project-A's batchId
made default undo(A or B) select A's batch and delete/restore A's REAL files.

Complete fix: groupBatches QUARANTINES a batchId that appears under two
canonical roots (drops the whole batch, not just the conflicting rows), and
newestBatchForProject selects only from that validated grouping by the batch's
own single canonical root — so a poisoned batchId is reachable by neither
default nor explicit undo. Adds a filesystem-level regression proving A's real
file survives a corrupt B-row reusing its batchId.

622 tests green, tsc clean.
… a security boundary (decision #45)

The post-PR gate escalated the corrupt-journal follow-up into a full
adversarial-journal-integrity surface (duplicate entry-ids, projectRoot not
constraining targetPath, quarantined-newest fallback). All of it is reachable
ONLY by writing semantically-valid malicious entries into the 0700 data dir =
attacker-owns-HOME = out of decision #45. On any legitimate journal nothing is
ever quarantined (unique randomUUID batchId, one canonical root, contained
targetPath — all by construction), so the guard is a no-op there.

The real defect was over-claiming comments: #52 and this branch read as
'fail-closed cross-project safety' they don't fully deliver. Fix the CLAIM, not
the behavior — keep the harmless best-effort quarantine, document it honestly as
corruption-tolerance defense-in-depth, and defer full journal-integrity hardening
to issue #53 (triggered only if the threat model expands to a hostile data dir).

622 tests green, tsc clean.
Copilot AI review requested due to automatic review settings July 22, 2026 17:02
@coderabbitai

coderabbitai Bot commented Jul 22, 2026 •

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 98342450-4d80-4d9b-bfdc-beec90ea7e1d

📥 Commits

Reviewing files that changed from the base of the PR and between 2c373c7 and 62c81e6.

📒 Files selected for processing (2)
  • src/provision/runs.ts
  • tests/provision-apply.test.ts
🚧 Files skipped from review as they are similar to previous changes (2)
  • src/provision/runs.ts
  • tests/provision-apply.test.ts

📝 Walkthrough

Walkthrough

The provisioning journal now quarantines batch IDs reused across canonical project roots. Newest-batch lookup uses validated grouped batches, and tests verify that corrupted cross-root entries cannot trigger undo or file deletion.

Changes

Batch quarantine

Layer / File(s) Summary
Quarantine grouping and validation
src/provision/runs.ts, tests/provision-apply.test.ts
groupBatches removes batches with cross-root batch-ID reuse, while tests verify safe reads and undo operations.
Grouped newest-batch selection
src/provision/runs.ts, tests/provision-apply.test.ts
newestBatchForProject selects the newest validated batch matching the canonical project root, with coverage for journal recency.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Possibly related issues

Possibly related PRs

  • jarodtaylor/agent-os#52 — Modifies journal reconstruction and undo handling for reused batch IDs across project roots.

Poem

A bunny found a batch gone wide,
With roots that crossed from side to side.
It sealed the batch and hopped away,
So undo leaves the files in place.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title matches the main change: quarantining corrupt journal batches and fixing undo handling for provision data.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/u5-cross-project-undo-quarantine

Comment @coderabbitai help to get the list of available commands.

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

Pull request overview

This PR hardens the provisioning undo batch reader against a corrupted undo journal by quarantining any batchId that appears under multiple canonical project roots, ensuring default/explicit undo never selects a cross-root batch.

Changes:

  • Update groupBatches to quarantine (drop) an entire batchId if it is observed under multiple canonicalized projectRoot values.
  • Update newestBatchForProject to select the newest batch from the already-validated grouping (so quarantined batches are never candidates).
  • Expand regression tests to assert quarantining behavior and to ensure a poisoned cross-root batchId cannot cause another project’s files to be reversed.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
tests/provision-apply.test.ts Replaces the prior “drop conflicting row” expectation with “quarantine whole batch” and adds an integration regression asserting poisoned batch IDs do not delete real files.
src/provision/runs.ts Implements batch quarantine on cross-root reuse and adjusts newest-batch selection to operate only on non-quarantined grouped batches.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/provision/runs.ts`:
- Around line 81-88: The batch selection in the flow using groupBatches must
preserve journal recency: after applying the existing quarantine validation and
projectRoot filter, select the batch associated with the last qualifying journal
entry rather than the last group ordered by first appearance. Update the
relevant selection logic around groupBatches and add a regression case covering
A1, B1, A2, which must select A.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 7f5d74f5-e332-44ca-8152-14d9b5190e12

📥 Commits

Reviewing files that changed from the base of the PR and between bb1b32f and 2c373c7.

📒 Files selected for processing (2)
  • src/provision/runs.ts
  • tests/provision-apply.test.ts

Comment thread src/provision/runs.ts Outdated
jarodtaylor added a commit that referenced this pull request Jul 22, 2026
U5 apply/undo orchestration merged (PR #52); follow-up #54 open (gate-approved).
Decisions #57 (U5 shipped) + #58 (decision-#45 applied — crafted-journal undo
attacks out of scope). Deferred #50/#51/#53 → U6. ▶ NEXT = /unit-loop U6 then U7.
…earance order (CodeRabbit #54)

My newestBatchForProject rewrite selected the last batch in groupBatches
first-appearance order, which diverges from the documented 'batch of the
LAST-APPEARING journal entry' under interleaved entries (A1,B1,A2 → should be A,
was B). Resolve each journal entry's batchId (newest-first) through the VALIDATED
grouping so a quarantined batchId is never a candidate and only a root-matching
batch is returned — restoring the documented recency while keeping the
cross-root quarantine. Adds the A1,B1,A2 recency regression.

623 tests green, tsc clean.
@jarodtaylor
jarodtaylor merged commit de245f4 into main Jul 22, 2026
1 check passed
@jarodtaylor
jarodtaylor deleted the fix/u5-cross-project-undo-quarantine branch July 22, 2026 17:30
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.

2 participants