You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maka.apache.org by as...@apache.org on 2026/09/17 09:20:16 UTC

(maka) 02/02: fix(runtime): attribute replayed reasoning only after the drop filter

This is an automated email from the ASF dual-hosted git repository.

Astro-Han pushed a commit to branch fix/responses-reasoning-replay-contract
in repository https://gitbox.apache.org/repos/asf/maka.git

commit 3e85930022c06def3ba5d39b41076ec6b65d3428
Author: AstroHan <le...@outlook.com>
AuthorDate: Thu Sep 17 17:19:52 2026 +0800

    fix(runtime): attribute replayed reasoning only after the drop filter
    
    emitStep collected reasoning eventIds before dropping unreplayable items,
    so memoryReplayMessageEvents credited dropped items as replayed. eventIds
    now derive from the post-filter pairs. Also removes the dead
    malformed.profile decode field (its only consumer was the pre-drop
    throw path) and two comments describing pre-change behavior.
    
    Generated with [Devin](https://devin.ai)
    
    Co-Authored-By: Devin <15...@users.noreply.github.com>
---
 packages/core/src/model-metadata.ts                 |  6 +++---
 .../src/__tests__/provider-contract-matrix.ts       |  4 ++--
 packages/runtime/src/ai-sdk-message-projection.ts   | 21 ++++++++++++---------
 packages/runtime/src/responses-reasoning-state.ts   |  6 +++---
 4 files changed, 20 insertions(+), 17 deletions(-)

diff --git a/packages/core/src/model-metadata.ts b/packages/core/src/model-metadata.ts
index bc9af6a159..523a4c40a9 100644
--- a/packages/core/src/model-metadata.ts
+++ b/packages/core/src/model-metadata.ts
@@ -158,9 +158,9 @@ export function lookupModelRuntimeOverride(
  * The request wire a model served over the OpenAI adapter must use.
  *
  * Provider/model routing facts live here even when the concrete Responses SDK
- * and replay policy are delegated to a Runtime profile. This is the single
- * declared source of the default protocol split, expressed through the
- * {@link ModelInfo.apiProtocol} seam.
+ * and replay policy are declared on the provider's `ProviderRuntimeAdapter`.
+ * This is the single declared source of the default protocol split, expressed
+ * through the {@link ModelInfo.apiProtocol} seam.
  */
 export function openAiAdapterApiProtocol(
   modelId: string,
diff --git a/packages/runtime/src/__tests__/provider-contract-matrix.ts b/packages/runtime/src/__tests__/provider-contract-matrix.ts
index 905d745209..4462b899cd 100644
--- a/packages/runtime/src/__tests__/provider-contract-matrix.ts
+++ b/packages/runtime/src/__tests__/provider-contract-matrix.ts
@@ -425,8 +425,8 @@ function reasoningReplayCell(
     };
   }
   // Native Anthropic / OpenAI / Google / Cohere SDKs own signed reasoning replay
-  // opaquely; except for the stateless Agent Plan contract above, the Maka
-  // provider layer adds no wire transform to derive from.
+  // opaquely; except for the declared per-adapter Responses contracts above, the
+  // Maka provider layer adds no wire transform to derive from.
   return {
     state: 'not-applicable',
     dimension: 'reasoning-replay',
diff --git a/packages/runtime/src/ai-sdk-message-projection.ts b/packages/runtime/src/ai-sdk-message-projection.ts
index e6c6191644..b6f4bcc91d 100644
--- a/packages/runtime/src/ai-sdk-message-projection.ts
+++ b/packages/runtime/src/ai-sdk-message-projection.ts
@@ -381,17 +381,20 @@ export class AiSdkMessageProjection {
     ) => {
       const calls = exchanges.map(({ call }) => call);
       const content: unknown[] = [];
+      const replayReasoning = (reasoning ?? [])
+        .map((item) => ({ eventId: item.eventId, replay: reasoningReplay(item) }))
+        .filter(
+          (entry): entry is { eventId: string; replay: ReplayReasoning } =>
+            entry.replay !== undefined,
+        );
       const eventIds = [
-        ...(reasoning ?? []).map((item) => item.eventId),
+        ...replayReasoning.map((entry) => entry.eventId),
         ...(text ? [text.eventId] : []),
         ...calls.map((call) => call.eventId),
         ...replayFacts.flatMap((fact) => fact.eventIds),
       ];
-      const replayReasoning = reasoning
-        ?.map(reasoningReplay)
-        .filter((item): item is ReplayReasoning => item !== undefined);
-      for (const item of replayReasoning ?? []) {
-        if (item.part) content.push(item.part);
+      for (const { replay } of replayReasoning) {
+        if (replay.part) content.push(replay.part);
       }
       // Provider-owned tools execute before the grounded assistant text in the
       // same provider step. Preserve that chronology for Responses item
@@ -439,9 +442,9 @@ export class AiSdkMessageProjection {
             : {}),
         });
       }
-      const replayProviderOptions = replayReasoning?.find(
-        (item) => item.providerOptions !== undefined,
-      )?.providerOptions;
+      const replayProviderOptions = replayReasoning.find(
+        (entry) => entry.replay.providerOptions !== undefined,
+      )?.replay.providerOptions;
       if (content.length > 0 || replayProviderOptions) {
         push(
           {
diff --git a/packages/runtime/src/responses-reasoning-state.ts b/packages/runtime/src/responses-reasoning-state.ts
index c0517bdbd1..6a2fe0c92d 100644
--- a/packages/runtime/src/responses-reasoning-state.ts
+++ b/packages/runtime/src/responses-reasoning-state.ts
@@ -36,7 +36,7 @@ export interface PlaintextResponsesReasoningState {
 export type PlaintextResponsesReasoningStateDecodeResult =
   | { readonly kind: 'missing' }
   | { readonly kind: 'unsupported-version'; readonly version: number }
-  | { readonly kind: 'malformed'; readonly profile?: string }
+  | { readonly kind: 'malformed' }
   | { readonly kind: 'valid'; readonly state: PlaintextResponsesReasoningState };
 
 export function plaintextResponsesReasoningProviderOptions(
@@ -71,7 +71,7 @@ export function decodePlaintextResponsesReasoningState(
   }
   const baseInvalid = record.version !== STATE_VERSION || !profile || !itemId;
   if (baseInvalid) {
-    return { kind: 'malformed', ...(profile ? { profile } : {}) };
+    return { kind: 'malformed' };
   }
   if (
     !isSafeSummaryPartLengths(record.summaryPartLengths) ||
@@ -79,7 +79,7 @@ export function decodePlaintextResponsesReasoningState(
       (key) => !['version', 'profile', 'itemId', 'summaryPartLengths'].includes(key),
     )
   ) {
-    return { kind: 'malformed', ...(profile ? { profile } : {}) };
+    return { kind: 'malformed' };
   }
   return {
     kind: 'valid',


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@maka.apache.org
For additional commands, e-mail: commits-help@maka.apache.org