Skip to content

fix(runtime): bound gateway waits and preserve failure reasons - #1094

Merged
mergify[bot] merged 4 commits into
matrixorigin:mainfrom
gouhongshen:codex/runtime-gateway-resilience
Oct 20, 2026
Merged

mergify[bot] merged 4 commits into
matrixorigin:mainfrom
gouhongshen:codex/runtime-gateway-resilience

Conversation

@gouhongshen

@gouhongshen gouhongshen commented Oct 20, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

Authenticated remote tool calls can outlast the fixed Agent Binding MCP response deadline, while transient Edge registration failures and root approval-delivery failures currently produce misleading diagnostics. This change fixes those boundaries in the existing runtime owners.

  • Accept optional capability_descriptors.mcp.metadata.tool_call_timeout_ms for tool-invocation RPCs. Keep the 120-second default and integer 1–3,600,000 ms range. Parse the declaration once at descriptor admission, before live MCP/skill discovery or snapshot setup, then apply the admitted budget to the shared runtime bundle.
  • Preserve the separate discovery budget and bounded cancellation-settlement wait. A cancellation acknowledgement alone does not prove remote execution stopped.
  • Close unavailable Edge registration/finalization with WebSocket 1013 instead of a permanent credential rejection. Keep failed setup unpublished and roll back finalization; actual authentication failures remain rejected.
  • Preserve both the policy reason and approval-delivery failure when a root run cannot obtain approval. Execution remains denied.
  • Add loopback HTTP/WebSocket, lifecycle-admission and permission integration regressions and document the contracts. The cancellation regression now bounds its final virtual-time wait, so a one-hour RPC deadline cannot masquerade as the 120-second settlement deadline.

Related issue

Closes #1092.

Related: #1016. This PR does not close the broader receiving-provider cancellation/settlement work. The separately observed live introspection argument-contract failure is tracked in #1096; this PR does not claim to fix it.

Change type

  • Feature
  • Bug fix
  • Documentation
  • Refactor or performance improvement
  • Test
  • Build, CI, or maintenance

User and compatibility impact

Existing gateways that omit the optional timeout retain 120 seconds. The authenticated gateway declares the response budget; model-selected tool arguments cannot override it. Invalid explicit declarations return 400 / agent_binding_capability_ref_invalid before either discovery request starts, for both live and snapshot preparation. Side-effect-free discovery keeps its existing budget. Cancellation retains at most 120 seconds to observe the original correlated response; without settlement evidence the outcome remains unknown.

Existing Edge reconnect handling can recover from registration storage unavailability without treating valid credentials as permanently rejected. Approval diagnostics now include the actionable policy cause without granting additional permission. No database schema, SDK, deployment defaults, or build recipes change.

Architecture and complexity delta

  • Canonical owner changed or extended: RuntimeMcpBundle / AgentBindingMcpRuntime, the shared Agent Binding lifecycle assembly, handle_edge_connection, and the existing permission gate. Timeout parsing stays in the MCP owner; the lifecycle validates once before discovery and passes the admitted duration to bundle setup.
  • Existing implementations and callers searched: live/snapshot construction, capability-source RPC dispatch, semantic-read preparation, cancellation correlation/ownership, Edge finalization/rollback/reconnect, and parent/root approval delivery.
  • Superseded code, states, tables, shims, or self-only tests removed: replaced registration-storage AuthError branches and the fixed invocation deadline; replaced post-discovery timeout validation with admission-time parsing. No storage or lifecycle state was added.
  • If parallel implementations remain, their boundary and retirement condition: none added. Ordinary MCP connection handling and provider-side process termination retain their owners; no fallback or business-specific argument inference was introduced.

Capability assessment

