Skip to content

fix(context): report unready graphs - #755

Merged
tirth8205 merged 3 commits into
tirth8205:mainfrom
HsiangNianian:fix/cold-worktree-readiness-734
Jul 27, 2026
Merged

fix(context): report unready graphs#755
tirth8205 merged 3 commits into
tirth8205:mainfrom
HsiangNianian:fix/cold-worktree-readiness-734

Conversation

@HsiangNianian

Copy link
Copy Markdown
Contributor

Linked issue

Closes #734

What & why

get_minimal_context_tool opened GraphStore before checking graph readiness. In a
cold worktree, that created an empty database and returned status: ok, which could
make an agent trust analysis that contained no graph data.

This change resolves graph paths without filesystem side effects before opening the
store and returns an actionable not_ready response for missing, empty, or
commit-stale graphs. The normal build path keeps its existing directory creation and
legacy migration behavior.

Regression coverage includes linked worktrees, default and external data directories,
registry overrides, legacy databases and sidecars, empty graphs, and stale build SHAs.

How it was tested

uv run pytest tests/ --tb=short -q --cov=code_review_graph --cov-report=term-missing --cov-fail-under=65
uv run ruff check code_review_graph/
uv run --with mypy --with types-networkx mypy code_review_graph/ --ignore-missing-imports --no-strict-optional
uv run --with bandit bandit -r code_review_graph/ -c pyproject.toml -q
  • 2090 passed, 5 skipped, 2 xpassed
  • 80.67% coverage

Checklist

  • Tests added for new functionality
  • All tests pass: uv run pytest tests/ --tb=short -q
  • Linting passes: uv run ruff check code_review_graph/
  • Type checking passes: uv run mypy code_review_graph/ --ignore-missing-imports --no-strict-optional
  • Lines are at most 100 characters
  • Docs updated where behavior changed (README, docs/, docstrings)

Resolve graph paths without filesystem side effects before serving minimal context, and distinguish missing, empty, and commit-stale graphs with actionable responses.
@github-actions

github-actions Bot commented Jul 27, 2026

Copy link
Copy Markdown

code-review-graph review

Overall risk: 0.60 (MEDIUM) — 17 changed function(s)/class(es), 0 affected flow(s), 5 test gap(s)

Risk-scored changes

Risk Level Symbol Location Tested
0.60 medium code_review_graph/tools/_common.py::graph_provenance code_review_graph/tools/_common.py:59 no
0.47 medium code_review_graph/main.py::get_minimal_context_tool code_review_graph/main.py:187 yes
0.40 medium code_review_graph/tools/context.py::_not_ready code_review_graph/tools/context.py:17 no
0.30 low tests/test_tools.py::TestGraphProvenance.test_missing_graph_database_has_no_envelope tests/test_tools.py:2091 (test)
0.25 low tests/test_tools.py::TestGetMinimalContext.test_mcp_wrapper_reports_missing_graph_without_creating_state tests/test_tools.py:1824 (test)
0.15 low code_review_graph/incremental.py::get_data_dir code_review_graph/incremental.py:305 yes
0.15 low code_review_graph/incremental.py::get_db_path code_review_graph/incremental.py:355 yes
0.15 low code_review_graph/tools/context.py::get_minimal_context code_review_graph/tools/context.py:48 yes
0.05 low tests/test_incremental.py::TestGetDbPath tests/test_incremental.py:150 no
0.05 low tests/test_incremental.py::TestGetDbPath.test_read_only_resolution_does_not_create_migrate_or_clean tests/test_incremental.py:179 (test)

Test gaps

  • code_review_graph/tools/_common.py::graph_provenance (code_review_graph/tools/_common.py:59)
  • code_review_graph/tools/context.py::_not_ready (code_review_graph/tools/context.py:17)
  • tests/test_incremental.py::TestGetDbPath (tests/test_incremental.py:150)
  • tests/test_tools.py::TestGetMinimalContext (tests/test_tools.py:1771)
  • tests/test_tools.py::TestGraphProvenance (tests/test_tools.py:1945)

Token savings: this graph-backed report used ~57,144 fewer tokens (~95%) than reading every changed file in full (estimated, chars/4 approximation).


Powered by code-review-graph — local-first analysis; no code leaves the CI runner.

@tirth8205

Copy link
Copy Markdown
Owner

After refreshing onto current main, the exact head exposed a real semantic conflict with merged #710: get_data_dir() still imported the removed _REGISTRY_PATH, so registry overrides were silently ignored, and the new registered-data test patched a symbol that no longer exists. I pushed cbe61f9 to use the dynamic default_registry_path() and isolate the test through CRG_HOME. Validation on the corrected head: 201 tools/incremental tests passed (1 skipped), 62 registry/daemon-path tests passed, real multiprocessing parity passed, Ruff/diff passed, and a 243-file graph build completed with zero errors. Waiting for the refreshed hosted matrix before merge.

@tirth8205
tirth8205 merged commit a6d29d4 into tirth8205:main Jul 27, 2026
11 checks passed
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.

MCP reports success for cold worktrees with an empty graph

2 participants