Skip to content

feat(mcp): M-level descent gating in read_context cascade + CoalescingBuffer fix#453

Open
jlunder00 wants to merge 1 commit into
devfrom
feature/descent-gating
Open

feat(mcp): M-level descent gating in read_context cascade + CoalescingBuffer fix#453
jlunder00 wants to merge 1 commit into
devfrom
feature/descent-gating

Conversation

@jlunder00

Copy link
Copy Markdown
Owner

Summary

  • M-level cascade depth gating (tether_mcp/tools/read_context.py): Added _cascade_depth counter tracked through _build_node_response_add_children recursion. When N > 0 and _cascade_depth >= N, _add_children returns immediately without fetching children. This stops cascade traversal at N levels from the source node of the read_context call, preventing unbounded recursion under depth=-1. N=0 preserves existing unlimited behavior (backward compat).
  • CoalescingBuffer auto-evict (interactive_agent_layer/coalescing.py): Added self.evict_expired() as the first line of record(), keeping the dict bounded to the last 5-second window without requiring an external caller.

What was already there (not changed)

  • The per-child N tree-distance scope check via get_node_tree_distance (checks edges from conversation's current_node_id) is unchanged and independent of the new cascade depth gating.
  • conversation_id requirement, M detail level, source filtering — all unchanged.

Tests

  • 5 new unit tests in tests/tether_mcp/test_read_context_cascade.py (mocked DB): cascade stops at N, includes nodes exactly at N, N=0 is unlimited, depth param still respected, conversation_id required.
  • 1 new test in tests/interactive_agent_layer/test_coalescing.py: expired entries evicted on record().
  • 880 tests pass, 0 failures.

Test plan

  • All existing tests green (880 passed)
  • test_cascade_stops_at_N_depth_from_source: grandchild absent when N=1
  • test_cascade_includes_nodes_up_to_and_including_N: child present at depth==N
  • test_cascade_unlimited_when_N_is_zero: grandchild present when N=0
  • test_cascade_respects_depth_param_independently: depth=1 still caps at 1
  • test_evict_expired_called_on_record: old_tool gone after record() triggers eviction

…uffer auto-evict

- read_context cascade now tracks _cascade_depth from the source node and
  stops descending when _cascade_depth >= N (scope envelope), preventing
  unbounded recursion when depth=-1 and N is set. N=0 preserves existing
  unlimited behavior.
- CoalescingBuffer.record() now calls self.evict_expired() on entry, keeping
  the cache bounded to the last window without requiring an external caller.
- Tests: 5 new cascade-gating unit tests (mocked DB), 1 new coalescing test.
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