Skip to content

Commit c0f777f

Browse files
committed
Merge origin/main into issue-watch/25707
2 parents 1581fb9 + ef81fd1 commit c0f777f

43 files changed

Lines changed: 788 additions & 421 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎apps/desktop/src/settings/DesktopAppSettings.test.ts‎

Lines changed: 25 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -200,16 +200,22 @@ describe("DesktopSettings", () => {
200200
withSettings(
201201
Effect.gen(function* () {
202202
const settings = yield* DesktopAppSettings.DesktopAppSettings;
203-
yield* writeSettingsPatch({
204-
mainWindowBounds: { x: 10.5, y: 20, width: 839, height: 620 },
205-
mainWindowMaximized: true,
206-
serverExposureMode: "network-accessible",
207-
});
208-
209-
const loaded = yield* settings.load;
210-
assert.isNull(loaded.mainWindowBounds);
211-
assert.isFalse(loaded.mainWindowMaximized);
212-
assert.equal(loaded.serverExposureMode, "network-accessible");
203+
for (const bounds of [
204+
{ x: 10.5, y: 20, width: 400, height: 360 },
205+
{ x: 10, y: 20, width: 399, height: 360 },
206+
{ x: 10, y: 20, width: 400, height: 359 },
207+
]) {
208+
yield* writeSettingsPatch({
209+
mainWindowBounds: bounds,
210+
mainWindowMaximized: true,
211+
serverExposureMode: "network-accessible",
212+
});
213+
214+
const loaded = yield* settings.load;
215+
assert.isNull(loaded.mainWindowBounds);
216+
assert.isFalse(loaded.mainWindowMaximized);
217+
assert.equal(loaded.serverExposureMode, "network-accessible");
218+
}
213219
}),
214220
),
215221
);
@@ -221,17 +227,24 @@ describe("DesktopSettings", () => {
221227
const fileSystem = yield* FileSystem.FileSystem;
222228
const settings = yield* DesktopAppSettings.DesktopAppSettings;
223229

224-
yield* settings.setMainWindowBounds({ x: -1200, y: 40, width: 1440, height: 960 }, true);
230+
yield* settings.setMainWindowBounds({ x: -1200, y: 40, width: 400, height: 360 }, true);
225231
yield* settings.setServerExposureMode("network-accessible");
226232

227233
const persisted = yield* decodeDesktopSettingsPatch(
228234
yield* fileSystem.readFileString(environment.desktopSettingsPath),
229235
);
230236
assert.deepEqual(persisted, {
231-
mainWindowBounds: { x: -1200, y: 40, width: 1440, height: 960 },
237+
mainWindowBounds: { x: -1200, y: 40, width: 400, height: 360 },
232238
mainWindowMaximized: true,
233239
serverExposureMode: "network-accessible",
234240
} satisfies typeof DesktopSettingsPatch.Type);
241+
242+
const restored = yield* Effect.gen(function* () {
243+
const freshSettings = yield* DesktopAppSettings.DesktopAppSettings;
244+
return yield* freshSettings.load;
245+
}).pipe(Effect.provide(DesktopAppSettings.layer));
246+
assert.deepEqual(restored.mainWindowBounds, persisted.mainWindowBounds);
247+
assert.isTrue(restored.mainWindowMaximized);
235248
}),
236249
),
237250
);

‎apps/desktop/src/settings/DesktopAppSettings.ts‎

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,12 @@ export interface DesktopSettingsChange {
4747
}
4848

