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/01 15:30:11 UTC

(maka) 07/19: fix(runtime): exclude child runs from prefix continuity

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

Astro-Han pushed a commit to branch feat/4299-semantic-prefix-continuity
in repository https://gitbox.apache.org/repos/asf/maka.git

commit 0dbea4f3890191484c622f38d63351a8b33e6faa
Author: AstroHan <le...@outlook.com>
AuthorDate: Tue Sep 1 01:59:57 2026 +0800

    fix(runtime): exclude child runs from prefix continuity
    
    Generated-by: Codex
---
 .../__tests__/semantic-prefix-continuity.test.ts   | 20 +++++++++++++++
 packages/runtime/src/agent-run.ts                  |  1 +
 packages/runtime/src/semantic-prefix-continuity.ts | 30 ++++++++++------------
 3 files changed, 34 insertions(+), 17 deletions(-)

diff --git a/packages/runtime/src/__tests__/semantic-prefix-continuity.test.ts b/packages/runtime/src/__tests__/semantic-prefix-continuity.test.ts
index 987387829f..fadefe49e6 100644
--- a/packages/runtime/src/__tests__/semantic-prefix-continuity.test.ts
+++ b/packages/runtime/src/__tests__/semantic-prefix-continuity.test.ts
@@ -90,6 +90,7 @@ test('uses the preceding physical retry as its durable baseline', async () => {
       await deriveAttemptSemanticPrefixContinuity({
         current,
         currentProviderStateIdentity: PROVIDER_STATE,
+        currentSessionInline: true,
         lineage: {},
         store: prefixStore([run('run-1', 'turn-1', PROVIDER_STATE)], [previous]),
       })
@@ -107,6 +108,7 @@ test('does not compare across provider execution identities', async () => {
       await deriveAttemptSemanticPrefixContinuity({
         current,
         currentProviderStateIdentity: PROVIDER_STATE,
+        currentSessionInline: true,
         lineage: {},
         store: prefixStore(
           [run('run-1', 'turn-1', OTHER_PROVIDER_STATE), run('run-2', 'turn-2', PROVIDER_STATE)],
@@ -132,6 +134,7 @@ test('does not choose between overlapping durable predecessor runs', async () =>
       await deriveAttemptSemanticPrefixContinuity({
         current,
         currentProviderStateIdentity: PROVIDER_STATE,
+        currentSessionInline: true,
         lineage: {},
         store: prefixStore(
           headers,
@@ -147,6 +150,23 @@ test('does not choose between overlapping durable predecessor runs', async () =>
   );
 });
 
+test('does not compare a child run against its parent session run', async () => {
+  const previous = attempt({ attemptId: 'parent-attempt', runId: 'run-parent' });
+  const current = attempt({ attemptId: 'child-attempt', runId: 'run-child' });
+  const input = {
+    current,
+    currentProviderStateIdentity: PROVIDER_STATE,
+    currentSessionInline: false,
+    lineage: { parentRunId: 'run-parent' },
+    store: prefixStore(
+      [run('run-parent', 'turn-1', PROVIDER_STATE), run('run-child', 'turn-1', PROVIDER_STATE)],
+      [previous],
+    ),
+  };
+
+  assert.equal((await deriveAttemptSemanticPrefixContinuity(input)).status, 'unavailable');
+});
+
 function observation(segments: PreparedRequestObservationSegment[]): PreparedRequestObservation {
   return {
     schemaVersion: 1,
diff --git a/packages/runtime/src/agent-run.ts b/packages/runtime/src/agent-run.ts
index 6edc658ffc..033bbf56b0 100644
--- a/packages/runtime/src/agent-run.ts
+++ b/packages/runtime/src/agent-run.ts
@@ -482,6 +482,7 @@ export class AgentRun {
         const requestPrefix = await deriveAttemptSemanticPrefixContinuity({
           current: attempt,
           currentProviderStateIdentity: this.providerStateIdentity,
+          currentSessionInline: this.isSessionInline(),
           lineage: {
             ...this.lineage,
             ...(this.header.conversationCopy ? { conversationCopy: true } : {}),
diff --git a/packages/runtime/src/semantic-prefix-continuity.ts b/packages/runtime/src/semantic-prefix-continuity.ts
index 2f67fa054b..a0d9213e02 100644
--- a/packages/runtime/src/semantic-prefix-continuity.ts
+++ b/packages/runtime/src/semantic-prefix-continuity.ts
@@ -57,9 +57,10 @@ interface RootAdmissionReader {
   ): Promise<{ runId: string; previousRootTurnId?: string | null } | undefined>;
 }
 
-export async function deriveAttemptSemanticPrefixContinuity(input: {
+interface AttemptContinuityInput {
   current: ModelCallAttempt;
   currentProviderStateIdentity?: `sha256:${string}`;
+  currentSessionInline: boolean;
   lineage: {
     conversationCopy?: boolean;
     parentRunId?: string;
@@ -70,9 +71,15 @@ export async function deriveAttemptSemanticPrefixContinuity(input: {
     parentSessionId?: string;
   };
   store: PrefixStore;
-}): Promise<SemanticPrefixContinuity> {
+}
+
+export async function deriveAttemptSemanticPrefixContinuity(
+  input: AttemptContinuityInput,
+): Promise<SemanticPrefixContinuity> {
   const { current } = input;
-  if (current.callKind !== 'main' || !current.requestObservation) return unavailable();
+  if (!input.currentSessionInline || current.callKind !== 'main' || !current.requestObservation) {
+    return unavailable();
+  }
 
   const predecessor = await predecessorAttempt(input);
   if (predecessor === null) {
@@ -153,20 +160,9 @@ function segmentRef(segment: PreparedRequestObservationSegment): SemanticPrefixS
   };
 }
 
-async function predecessorAttempt(input: {
-  current: ModelCallAttempt;
-  currentProviderStateIdentity?: `sha256:${string}`;
-  lineage: {
-    conversationCopy?: boolean;
-    parentRunId?: string;
-    parentTurnId?: string;
-    retriedFromTurnId?: string;
-    regeneratedFromTurnId?: string;
-    branchOfTurnId?: string;
-    parentSessionId?: string;
-  };
-  store: PrefixStore;
-}): Promise<{ attempt: ModelCallAttempt; run: AgentRunHeader } | null | undefined> {
+async function predecessorAttempt(
+  input: AttemptContinuityInput,
+): Promise<{ attempt: ModelCallAttempt; run: AgentRunHeader } | null | undefined> {
   const { current, lineage, store } = input;
   const runs = await store.listSessionRuns(current.sessionId);
   const currentRun = runs.find((run) => run.runId === current.runId);


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