fix(mobile): preserve active thread state

Keep executing runs visible when newer work is queued, expose provider errors in compact shells, and preserve mobile creation metadata for fork and merge operations.

Co-authored-by: codex <[email protected]>
This commit is contained in:
Julius Marmingeandcodex committed 2026-07-28 12:15:53 +02:00
1 parent ae3a25649a
commit e56b1c3dde
16 files changed
+230 -44

No files matched your search

@@ -124,13 +124,13 @@ it.layer(TestLayer)("ProjectionStoreV2", (it) => {
id: providerSessionId,
driver,
providerInstanceId,
status: "ready" as const,
status: "error" as const,
cwd: "/workspace",
model: modelSelection.model,
capabilities: CodexProviderCapabilitiesV2,
createdAt: now,
updatedAt: now,
lastError: null,
lastError: "provider process exited",
};
yield* projectionStore.apply({
@@ -174,6 +174,16 @@ it.layer(TestLayer)("ProjectionStoreV2", (it) => {
),
[providerSessionId],
);
assert.deepEqual(
(yield* projectionStore.getShellSnapshot()).threads.map((thread) => ({
id: thread.id,
lastError: thread.lastError,
})),
[
{ id: firstThreadId, lastError: "provider process exited" },
{ id: secondThreadId, lastError: "provider process exited" },
],
);
yield* projectionStore.apply({
id: EventId.make("event:projection-shared-provider-session:first-detached"),
@@ -390,6 +390,7 @@ type ShellThreadRow = {
readonly latest_run_id: string | null;
readonly latest_run_status: string | null;
readonly active_run_id: string | null;
readonly last_error: string | null;
readonly pending_request_payload_json: string | null;
readonly latest_message_payload_json: string | null;
readonly latest_user_message_at: string | null;
@@ -767,6 +768,13 @@ export function threadShellFromProjection(
(left, right) =>
DateTime.toEpochMillis(right.updatedAt) - DateTime.toEpochMillis(left.updatedAt),
)[0] ?? null;
const providerSession =
projection.providerSessions
.filter((session) => session.providerInstanceId === projection.thread.providerInstanceId)
.toSorted(
(left, right) =>
DateTime.toEpochMillis(right.updatedAt) - DateTime.toEpochMillis(left.updatedAt),
)[0] ?? null;
return {
createdBy: projection.thread.createdBy,
creationSource: projection.thread.creationSource,
@@ -788,6 +796,7 @@ export function threadShellFromProjection(
latestRunId: latestRun?.id ?? null,
activeRunId: activeRun?.id ?? null,
status: latestRun?.status ?? "idle",
lastError: providerSession?.lastError ?? null,
pendingRuntimeRequest:
pendingRuntimeRequest === null
? null
@@ -836,6 +845,7 @@ type ShellThreadState = {
readonly latestRunId: RunId | null;
readonly latestRunStatus: OrchestrationV2ShellThreadStatus;
readonly activeRunId: RunId | null;
readonly lastError: string | null;
readonly pendingRuntimeRequest: OrchestrationV2ThreadProjection["runtimeRequests"][number] | null;
readonly latestVisibleMessage: OrchestrationV2ConversationMessage | null;
readonly latestUserMessageAt: DateTime.Utc | null;
@@ -953,6 +963,7 @@ function shellFromState(input: {
latestRunId: input.state.latestRunId,
activeRunId: input.state.activeRunId,
status: input.state.latestRunStatus,
lastError: input.state.lastError,
pendingRuntimeRequest:
input.state.pendingRuntimeRequest === null
? null
@@ -2099,6 +2110,16 @@ export const layer: Layer.Layer<ProjectionStoreV2, never, SqlClient.SqlClient> =
ORDER BY r.ordinal DESC, r.run_id DESC
LIMIT 1
) AS active_run_id,
(
SELECT json_extract(session.payload_json, '$.lastError')
FROM orchestration_v2_projection_provider_sessions session
INNER JOIN orchestration_v2_projection_provider_session_bindings binding
ON binding.provider_session_id = session.provider_session_id
WHERE binding.thread_id = t.thread_id
AND session.provider_instance_id = t.provider_instance_id
ORDER BY session.updated_at DESC, session.provider_session_id DESC
LIMIT 1
) AS last_error,
(
SELECT request.payload_json
FROM orchestration_v2_projection_runtime_requests request
@@ -2193,6 +2214,7 @@ export const layer: Layer.Layer<ProjectionStoreV2, never, SqlClient.SqlClient> =
latestRunId: row.latest_run_id === null ? null : RunId.make(row.latest_run_id),
latestRunStatus: shellStatusFromStoredRunStatus(row.latest_run_status),
activeRunId: row.active_run_id === null ? null : RunId.make(row.active_run_id),
lastError: row.last_error,
pendingRuntimeRequest,
latestVisibleMessage,
latestUserMessageAt: