Skip to content

Commit c8a2524

Browse files
committed
fix(gateway): satisfy restart recovery guards
1 parent 2dd6233 commit c8a2524

14 files changed

Lines changed: 64 additions & 48 deletions

‎apps/shared/OpenClawKit/Sources/OpenClawProtocol/GatewayModels.swift‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1324,6 +1324,7 @@ public struct AgentParams: Codable, Sendable {
13241324
public let replyto: String?
13251325
public let sessionid: String?
13261326
public let sessionkey: String?
1327+
public let expectedexistingsessionid: String?
13271328
public let thinking: String?
13281329
public let deliver: Bool?
13291330
public let attachments: [AnyCodable]?
@@ -1368,6 +1369,7 @@ public struct AgentParams: Codable, Sendable {
13681369
replyto: String? = nil,
13691370
sessionid: String? = nil,
13701371
sessionkey: String? = nil,
1372+
expectedexistingsessionid: String? = nil,
13711373
thinking: String? = nil,
13721374
deliver: Bool? = nil,
13731375
attachments: [AnyCodable]? = nil,
@@ -1411,6 +1413,7 @@ public struct AgentParams: Codable, Sendable {
14111413
self.replyto = replyto
14121414
self.sessionid = sessionid
14131415
self.sessionkey = sessionkey
1416+
self.expectedexistingsessionid = expectedexistingsessionid
14141417
self.thinking = thinking
14151418
self.deliver = deliver
14161419
self.attachments = attachments
@@ -1456,6 +1459,7 @@ public struct AgentParams: Codable, Sendable {
14561459
case replyto = "replyTo"
14571460
case sessionid = "sessionId"
14581461
case sessionkey = "sessionKey"
1462+
case expectedexistingsessionid = "expectedExistingSessionId"
14591463
case thinking
14601464
case deliver
14611465
case attachments

‎scripts/check-kysely-guardrails.mjs‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ const rawSqliteAllowPathGroups = {
3737
"src/infra/sqlite-transaction.ts",
3838
"src/infra/sqlite-user-version.ts",
3939
"src/infra/sqlite-wal.ts",
40+
"src/state/openclaw-agent-db-session-migrations.ts",
4041
"src/state/openclaw-agent-db.ts",
4142
"src/state/openclaw-state-db.ts",
4243
"src/state/sqlite-schema-shape.test-support.ts",

‎src/auto-reply/reply/restart-recovery-claim.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { loadSessionEntry, updateSessionEntry } from "../../config/sessions/sess
55
import type { SessionEntry } from "../../config/sessions/types.js";
66
import type { DeliveryContext } from "../../utils/delivery-context.shared.js";
77

8-
export type ReplyRestartRecoveryClaimController = {
8+
type ReplyRestartRecoveryClaimController = {
99
clear: () => Promise<void>;
1010
isArmed: () => boolean;
1111
persist: () => Promise<void>;

‎src/config/sessions/restart-recovery-state.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ function normalizeRunId(value: unknown): string | undefined {
77
}
88

99
/** Keeps a bounded durable set of client runs that must never execute again. */
10-
export function normalizeRestartRecoveryTerminalRunIds(value: unknown): string[] | undefined {
10+
function normalizeRestartRecoveryTerminalRunIds(value: unknown): string[] | undefined {
1111
if (!Array.isArray(value)) {
1212
return undefined;
1313
}

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

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -105,30 +105,6 @@ export type SessionTranscriptTurnMessageAppend = TranscriptMessageAppendOptions<
105105
shouldAppend?: (context: SessionTranscriptTurnWriteContext) => Promise<boolean> | boolean;
106106
};
107107

108-
export type SessionTranscriptTurnExpectedState = {
109-
abortedLastRun: SessionEntry["abortedLastRun"];
110-
restartRecoveryDeliveryRequestFingerprint: SessionEntry["restartRecoveryDeliveryRequestFingerprint"];
111-
restartRecoveryDeliveryRunId: SessionEntry["restartRecoveryDeliveryRunId"];
112-
restartRecoveryDeliverySourceRunId: SessionEntry["restartRecoveryDeliverySourceRunId"];
113-
status: SessionEntry["status"];
114-
updatedAt: SessionEntry["updatedAt"];
115-
};
116-
117-
export type SessionTranscriptTurnLifecyclePatch = {
118-
abortedLastRun?: SessionEntry["abortedLastRun"];
119-
endedAt?: SessionEntry["endedAt"];
120-
restartRecoveryDeliveryContext?: SessionEntry["restartRecoveryDeliveryContext"];
121-
restartRecoveryDeliveryRequestFingerprint?: SessionEntry["restartRecoveryDeliveryRequestFingerprint"];
122-
restartRecoveryDeliveryRunId?: SessionEntry["restartRecoveryDeliveryRunId"];
123-
restartRecoveryDeliverySourceRunId?: SessionEntry["restartRecoveryDeliverySourceRunId"];
124-
/** Durable tombstones merged with the fresh row inside the SQLite write transaction. */
125-
restartRecoveryTerminalRunIds?: SessionEntry["restartRecoveryTerminalRunIds"];
126-
runtimeMs?: SessionEntry["runtimeMs"];
127-
startedAt?: SessionEntry["startedAt"];
128-
status?: SessionEntry["status"];
129-
updatedAt?: SessionEntry["updatedAt"];
130-
};
131-
132108
export type SessionTranscriptTurnWriteContext = {
133109
agentId?: string;
134110
sessionFile: string;

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,6 @@ import type {
8686
SessionTranscriptReadScope,
8787
SessionTranscriptStats,
8888
SessionTranscriptTurnMessageAppend,
89-
SessionTranscriptTurnExpectedState,
90-
SessionTranscriptTurnLifecyclePatch,
9189
SessionTranscriptTurnWriteContext,
9290
SessionTranscriptWriteScope,
9391
SessionParentForkDecision,
@@ -106,6 +104,10 @@ import {
106104
deleteSessionTranscriptIndexInTransaction,
107105
indexAppendedTranscriptEventInTransaction,
108106
} from "./session-transcript-index.js";
107+
import type {
108+
SessionTranscriptTurnExpectedState,
109+
SessionTranscriptTurnLifecyclePatch,
110+
} from "./session-transcript-turn-lifecycle.types.js";
109111
import {
110112
buildExpectedTranscriptTurnSessionPatch,
111113
sessionMatchesExpectedTranscriptTurn,

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,6 @@ import {
2929
shouldSkipPluginHostCleanupStore,
3030
type PluginHostSessionCleanupStoreParams,
3131
} from "./plugin-host-cleanup.js";
32-
import type {
33-
SessionTranscriptTurnExpectedState,
34-
SessionTranscriptTurnLifecyclePatch,
35-
} from "./session-accessor.sqlite-contract.js";
3632
import {
3733
appendSqliteTranscriptEvent,
3834
appendSqliteTranscriptEventSync,
@@ -82,6 +78,10 @@ import {
8278
resolveFreshestTargetEntry,
8379
resolveProjectionExistingEntry,
8480
} from "./session-entry-selection.js";
81+
import type {
82+
SessionTranscriptTurnExpectedState,
83+
SessionTranscriptTurnLifecyclePatch,
84+
} from "./session-transcript-turn-lifecycle.types.js";
8585
import {
8686
formatSqliteSessionFileMarker,
8787
parseSqliteSessionFileMarker,
@@ -131,7 +131,7 @@ export type {
131131
export type {
132132
SessionTranscriptTurnExpectedState,
133133
SessionTranscriptTurnLifecyclePatch,
134-
} from "./session-accessor.sqlite-contract.js";
134+
} from "./session-transcript-turn-lifecycle.types.js";
135135

136136
/**
137137
* Session access API for callers that need entries or transcripts without
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import type { SessionRestartRecoveryState } from "./restart-recovery-types.js";
2+
3+
type SessionRunStatus = "running" | "done" | "failed" | "killed" | "timeout";
4+
5+
/** Authoritative lifecycle snapshot required for an atomic transcript admission. */
6+
export type SessionTranscriptTurnExpectedState = {
7+
abortedLastRun: boolean | undefined;
8+
restartRecoveryDeliveryRequestFingerprint: SessionRestartRecoveryState["restartRecoveryDeliveryRequestFingerprint"];
9+
restartRecoveryDeliveryRunId: SessionRestartRecoveryState["restartRecoveryDeliveryRunId"];
10+
restartRecoveryDeliverySourceRunId: SessionRestartRecoveryState["restartRecoveryDeliverySourceRunId"];
11+
status: SessionRunStatus | undefined;
12+
updatedAt: number;
13+
};
14+
15+
/** Lifecycle fields committed with an accepted transcript turn. */
16+
export type SessionTranscriptTurnLifecyclePatch = {
17+
abortedLastRun?: boolean;
18+
endedAt?: number;
19+
restartRecoveryDeliveryContext?: SessionRestartRecoveryState["restartRecoveryDeliveryContext"];
20+
restartRecoveryDeliveryRequestFingerprint?: SessionRestartRecoveryState["restartRecoveryDeliveryRequestFingerprint"];
21+
restartRecoveryDeliveryRunId?: SessionRestartRecoveryState["restartRecoveryDeliveryRunId"];
22+
restartRecoveryDeliverySourceRunId?: SessionRestartRecoveryState["restartRecoveryDeliverySourceRunId"];
23+
/** Durable tombstones merged with the fresh row inside the SQLite write transaction. */
24+
restartRecoveryTerminalRunIds?: SessionRestartRecoveryState["restartRecoveryTerminalRunIds"];
25+
runtimeMs?: number;
26+
startedAt?: number;
27+
status?: SessionRunStatus;
28+
updatedAt?: number;
29+
};

‎src/config/sessions/session-transcript-turn-state.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { mergeRestartRecoveryTerminalRunIds } from "./restart-recovery-state.js"
22
import type {
33
SessionTranscriptTurnExpectedState,
44
SessionTranscriptTurnLifecyclePatch,
5-
} from "./session-accessor.sqlite-contract.js";
5+
} from "./session-transcript-turn-lifecycle.types.js";
66
import type { SessionEntry } from "./types.js";
77

88
export function sessionMatchesExpectedTranscriptTurn<T extends { entry: SessionEntry }>(

‎src/gateway/server-methods/agent-expected-session.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import {
55
type SessionWorkAdmissionLease,
66
} from "../../sessions/session-lifecycle-admission.js";
77

8-
export type ExpectedExistingSessionConstraint = {
8+
type ExpectedExistingSessionConstraint = {
99
handoffId?: string;
1010
sessionId: string;
1111
};

0 commit comments

Comments
 (0)