Skip to content

Commit 076bf9e

Browse files
fix(ui): harden optimistic worktree startup
1 parent ac2b004 commit 076bf9e

38 files changed

Lines changed: 1642 additions & 791 deletions

‎ITERATION-NOTES.md‎

Lines changed: 0 additions & 6 deletions
This file was deleted.

‎apps/android/app/src/main/java/ai/openclaw/app/gateway/GatewayProtocol.kt‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -554,6 +554,7 @@ enum class GatewayMethod(
554554
SessionsRewind("sessions.rewind"),
555555
SessionsFork("sessions.fork"),
556556
SessionsCreate("sessions.create"),
557+
SessionsStartupResolve("sessions.startup.resolve"),
557558
SessionsRecover("sessions.recover"),
558559
SessionsSend("sessions.send"),
559560
SessionsAbort("sessions.abort"),

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

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6432,6 +6432,7 @@ public struct SessionRow: Codable, Sendable {
64326432
public let subagentcontrolscope: AnyCodable?
64336433
public let swarmgroupid: String?
64346434
public let worktree: [String: AnyCodable]?
6435+
public let startupstate: AnyCodable?
64356436
public let execnode: String?
64366437
public let execcwd: String?
64376438
public let spawnedworkspacedir: String?
@@ -6502,6 +6503,7 @@ public struct SessionRow: Codable, Sendable {
65026503
subagentcontrolscope: AnyCodable? = nil,
65036504
swarmgroupid: String? = nil,
65046505
worktree: [String: AnyCodable]? = nil,
6506+
startupstate: AnyCodable? = nil,
65056507
execnode: String? = nil,
65066508
execcwd: String? = nil,
65076509
spawnedworkspacedir: String? = nil,
@@ -6571,6 +6573,7 @@ public struct SessionRow: Codable, Sendable {
65716573
self.subagentcontrolscope = subagentcontrolscope
65726574
self.swarmgroupid = swarmgroupid
65736575
self.worktree = worktree
6576+
self.startupstate = startupstate
65746577
self.execnode = execnode
65756578
self.execcwd = execcwd
65766579
self.spawnedworkspacedir = spawnedworkspacedir
@@ -6642,6 +6645,7 @@ public struct SessionRow: Codable, Sendable {
66426645
case subagentcontrolscope = "subagentControlScope"
66436646
case swarmgroupid = "swarmGroupId"
66446647
case worktree
6648+
case startupstate = "startupState"
66456649
case execnode = "execNode"
66466650
case execcwd = "execCwd"
66476651
case spawnedworkspacedir = "spawnedWorkspaceDir"
@@ -9401,6 +9405,7 @@ public struct SessionsCreateResult: Codable, Sendable {
94019405
public let messageseq: Int?
94029406
public let runerror: ErrorShape?
94039407
public let worktree: SessionWorktreeInfo?
9408+
public let startupstate: AnyCodable?
94049409

94059410
public init(
94069411
ok: Bool,
@@ -9411,7 +9416,8 @@ public struct SessionsCreateResult: Codable, Sendable {
94119416
runid: String? = nil,
94129417
messageseq: Int? = nil,
94139418
runerror: ErrorShape? = nil,
9414-
worktree: SessionWorktreeInfo? = nil)
9419+
worktree: SessionWorktreeInfo? = nil,
9420+
startupstate: AnyCodable? = nil)
94159421
{
94169422
self.ok = ok
94179423
self.key = key
@@ -9422,6 +9428,7 @@ public struct SessionsCreateResult: Codable, Sendable {
94229428
self.messageseq = messageseq
94239429
self.runerror = runerror
94249430
self.worktree = worktree
9431+
self.startupstate = startupstate
94259432
}
94269433

94279434
private enum CodingKeys: String, CodingKey {
@@ -9434,6 +9441,43 @@ public struct SessionsCreateResult: Codable, Sendable {
94349441
case messageseq = "messageSeq"
94359442
case runerror = "runError"
94369443
case worktree
9444+
case startupstate = "startupState"
9445+
}
9446+
}
9447+
9448+
public struct SessionsStartupResolveParams: Codable, Sendable {
9449+
public let key: String
9450+
public let operationid: String
9451+
public let action: AnyCodable
9452+
9453+
public init(
9454+
key: String,
9455+
operationid: String,
9456+
action: AnyCodable)
9457+
{
9458+
self.key = key
9459+
self.operationid = operationid
9460+
self.action = action
9461+
}
9462+
9463+
private enum CodingKeys: String, CodingKey {
9464+
case key
9465+
case operationid = "operationId"
9466+
case action
9467+
}
9468+
}
9469+
9470+
public struct SessionsStartupResolveResult: Codable, Sendable {
9471+
public let ok: Bool
9472+
9473+
public init(
9474+
ok: Bool)
9475+
{
9476+
self.ok = ok
9477+
}
9478+
9479+
private enum CodingKeys: String, CodingKey {
9480+
case ok
94379481
}
94389482
}
94399483

‎config/assertion-safety-baseline.txt‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3027,7 +3027,6 @@ src/gateway/server-methods/session-recovery-continuation.ts 1
30273027
src/gateway/server-methods/sessions-abort.ts 3
30283028
src/gateway/server-methods/sessions-archive-lifecycle.ts 3
30293029
src/gateway/server-methods/sessions-compact.ts 1
3030-
src/gateway/server-methods/sessions-create.ts 1
30313030
src/gateway/server-methods/sessions-messaging.ts 11
30323031
src/gateway/server-methods/sessions-patch-engine.ts 1
30333032
src/gateway/server-methods/sessions-read.ts 2

‎docs/web/control-ui.md‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,8 @@ The **+** in the sidebar's **Sessions** toolbar opens a full-page draft at `/new
258258

259259
The folder defaults to the agent workspace. Write-scoped connections can browse, restore recent Gateway folders, and start sessions anywhere inside a configured agent workspace; another absolute Gateway path requires `operator.admin` but can run directly without being a Git checkout. Local placement keeps the optional **Worktree** control with a base-branch picker backed by `worktrees.branches` (no fetch) and an optional worktree name (the branch becomes `openclaw/<name>`). Choosing either a device or cloud profile forces a managed worktree from the selected Gateway source. **Start in terminal** is available only for local placement.
260260

261+
When you start a local managed-worktree session, the session opens immediately with the first message and a checkout card. The card streams setup progress and offers **Cancel** or **Work locally** until the worktree is ready; the agent starts only after that setup finishes or you choose the existing workspace.
262+
261263
For a remote target, the Control UI creates the managed-worktree session with an empty initial message and no `execNode`, dispatches it by exact `deviceId` or `profileId` (plus an optional cloud machine class), waits for active placement, and then sends the first message and attachments with the same idempotency key used by recovery. Device dispatch requires `operator.write`; cloud profile dispatch requires `operator.admin`. The composer footer chooses the new session's model and reasoning level.
262264

263265
Canceling or recovering an interrupted remote-placement startup reclaims the placement by session key. Cleanup archives a newly created draft before deleting it with the write-scoped archived-only contract, and any cleanup error remains visible for recovery.

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,8 @@ export {
244244
SessionWorktreeInfoSchema,
245245
SessionsCreateParamsSchema,
246246
SessionsCreateResultSchema,
247+
SessionsStartupResolveParamsSchema,
248+
SessionsStartupResolveResultSchema,
247249
SessionsRecoverParamsSchema,
248250
SessionsRecoverResultSchema,
249251
SessionsDispatchParamsSchema,

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ export * from "./schema/secrets.js";
3636
export * from "./schema/session-placement.js";
3737
export * from "./schema/session-discussion.js";
3838
export * from "./schema/sessions.js";
39+
export * from "./schema/sessions-startup.js";
3940
export * from "./schema/session-github-publication.js";
4041
export * from "./schema/sessions-viewer-presence.js";
4142
export * from "./schema/sessions-sharing.js";

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import * as startup from "./sessions-startup.js";
12
import * as viewerPresence from "./sessions-viewer-presence.js";
23
import * as sessions from "./sessions.js";
34

@@ -40,8 +41,8 @@ export const SessionLifecycleProtocolSchemas = {
4041
SessionWorktreeInfo: sessions.SessionWorktreeInfoSchema,
4142
SessionsCreateParams: sessions.SessionsCreateParamsSchema,
4243
SessionsCreateResult: sessions.SessionsCreateResultSchema,
43-
SessionsStartupResolveParams: sessions.SessionsStartupResolveParamsSchema,
44-
SessionsStartupResolveResult: sessions.SessionsStartupResolveResultSchema,
44+
SessionsStartupResolveParams: startup.SessionsStartupResolveParamsSchema,
45+
SessionsStartupResolveResult: startup.SessionsStartupResolveResultSchema,
4546
SessionsRecoverParams: sessions.SessionsRecoverParamsSchema,
4647
SessionsRecoverResult: sessions.SessionsRecoverResultSchema,
4748
SessionsSendParams: sessions.SessionsSendParamsSchema,

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

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import type { Static } from "typebox";
22
import { Type } from "typebox";
33
import { closedObject } from "./closed-object.js";
4-
import { ChatAttachmentsSchema } from "./logs-chat.js";
54
import { NonEmptyString } from "./primitives.js";
65
import { SessionClassificationSchema, SessionPeerKindSchema } from "./session-classification.js";
76
import { SessionSharingRoleSchema, SessionVisibilitySchema } from "./sessions-sharing-values.js";
@@ -47,9 +46,19 @@ export const SessionStartupStageSchema = Type.Union([
4746
Type.Literal("running-setup"),
4847
]);
4948

49+
const SessionStartupAttachmentSchema = closedObject({
50+
type: Type.Optional(Type.String({ maxLength: 64 })),
51+
mimeType: Type.Optional(Type.String({ maxLength: 128 })),
52+
fileName: Type.Optional(Type.String({ maxLength: 512 })),
53+
sizeBytes: Type.Optional(Type.Number({ minimum: 0 })),
54+
durationMs: Type.Optional(Type.Number({ minimum: 0 })),
55+
width: Type.Optional(Type.Number({ minimum: 0 })),
56+
height: Type.Optional(Type.Number({ minimum: 0 })),
57+
});
58+
5059
const SessionStartupInitialTurnSchema = closedObject({
5160
message: Type.Optional(Type.String({ maxLength: 100_000 })),
52-
attachments: Type.Optional(ChatAttachmentsSchema),
61+
attachments: Type.Optional(Type.Array(SessionStartupAttachmentSchema, { maxItems: 32 })),
5362
});
5463

5564
const SessionStartupOutputSchema = Type.String({ maxLength: 16_384 });
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import type { Static } from "typebox";
2+
import { Type } from "typebox";
3+
import { closedObject } from "./closed-object.js";
4+
import { NonEmptyString } from "./primitives.js";
5+
6+
export const SessionsStartupResolveParamsSchema = closedObject({
7+
key: NonEmptyString,
8+
operationId: NonEmptyString,
9+
action: Type.Union([Type.Literal("cancel"), Type.Literal("work-local")]),
10+
});
11+
12+
export const SessionsStartupResolveResultSchema = closedObject({ ok: Type.Literal(true) });
13+
14+
export type SessionsStartupResolveParams = Static<typeof SessionsStartupResolveParamsSchema>;
15+
export type SessionsStartupResolveResult = Static<typeof SessionsStartupResolveResultSchema>;

0 commit comments

Comments
 (0)