The existing capability assessment still applies: MCP tool execution and provider admission remain Beta; User Runner execution and permissions/sandbox remain Partial. These changes clarify bounded waits, retryable setup failures and denied-approval diagnostics within already supported profiles. They do not certify remote cancellation settlement (#1016), universal sandbox containment, autonomous repository-build stability, or a new maturity level. The transport-budget contract is documented in docs/design/capability-provider-runtime.md.

Verification

Current head: 137cff045c0bcfd5e3ee1ae8c522594900e01513, including upstream main 8514005c730a98f9b80141e1882f7b46c8f68227.

  • Current-head Test Suite and Static Checks / Clippy succeeded. Selected runtime, CLI, online integration and fresh-MOI compatibility lanes passed. SDK, Web and turn-core/services/plan heavy work was skipped by existing scope routing.
  • Runtime CI executed 6032 passing tests with 192 existing skips. It explicitly passed both review regressions: invalid_mcp_timeout_is_rejected_before_live_or_snapshot_discovery and extended_gateway_call_keeps_cancellation_settlement_bounded (runtime job). The first asserts the same 400/code for both preparation paths with no outbound discovery; the second requires completion within a one-second virtual window after advancing 121 seconds. No local mutation-test execution is claimed.
  • The additional live harness, attempt 1 completed 18 cases with 17 passing. introspection_reflection_source_boundary failed the introspect argument predicates for depth=diagnostic and horizon=recent; both diagnostic tool calls, their order, successful outcomes and final scope judgment passed. Readiness, model registration and preflight passed. Safe public artifacts withhold the original arguments, so the root cause is not established. The observation/schema-selection paths and case are unchanged by this PR. Evidence and investigation are tracked in #1096, without claiming a model-only cause or a fix.
  • The single diagnostic live-harness rerun, attempt 2 on this exact head completed successfully: 18/18 cases passed, including all introspection argument predicates. No code, case, assertion, model input configuration or budget was changed between attempts. The first failure remains recorded in [Bug]: Live introspection intermittently violates depth/horizon argument contract #1096, which stays open because this passing control does not establish the root cause or stable compliance. No further diagnostic rerun was requested. Human re-review remains requested from XuPeng-SH.
  • Previous PR head abc1f6ddf passed its live harness 18/18; latest-main control 8514005c also passed. These controls do not establish this head as live-harness green or explain its failure.
  • Current local checks: make format-check and git diff --check PASS; static review completed. No local Rust tests, Clippy, test recompilation, live-model scenarios or deployment were started, as requested by the user.
  • Earlier local checks on the original PR snapshot: Python 3.13 repository validation PASS; Python 3.13 CI-script unit tests with canonical TMPDIR=/private/tmp PASS (134 tests, 5 existing skips). The local MCP Rust build was stopped before test execution; permission/Edge tests and Clippy were not run locally.
  • Public entrypoints covered by regression fixtures: authenticated MCP HTTP dispatch, shared live/snapshot lifecycle admission, actual Edge WebSocket route and root/parent permission gate. Unhappy paths include invalid declarations before outbound discovery, response deadline expiry, unacknowledged settlement, preserved discovery budget, unavailable registration storage, failed/lost finalization with rollback, genuine credential rejection and unavailable approval delivery.
  • Database verification: no SQL, transaction, schema or migration changes. Registry storage failures are injected at the existing service boundary in WebSocket integration tests. Broader database compatibility is exercised by CI; no local database journey was restarted.
  • Prior real-world validation: local MOI public-repository clone/build workflows exercised these runtime changes before the later main syncs. MatrixOne builds succeeded repeatedly; Astra completed an assisted warm build, while autonomous Astra build stability was not established. These historical results do not replace current-head CI.

Final checklist

  • I added or updated tests at the layer that owns the behavior, or explained why no test is needed.
  • I updated public or design documentation for contract changes, or the change needs no documentation update.
  • I checked the diff for credentials, private URLs, customer data, generated files, and other sensitive information.
  • The PR title follows the repository's Conventional Commit format.

@gouhongshen gouhongshen self-assigned this Oct 20, 2026
@gouhongshen
gouhongshen marked this pull request as ready for review October 20, 2026 10:51

@XuPeng-SH XuPeng-SH left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

The changes stay within the existing runtime owners, and the separation between invocation, discovery and cancellation-settlement budgets is appropriate. Two P2 issues remain: invalid timeout metadata is validated after live discovery, and the new cancellation regression does not actually enforce its 120-second bound. Both can be corrected within the current design.

Validation: 77/78 selected tests passed initially; the unchanged capacity fixture passed in an isolated no-proxy control. Targeted Clippy passed. An additional lifecycle probe reproduced the admission-order defect, and a same-version Tokio probe demonstrated the paused-time assertion gap. Execution evidence is from e3cc297; the latest main merge leaves the complete PR delta byte-identical.

@XuPeng-SH XuPeng-SH left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Deep source re-review of 137cff0 against base 8514005. No new actionable findings.

Both prior P2 findings are fixed in the actual source: timeout metadata is parsed before live discovery or snapshot preparation, with zero-outbound-request regression coverage; the extended-call cancellation test now bounds the final await after advancing 121 virtual seconds, so losing the settlement guard would fail rather than silently auto-advance to the one-hour call budget.

Traced invocation budgets through HTTP dispatch and effectful capability-source calls, separate discovery/semantic-read budgets, per-request copy-on-write isolation, correlated cancellation settlement and non-retryable uncertainty, Edge rollback/generation fencing and retryable close handling, and approval-delivery failure remaining a denial. No new SQL/schema/transaction path or parallel lifecycle/storage owner was introduced. Longer calls can occupy existing endpoint permits longer (default 128 per endpoint, unchanged 8 MiB response cap); no load-performance claim is made.

Change accounting, excluding pure moves (none): implementation +109/-52, net +57; tests/fixtures +377/-5, net +372; documentation +28/-0, net +28; total +514/-57, net +457. Seven regressions added and one existing registration-failure test updated. Added complexity supports concrete long-operation, recovery and diagnostic behavior without removing useful existing paths.

Validation: local cargo fmt and git diff --check passed. No Rust tests completed locally: offline dependencies were unavailable; a subsequent locked build reached runtime compilation and was stopped, with remaining compiler work terminated. Exact-head Test Suite and Static Checks succeeded; runtime CI records 6032 passes and 192 skips, including both corrected regressions. At submission recheck, latest visible checks contain no failure or running check; three scope checks remain skipped and the Mergify queue check is neutral. The live harness had an earlier failed attempt; latest visible harness check is successful, without establishing the earlier failure's source cause.

Publication limitation: authoritative main branch-protection required contexts could not be fully verified because the integration returned 403 Resource not accessible by integration. This is a source-quality approval, not certification that all required CI was independently verified. Submitted at the user's explicit direction after disclosing that limitation. No protection change, CI rerun, branch update or direct merge was performed.

@mergify mergify Bot added the queued label Oct 20, 2026
@mergify

mergify Bot commented Oct 20, 2026 •

Copy link
Copy Markdown
Contributor

Merge Queue Status

  • ✅ Entered queue — 2026-10-20 13:07 UTC · Rule: main · triggered by rule Automatic queue on approval for main
  • ✅ Checks skipped · PR is already up-to-date
  • ✅ Merged — 2026-10-20 13:08 UTC · at e45f983d33000960040bf9f4eaba34ee1d63beab · squash

This pull request spent 14 seconds in the queue, including 1 second running CI.

Required conditions to merge
  • #review-threads-unresolved = 0 [🛡 GitHub branch protection]
  • github-review-approved [🛡 GitHub branch protection]
  • any of [🛡 GitHub branch protection]:
    • check-success = Check PR title
    • check-neutral = Check PR title
    • check-skipped = Check PR title
  • any of [🛡 GitHub branch protection]:
    • check-success = check
    • check-neutral = check
    • check-skipped = check
  • any of [🛡 GitHub branch protection]:
    • check-success = Test: core crates + bridge hooks
    • check-neutral = Test: core crates + bridge hooks
    • check-skipped = Test: core crates + bridge hooks
  • any of [🛡 GitHub branch protection]:
    • check-success = Test: astra-runtime
    • check-neutral = Test: astra-runtime
    • check-skipped = Test: astra-runtime
  • any of [🛡 GitHub branch protection]:
    • check-success = Test: astra-cli (edge-fs-tools)
    • check-neutral = Test: astra-cli (edge-fs-tools)
    • check-skipped = Test: astra-cli (edge-fs-tools)
  • any of [🛡 GitHub branch protection]:
    • check-success = Test: astra-cli (edge-git-gix)
    • check-neutral = Test: astra-cli (edge-git-gix)
    • check-skipped = Test: astra-cli (edge-git-gix)
  • any of [🛡 GitHub branch protection]:
    • check-success = Test: astra-cli (edge-rest)
    • check-neutral = Test: astra-cli (edge-rest)
    • check-skipped = Test: astra-cli (edge-rest)
  • any of [🛡 GitHub branch protection]:
    • check-success = Test: astra-cli (edge-shell)
    • check-neutral = Test: astra-cli (edge-shell)
    • check-skipped = Test: astra-cli (edge-shell)
  • any of [🛡 GitHub branch protection]:
    • check-success = Test: astra-cli (non-edge)
    • check-neutral = Test: astra-cli (non-edge)
    • check-skipped = Test: astra-cli (non-edge)
  • any of [🛡 GitHub branch protection]:
    • check-success = Test: online (core)
    • check-neutral = Test: online (core)
    • check-skipped = Test: online (core)
  • any of [🛡 GitHub branch protection]:
    • check-success = Test: online (integration)
    • check-neutral = Test: online (integration)
    • check-skipped = Test: online (integration)
  • any of [🛡 GitHub branch protection]:
    • check-skipped = Test: turn-core + services + plan
    • check-neutral = Test: turn-core + services + plan
    • check-success = Test: turn-core + services + plan
  • any of [🛡 GitHub branch protection]:
    • check-skipped = web (typecheck, test, build)
    • check-neutral = web (typecheck, test, build)
    • check-success = web (typecheck, test, build)
  • any of [🛡 GitHub branch protection]:
    • check-skipped = Astra SDK (typecheck, test+coverage, build)
    • check-neutral = Astra SDK (typecheck, test+coverage, build)
    • check-success = Astra SDK (typecheck, test+coverage, build)
  • any of [🛡 GitHub branch protection]:
    • check-success = Test: macOS workspace coordination
    • check-neutral = Test: macOS workspace coordination
    • check-skipped = Test: macOS workspace coordination

@mergify
mergify Bot merged commit e45f983 into matrixorigin:main Oct 20, 2026
@mergify mergify Bot removed the queued label Oct 20, 2026
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.

[Bug]: Bound MCP waits and preserve retryable runtime failure reasons

2 participants