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/08/23 14:48:43 UTC

(maka) 06/08: fix: make sent steering non-retractable

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

Astro-Han pushed a commit to branch fix/steering-durable-admission
in repository https://gitbox.apache.org/repos/asf/maka.git

commit 3e963da70e6e78a7076038a4aba5d683e615d004
Author: AstroHan <le...@outlook.com>
AuthorDate: Sun Aug 23 22:32:18 2026 +0800

    fix: make sent steering non-retractable
    
    Generated-by: Maka
---
 .../src/__tests__/message-coordinator.test.ts      | 35 ++++++++++++++-----
 .../runtime-host/src/server/message-coordinator.ts | 39 ++++++++++++----------
 2 files changed, 49 insertions(+), 25 deletions(-)

diff --git a/packages/runtime-host/src/__tests__/message-coordinator.test.ts b/packages/runtime-host/src/__tests__/message-coordinator.test.ts
index 19afe4078..6a76f80a2 100644
--- a/packages/runtime-host/src/__tests__/message-coordinator.test.ts
+++ b/packages/runtime-host/src/__tests__/message-coordinator.test.ts
@@ -328,7 +328,7 @@ test('full snapshot preflight rejection leaves queue, receipt, residency, and pu
     { originHostEpoch: 'epoch-1', sessionId: ROOT.sessionId, retractId: 'cleanup-capacity' },
     operationContext(),
   );
-  fixture.coordinator.abandonRootReservation(ROOT);
+  completeActiveRoot(fixture);
   await fixture.coordinator.close();
 });
 
@@ -359,7 +359,7 @@ test('persists a steering message before admitting it to the active Turn queue',
     { originHostEpoch: 'epoch-1', sessionId: ROOT.sessionId, retractId: 'cleanup-durable' },
     operationContext(),
   );
-  fixture.coordinator.abandonRootReservation(ROOT);
+  completeActiveRoot(fixture);
   await fixture.coordinator.close();
 });
 
@@ -408,7 +408,7 @@ test('queue admission rejects content that cannot form a durable follow-up Turn'
     operationContext(),
   );
   assert.equal(retracted.ok, true);
-  fixture.coordinator.abandonRootReservation(ROOT);
+  completeActiveRoot(fixture);
   await fixture.coordinator.close();
 });
 
@@ -531,15 +531,16 @@ test('entry retract removes one queued entry, replays its receipt, and rejects s
     },
     operationContext(),
   );
-  assert.equal(steering.ok, true);
-  assert.deepEqual(fixture.coordinator.projection(ROOT.sessionId).steering, []);
-  assert.equal(fixture.liveResidencies(), 1);
+  assert.equal(steering.ok, false);
+  if (!steering.ok) assert.equal(steering.error.code, 'operation_conflict');
+  assert.equal(fixture.coordinator.projection(ROOT.sessionId).steering.length, 1);
+  assert.equal(fixture.liveResidencies(), 2);
 
   await fixture.coordinator.handlers['queue.retract'](
     { originHostEpoch: 'epoch-1', sessionId: ROOT.sessionId, retractId: 'cleanup-entry' },
     operationContext(),
   );
-  fixture.coordinator.abandonRootReservation(ROOT);
+  completeActiveRoot(fixture);
   await fixture.coordinator.close();
 });
 
@@ -834,6 +835,8 @@ test('submit mutation is visible before its receipt and concurrent retries share
     { originHostEpoch: 'epoch-1', sessionId: ROOT.sessionId, retractId: 'cleanup-submit-cut' },
     operationContext(),
   );
+  const cleanupLeases = owner.pull();
+  owner.ack(cleanupLeases.map((lease) => lease.id));
   owner.release();
   const batch = fixture.coordinator.beginTerminalTransition(ROOT);
   fixture.coordinator.completeIdle(batch);
@@ -901,6 +904,8 @@ test('retract mutation is visible while its receipt waits and preserves its exac
     { originHostEpoch: 'epoch-1', sessionId: ROOT.sessionId, retractId: 'cleanup-retract-cut' },
     operationContext(),
   );
+  const remaining = owner.pull();
+  owner.ack(remaining.map((lease) => lease.id));
   owner.release();
   const batch = fixture.coordinator.beginTerminalTransition(ROOT);
   fixture.coordinator.completeIdle(batch);
@@ -1582,6 +1587,8 @@ test('submit retries use keyed receipts and durable proof while old-Epoch rich c
     operationContext(),
   );
   assert.equal(retracted.ok, true);
+  const cleanupLeases = owner.pull();
+  owner.ack(cleanupLeases.map((lease) => lease.id));
   owner.release();
   const batch = fixture.coordinator.beginTerminalTransition(ROOT);
   fixture.coordinator.completeIdle(batch);
@@ -1920,8 +1927,10 @@ test('canonical retry omits redundant display text and empty ordered refs', asyn
   );
   assert.equal(retracted.ok, true);
   if (retracted.ok) {
-    assert.deepEqual(retracted.result.retracted[0]?.content, { text: 'same' });
+    assert.deepEqual(retracted.result.retracted, []);
   }
+  const remaining = owner.pull();
+  owner.ack(remaining.map((lease) => lease.id));
   owner.release();
   const batch = fixture.coordinator.beginTerminalTransition(ROOT);
   fixture.coordinator.completeIdle(batch);
