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/07 00:26:23 UTC
(maka) 08/15: fix(runtime): owe a run's prompt from before its invocation opens
This is an automated email from the ASF dual-hosted git repository.
Astro-Han pushed a commit to branch refactor/4791-single-transcript-authority
in repository https://gitbox.apache.org/repos/asf/maka.git
commit 7b0451c67fc14cb6c30de846a32a087d80ed82b6
Author: AstroHan <le...@outlook.com>
AuthorDate: Sun Sep 6 19:03:07 2026 +0800
fix(runtime): owe a run's prompt from before its invocation opens
The pending flag was set after `openInvocation()`, so the one failure it did
not cover was a throw from the opening itself: `finalize` reopens what it can,
and a run it manages to open then sealed with a terminal and no prompt — the
same hole the previous commit closed, entered from one step earlier.
Moving the flag ahead of the opening costs nothing when the invocation never
opens: `finalize`'s reopen fails too, and the backfill is a no-op on a run that
does not exist.
Reported as a residual on #4879 and not asked for; it is one line and it closes
the last entrance to a shape that cannot be repaired after the fact.
runtime 3131 pass, runtime-host 1723 pass, cli 805 pass, 0 failures.
Generated-by: Claude Code
---
.../session-manager-terminal-ledger.test.ts | 28 ++++++++++++++++++++++
packages/runtime/src/agent-run.ts | 4 +++-
2 files changed, 31 insertions(+), 1 deletion(-)
diff --git a/packages/runtime/src/__tests__/session-manager-terminal-ledger.test.ts b/packages/runtime/src/__tests__/session-manager-terminal-ledger.test.ts
index 205d113bb4..0a602b40e8 100644
--- a/packages/runtime/src/__tests__/session-manager-terminal-ledger.test.ts
+++ b/packages/runtime/src/__tests__/session-manager-terminal-ledger.test.ts
@@ -1281,6 +1281,34 @@ describe('SessionManager terminal ledger invariants', () => {
assert.strictEqual(events.filter(isTerminalRuntimeEvent).length, 1);
});
+ test('a run that failed while opening still records its prompt once finalize reopens it', async () => {
+ const store = new TinySessionStore();
+ const runStore = new TinyAgentRunStore({ durability: 'canonical' });
+ // The opening append is what `begin()` fails on here, so the prompt is owed
+ // from before it — `finalize` reopens the invocation, and a run it can open
+ // is a run that has to say what it was asked to do.
+ runStore.rejectRuntimeEventIdsOnce.add('id-1');
+ const session = await store.create(makeInput());
+ const run = new AgentRun({
+ sessionId: session.id,
+ header: session,
+ runId: 'run-1',
+ userInput: { turnId: 'turn-1', text: 'hello' },
+ runStore,
+ runtimeEventStore: runStore,
+ newId: nextId(),
+ now: nextNow(41_900),
+ hooks: inertAgentRunHooks(store),
+ });
+
+ await assert.rejects(run.begin());
+ await run.finalize();
+
+ const events = await runStore.readRuntimeEvents(session.id, 'run-1');
+ assert.strictEqual(events.find((event) => event.role === 'user')?.id, 'run-1-admitted-prompt');
+ assert.strictEqual(events.filter(isTerminalRuntimeEvent).length, 1);
+ });
+
test('a stop settlement racing finalize commits exactly one terminal run event', async () => {
const store = new TinySessionStore();
const settleReachedAppend = deferred<void>();
diff --git a/packages/runtime/src/agent-run.ts b/packages/runtime/src/agent-run.ts
index df4373f0d0..f9542b2f6a 100644
--- a/packages/runtime/src/agent-run.ts
+++ b/packages/runtime/src/agent-run.ts
@@ -692,10 +692,12 @@ export class AgentRun {
}
async begin(): Promise<AgentRunBeginResult> {
+ // Owed from here, not from after the opening: `openInvocation` can leave the
+ // invocation open and still throw, and `finalize` reopens what it can.
+ this.initialRuntimeEventPending = true;
await this.openInvocation();
this.lastTs = this.input.now();
- this.initialRuntimeEventPending = true;
const initialRuntimeEvent = await this.recordInitialRuntimeEvent(this.lastTs);
this.active = await this.input.hooks.reserveRun(this.sessionId, this.header, this);
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@maka.apache.org
For additional commands, e-mail: commits-help@maka.apache.org