Skip to content

feat(init): make codebase-memory graph indexing opt-in (default off) - #324

Merged
abogartz merged 3 commits into
mainfrom
323-graph-opt-in
Nov 8, 2026
Merged

abogartz merged 3 commits into
mainfrom
323-graph-opt-in

Conversation

@abogartz

@abogartz abogartz commented Nov 6, 2026

Copy link
Copy Markdown
Owner

Problem

memory_init built a codebase-memory graph on every run, and nothing consumed it.

Measured on this repository before the change:

  • ensureGraph — 11.5 s
  • memory_init end to end — ~26 s

The graph is not read by the write gate. Gate evidence (graph_current, graph_drift) comes from gate1's live file-tree scan, so gate decisions are identical with the graph on or off. The benchmark stores confirmed the same thing from the other side: 29 runs reported graph=unavailable against 3 that reported indexed, with no difference in gate outcomes.

Keeping a 26 s step that nothing reads is not a good default.

Change

Graph indexing is now opt-in via OPENCODE_MEMORY_GRAPH=1. Default is off.

  • src/core/config/paths.ts — graphEnabled(); also corrects a stale comment that claimed the resolver cross-checks the graph.
  • src/init/run.ts — runInit skips ensureGraph unless enabled, and the skip path no longer reports indexed.
  • src/init/detect.ts — GraphStatus gains "disabled".
  • src/tools/init.ts, command/repo-init.md, README.md — surface the new state and the opt-in.
  • test/init.test.ts — two spawn-proof tests using a marker script: default performs no spawn, opt-in reaches the binary.

Evidence

  • Typecheck clean, full suite 1058 pass / 0 fail, lint clean.
  • End-to-end opencode run against this build: memory_init 0.13 s, reports Graph: disabled, zero codebase-memory spawns, scripts still remembered.
  • The pre-push merge gate initially failed on e2e/characterization.test.ts, which pins the host-facing memory_init output shape and did not allow the new state. That contract now accepts disabled (7f965c0), and the full gate is green.

Risk

Users who want the graph set OPENCODE_MEMORY_GRAPH=1. Nothing else changes: store, gates, injection and recall are untouched.

Closes #323

ocsi and others added 2 commits November 6, 2026 07:53
runInit skips ensureGraph unless OPENCODE_MEMORY_GRAPH=1. Measured: the
one-shot index spawn cost 11-26s per init, failed 29/32 real runs, and no
read or gate path consumes the index (gate evidence identical with/without).
memory_init 25s -> 0.13s; gate behavior unchanged.

- paths.ts: graphEnabled(); correct stale 'resolver cross-checks the graph' comment
- detect.ts: GraphStatus action adds 'disabled'
- run.ts: gate the spawn; skip-path reports this build's state, not the prior stamp's
- tools/init.ts + command/repo-init.md: drop the graph-index promise
- init.test.ts: default no-spawn + opt-in reaches-binary (marker script); hermetic env
- README: code graph now opt-in; env table + troubleshooting updated

Refs #323, #317, #315

@WhollyMindless WhollyMindless left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed 7f965c0b2b25025b29d000cbfd8ad4ae1cad6c65 against the human-authored #323 contract.

F1 — make the new graph-spawn fixture work on Windows (test/init.test.ts:91–102). The opt-in test writes an extensionless #!/bin/sh executable and launches it through Bun.spawn([fake, ...]). On native Windows this fixture does not execute: the expected marker is absent. I reproduced the same failure locally with Bun 1.4.4: bun test ./test/init.test.ts ./test/scenarios.test.ts ./test/resolver.test.ts gives 35 pass, 1 fail, at expect(existsSync(marker)).toBe(true). Hosted Windows fails at the same assertion (job log). This failure is independent of contention or timeout margins.

Please use a cross-platform spawn fixture or a narrowly scoped Bun.spawn spy, retaining both the no-spawn default assertion and an opt-in positive control. Merely skipping the opt-in test would lose the requested Windows coverage. A successful-index result is also useful: Graph: unavailable alone cannot distinguish reaching the fixture from failing to launch it.

The small production change looks consistent with #323. My separate temporary probe intercepted only the synthetic graph command and verified exact "1" flag semantics, zero graph spawns for unset/0/true, successful opt-in indexing, preserved command detection, and the disabled state on a repeated init (1 pass, 19 assertions). Optional dependency retained; no tracked source changes made. This is not a full-suite or live-host performance verification.

