Skip to content

P2: memory_update claims nothing was written after post-append audit failure; retry leaves two active rows #155

Closed

Description

@WhollyMindless

Reproduced on current main 91f7a56 (v0.14.13), Windows/Bun 1.3.10, using deterministic fault injection at the write_promoted evidence call. The gate, store append, update tool, and retry run normally. The test injects an exception to model an evidence I/O failure; it does not claim that an actual disk-full condition occurred.

Sequence:

  1. Seed an active row and call memory_update for its exact id.
  2. Let the replacement append succeed.
  3. Throw on the gate's subsequent record("write_promoted", ...).
  4. Observe the replacement on disk while the original is still active.
  5. Remove the injected fault and repeat the exact update.

Observed:

First call: memory_update blocked: ENOSPC: injected evidence append failure Nothing was written.
Retry:      Duplicate ignored: context/planning
Active rows: 2

Cause: runWriteGate awaits evidence after appending, so the tool never receives the promoted row id when that evidence write throws. The update catch incorrectly assumes only a pre-write lock timeout can reach it. It reports no write, and the retry's duplicate outcome never completes supersession of the original.

This is distinct from the merge-review partial-result defect fixed by #135. That fix still passes its regression; the analogous update path retains the same incorrect no-op report.

Suggested fix / acceptance: preserve durable-write outcome/row identity across post-append evidence failures, report a truthful partial result, and make retry finish or explicitly recover the incomplete update without leaving two active versions. Do not simply swallow every gate exception: genuine pre-mutation failures must remain fail-closed. Pin both a post-append evidence failure and a pre-write failure, including the retry behavior.

Runnable regression test (expected red on v0.14.13)

Save as review-update-partial.test.ts at the repository root, then run bun test ./review-update-partial.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("a post-append audit failure must not make update claim that nothing was written", async () => {
  const pa = await plugin(a);
  const original = await seed(a, "Plan to prune aged queue entries every evening");
  const record = evidence.record;
  const spy = spyOn(evidence, "record").mockImplementation(async (...args: Parameters<typeof record>) => {
    if (args[0] === "write_promoted") throw new Error("ENOSPC: injected evidence append failure");
    return record(...args);
  });
  let result: { content: string };
  try {
    result = await pa.tools.memory_update.execute({ type: "context", scope: "planning", query: original, content: "Plan to prune aged queue entries every morning", status: "open" }, ctx("ses-a"));
  } finally { spy.mockRestore(); }
  const all = await loadAll();
  expect(all.some(m => m.content.includes("every morning"))).toBe(true);
  expect(all.find(m => m.ts === original)?.superseded_by).toBeUndefined();
  const retry = await pa.tools.memory_update.execute({ type: "context", scope: "planning", query: original, content: "Plan to prune aged queue entries every morning", status: "open" }, ctx("ses-a"));
  console.log("update-post-append-fault", JSON.stringify({result: result.content, retry: retry.content, activeRows: (await loadAll()).filter(m => !m.superseded_by).length}));
  expect(retry.content).toContain("Duplicate ignored");
  expect(result.content).not.toContain("Nothing was written");
});

Activity

  1. WhollyMindless commented on Oct 28, 2026

    @WhollyMindless
    ContributorAuthor

    Taking this one — same branch as #154 (fix/security-154-155): the memory_update twin of the merge_review partial-result fix that landed as 156e887 on this very program — the catch's premise ("only the fail-closed lock timeout throws here") is now demonstrably false since the gate awaits evidence AFTER the append. Plan per the acceptance: the post-append failure path completes (or explicitly recovers) the supersession so the store never sits with two active versions — the supersede is first-call-wins, so completing it in the failure path is safe — reports a truthful partial like merge_review does, and keeps genuine pre-mutation failures fail-closed with nothing written. Both a post-append-evidence fault and a pre-write fault pinned, including the retry's outcome. Probe verified red on 91f7a56; deterministic fault injection exactly as the issue stages it.

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

    @abogartz-opencode-self-improvement

    🎉 This issue has been resolved in version 0.14.18 🎉

    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

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions