Skip to content

add trace pruning collapsing cross-service (PR-TRACE-1b)#245

Merged
HumanBean17 merged 3 commits into
experimentalfrom
feat/trace-pruning
May 30, 2026
Merged

add trace pruning collapsing cross-service (PR-TRACE-1b)#245
HumanBean17 merged 3 commits into
experimentalfrom
feat/trace-pruning

Conversation

@HumanBean17

Copy link
Copy Markdown
Owner

Summary

  • prune_roles soft gate: edges to pruned-role nodes are recorded in result, but the node is not added to the next BFS frontier. stats.nodes_pruned_role counts pruned nodes.
  • fan_out_cap with ranking: per-node cap on candidate edges sorted by confidence (desc) → role priority (desc) → fqn (asc). Scaffolding edges (DECLARES_CLIENT, DECLARES_PRODUCER) are exempt. stats.nodes_pruned_fan_out counts dropped nodes.
  • collapse_trivial post-BFS pass: degree-1 intermediates (1 in + 1 out CALLS, role OTHER) are collapsed into single edges with collapsed=True and collapsed_intermediates=[B.id]. parent_edge_id is recomputed for child edges referencing removed edges. stats.edges_collapsed_trivial counts collapsed chains.
  • Cross-service boundary detection: when HTTP_CALLS/ASYNC_CALLS is in edge_types, BFS follows scaffolding edges (consuming a hop) to Client/Producer, then follows cross-service edges to downstream Route. Edges marked cross_service_boundary=True. Downstream node included in nodes dict but NOT added to frontier (boundary-stop).

Test plan

  • 33 unique tests in tests/test_mcp_trace.py (31 passed, 2 skipped on fixture graph gaps)
  • test_trace_filter_vs_prune_roles replaces 1a's test_trace_prune_roles_param_accepted_noop stub
  • 10 new 1b tests: prune_roles, fan_out_cap, scaffolding exempt, collapse_trivial, collapse disabled, parent_edge_id consistency, cross-service HTTP, cross-service async, cross-service attrs, boundary stops
  • .venv/bin/ruff check . clean
  • .venv/bin/python -m pytest tests -v green (648 passed, 11 skipped)
  • Sentinel check: git diff experimental -- mcp_v2.py kuzu_queries.py server.py empty

Scope

  • mcp_trace.py — pruning, collapsing, cross-service implementation
  • tests/test_mcp_trace.py — 11 new/replaced tests
  • No changes to mcp_v2.py, kuzu_queries.py, server.py, build_ast_graph.py, java_ontology.py

🤖 Generated with Claude Code

Implements four pruning features for the trace BFS engine:
- prune_roles soft gate (edges recorded, frontier stops)
- fan_out_cap with confidence + role ranking (scaffolding exempt)
- collapse_trivial post-BFS pass with parent_edge_id recomputation
- cross-service boundary detection (DECLARES_CLIENT/PRODUCER → HTTP/ASYNC_CALLS)

Replaces 1a's test_trace_prune_roles_param_accepted_noop stub with
test_trace_filter_vs_prune_roles. 10 additional 1b tests. 33 total
unique tests (31 pass, 2 skip on fixture gaps). Full suite green (648
passed). No changes to mcp_v2.py, kuzu_queries.py, server.py.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
@HumanBean17

Copy link
Copy Markdown
Owner Author

PR-TRACE-1b Review

Solid implementation — clean separation between the four features, good test coverage, and consistent with project conventions. A few items:

Medium

  • Vacuous assertion in test_trace_cross_service_edge_attrslen(xe.attrs) >= 0 is always true. Should assert on specific attribute keys or use > 0.

Low

  • _collapse_trivial_chains is single-pass. For A→B→C→D where B and C are both trivial intermediates, only B gets collapsed (collapsed edges are skipped on line 65). Fine if intentional, but worth a docstring note about the single-pass limitation. If multi-level chains are expected, consider looping until collapsed_count == 0.

  • Silent except Exception: continue in cross-service handling (~lines 279, 340). A malformed graph could silently produce incomplete results. Consider logging to stderr (safe per AGENTS.md — server is stdio-based).

  • Per-node _neighbors_batched calls in cross-service (~line 312). Each Client/Producer node triggers a separate query. Could be batched if this becomes a bottleneck at scale.

  • _collapse_trivial_chains mutates caller's nodes, edges, and edge_id_map in-place. A brief docstring note about mutation would help future readers.

What looks good

  • prune_roles soft gate vs NodeFilter hard gate — clean semantic distinction
  • Scaffolding exemption from fan_out_cap — sensible design
  • parent_edge_id recomputation after collapse
  • Boundary-stop semantics (node in nodes, not in frontier)
  • Tests assert on invariants, not exact counts — consistent with testing philosophy
  • test_trace_filter_vs_prune_roles is a good upgrade from the previous stub

HumanBean17 and others added 2 commits May 30, 2026 19:48
- Fix vacuous assertion in test_trace_cross_service_edge_attrs
- Add docstring to _collapse_trivial_chains noting single-pass and mutation
- Add stderr logging to cross-service exception handlers

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
Dead code introduced in review fix commit.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
@HumanBean17 HumanBean17 merged commit 4e4afee into experimental May 30, 2026
1 check passed
HumanBean17 added a commit that referenced this pull request May 30, 2026
* add trace pruning, collapsing, cross-service (PR-TRACE-1b)

Implements four pruning features for the trace BFS engine:
- prune_roles soft gate (edges recorded, frontier stops)
- fan_out_cap with confidence + role ranking (scaffolding exempt)
- collapse_trivial post-BFS pass with parent_edge_id recomputation
- cross-service boundary detection (DECLARES_CLIENT/PRODUCER → HTTP/ASYNC_CALLS)

Replaces 1a's test_trace_prune_roles_param_accepted_noop stub with
test_trace_filter_vs_prune_roles. 10 additional 1b tests. 33 total
unique tests (31 pass, 2 skip on fixture gaps). Full suite green (648
passed). No changes to mcp_v2.py, kuzu_queries.py, server.py.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>

* fix: address review feedback on PR-TRACE-1b (#245)

- Fix vacuous assertion in test_trace_cross_service_edge_attrs
- Add docstring to _collapse_trivial_chains noting single-pass and mutation
- Add stderr logging to cross-service exception handlers

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>

* fix: remove duplicate continue in cross-service exception handler

Dead code introduced in review fix commit.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 4.7 <noreply@anthropic.com>
HumanBean17 added a commit that referenced this pull request May 31, 2026
* add trace pruning, collapsing, cross-service (PR-TRACE-1b)

Implements four pruning features for the trace BFS engine:
- prune_roles soft gate (edges recorded, frontier stops)
- fan_out_cap with confidence + role ranking (scaffolding exempt)
- collapse_trivial post-BFS pass with parent_edge_id recomputation
- cross-service boundary detection (DECLARES_CLIENT/PRODUCER → HTTP/ASYNC_CALLS)

Replaces 1a's test_trace_prune_roles_param_accepted_noop stub with
test_trace_filter_vs_prune_roles. 10 additional 1b tests. 33 total
unique tests (31 pass, 2 skip on fixture gaps). Full suite green (648
passed). No changes to mcp_v2.py, kuzu_queries.py, server.py.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>

* fix: address review feedback on PR-TRACE-1b (#245)

- Fix vacuous assertion in test_trace_cross_service_edge_attrs
- Add docstring to _collapse_trivial_chains noting single-pass and mutation
- Add stderr logging to cross-service exception handlers

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>

* fix: remove duplicate continue in cross-service exception handler

Dead code introduced in review fix commit.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 4.7 <noreply@anthropic.com>
HumanBean17 added a commit that referenced this pull request May 31, 2026
* add trace pruning, collapsing, cross-service (PR-TRACE-1b)

Implements four pruning features for the trace BFS engine:
- prune_roles soft gate (edges recorded, frontier stops)
- fan_out_cap with confidence + role ranking (scaffolding exempt)
- collapse_trivial post-BFS pass with parent_edge_id recomputation
- cross-service boundary detection (DECLARES_CLIENT/PRODUCER → HTTP/ASYNC_CALLS)

Replaces 1a's test_trace_prune_roles_param_accepted_noop stub with
test_trace_filter_vs_prune_roles. 10 additional 1b tests. 33 total
unique tests (31 pass, 2 skip on fixture gaps). Full suite green (648
passed). No changes to mcp_v2.py, kuzu_queries.py, server.py.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>

* fix: address review feedback on PR-TRACE-1b (#245)

- Fix vacuous assertion in test_trace_cross_service_edge_attrs
- Add docstring to _collapse_trivial_chains noting single-pass and mutation
- Add stderr logging to cross-service exception handlers

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>

* fix: remove duplicate continue in cross-service exception handler

Dead code introduced in review fix commit.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 4.7 <noreply@anthropic.com>
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