Skip to content

P1: unresolved named sessions publish private memories into the last repo or globally #152

Closed

Description

@WhollyMindless

Reproduced on current main 91f7a56 (v0.14.13), Windows/Bun 1.3.10, through the registered memory_remember and memory_recall tools. This is the durable-write counterpart of the unresolved-session evidence defect fixed in #133; the existing evidence/read regression tests remain green.

A server-style plugin with no setup directory cannot bind a fresh session when the context/session APIs cannot resolve it. The caller still supplies a real sessionID and does not request global:true. Its write is nevertheless promoted:

  • If a repo-B plugin loaded last, the new row receives B's repo key and B can recall A's private content.
  • If no module scope exists, the row is unstamped/global and a subsequently loaded B plugin can recall it.

No concurrent interleave is required. The test includes a bound-session control, which correctly keeps the same candidate private.

Cause: appendMemory's stamp resolution still calls repoScopeFor(input.sessionID ?? getCurrent().sid). repoScopeFor returns the module scope when the named session is unresolved. With null scope, no stamp is emitted and readers treat the new row as global. Threading the sid (#121) alone does not fix this fallback.

Observed output in both cases:

Remembered: context in planning
B recall: Found 1 (1 total)
- [2026-10-28] [open] context/planning: UNRESOLVED_A_PRIVATE_RELEASE_PLAN

Suggested fix / acceptance: resolve a named writer's scope without the ambient/module fallback. If identity remains unresolved, refuse the non-global write or persist it privately to that session; it must not become another repo's row or a legacy/global row. Preserve explicit global:true and the deliberately sessionless admin path. Carry the chosen write identity through async work rather than silently changing it if its session binding disappears. Pin both no-module-scope and later-B-setup cases, plus the ordinary bound-session control.

Related: #127, #121. This is not #143's export bypass: B receives the content through ordinary scoped recall.

Runnable regression test (expected red on v0.14.13)

Save as review-unresolved-writes.test.ts at the repository root, then run bun test ./review-unresolved-writes.test.ts. Uses the repository's existing inert host harness and temporary stores; no live memory or model calls.

import { afterEach, beforeEach, expect, spyOn, test } from "bun:test";
import { mkdirSync, mkdtempSync, rmSync } from "node:fs";
import { tmpdir } from "node:os";
import { basename, dirname, join, resolve } from "node:path";
import { loadPlugin, type LoadedPlugin } from "./test/harness.ts";
import { appendMemory, loadAll, snapshotFiles } from "./src/memory.ts";
import { rememberSessionDir, resetSessionScopes, resolveRepo, setRepoScope } from "./src/repokey.ts";
import { resetState } from "./src/state.ts";
import * as evidence from "./src/evidence.ts";

let root: string, a: string, b: string;
let plugins: LoadedPlugin[];
beforeEach(() => {
  root = mkdtempSync(join(tmpdir(), "osi-review-v01413-"));
  a = join(root, "repo-a"); b = join(root, "repo-b");
  mkdirSync(a); mkdirSync(b);
  process.env.OPENCODE_MEMORY_DIR = join(root, "memory");
  process.env.OPENCODE_COMMANDS_DIR = join(root, "commands");
  resetState(); resetSessionScopes(); setRepoScope(null); plugins = [];
});
afterEach(async () => {
  for (const p of plugins) await p.cleanup();
  resetState(); resetSessionScopes(); setRepoScope(null);
  delete process.env.OPENCODE_MEMORY_DIR; delete process.env.OPENCODE_COMMANDS_DIR;
  if (dirname(resolve(root)) !== resolve(tmpdir()) || !basename(root).startsWith("osi-review-v01413-")) {
    throw new Error("Unexpected fixture cleanup path");
  }
  rmSync(root, { recursive: true, force: true, maxRetries: 5, retryDelay: 20 });
});
async function plugin(dir: string | null) {
  const p = await loadPlugin(dir); plugins.push(p); return p;
}
async function seed(dir: string, content: string) {
  const scope = resolveRepo(dir);
  return appendMemory({ type: "context", scope: "planning", content, status: "open", repo: scope.key, repoPath: scope.path });
}
const ctx = (sessionID: string) => ({ sessionID, id: "review-proof" });
const candidate = { type: "context", scope: "planning", status: "open", content: "UNRESOLVED_A_PRIVATE_RELEASE_PLAN" };

