Skip to content

fix: headless init does not stamp project time_initialized so memory stays inert #404

Description

@LeXwDeX

Why

Running /init through headless entrypoints (opencode run, opencode serve + HTTP API) writes AGENTS.md but never stamps project.time_initialized in the DB, so MEMORY stays fail-closed inert forever with no hint. Interactive TUI stamps correctly. Verified on released v1.0.29 and v1.0.28 binaries (not a 1.0.29 regression; long-standing headless gap).

Repro (verified on darwin-arm64 release binaries)

  1. Fresh git repo, then: opencode run "/init" twice → AGENTS.md written, but sqlite3 ~/.local/share/opencode/opencode.db "SELECT time_initialized FROM project WHERE worktree LIKE '%<repo>%''" stays empty
  2. opencode serve + POST /session/:id/message with /init → same result
  3. Interactive TUI on same repo → stamp lands

Suspected mechanism

packages/opencode/src/project/project.ts (~L418-428) initState listens for Command.Event.Executed and matches event.location?.directory === ctx.directory. The EventV2 bridge (src/event-v2-bridge.ts) injects location from InstanceRef; when headless runs publish without a location (InstanceRef absent or a different fiber context), the listener silently drops the event.

Evidence

  • DB row exists with NULL stamp after headless /init (both run and serve paths)
  • git log -S 'Command.Default.INIT' shows the listener predates 1.0.29
  • v1.0.28 binary reproduces identically

Acceptance

  • opencode run "/init" on a fresh repo stamps time_initialized
  • serve + HTTP API /init stamps as well
  • Regression test covering the headless command-executed → stamp path
  • TUI path keeps working (no regression)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions