Skip to content

fix(graph): admit impact grounding records before callers and source - #238

Merged
theyashasvipandey merged 2 commits into
mex-memory:mainfrom
chiliec:fix-225-impact-grounding-budget
Sep 24, 2026
Merged

theyashasvipandey merged 2 commits into
mex-memory:mainfrom
chiliec:fix-225-impact-grounding-budget

Conversation

@chiliec

@chiliec chiliec commented Sep 22, 2026

Copy link
Copy Markdown
Contributor

What

mex impact admits grounding records right after the target's defines records, before transitive callers and source ranges, instead of last. Adds a regression test and a CHANGELOG entry.

Why

closes #225

ledger.tryAdd fails once the budget is spent. Grounding was the last record type added to the ledger, so any target with a moderate number of callers lost its knowledge links at the default 1,500-token budget. Grounding records are ~20 tokens each and are the one thing impact returns that no other command does; a caller fact costs ~50. The emitted order (target, defines, caller…, source…, grounding…) is unchanged — only the admission order moves, so the existing order-asserting test still passes. truncated is still set when callers are cut.

Type of change

  • Bug fix
  • New feature
  • Refactor
  • Docs
  • CI/Tooling

How to test

  1. npx vitest run test/graph-cli-agent.test.ts -t "exhaust the default budget"
  2. On main the new test fails: a target with 60 callers and 6 groundings at the default budget returns 15 callers and only 1 of 6 grounding records. With this change all 6 come back and truncated stays true.

Checklist

  • Tests pass (npm test) — npm run typecheck clean; test/graph-cli-agent.test.ts 12/12, plus graph-cli-*, graph-140-fixes, graph-grounding, cli-smoke (75 passed, 1 skipped). In the full npm test on my machine the only failures are 15 s vitest timeouts in the two-clone Relay / real-Git integration tests, which are unrelated to impact (none of them touch cli-agent.ts).
  • No breaking changes (or documented below)
  • Tested locally with a real project

Code-graph changes

  • This PR targets main
  • A linked issue agrees on the bounded extractor/resolver scope
  • The change follows the frozen LanguageExtractor or FrameworkResolver interface
  • A focused fixture and assertions for the expected node/edge shape are included
  • Any new grammar WASM, extension mapping, extractor, or resolver is registered
  • No graph identity, reconciliation, schema, or drift-semantics changes are included, or a core / discuss-first issue is linked above

@chiliec

chiliec commented Sep 22, 2026

Copy link
Copy Markdown
Contributor Author

CI note: storage-portability (windows-2022) is red on one test, src/team/activity/__tests__/repository.test.ts > ActivityRepository > counts malformed canonical candidates … → Test timed out in 15000ms. That file is not touched here and does not exercise impact; the same job passes on macos-14 and both check matrices are green. Looks like a Windows runner timeout — a re-run should clear it.

Pin the other half of mex-memory#225: at the smallest accepted output budget the
impact response carries no grounding records, stays within budget, and
is still marked truncated. Record why grounding is admitted before
callers and source, and name the accepted cost in the CHANGELOG.
@theyashasvipandey

theyashasvipandey commented Sep 24, 2026 •

Copy link
Copy Markdown
Collaborator

Thanks @chiliec, this is the right fix. Verified end to end: the new test fails on main and passes here. On a real repo with 12 callers and 13 groundings, mex impact at the default budget went from 0/13 grounding records to 13/13, still truncated. Edge cases (tiny budgets, --detail source, file targets) stay well-formed and within budget.

I pushed b470372 on top (no behaviour change): a test for a budget where even grounding can't fit, a comment explaining why grounding is admitted first, and the accepted cost in the CHANGELOG entry. CI is green. The Windows job needed one rerun for an unrelated timing flake.

Looks good to merge.

@theyashasvipandey
theyashasvipandey merged commit 58ab696 into mex-memory:main Sep 24, 2026
17 of 18 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.

impact drops grounding records first when it runs out of budget

2 participants