Skip to content

fix(runtime): gate provider reasoning replay by source model - #4286

Draft
Astro-Han wants to merge 3 commits into
apache:mainfrom
Astro-Han:fix/reasoning-replay-provenance
Draft

fix(runtime): gate provider reasoning replay by source model#4286
Astro-Han wants to merge 3 commits into
apache:mainfrom
Astro-Han:fix/reasoning-replay-provenance

Conversation

@Astro-Han

@Astro-Han Astro-Han commented Aug 30, 2026

Copy link
Copy Markdown
Contributor

Summary

Fix provider-owned reasoning replay at the existing ModelAdapter → RuntimeEvent → AiSdkBackend boundary.

  • Persist Anthropic redacted thinking from reasoning-start provider metadata into the existing thinking RuntimeEvent provider options, then let the existing AI SDK request converter reconstruct redacted_thinking.
  • Carry existing AgentRun headers beside prior RuntimeEvents and replay provider-owned reasoning only when source and target use the exact same connection ID and model ID.
  • Apply the same provenance gate to provider-native OpenAI Codex history compaction, including manual, pre-turn, and mid-turn compaction.
  • Keep malformed-summary failure fingerprints stable when unrelated run headers are added without changing folded provider input.
  • Reuse the existing openai-chat-plaintext replay contract for GitHub Copilot OpenAI Chat while preserving observed request-field behavior.

Root cause

The durable transcript already retained signed and plaintext provider reasoning, but replay projection had no source-route proof. Anthropic redacted thinking was emitted on reasoning-start metadata, which ModelAdapter previously discarded. Copilot OpenAI Chat returned reasoning_content but did not participate in the existing plaintext replay transport.

Fresh review also found that native OpenAI Codex history compaction projected RuntimeEvents without the AgentRun route headers used by normal replay. Cross-model provider reasoning could therefore enter a compaction request, making admitted replay differ from dispatched replay.

After adding route provenance to compaction, the malformed-summary circuit initially hashed every available run header. A failed manual compaction adds a header without adding model-visible folded content, so an unchanged retry received a different fingerprint and redispatched the same doomed request. The fingerprint now includes only routes referenced by folded events, in stable order.

Ownership and compatibility

RuntimeEvent remains the durable transcript authority. AgentRunHeader remains the route-provenance authority. ModelAdapter remains the only AI SDK boundary. Maka ToolRuntime and the outer loop continue to own execution, permissions, concurrency, and recovery.

This change does not add a provider serializer, duplicate provenance fields, a second replay converter, or another agent loop.

Provider-owned reasoning from another model, another connection, or legacy history without matching provenance now fails closed. Ordinary text, tool calls, and tool results remain available. Exact same-route Anthropic, Copilot OpenAI Chat, and OpenAI Responses replay remain enabled.

Commit structure

The three commits form an intentional dependency series, not three arbitrary-order revert units:

  1. The first commit establishes the shared source-route replay gate and compaction projection.
  2. The Anthropic redacted-thinking commit requires that gate.
  3. The Copilot OpenAI Chat reasoning commit requires that gate.

Either provider capability can be reverted independently. Removing the shared gate requires reverting the dependent provider commits first. This keeps one gate instead of duplicating safety policy per provider.

Simplification

The adjacent simplification pass removed:

  • Two redundant thin Anthropic backend replay tests.
  • One Copilot internal factory-spy test.
  • One test-only compaction alias and its duplicate test.

Public wire and runtime composition coverage remains.

Verification

  • Observed RED before GREEN for manual compaction route-header propagation.
  • Observed RED before GREEN for native Codex cross-model reasoning leakage.
  • Observed RED before GREEN for an unchanged malformed compaction retry receiving an unrelated run header: two dispatches before the fix, one after it.
  • Confirmed changed folded source history remains eligible for a new compaction attempt.
  • Built @maka/core, @maka/runtime, and @maka/runtime-host.
  • Passed the related runtime suites: ai-sdk-backend, computer-use-provider-protocol, model-adapter, openai-codex-history-compactor, and session-manager.
  • Passed the full runtime-host execution-model-composition suite.
  • Passed typecheck for @maka/core, @maka/runtime, and @maka/runtime-host.
  • Passed Biome check on all 18 changed files.
  • Passed git diff --check.

AI use

Select exactly one:

  • No generative tool made a substantive contribution
  • Generative tooling made a substantive contribution

Tool(s) and scope: Codex implemented the runtime contract changes and tests through debug, TDD, adversarial review, and simplification-audit workflows. All three material commits include the Generated-by: Codex trailer.

Checklist

  • Tests cover the change and fail without it.
  • Lint, format, typecheck, and affected suites pass locally.

Does this PR entail a change in behavior?

  • Yes — described under Summary above.
  • No

@github-actions github-actions Bot added the effort/L Under 1000 readable lines label Aug 30, 2026
@Astro-Han
Astro-Han force-pushed the fix/reasoning-replay-provenance branch 3 times, most recently from 2f5e97b to a8d4bcb Compare August 31, 2026 01:21
Requires the source-route replay gate established by the preceding commit.

Generated-by: Codex
Requires the source-route replay gate established by the first commit in this series.

Generated-by: Codex
@Astro-Han
Astro-Han force-pushed the fix/reasoning-replay-provenance branch from a8d4bcb to 1feb2ef Compare August 31, 2026 01:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

effort/L Under 1000 readable lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant