Skip to content

Commit 91f0449

Browse files
authored
fix(sessions): defer agent self-archive until run completion (#114522)
1 parent 187b604 commit 91f0449

9 files changed

Lines changed: 991 additions & 10 deletions

File tree

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7497,6 +7497,8 @@ public struct SessionsAbortParams: Codable, Sendable {
74977497
public struct SessionsPatchParams: Codable, Sendable {
74987498
public let key: String
74997499
public let agentid: String?
7500+
public let expectedsessionid: String?
7501+
public let expectedlifecyclerevision: String?
75007502
public let label: AnyCodable?
75017503
public let category: AnyCodable?
75027504
public let boardface: AnyCodable?
@@ -7529,6 +7531,8 @@ public struct SessionsPatchParams: Codable, Sendable {
75297531
public init(
75307532
key: String,
75317533
agentid: String? = nil,
7534+
expectedsessionid: String? = nil,
7535+
expectedlifecyclerevision: String? = nil,
75327536
label: AnyCodable? = nil,
75337537
category: AnyCodable? = nil,
75347538
boardface: AnyCodable? = nil,
@@ -7560,6 +7564,8 @@ public struct SessionsPatchParams: Codable, Sendable {
75607564
{
75617565
self.key = key
75627566
self.agentid = agentid
7567+
self.expectedsessionid = expectedsessionid
7568+
self.expectedlifecyclerevision = expectedlifecyclerevision
75637569
self.label = label
75647570
self.category = category
75657571
self.boardface = boardface
@@ -7593,6 +7599,8 @@ public struct SessionsPatchParams: Codable, Sendable {
75937599
private enum CodingKeys: String, CodingKey {
75947600
case key
75957601
case agentid = "agentId"
7602+
case expectedsessionid = "expectedSessionId"
7603+
case expectedlifecyclerevision = "expectedLifecycleRevision"
75967604
case label
75977605
case category
75987606
case boardface = "boardFace"

‎packages/gateway-protocol/src/index.test.ts‎

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,29 @@ describe("lazy protocol validators", () => {
113113
expect(validateSessionsListParams({ face: "dashboard" })).toBe(false);
114114
});
115115

116+
it("validates session patch compare-and-swap identity", () => {
117+
expect(
118+
validateSessionsPatchParams({
119+
key: "agent:main:self-archive",
120+
archived: true,
121+
expectedSessionId: "session-self-archive",
122+
expectedLifecycleRevision: "revision-self-archive",
123+
}),
124+
).toBe(true);
125+
expect(
126+
validateSessionsPatchParams({
127+
key: "agent:main:self-archive",
128+
expectedSessionId: "",
129+
}),
130+
).toBe(false);
131+
expect(
132+
validateSessionsPatchParams({
133+
key: "agent:main:self-archive",
134+
expectedLifecycleRevision: "",
135+
}),
136+
).toBe(false);
137+
});
138+
116139
it("keeps validation errors readable on the exported validator", () => {
117140
expect(validateConnectParams({})).toBe(false);
118141
expect(formatValidationErrors(validateConnectParams.errors)).toContain("must have required");

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -470,6 +470,9 @@ export const SessionsAbortParamsSchema = closedObject({
470470
export const SessionsPatchParamsSchema = closedObject({
471471
key: NonEmptyString,
472472
agentId: Type.Optional(NonEmptyString),
473+
/** Reject the mutation if the session was reset or replaced before it commits. */
474+
expectedSessionId: Type.Optional(NonEmptyString),
475+
expectedLifecycleRevision: Type.Optional(NonEmptyString),
473476
label: Type.Optional(Type.Union([SessionLabelString, Type.Null()])),
474477
/** User-defined organization bucket ("category", not chat-group); null clears it. */
475478
category: Type.Optional(Type.Union([SessionLabelString, Type.Null()])),

0 commit comments

Comments
 (0)