@@ -2155,6 +2164,16 @@ function memoryReceiptStore(
   };
 }
 
+function completeActiveRoot(fixture: ReturnType<typeof createFixture>): void {
+  const owner = fixture.coordinator.bindRun(ROOT);
+  const leases = owner.pull();
+  owner.ack(leases.map((lease) => lease.id));
+  owner.release();
+  const batch = fixture.coordinator.beginTerminalTransition(ROOT);
+  assert.equal(batch.sources.length, 0);
+  fixture.coordinator.completeIdle(batch);
+}
+
 function submit(
   fixture: ReturnType<typeof createFixture>,
   messageId: string,
diff --git a/packages/runtime-host/src/server/message-coordinator.ts b/packages/runtime-host/src/server/message-coordinator.ts
index 8b91cfa81..66103ab4c 100644
--- a/packages/runtime-host/src/server/message-coordinator.ts
+++ b/packages/runtime-host/src/server/message-coordinator.ts
@@ -792,18 +792,18 @@ export class HostMessageCoordinator implements RuntimeMessageAuthority {
     if (
       !retractionResultFits(
         state,
-        state.revision + (queuedEntryCount(state) > 0 ? 1 : 0),
+        state.revision + (state.followup.length > 0 ? 1 : 0),
         MESSAGE_OPERATION_RESULT_MAX_BYTES,
       )
     ) {
       return failure('session_busy', 'Retract result exceeds protocol capacity');
     }
-    const queued = [...state.steering, ...state.followup];
+    const queued = [...state.followup];
     const result = {
       queueRevision: state.revision + (queued.length > 0 ? 1 : 0),
       retracted: queued.map(retractedSnapshot),
     };
-    const retracted = this.#retractQueued(state);
+    const retracted = this.#retractFollowups(state);
     if (retracted.length > 0) this.#mutated(state);
     if (!isDeepStrictEqual(result, { queueRevision: state.revision, retracted })) {
       throw new RuntimeMessageAuthorityInvariantError(
@@ -961,8 +961,11 @@ export class HostMessageCoordinator implements RuntimeMessageAuthority {
     }
     const queued = findQueuedEntry(state, input.entryId);
     if (!queued) {
-      if ([...state.inFlight.values()].some((entry) => entry.entryId === input.entryId)) {
-        return failure('operation_conflict', 'Message entry is already being delivered');
+      if (
+        state.steering.some((entry) => entry.entryId === input.entryId) ||
+        [...state.inFlight.values()].some((entry) => entry.entryId === input.entryId)
+      ) {
+        return failure('operation_conflict', 'Sent steering messages cannot be retracted');
       }
       return failure('not_found', 'Message queue entry does not exist');
     }
@@ -1467,7 +1470,8 @@ export class HostMessageCoordinator implements RuntimeMessageAuthority {
       );
     }
     state.phase = 'closed';
-    const retracted = this.#retractQueued(state);
+    const retracted = this.#retractFollowups(state);
+    this.#discardQueuedSteering(state);
     state.generation += 1;
     this.#mutated(state);
     const result = { queueRevision: state.revision, retracted };
@@ -1475,14 +1479,19 @@ export class HostMessageCoordinator implements RuntimeMessageAuthority {
     return result;
   }
 
-  #retractQueued(state: SessionState): RetractedMessageSnapshot[] {
-    const entries = [...state.steering, ...state.followup];
-    state.steering = [];
+  #retractFollowups(state: SessionState): RetractedMessageSnapshot[] {
+    const entries = state.followup;
     state.followup = [];
     for (const entry of entries) this.#releaseEntry(entry);
     return entries.map(retractedSnapshot);
   }
 
+  #discardQueuedSteering(state: SessionState): void {
+    const entries = state.steering;
+    state.steering = [];
+    for (const entry of entries) this.#releaseEntry(entry);
+  }
+
   #commitTransition(state: SessionState): void {
     const transition = state.transition;
     if (!transition) throw new RuntimeMessageAuthorityInvariantError('Missing terminal transition');
@@ -1625,13 +1634,9 @@ function findQueuedEntry(
   state: SessionState,
   entryId: string,
 ): { readonly entry: LiveEntry; remove(): void } | undefined {
-  for (const queue of [state.steering, state.followup]) {
-    const index = queue.findIndex((entry) => entry.entryId === entryId);
-    const entry = index === -1 ? undefined : queue[index];
-    if (!entry) continue;
-    return { entry, remove: () => queue.splice(index, 1) };
-  }
-  return undefined;
+  const index = state.followup.findIndex((entry) => entry.entryId === entryId);
+  const entry = index === -1 ? undefined : state.followup[index];
+  return entry ? { entry, remove: () => state.followup.splice(index, 1) } : undefined;
 }
 
 function decodeInterruptReceiptOutcome(value: unknown): MessageOutcome<TurnInterruptResult> {
@@ -1796,7 +1801,7 @@ function retractionResultFits(
   queueRevision: number,
   maxBytes: number,
 ): boolean {
-  const retracted = [...state.steering, ...state.followup].map(retractedSnapshot);
+  const retracted = state.followup.map(retractedSnapshot);
   return fitsEncodedByteLimit({ queueRevision, retracted }, maxBytes);
 }
 


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