The hosted job also has six concurrency failures; I have not reproduced or attributed those to this diff. The independently reproduced PR-owned test failure above is the requested change.

…iew F1)

The extensionless #!/bin/sh fixture never executes on Windows, so the
opt-in test failed there and the default no-spawn assertion passed only
trivially. Replace both marker-script fixtures with a narrowly scoped
Bun.spawn spy: the default test proves zero spawns against a fake that
would answer successfully, the opt-in test adds a successful-index
positive control (Graph: indexed (repo), argv asserted), and a third
test keeps the failing-binary degradation. Cross-platform, hermetic.
@abogartz

abogartz commented Nov 8, 2026

Copy link
Copy Markdown
Owner Author

F1 fixed in d7c6340. Both marker-script fixtures replaced with a narrowly scoped Bun.spawn spy in test/init.test.ts (the option the review allowed):

  • default: no graph spawn occurs — the spy is installed with a fake that would answer every call successfully; asserts zero recorded spawns. On Windows the old marker test passed only trivially (the fixture never executed); this assertion now has teeth on every platform.
  • opt-in: reaches the graph binary — now a successful-index positive control: list_projects returns the fixture root only after index_repository lands, so the run must reach Graph: indexed (repo). Also asserts argv: argv[0] is the configured OPENCODE_CBM_BIN, plus --repo-path <fixture> and --mode moderate. Graph: unavailable can no longer be the only opt-in verdict, per the review note that it cannot distinguish reaching the fixture from failing to launch it.
  • opt-in: failing binary degrades to unavailable — keeps the old exit-3 degradation coverage, spy-based so it is also Windows-honest, and asserts the spawn was attempted against the configured binary.

The spy patches only Bun.spawn (the single graph-path call site, run() in src/init/run.ts), restores in finally, and leaves Bun.spawnSync (git probing) untouched. Verified patchable on this Bun; hermetic, no executable fixture, no shell.

Local: bun test ./test/init.test.ts 9 pass; full suite 1070 pass / 0 fail; tsc --noEmit clean; lint exit 0.

The six concurrency failures (test/concurrency.test.ts) are not attributed to this diff and not touched here: the diff touches no store/lock/evidence path, and the same tests pass on the hosted runner on sibling PRs from the identical base (e.g. run 42340075302 on 329-capture-precision: all racing-appends and two-processes tests green). In the failing job all six share one temp root (osi-race-eB92i3) whose evidence dir hit ENOENT after the first test's 7.4 s stall — a loaded-runner cascade, consistent with flake. Will follow up separately if it recurs.

@abogartz

abogartz commented Nov 8, 2026

Copy link
Copy Markdown
Owner Author

CI after d7c6340: test-windows is green — the F1 fixture failure is gone. The first run's Linux test job hit the same concurrency cascade (supersede/prune/restore racing appends, two processes sharing one store, plus the two viewer/scenario races) with the identical signature: an fs burst overrunning the 5 s store-lock deadline (memory store is busy: ... locked for 5000ms — retry), then teardown racing the stalled test's still-running promises. A plain rerun of the same commit is fully green: lint, test, test-windows, smoke — load-dependent flake, consistent with the #245 note in test/concurrency.test.ts, not a product of this diff.

@WhollyMindless WhollyMindless left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rechecked head d7c6340fd23f396c0b5312f1fd6d05757a94ec9c. F1 is resolved; this approval supersedes my earlier changes request.

The delta from the reviewed head changes only test/init.test.ts. The scoped spawn spy restores in finally, leaves git probing untouched, asserts zero graph spawns by default, and exercises both successful indexing (including configured binary, repository path and mode) and exit-failure degradation. The extensionless shell fixture is gone.

Independent native Windows / Bun 1.4.4 verification: the same three focused suites now pass, 37 tests / 206 assertions / 0 failures; typecheck passes. All four hosted checks, including Windows, are green at this head. I did not rerun the full suite or live-host timing benchmark; the earlier six concurrency failures remain unattributed by me. No remaining blocking finding from my review; merge timing remains the maintainer's decision.

@abogartz
abogartz merged commit 474240d into main Nov 8, 2026
7 of 8 checks passed
@abogartz-opencode-self-improvement

Copy link
Copy Markdown

🎉 This PR is included in version 0.16.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

@abogartz
abogartz deleted the 323-graph-opt-in branch November 19, 2026 05:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Make codebase-memory graph indexing opt-in (default OFF): 25s/init for an artifact nothing reads

2 participants