4949
const DEFAULT_TAILSCALE_SERVE_PORT = 443;
50-
const MIN_MAIN_WINDOW_SIZE = {
51-
width: 840,
52-
height: 620,
50+
// Fits half and third tiles of common scaled displays (down to 480x432 DIP) on
51+
// Wayland, where Electron's client-side frame adds 32x42 DIP to the enforced
52+
// minimum. The web layout already handles phone widths.
53+
export const MIN_MAIN_WINDOW_SIZE = {
54+
width: 400,
55+
height: 360,
5356
} as const;
5457
export const DesktopWindowBoundsSchema = Schema.Struct({
5558
x: Schema.Int,

‎apps/desktop/src/window/DesktopWindow.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -399,8 +399,8 @@ export const make = Effect.gen(function* () {
399399
if (yield* Ref.get(desktopState.quitting)) return Option.none();
400400
const window = yield* electronWindow.create({
401401
...initialBounds,
402-
minWidth: 840,
403-
minHeight: 620,
402+
minWidth: DesktopAppSettings.MIN_MAIN_WINDOW_SIZE.width,
403+
minHeight: DesktopAppSettings.MIN_MAIN_WINDOW_SIZE.height,
404404
show: false,
405405
autoHideMenuBar: true,
406406
...(environment.platform === "darwin" ? { disableAutoHideCursor: true } : {}),

‎apps/mobile/src/features/terminal/ThreadTerminalRouteScreen.tsx‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -487,6 +487,7 @@ function ThreadTerminal(props: {
487487
cols: initialAttachGridSize.cols,
488488
rows: initialAttachGridSize.rows,
489489
...(pendingLaunch?.env ? { env: pendingLaunch.env } : {}),
490+
...(pendingLaunch ? { stopOnSettle: pendingLaunch.stopOnSettle ?? false } : {}),
490491
...(pendingLaunch ? { restartIfNotRunning: true } : {}),
491492
}
492493
: null,

‎apps/mobile/src/features/terminal/terminalLaunchContext.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ export interface PendingTerminalLaunch {
1717
readonly worktreePath: string | null;
1818
readonly env?: Record<string, string>;
1919
readonly initialInput?: string;
20+
readonly stopOnSettle?: boolean;
2021
}
2122

2223
const pendingTerminalLaunches = new Map<string, PendingTerminalLaunch>();
@@ -34,6 +35,7 @@ export function stagePendingTerminalLaunch(input: {
3435
worktreePath: input.launch.worktreePath,
3536
env: input.launch.env ? { ...input.launch.env } : undefined,
3637
initialInput: input.launch.initialInput,
38+
stopOnSettle: input.launch.stopOnSettle,
3739
});
3840
}
3941

‎apps/mobile/src/features/threads/ThreadRouteScreen.tsx‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -767,6 +767,7 @@ function ThreadRouteContent(
767767
worktreePath: preferredWorktreePath,
768768
env,
769769
initialInput: projectScriptTerminalInput(script.command),
770+
stopOnSettle: script.stopOnSettle ?? false,
770771
},
771772
});
772773

‎apps/server/src/orchestration-v2/ProjectionRecovery.test.ts‎

Lines changed: 82 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -213,55 +213,87 @@ it.effect.each(["startup", "shutdown"] as const)(
213213
}).pipe(Effect.provide(layerRecoveryTest)),
214214
);
215215

216-
it.effect("stops a session its thread detached, which kept its live status", () =>
217-
Effect.gen(function* () {
218-
const projections = yield* ProjectionStore.ProjectionStoreV2;
219-
const recovery = yield* ProviderRuntimeRecovery.ProviderRuntimeRecoveryService;
220-
const now = yield* DateTime.now;
221-
const threadId = yield* createThread("detached-session");
222-
const providerSessionId = ProviderSessionId.make("session:recovery:detached");
223-
yield* projections.apply({
224-
id: EventId.make("event:recovery:detached-session:attached"),
225-
type: "provider-session.attached",
226-
threadId,
227-
driver,
228-
providerInstanceId,
229-
occurredAt: now,
230-
payload: {
231-
id: providerSessionId,
216+
it.effect.each(["startup", "shutdown"] as const)(
217+
"stops a detached session and its orphaned active provider thread on %s",
218+
(trigger) =>
219+
Effect.gen(function* () {
220+
const projections = yield* ProjectionStore.ProjectionStoreV2;
221+
const recovery = yield* ProviderRuntimeRecovery.ProviderRuntimeRecoveryService;
222+
const now = yield* DateTime.now;
223+
const threadId = yield* createThread("detached-session");
224+
const providerSessionId = ProviderSessionId.make("session:recovery:detached");
225+
yield* projections.apply({
226+
id: EventId.make("event:recovery:detached-session:attached"),
227+
type: "provider-session.attached",
228+
threadId,
232229
driver,
233230
providerInstanceId,
234-
status: "ready",
235-
cwd: "/workspace",
236-
model: modelSelection.model,
237-
capabilities: CodexProviderCapabilitiesV2,
238-
createdAt: now,
239-
updatedAt: now,
240-
lastError: null,
241-
},
242-
});
243-
yield* projections.apply({
244-
id: EventId.make("event:recovery:detached-session:detached"),
245-
type: "provider-session.detached",
246-
threadId,
247-
driver,
248-
providerInstanceId,
249-
occurredAt: now,
250-
payload: { providerSessionId, detachedAt: now, reason: "Thread settled." },
251-
});
252-
assert.deepEqual(yield* projections.getRecoveryThreadIds("runtime"), [threadId]);
231+
occurredAt: now,
232+
payload: {
233+
id: providerSessionId,
234+
driver,
235+
providerInstanceId,
236+
status: "ready",
237+
cwd: "/workspace",
238+
model: modelSelection.model,
239+
capabilities: CodexProviderCapabilitiesV2,
240+
createdAt: now,
241+
updatedAt: now,
242+
lastError: null,
243+
},
244+
});
245+
yield* projections.apply({
246+
id: EventId.make("event:recovery:detached-session:detached"),
247+
type: "provider-session.detached",
248+
threadId,
249+
driver,
250+
providerInstanceId,
251+
occurredAt: now,
252+
payload: { providerSessionId, detachedAt: now, reason: "Thread settled." },
253+
});
254+
const providerThreadId = ProviderThreadId.make("provider-thread:recovery:detached");
255+
yield* projections.apply({
256+
id: EventId.make("event:recovery:detached-provider-thread"),
257+
type: "provider-thread.updated",
258+
threadId,
259+
occurredAt: now,
260+
payload: {
261+
id: providerThreadId,
262+
appThreadId: threadId,
263+
ownerNodeId: null,
264+
driver,
265+
providerInstanceId,
266+
providerSessionId: null,
267+
nativeThreadRef: null,
268+
nativeConversationHeadRef: null,
269+
status: "active",
270+
firstRunOrdinal: null,
271+
lastRunOrdinal: null,
272+
handoffIds: [],
273+
forkedFrom: null,
274+
createdAt: now,
275+
updatedAt: now,
276+
},
277+
});
278+
assert.deepEqual(yield* projections.getRecoveryThreadIds("runtime"), [threadId]);
253279

254-
const summary = yield* recovery.reconcile("startup");
280+
const summary = yield* recovery.reconcile(trigger);
255281

256-
assert.equal(summary.stoppedSessions, 1);
257-
const sql = yield* SqlClient.SqlClient;
258-
const rows = yield* sql<{ readonly status: string }>`
282+
assert.equal(summary.stoppedSessions, 1);
283+
const sql = yield* SqlClient.SqlClient;
284+
const rows = yield* sql<{ readonly status: string }>`
259285
SELECT status FROM orchestration_v2_projection_provider_sessions
260286
WHERE provider_session_id = ${providerSessionId}
261287
`;
262-
assert.deepEqual(rows, [{ status: "stopped" }]);
263-
assert.deepEqual(yield* projections.getRecoveryThreadIds("runtime"), []);
264-
}).pipe(Effect.provide(layerRecoveryTest)),
288+
assert.deepEqual(rows, [{ status: "stopped" }]);
289+
const projection = yield* projections.getThreadProjection(threadId);
290+
assert.equal(projection.providerThreads[0]?.status, "idle");
291+
const eventStore = yield* EventStore.EventStoreV2;
292+
const sequence = yield* eventStore.latestSequence();
293+
assert.deepEqual(yield* projections.getRecoveryThreadIds("runtime"), []);
294+
yield* recovery.reconcile(trigger);
295+
assert.equal(yield* eventStore.latestSequence(), sequence);
296+
}).pipe(Effect.provide(layerRecoveryTest)),
265297
);
266298

267299
it.effect.each(["attached", "detached", "replaced"] as const)(
@@ -964,11 +996,18 @@ it.effect("bounds streaming recovery reads by candidate runs and preserves messa
964996
assert.equal(statements.length, 2);
965997
for (const [query, params] of statements) {
966998
const plan = yield* sql.unsafe<{ detail: string }>(`EXPLAIN QUERY PLAN ${query}`, params);
967-
assert.isTrue(plan[0]?.detail.includes("SEARCH run "), JSON.stringify(plan));
999+
assert.isTrue(
1000+
plan.some((row) => row.detail.includes("SEARCH message_run ")),
1001+
JSON.stringify(plan),
1002+
);
9681003
assert.isTrue(
9691004
plan.some((row) => row.detail.includes("messages_run_idx")),
9701005
JSON.stringify(plan),
9711006
);
1007+
assert.isFalse(
1008+
plan.some((row) => /\bSCAN message\b/.test(row.detail)),
1009+
JSON.stringify(plan),
1010+
);
9721011
assert.isFalse(
9731012
plan.some((row) => row.detail.includes("messages_thread_created_idx")),
9741013
JSON.stringify(plan),

‎apps/server/src/orchestration-v2/ProjectionStore.test.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8439,6 +8439,7 @@ it.layer(layerTest)("ProjectionStoreV2", (it) => {
84398439
.pipe(Effect.withTracer(tracer))).runs.map((run) => run.id),
84408440
[runId, newerRunId],
84418441
);
8442+
assert.lengthOf(statements, 2);
84428443
// Live-item filters must hit the active partial indexes, not walk the thread's history.
84438444
const sql = yield* SqlClient.SqlClient;
84448445
for (const statement of statements.filter((query) => query.includes("turn_items"))) {

0 commit comments

Comments
 (0)