Skip to content

Init's stamp lives in the memory store, so a forged row can suppress init #374

Closed

Description

@abogartz

The problem

memory_init decides whether a repository has already been set up by looking for a row in the memory store: a context row in the repository's scope carrying the tag init-stamp, whose content names the current short HEAD (src/init/run.ts:91-100).

That row is plugin-internal state, but it lives in the same store that memory_remember writes and memory_import reads, and nothing reserves the tag. So any session can create one:

  1. git rev-parse --short HEAD in the checkout.
  2. memory_remember with type: context, the repo's scope, tags: ["init-stamp"] and content naming that HEAD.
  3. Every later memory_init in that repository answers "Already initialized" and writes no command rows — for that commit, and the session never has to say why.

Reported by @abogartz in #292 item 7 against 0.15.21 and confirmed against main at d0929a6 by reading the code: there is no reserved-tag list anywhere in src/, and the stamp lookup checks only type, scope, tag and HEAD.

Impact is small — init writes build commands, and a session that can forge this can mostly do its damage anyway — but the failure is silent and it is the store talking to itself through a door a model can knock on.

Fix direction

Move the stamp out of the memory store rather than filtering for forgeries. A stamp file under the memory root (keyed by repo, holding HEAD and the init timestamp) is read and written only by src/init/, so no tool can reach it and memory_recall, export and the viewer stop showing a row that was never meant to be read by anyone.

A one-time migration keeps installed repos working: if the file is absent and a store row matches today's lookup, honour it once and write the file, then leave the old row alone. Without that, every existing checkout re-inits on the next release.

The cheap alternative is a reserved-tag list in the schema that refuses init-stamp on memory_remember. That protects the door and not the room: memory_import takes rows straight from a file, and it leaves the same design smell — internal state masquerading as a memory.

Acceptance

  • RED: with a hand-written context row tagged init-stamp naming the current HEAD, memory_init reports "Already initialized" and writes no rows. Fails on main for exactly that reason.
  • GREEN: the same forged row is ignored — init runs and writes its commands — while a real init followed by a second init is still a no-op.
  • A checkout initialized by the previous release does not re-run init after upgrading: its store row is honoured once and migrated.
  • bun run gate green, bun run test:e2e since src/ changed.

Activity

  1. added
    bug
    store-security
    severity:medium
    on Nov 9, 2026
  2. abogartz-opencode-self-improvement commented on Nov 12, 2026

    @abogartz-opencode-self-improvement

    🎉 This issue has been resolved in version 0.23.1 🎉

    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

    bugreleasedseverity:mediumstore-security

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions