Skip to content

Commit bb3e1b4

Browse files
committed
fix(sessions): defer agent self-archive until run completion
1 parent 91b1f96 commit bb3e1b4

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
@@ -99,6 +99,29 @@ describe("lazy protocol validators", () => {
9999
expect(validateSessionsListParams({ face: "dashboard" })).toBe(false);
100100
});
101101

102+
it("validates session patch compare-and-swap identity", () => {
103+
expect(
104+
validateSessionsPatchParams({
105+
key: "agent:main:self-archive",
106+
archived: true,
107+
expectedSessionId: "session-self-archive",
108+
expectedLifecycleRevision: "revision-self-archive",
109+
}),
110+
).toBe(true);
111+
expect(
112+
validateSessionsPatchParams({
113+
key: "agent:main:self-archive",
114+
expectedSessionId: "",
115+
}),
116+
).toBe(false);
117+
expect(
118+
validateSessionsPatchParams({
119+
key: "agent:main:self-archive",
120+
expectedLifecycleRevision: "",
121+
}),
122+
).toBe(false);
123+
});
124+
102125
it("keeps validation errors readable on the exported validator", () => {
103126
expect(validateConnectParams({})).toBe(false);
104127
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)