Skip to content

context-graph: propagate resolved Memgraph/LLM config to the reconcile subprocess - #253

Merged
antejavor merged 2 commits into
mainfrom
worktree-env-passing-context-graph-reconcile
Aug 11, 2026
Merged

antejavor merged 2 commits into
mainfrom
worktree-env-passing-context-graph-reconcile

Conversation

@antejavor

Copy link
Copy Markdown
Contributor

Summary

  • SessionsGraphConnector._spawn_reconciliation spawns a detached sessions-graph reconcile subprocess on SESSION_END (when auto_reconcile is on) via a bare subprocess.Popen with no explicit env=. Per ADR 0002, the parent hook process resolves Memgraph credentials from ~/.config/context-graph/config.toml purely as constructor kwargs — never writing them to os.environ — so the spawned subprocess silently fell back to Memgraph defaults, and had no path at all to an LLM API key (LightRAG's default llm_model_func reads OPENAI_API_KEY from os.environ and raises if it's missing).
  • Extends the config-file-only resolution mechanism from ADR 0002 with an [llm] section (openai_api_key, anthropic_api_key) and resolve_llm_env(), mirroring resolve_memgraph_env(). bootstrap captures OPENAI_API_KEY/ANTHROPIC_API_KEY from the environment into the config file the same way it already does for Memgraph credentials.
  • _spawn_reconciliation now builds an explicit env= for the child: ambient os.environ overlaid with non-empty resolved Memgraph + LLM values, so the detached subprocess gets what the hook process resolved regardless of the harness's own ambient environment.
  • sessions-graph reconcile (run standalone via cron/manually) does the same best-effort fill-in at startup via an optional import, so it behaves consistently whether spawned by the hook or invoked directly.
  • agent-context-graph config set/get/show and doctor gain the new llm.* keys; command-hooks.md documents them.

Test plan

  • uv run --package agent-context-graph --extra test pytest tests/ -v — 83 passed
  • uv run --package sessions-graph --extra test --extra agent-context-graph --extra reconciliation pytest tests/ -v — 50 passed, 1 skipped (live-Memgraph e2e test)
  • ruff check / ruff format --check on changed files
  • Manual smoke test: agent-context-graph config set llm.openai_api_key, config show, config get, and doctor all reflect the new [llm] section correctly in an isolated $HOME

…e subprocess

SessionsGraphConnector spawns a detached `sessions-graph reconcile`
subprocess on SESSION_END for auto-reconciliation, via a bare
subprocess.Popen with no explicit env=. Per ADR 0002, the parent hook
process resolves Memgraph credentials from config.toml purely as
constructor kwargs, never writing them to os.environ, so the spawned
subprocess silently fell back to Memgraph defaults and had no path at
all to an LLM API key (LightRAG needs OPENAI_API_KEY/ANTHROPIC_API_KEY).

Extend the config-file resolution (agent_context_graph.adapters._identity)
with an [llm] section and resolve_llm_env(), and have the spawn site build
an explicit env for the child by overlaying resolved Memgraph + LLM config
onto ambient os.environ. sessions-graph reconcile also does the same
best-effort fill-in at startup so standalone/cron invocations behave the
same way.
@antejavor
antejavor merged commit e034aa7 into main Aug 11, 2026
20 checks passed
@antejavor
antejavor deleted the worktree-env-passing-context-graph-reconcile branch August 11, 2026 11:17
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.

1 participant