Skip to content

P3: the collapse-completion trusts an unstated visibility invariant; repo compared without repoPath #175

Closed

Description

@abogartz

Why this exists

Two non-blocking nits from my review of #158 (merged as 7bef31a, head 0a6999e). Neither is a defect today — both are load-bearing assumptions with nothing written down at the place that depends on them. Filed from the review so they stop living only in that thread.

1. The fold's survivor lookup has no visibility guard

In memory_update's collapse-completion path, the survivor is resolved with:

(await loadAll()).find((m) => m.ts === survivorTs && !m.superseded_by)

There is no isVisibleTo filter on that row. It is safe right now for one reason only: outcome.collapsedWith originates in GATE-3's poll, which already filters through the reader's visibility — a fact held two files away in gates.ts, with nothing at the lookup stating the dependency.

The fold's own predicate does check visibility (the author added that in round 3, and it was a good catch: folding a global row into a repo-private survivor narrows visibility, the reverse leaks). So the guard exists one step later than the row is first trusted.

Two ways to close it, either is fine:

  • add && isVisibleTo(m, reader) to the find, or
  • leave the code and state the invariant in a comment where the lookup happens, so the next reader doesn't move or reuse the lookup without it.

I'd take the guard. A comment protects against forgetting; the guard protects against refactoring.

2. The predicate compares repo but not repoPath

The requested-state vs survivor predicate compares the repo stamp and stops there. That holds only while a repo key implies its path. isVisibleTo itself accepts either match:

return m.repo === reader.scope.key || (!!m.repoPath && m.repoPath === reader.scope.path);

so the store's own notion of "same owner" is broader than the fold's. If a row ever carries a repoPath that disagrees with its repo key — a moved workspace, a worktree, a relocated checkout — the fold can call two differently-owned rows the same owner.

Worth either comparing both fields, or a comment recording why repo alone is sufficient.

What is already covered

Do not re-litigate these; #158 handles them and they are pinned:

Verification already done on 0a6999e

  • CI 4/4 green; full local suite 644 pass / 12 skip / 0 fail
  • cache-injection pins (epoch, status, injection-framing, gated-injection, frontier): 97 pass / 0 fail
  • test/outcome-truth-audit.test.ts: 6 of 8 red on main, green on the PR head

Activity

  1. added
    store-security
    on Oct 29, 2026
  2. WhollyMindless commented on Oct 29, 2026

    @WhollyMindless
    Contributor

    Investigated against d1d83145b8f5119bba23147f718d32d4326a9818 on Windows / Bun 1.4.4. I recommend the executable guards for both points: the path concern has a sequential reproduction, and the survivor-visibility assumption can break when a session binding changes during the gate.

    1. Equal repository keys do not preserve the same set of readers.

    I used two temporary Git repositories with the same origin, and seeded both rows through the real memory_remember tool. No hand-edited store rows, fake repository hashes, or mocked gate outcomes:

    1. Checkout A writes target T; checkout B writes survivor S. Both are open context rows in the same scope, with different prose and otherwise matching metadata. Their stamps are (K, pathA) and (K, pathB).
    2. Change A's origin to a fork, then clear/rebind the session-scope cache to model fresh identity resolution after a host restart. A now resolves to (K2, pathA); B remains (K, pathB).
    3. A's real memory_recall finds T through the path fallback. S is invisible to A.
    4. From B, call memory_update with query: T.ts and content: S.content.
    5. The gate collapses to S; the completion compares K === K and retires T. A's recall changes from Found 1 (1 total) to No memories found.

    The update reports was retired in its favor. Nothing new was written. There is no concurrent operation in this reproduction. The row is recoverable, but A has lost access to an active replacement. The existing isVisibleTo semantics give a private row the reader set “matching key OR matching path”; equal keys alone do not make those sets equal. Merely having different checkout paths does not immediately hide a row while both readers still have K—the origin change makes the discrepancy observable.

    2. GATE-3 need not use the reader captured by memory_update.

    memory_update captures its reader before awaiting the update lock. The gate awaits gate_start, then resolves readerForSession(ctx.sessionID). Capturing the session ID does not freeze that session's repository binding.

    For a deterministic interleaving, I wrapped the real evidence.record at gate_start, pushed a session.moved event through the harness's actual plugin listener, waited for the binding to update, then called the original recorder. I did not mock runWriteGate or manufacture a collapsed result.

    With ordinary A/B repositories having different origins, T in A and S in B, the move lets GATE-3 select S even though isVisibleTo(S, entryReader) is false. A differing issue field prevents retirement, but the response still prints S's issue value:

    was NOT retired ... (issue - vs PRIVATE-SURVIVOR-175; visibility ...)
    

    PRIVATE-SURVIVOR-175 is a fixture marker. This demonstrates metadata crossing the call's captured-reader boundary; it is not a claim that an unauthorized actor can move sessions. A related same-key/path-fallback case also retires T into a survivor invisible to the entry reader. The race is deterministically scheduled in the test, not a claim of having observed this timing in a live host.

    Suggested narrow scope

    • Add isVisibleTo(m, reader) to the survivor lookup, before reading its metadata or composing diagnostics.
    • Keep the existing normalized repo comparison and also require equal effective repoPath for private rows. Normalize absent/empty paths consistently with isVisibleTo; do not normalize path spelling differently from the read predicate. Global/legacy-global rows ignore path for visibility, so they should not require equal paths.
    • On a private path mismatch, preserve both rows and give an explicit path/visibility mismatch reason. Ordinary same-key, same-path duplicate completion should continue to work.

    I tested those two guards independently: the reader guard alone leaves the sequential path-loss case; the path guard alone leaves the invisible-metadata diagnostic. Together, a throwaway prototype passes all five focused probes (three regressions and two controls), plus all 24 tests across update-supersede-truth, update-partial-failure, update-provenance, and outcome-truth-audit.

    This checks the collapse branch, not immutable identity across every gate operation. Pinning a full reader through the gate could be a separate design decision. No fix branch was pushed; the temporary source edits were restored byte-for-byte. These results give concrete regression cases for a small #175 fix if that scope fits your intent.

  3. abogartz-opencode-self-improvement commented on Oct 29, 2026

    @abogartz-opencode-self-improvement

    🎉 This issue has been resolved in version 0.14.21 🎉

    The release is available on:

    Your semantic-release bot 📦🚀

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

    releasedstore-security

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions