Skip to content

Repair exact tooling recovery and adaptive deadlines - #346

Merged
witbrock merged 1 commit into
mainfrom
codex/JVNAUTOSCI-2623-general-tooling-recovery
Aug 5, 2026
Merged

witbrock merged 1 commit into
mainfrom
codex/JVNAUTOSCI-2623-general-tooling-recovery

Conversation

@witbrock

@witbrock witbrock commented Aug 5, 2026

Copy link
Copy Markdown
Member

Outcome

Repairs the general model-led path behind JVNAUTOSCI-2623 without adding Gmail-, student-, email-address-, or arXiv-specific routing.

  • fetch_concept now performs bounded exact ID, registered virtual-concept, and exact CODE-alias lookup; misses return typed concept_not_found instead of falling into broad lexical resolution.
  • A denied canonical relationship write exposes a scoped-assertion recovery only when the exact represented predicate establishes the object kind. A successful matching recovery reconciles turn finality; subject, predicate, value, and object-kind mismatches do not.
  • Frequently used Gmail and scoped-assertion operations use adaptive advisory timing with no arbitrary outer hard deadline.
  • The two observed slow file operations seed adaptive windows from their longest known successful duration: warning at 1.25x, hard boundary at 2x. Longer valid successes grow both; failed, invalid, zero, or non-finite durations do not train them.
  • Dynamic tool proxies preserve timing policy.
  • Removes the stale RAG identity-service import and query arguments left behind when the legacy fixed Mongo query deadline was removed.

Evidence

  • 140 internal MCP transport, catalogue, fetch, dynamic registration, external identity, predicate, and scoped-authority tests passed.
  • 28 neighbouring adaptive-turn authority/recovery tests passed.
  • Additional independent focused reviews passed 67 timing tests, 39 canonical relationship tests, and 19 recovery/finality tests.
  • Python compilation, Ruff fatal checks, and git diff --check passed.
  • Fresh authenticated Terra replay completed in 6m23s through the direct model-led path. It used Gmail list/get only, selected exact concept #V#timothy_pistotti, reused the existing #V#has_email assertion, and created no duplicate or mailbox mutation.

Boundaries

  • Adaptive runtime maxima are process-local; evidence-backed cold-start seeds survive restart for the two retained hard-boundary capabilities.
  • The current RAG corpus still reports not_indexed with pending work; this change fixes its deterministic stale-import failure, not index population.
  • Existing Thinking/situation and top-level telemetry gaps observed in the replay are not changed here.
  • One broader adaptive-turn test remains environment-sensitive because its test handler has a fixed one-second release wait while Mongo failover can delay the turn; no production change was made to hide that pre-existing race.

Copilot AI lite review requested due to automatic review settings August 5, 2026 09:08
@witbrock
witbrock marked this pull request as ready for review August 5, 2026 09:08

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Repairs the model-led Internal MCP tooling path by making concept fetches strictly bounded (exact ID / virtual concept / alias only), improving scoped-assertion recovery behaviour for denied canonical relationship writes, and replacing fixed timeouts with adaptive advisory/hard windows seeded by observed successful durations.

Changes:

  • Tightens fetch_concept to avoid fuzzy/name resolution on misses, returning a typed concept_not_found response instead.
  • Adds adaptive deadline history to Internal MCP gateway execution, including seeding long-running tool windows and preserving timing policy through dynamic tool proxies.
  • Refines scoped-assertion recovery eligibility for denied relationship writes by using canonical predicate typing (text vs concept) and reconciling successful recoveries more robustly.

Reviewed changes

Copilot reviewed 13 out of 13 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
tests/backend/test_internal_mcp_transport_deadlines.py Expands coverage for adaptive advisory/hard timeout learning, clamping, and late-success training.
tests/backend/test_internal_mcp_scoped_assertion_authority.py Updates monkeypatch target to the new exact concept lookup API.
tests/backend/test_internal_mcp_fetch_concept_bounded.py Adds new tests asserting bounded fetch_concept behaviour (exact hit, alias, virtual concept, typed miss).
tests/backend/test_internal_mcp_dynamic_tool_registration.py Verifies dynamic proxies preserve target timing policy (bootstrap + derived windows).
tests/backend/test_internal_mcp_catalogue_builds.py Updates catalogue timing assertions to the new adaptive/bootstrap policy and extends advisory-only coverage.
tests/backend/test_blocked_thing_parent_type.py Updates monkeypatch target to the new exact concept lookup API.
tests/backend/test_adaptive_turn_service.py Adds/adjusts tests for scoped-assertion recovery gating based on canonical predicate typing and object matching.
src/backend/services/relationship_write_service.py Introduces canonical predicate object-kind resolution (text vs concept) for exact predicates.
src/backend/services/concept_external_identity_service.py Removes stale max-time query wiring tied to the legacy fixed Mongo deadline.
src/backend/services/adaptive_turn_service.py Tightens relationship-denial recovery affordances to require canonical predicate typing and improves recovery reconciliation keys.
src/backend/integrations/internal_mcp/gateway.py Implements adaptive deadline history (successful max duration) and uses it to derive next advisory/hard windows.
src/backend/integrations/internal_mcp/dynamic_tool_loader.py Ensures dynamic tool proxies inherit advisory timing and adaptive window seeds unless explicitly overridden.
src/backend/integrations/internal_mcp/catalogue.py Makes fetch_concept bounded (exact/virtual/alias only) and returns typed not-found responses.

Comment on lines +444 to +453
resolved_id = resolve_concept_by_alias(concept_id)
if resolved_id and resolved_id != concept_id:
try:
concept = get_concept_by_concept_id_exact(
concept_id=resolved_id
)
except ConceptNotFoundError:
concept = None
else:
concept = None
Comment on lines 828 to 847
@@ -665,15 +847,35 @@ def _record_failure(
metrics.saturations += 1
Comment on lines +792 to +807
def _record_success(
self,
method_name: str,
duration_ms: float | None,
*,
include_in_adaptive_history: bool = True,
) -> None:
self._total_calls += 1
metrics = self._method_metrics[method_name]
metrics.calls += 1
metrics.last_duration_ms = duration_ms
metrics.last_error = None
metrics.last_outcome = "completed"
if include_in_adaptive_history and duration_ms is not None:
self._record_successful_duration(method_name, duration_ms)

@witbrock
witbrock merged commit 23f42a4 into main Aug 5, 2026
5 checks passed
@witbrock
witbrock deleted the codex/JVNAUTOSCI-2623-general-tooling-recovery branch August 18, 2026 20:36
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.

2 participants