test("an unresolved named session must not write a private row into the last setup's repo", async () => {
  const pa = await plugin(null);
  const pb = await plugin(b);
  const result = await pa.tools.memory_remember.execute(candidate, ctx("ses-unresolved-a"));
  const row = (await loadAll()).find(m => m.content === candidate.content);
  const seen = await pb.tools.memory_recall.execute({ query: candidate.content }, ctx("ses-b"));
  console.log("unresolved-after-B", JSON.stringify({result: result.content, writtenRepo: row?.repo, bRepo: resolveRepo(b).key, foreignRecall: seen.content}));
  expect(seen.content).not.toContain(candidate.content);
});

test("an unresolved named session must not silently publish a global memory", async () => {
  const pa = await plugin(null);
  const result = await pa.tools.memory_remember.execute(candidate, ctx("ses-unresolved-a"));
  const row = (await loadAll()).find(m => m.content === candidate.content);
  const pb = await plugin(b);
  const seen = await pb.tools.memory_recall.execute({ query: candidate.content }, ctx("ses-b"));
  console.log("unresolved-before-B", JSON.stringify({result: result.content, writtenRepo: row?.repo ?? "unstamped/global", foreignRecall: seen.content}));
  expect(seen.content).not.toContain(candidate.content);
});

test("control: a bound caller still stores private memory only for its own repo", async () => {
  const pa = await plugin(a);
  const pb = await plugin(b);
  rememberSessionDir("ses-a", a);
  const result = await pa.tools.memory_remember.execute(candidate, ctx("ses-a"));
  expect(result.content).toContain("Remembered");
  expect((await pa.tools.memory_recall.execute({ query: candidate.content }, ctx("ses-a"))).content).toContain(candidate.content);
  expect((await pb.tools.memory_recall.execute({ query: candidate.content }, ctx("ses-b"))).content).not.toContain(candidate.content);
});

Activity

  1. added
    store-security
    on Oct 28, 2026
  2. self-assigned this
    on Oct 28, 2026
  3. abogartz commented on Oct 28, 2026

    @abogartz
    Owner

    Claimed by @abogartz — branch fix/152-unresolved-writer-scope (base main).

    Severity triage across the open security queue (confidentiality/integrity impact × how ordinary the trigger is):

    # Class Trigger Verdict
    #152 cross-repo confidentiality on the durable write path any memory_remember from a session the host cannot resolve — no force, no admin, no interleave taken first
    #153 cross-repo integrity (memory_undo force rollback) needs force:true and leaves the safety snapshot next
    #143 cross-repo confidentiality via memory_export whole store, but to a local file the caller already owns next
    #35 / #38 deletion durability / write-side threat scan P0/P1 labels, but hardening of an already-gated path, not an active leak later

    #152 is the worst open one: the read side already fails closed to global-only for an unbound session (#127/#133), while the write side still falls back to repoScopeFor() — the module scope of whoever called setup() last, or null (= global). So the same unknown identity reads almost nothing and writes into somebody else's repository. Fix follows the read side's rule: a named session with no resolved repository has no write target — refuse rather than inherit or publish globally. Explicit global:true and the deliberately sessionless admin/viewer path are unchanged.

  4. WhollyMindless commented on Oct 28, 2026

    @WhollyMindless
    ContributorAuthor

    SUPERSEDED — standing down. The maintainer claimed this 18 minutes before this comment landed (assignee + branch + PR #157 at 19:59 UTC); our notification stream didn't show it when this was queued, and it posted 45 seconds after #157 opened. @abogartz's ix/152-unresolved-writer-scope is the fix to review; nothing is being pushed against #152 from this side. The field observation in the comment above (this channel bit our own test authors during #156) still stands as evidence for the fail-closed design their PR implements. Meanwhile the queue's 'next' items #143/#153 already have a checks-green PR: #156.

  5. abogartz commented on Oct 28, 2026

    @abogartz
    Owner

    Fix up as PR #157 (branch fix/152-unresolved-writer-scope, base main). Both reported cases plus the two paths the report did not name (memory_import, auto-capture) were reproduced locally on macOS / Bun 1.4.3 before the change; the fix makes the write side resolve identity the way the read side already does — a named session with no resolved repository has no write target — and covers it at the store's choke point, not just at the tools. Explicit global:true and the sessionless admin path are unchanged; the one flipped contract (the server-start window used to store a global row) is called out in the PR.

  6. added a commit that references this issue on Oct 28, 2026
  7. abogartz-opencode-self-improvement commented on Oct 28, 2026

    @abogartz-opencode-self-improvement

    🎉 This issue has been resolved in version 0.14.14 🎉

    The release is available on:

    Your semantic-release bot 📦🚀

  8. added a commit that references this issue on Oct 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

releasedstore-security

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions