Skip to content

Commit b8696bd

Browse files
yanmo42jesse-merhi
authored andcommitted
fix(ui): recover queued follow-ups from settled runs
Co-authored-by: jesse-merhi <[email protected]>
1 parent 8d6cbee commit b8696bd

25 files changed

Lines changed: 230 additions & 15 deletions

‎packages/gateway-protocol/src/schema/sessions-row.test.ts‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ describe("SessionRowSchema", () => {
88
const row = {
99
key: "agent:main:main",
1010
kind: "global",
11+
lastRunId: "run-settled",
1112
activeLeafEntryId: "leaf-rendered",
1213
createdActor: {
1314
type: "human",
@@ -37,6 +38,7 @@ describe("SessionRowSchema", () => {
3738
const roundTripped = structuredClone(row);
3839

3940
expect(SessionRowSchema.properties.activeLeafEntryId).toBeDefined();
41+
expect(SessionRowSchema.properties.lastRunId).toBeDefined();
4042
expect(Value.Check(SessionRowSchema, roundTripped)).toBe(true);
4143
expect(Value.Check(SessionRowSchema, { ...roundTripped, activeLeafEntryId: null })).toBe(true);
4244
expect(
@@ -50,6 +52,7 @@ describe("SessionRowSchema", () => {
5052
).toBe(false);
5153
expect(roundTripped).toMatchObject({
5254
activeLeafEntryId: "leaf-rendered",
55+
lastRunId: "run-settled",
5356
createdActor: { avatarUrl: "/api/users/profile-ada/avatar?v=7" },
5457
participantCount: 2,
5558
archivedBy: { type: "human", id: "profile-bob", label: "Bob" },
@@ -63,6 +66,7 @@ describe("SessionRowSchema", () => {
6366
expect(Value.Check(SessionRowSchema, { ...roundTripped, permissionMode: "unrestricted" })).toBe(
6467
false,
6568
);
69+
expect(Value.Check(SessionRowSchema, { ...roundTripped, lastRunId: "" })).toBe(false);
6670
});
6771

6872
it("keeps sessions.assignOwner target actors closed and non-empty", () => {

‎packages/gateway-protocol/src/schema/sessions-row.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,8 @@ export const SessionRowSchema = Type.Object(
8888
]),
8989
),
9090
lastRunError: Type.Optional(Type.String()),
91+
/** Exact run that produced the latest terminal lifecycle projection. */
92+
lastRunId: Type.Optional(NonEmptyString),
9193
restartRecoveryStatus: Type.Optional(Type.Literal("tombstoned")),
9294
activeLeafEntryId: Type.Optional(Type.Union([NonEmptyString, Type.Null()])),
9395
spawnedBy: Type.Optional(Type.String()),

‎src/config/sessions/session-accessor.conformance.test.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2354,6 +2354,7 @@ describe("sqlite session normalization", () => {
23542354
const sourceEntry: InternalSessionEntry = {
23552355
label: "Source",
23562356
lifecycleRunId: "source-run",
2357+
lastRunId: "settled-source-run",
23572358
sessionId: "source-session",
23582359
updatedAt: 10,
23592360
compactionCheckpoints: [checkpoint],
@@ -2397,6 +2398,7 @@ describe("sqlite session normalization", () => {
23972398
}),
23982399
);
23992400
expect((result.entry as InternalSessionEntry).lifecycleRunId).toBeUndefined();
2401+
expect((result.entry as InternalSessionEntry).lastRunId).toBeUndefined();
24002402
await expect(loadTranscriptEvents(branchScope)).resolves.toEqual([
24012403
expect.objectContaining({ type: "session", id: result.entry.sessionId }),
24022404
expect.objectContaining({ id: "pre-msg", type: "message" }),

‎src/config/sessions/session-accessor.sqlite-checkpoint.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -455,6 +455,7 @@ function cloneSqliteCheckpointSessionEntry(params: {
455455
systemSent: false,
456456
abortedLastRun: false,
457457
lifecycleRunId: undefined,
458+
lastRunId: undefined,
458459
startedAt: undefined,
459460
endedAt: undefined,
460461
runtimeMs: undefined,

‎src/config/sessions/session-accessor.sqlite-message-cut.test.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ async function createSession(options: { activeLeafTarget?: string } = {}) {
9696
forkSource: { sessionKey: "agent:main:root", sessionId: "root-session" },
9797
lifecycleRevision: "source-lifecycle-revision",
9898
lifecycleRunId: "source-run",
99+
lastRunId: "settled-source-run",
99100
modelOverride: "gpt-5",
100101
modelOverrideSource: "user",
101102
providerOverride: "openai",
@@ -578,6 +579,7 @@ describe("SQLite session message cuts", () => {
578579
expect(loadSessionEntry(scope)?.sessionId).toBe(scope.sessionId);
579580
expect(result.entry.lifecycleRevision).not.toBe("source-lifecycle-revision");
580581
expect((result.entry as InternalSessionEntry).lifecycleRunId).toBeUndefined();
582+
expect((result.entry as InternalSessionEntry).lastRunId).toBeUndefined();
581583
expect(result.entry.cliSessionBindings).toBeUndefined();
582584
expect(deliveryContextFromSession(result.entry)).toBeUndefined();
583585
expect(result.entry.parentSessionKey).toBe(canonicalSourceKey);

‎src/config/sessions/session-accessor.sqlite-message-cut.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -509,6 +509,7 @@ function cloneMessageCutSessionEntry(params: {
509509
systemSent: false,
510510
abortedLastRun: false,
511511
lifecycleRunId: undefined,
512+
lastRunId: undefined,
512513
startedAt: undefined,
513514
endedAt: undefined,
514515
runtimeMs: undefined,

‎src/config/sessions/session-accessor.sqlite-parent-session.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,7 @@ export async function forkSessionEntryFromParentTarget(
235235
},
236236
forkedFromParent: true,
237237
lifecycleRunId: undefined,
238+
lastRunId: undefined,
238239
sessionId: fork.transcript.sessionId,
239240
totalTokens: undefined,
240241
totalTokensFresh: false,

‎src/config/sessions/session-entry-projection.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,15 @@ import type { InternalSessionEntry, SessionEntry } from "./types.js";
22

33
export const SESSION_ENTRY_PRIVATE_CLEAR_PATCH = {
44
activeWriterRunId: undefined,
5+
lastRunId: undefined,
56
lifecycleRunId: undefined,
67
mainRestartRecovery: undefined,
78
sessionDiffBaselineCapture: undefined,
89
} satisfies Partial<InternalSessionEntry>;
910

1011
const PRIVATE_SESSION_ENTRY_KEYS = [
1112
"activeWriterRunId",
13+
"lastRunId",
1214
"lifecycleRunId",
1315
"mainRestartRecovery",
1416
"sessionDiffBaselineCapture",

‎src/config/sessions/terminal-status.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ export function recoverTerminalSessionEntryForVisibleTurn(entry: SessionEntry):
1313
...entry,
1414
status: undefined,
1515
lifecycleRunId: undefined,
16+
lastRunId: undefined,
1617
startedAt: undefined,
1718
endedAt: undefined,
1819
runtimeMs: undefined,

‎src/config/sessions/types.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -624,6 +624,8 @@ export interface SessionEntry extends SessionEntryCore {}
624624
export type InternalSessionEntryCore = SessionEntryCore & {
625625
/** Run that owns the current non-terminal Gateway lifecycle projection. */
626626
lifecycleRunId?: string;
627+
/** Exact run that produced the latest terminal Gateway lifecycle projection. */
628+
lastRunId?: string;
627629
/** Run admitted by the session lane; overwritten at admission and checked by transcript writes. */
628630
activeWriterRunId?: string;
629631
/** Private per-generation ownership for the pre-runtime checkout baseline capture. */

0 commit comments

Comments
 (0)