Skip to content

fix(graph): persist + read node.Context so cat context works on a mounted .db (mache-b8fe72)#467

Merged
jamestexas merged 1 commit into
mainfrom
dx/mache-b8fe72-context-sqlite
Jul 2, 2026
Merged

fix(graph): persist + read node.Context so cat context works on a mounted .db (mache-b8fe72)#467
jamestexas merged 1 commit into
mainfrom
dx/mache-b8fe72-context-sqlite

Conversation

@jamestexas

Copy link
Copy Markdown
Contributor

The bug (first-impression / headline feature)

mache … --infer projects 236 source files but 0 context files — the blog's headline differentiator cat context ("only the imports/types visible to this scope") is absent for every construct on a mounted or built .db.

Root cause (confirmed by tracing the data flow): node.Context is populated at ingest (engine_walk.go) and works in MemoryStore, but the SQLite path silently drops it:

  • the nodes table had no context column,
  • SQLiteWriter.AddNode never wrote it,
  • neither read path (SQLiteWriter.GetNode, NodesTableReader.GetNode) selected it.

So vfs.ContextHandler always saw len(node.Context)==0 and served nothing. Same claim-vs-reality class as the earlier find_definition-broken-on-projection finding.

Fix (end to end)

  • nodes gains a context BLOB column; AddNode persists n.Context (nil → NULL).
  • Both GetNode paths select it. SQLiteWriter.GetNode must round-trip Context too, or the engine's two-pass write nulls it via INSERT OR REPLACE — exactly the Properties bug mache-d28eb1.
  • NodesTableReader (the mount read path shared by SQLiteGraph + WritableGraph) selects context only when the column exists (new graph.ColumnExists), so old / leyline-produced nodes tables degrade to empty Context instead of erroring. Incremental builds ALTER the column in.

Tests (the gap was: no test covered the SQLite path)

  • internal/ingest: writer persists to the context column (raw-SQL assert) + SQLiteWriter.GetNode round-trips it (two-pass protection).
  • internal/graph: NodesTableReader.GetNode carries Context (mount path) + backward-compat when the column is missing.
  • vfs.ContextHandler was already tested against node.Context; the chain is now covered ingest → persist → read → serve.

Verification

  • go test ./internal/graph/ ./internal/ingest/ ./internal/vfs/ → ok
  • -race on the round-trip/reader → ok
  • go vet + golangci-lint (pre-commit) → pass

…t` works on a mounted .db

The headline `context` virtual file was absent for every construct on a
mounted/built .db: node.Context is populated at ingest (engine_walk.go) and
works in MemoryStore, but the SQLite path dropped it — the nodes table had
no context column, SQLiteWriter.AddNode never wrote it, and neither GetNode
read path (SQLiteWriter.GetNode, NodesTableReader.GetNode) selected it. So
vfs.ContextHandler always saw len(node.Context)==0 and served nothing.

Fix, end to end:
- nodes table gains a `context BLOB` column; AddNode persists n.Context.
- Both GetNode paths select it. SQLiteWriter.GetNode must round-trip it too
  or the engine two-pass write nulls it via INSERT OR REPLACE (same class as
  the Properties fix, mache-d28eb1).
- NodesTableReader (the mount read path, shared by SQLiteGraph + WritableGraph)
  selects context only when the column exists (new graph.ColumnExists), so
  old / leyline-produced nodes tables degrade to empty Context instead of
  erroring. Incremental builds ALTER the column in.

Tests: writer persistence + writer GetNode round-trip (ingest), mount-path
NodesTableReader.GetNode carries Context + backward-compat missing-column
(graph). Closes the claim-vs-reality gap on the blog M2 feature.
@github-actions

github-actions Bot commented Jul 1, 2026

Copy link
Copy Markdown

find_smells (advisory)

Scoped to files changed in this PR. Rules below run on the standalone (no-LLO) cross-ref tables; _ast rules (cyclomatic_complexity, long_function, long_file, magic_int_in_comparison) are not exercised here.

untested_function — 1 finding(s) in changed files
Source Node Metric
internal/graph/nodes_table_reader.go graph/functions/ColumnExists 0
god_file — 1 finding(s) in changed files
Source Node Metric
internal/ingest/sqlite_writer.go 117

Rules: the registry is cmd/smell_rules.go (source of truth); see the authoring guide to add one. Advisory only — these are heuristics, not gates.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

This PR fixes a missing persistence/read-path for node.Context in the SQLite-backed graph so the context virtual file (used by cat context) works correctly when operating on a mounted or built .db.

Changes:

  • Add a context BLOB column to the SQLite nodes table and persist node.Context during ingestion writes.
  • Ensure both SQLite read paths (SQLiteWriter.GetNode and NodesTableReader.GetNode) round-trip Context, including guarding the mount reader for older DBs missing the column.
  • Add targeted tests covering write persistence, read round-trip, and backward-compat behavior when the column is absent.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.

File Description
internal/ingest/sqlite_writer.go Adds nodes.context schema + incremental ALTER, persists and reads Context in writer paths.
internal/ingest/sqlite_writer_test.go Adds an ingest-side regression test ensuring Context is stored and round-trips via GetNode.
internal/graph/nodes_table_reader.go Adds column detection and conditionally selects context for backward-compatible mount reads.
internal/graph/context_roundtrip_test.go Adds graph-layer tests for mount-path context read and missing-column compatibility.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@jamestexas jamestexas merged commit 32ee224 into main Jul 2, 2026
16 checks passed
@jamestexas jamestexas deleted the dx/mache-b8fe72-context-sqlite branch July 2, 2026 00:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants