Skip to content
This repository was archived by the owner on Jul 13, 2026. It is now read-only.

Commit cb53011

Browse files
fix(pi/workspaces): CAS workspace-fingerprint parity + ctx_search source attribution
Two Pi-only parity gaps from a workspaces council audit: - cachedPiRowMatchesSnapshot compared the session's own projectMemoryEpoch but NOT the workspace fingerprint, unlike OpenCode's cachedRowMatchesState. A FOREIGN workspace member's epoch bump changes the fingerprint without touching this session's epoch, so a sibling-materialized row under different membership could pass the CAS and be adopted with the wrong union baseline. Added the fingerprint compare (both sides already carry it in markers). - Pi ctx_search memory line omitted the source= attribution OpenCode emits, so a foreign member's memory wasn't labeled with its origin project. Verified mustMaterializePi already checks the fingerprint symmetrically (so a membership change is a correct HARD fold, not a soft-refresh race — the council's HIGH cortexkit#2 is not exploitable). Documented the two post-ship edge cases (v22 rekey fan-out, epoch-0 fingerprint collision) as A45/A46. Pi 441/0. Co-authored-by: Alfonso [Magic Context] <[email protected]>
1 parent e44c059 commit cb53011

3 files changed

Lines changed: 32 additions & 2 deletions

File tree

‎docs/AUDIT-KNOWN-ISSUES.md‎

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -681,6 +681,25 @@ slice (25% of the memory budget) reconciled into m[0] on the next hard bust, so
681681
it intentionally uses `trimMemoriesToBudgetV2` — applying floors to a tiny delta
682682
adds determinism cost for no fairness benefit. Matches the v2.2 workspace spec.
683683

684+
### A45. Dashboard workspace epoch fan-out does not consult the v22 identity-rekey map (self-heals)
685+
686+
`workspace_member_identities_for_project` resolves a session's project to the
687+
union of its workspace siblings' identities, but does not expand pre-v22 path
688+
aliases via `v22_identity_rekey_map`. A memory stored under a legacy raw path
689+
(not yet rekeyed to its `git:`/`dir:` identity) could miss an epoch fan-out on a
690+
membership mutation. Self-heals: the v22 backfill rekeys those rows to their
691+
canonical identity, after which the fan-out matches. The window is narrow
692+
(pre-v22 rows on a workspaced project, before backfill drains) and the only
693+
symptom is a delayed m[0] refold, not data loss. Post-ship hardening.
694+
695+
### A46. `computeWorkspaceEpochFingerprint` treats a missing project_state row as epoch 0 (out-of-band only)
696+
697+
A member project with no `project_state` row hashes as epoch 0, colliding with a
698+
member genuinely at epoch 0. Only reachable if membership is added OUTSIDE the
699+
normal CRUD path (which seeds `project_state`); the dashboard/plugin mutation
700+
paths always create the row. Post-ship defense-in-depth: include the sorted
701+
member-identity list in the fingerprint hash so absent-vs-zero can't collide.
702+
684703
### A44. `ctx_search` cross-source rank uses linear-band remap, not raw IDF magnitude (parked — message embeddings supersede)
685704

686705
A common-literal probe-only message can still reach the top of the message list

‎packages/pi-plugin/src/inject-compartments-pi.ts‎

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1839,7 +1839,15 @@ function cachedPiRowMatchesSnapshot(args: {
18391839
// that re-materialized under a new system/tool/model identity must invalidate
18401840
// this process's cached row so the soft-refresh CAS adopts the sibling's m[0].
18411841
(rowMarkers.systemHash ?? "") === (args.markers.systemHash ?? "") &&
1842-
(rowMarkers.modelKey ?? "") === (args.markers.modelKey ?? "")
1842+
(rowMarkers.modelKey ?? "") === (args.markers.modelKey ?? "") &&
1843+
// Workspace fingerprint (parity with OpenCode cachedRowMatchesState):
1844+
// projectMemoryEpoch above only tracks THIS session's own project, but a
1845+
// FOREIGN member's epoch bump changes the workspace fingerprint without
1846+
// touching this session's epoch. Without this compare, a sibling row
1847+
// materialized under different workspace membership would pass the CAS and
1848+
// be adopted with the wrong union baseline.
1849+
(rowMarkers.workspaceFingerprint ?? null) ===
1850+
(args.markers.workspaceFingerprint ?? null)
18431851
);
18441852
}
18451853

‎packages/pi-plugin/src/tools/ctx-search.ts‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,11 @@ function formatAge(committedAtMs: number): string {
8181

8282
function formatResult(result: UnifiedSearchResult, index: number): string {
8383
if (result.source === "memory") {
84+
// `source=` attributes a foreign workspace member's memory to its origin
85+
// project (parity with OpenCode ctx-search/tools.ts); empty for own-project.
86+
const source = result.sourceName ? ` source=${result.sourceName}` : "";
8487
return [
85-
`[${index}] [memory] score=${result.score.toFixed(2)} id=${result.memoryId} category=${result.category} match=${result.matchType}`,
88+
`[${index}] [memory] score=${result.score.toFixed(2)} id=${result.memoryId} category=${result.category}${source} match=${result.matchType}`,
8689
result.content,
8790
].join("\n");
8891
}

0 commit comments

Comments
 (0)