@devries-cameron20 / t3code-1 / commits / 9888694f80
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

fix(client): refresh open archive when threads are archived elsewhere (#36909)

Co-authored-by: Julius Marminge <julius0216@outlook.com>

Wout Stiens committed Nov 14, 2026 at 21:37 UTC 9888694f80399926bfef6068b2f85b5089b785ea
3 files changed +174 -1
packages/client-runtime/src/state/orchestration.ts
+8 -1
@@ -38,7 +38,7 @@ import { fetchEnvironmentThreadTranscript } from "./threadTranscriptHttp.ts";
38 export function createOrchestrationEnvironmentAtoms<R, E>(
39 runtime: Atom.AtomRuntime<EnvironmentRegistry | HttpClient.HttpClient | R, E>,
40 options: {
41 - /** Re-checks `threadTitles` when one of their threads leaves the shell. */
41 + /** Re-checks `threadTitles` when one of their threads leaves the shell, and the archive on any removal. */
42 readonly shellState?: (
43 environmentId: EnvironmentId,
44 ) => Atom.Atom<Pick<EnvironmentShellState, "removedAt">>;
@@ -239,6 +239,13 @@ export function createOrchestrationEnvironmentAtoms<R, E>(
239 archivedShellSnapshot: createEnvironmentRpcQueryAtomFamily(runtime, {
240 label: "environment-data:orchestration:archived-shell-snapshot",
241 tag: ORCHESTRATION_V2_WS_METHODS.getArchivedShellSnapshot,
242 + // The shell reports archiving a thread, and deleting or changing an archived one, as a removal,
243 + // and replaces `removedAt` on each one.
244 + refreshTrigger: ({ environmentId }) => {
245 + if (shellState === undefined) return undefined;
246 + const state = shellState(environmentId);
247 + return Atom.make((get) => get(state).removedAt);
248 + },
249 }),
250 threadFamily: createEnvironmentRpcQueryAtomFamily(runtime, {
251 label: "environment-data:orchestration:thread-family-for-delete",
packages/client-runtime/src/state/runtime.test.ts
+54
@@ -7,6 +7,7 @@ import {
7 EnvironmentId,
8 type FilesystemBrowseEntry,
9 ORCHESTRATION_V2_WS_METHODS,
10 + type OrchestrationV2ArchivedShellSnapshot,
11 ThreadId,
12 ProjectId,
13 type ReviewDiffPreviewInput,
@@ -53,6 +54,7 @@ import { createPreviewEnvironmentAtoms } from "./preview.ts";
54 import { createFilesystemEnvironmentAtoms } from "./filesystem.ts";
55 import type { QueryPersistence } from "./queryPersistence.ts";
56 import type { EnvironmentShellState } from "./shell.ts";
57 +import { v2Now, v2Project, v2ThreadId, v2ThreadShell } from "./orchestrationV2TestFixtures.ts";
58 import { createTerminalEnvironmentAtoms } from "./terminal.ts";
59 import {
60 createAtomCommandScheduler,
@@ -1399,6 +1401,58 @@ describe("environment query lifecycle", () => {
1401 expect(settled).toEqual([{ fork: "Fork" }, {}]);
1402 }),
1403 );
1404 +
1405 + it.effect("re-reads an open archive when a thread leaves the shell", () =>
1406 + Effect.gen(function* () {
1407 + const requests =
1408 + yield* Queue.unbounded<Deferred.Deferred<OrchestrationV2ArchivedShellSnapshot>>();
1409 + const harness = yield* makeEnvironmentQueryHarness(Effect.void, {
1410 + rpcSession: {
1411 + client: {
1412 + [ORCHESTRATION_V2_WS_METHODS.getArchivedShellSnapshot]: () =>
1413 + Effect.gen(function* () {
1414 + const answer = yield* Deferred.make<OrchestrationV2ArchivedShellSnapshot>();
1415 + yield* Queue.offer(requests, answer);
1416 + return yield* Deferred.await(answer);
1417 + }),
1418 + },
1419 + } as unknown as RpcSession.RpcSession,
1420 + });
1421 + const shellState = Atom.make<Pick<EnvironmentShellState, "removedAt">>({
1422 + removedAt: new Map(),
1423 + }).pipe(Atom.keepAlive);
1424 + const runtime = harness.runtime as unknown as Atom.AtomRuntime<
1425 + EnvironmentRegistry.EnvironmentRegistry | HttpClient.HttpClient
1426 + >;
1427 + const atom = createOrchestrationEnvironmentAtoms(runtime, {
1428 + shellState: () => shellState,
1429 + }).archivedShellSnapshot({ environmentId: QUERY_ENVIRONMENT.environmentId, input: {} });
1430 + const page = (threads: OrchestrationV2ArchivedShellSnapshot["threads"]) => ({
1431 + schemaVersion: 1,
1432 + snapshotSequence: 1,
1433 + projects: [v2Project],
1434 + threads,
1435 + });
1436 + const registry = yield* mountEnvironmentQuery(atom);
1437 + const archivedIds = Effect.map(readEnvironmentQuery(registry, atom), (snapshot) =>
1438 + snapshot.threads.map((thread) => thread.id),
1439 + );
1440 + yield* Deferred.succeed(yield* Queue.take(requests), page([]));
1441 + expect(yield* archivedIds).toEqual([]);
1442 +
1443 + // Another client archives the thread, then deletes it from the archive.
1444 + registry.set(shellState, { removedAt: new Map([[v2ThreadId, 2]]) });
1445 + expect(registry.get(atom).waiting).toBe(true);
1446 + yield* Deferred.succeed(
1447 + yield* Queue.take(requests),
1448 + page([{ ...v2ThreadShell, archivedAt: v2Now }]),
1449 + );
1450 + expect(yield* archivedIds).toEqual([v2ThreadId]);
1451 + registry.set(shellState, { removedAt: new Map([[v2ThreadId, 3]]) });
1452 + yield* Deferred.succeed(yield* Queue.take(requests), page([]));
1453 + expect(yield* archivedIds).toEqual([]);
1454 + }),
1455 + );
1456 });
1457
1458 describe("executeAtomQuery", () => {
scripts/scenarios/archive-lists-thread-archived-elsewhere.e2e.ts new
+112
@@ -0,0 +1,112 @@
1 +import { expect } from "e2e";
2 +import * as Effect from "effect/Effect";
3 +import * as FileSystem from "effect/FileSystem";
4 +import * as Path from "effect/Path";
5 +import * as Schema from "effect/Schema";
6 +import { FetchHttpClient, HttpClient, HttpClientRequest } from "effect/http";
7 +
8 +import { T3_HOME } from "../e2e.config.ts";
9 +import { ScenarioError } from "./shell.ts";
10 +import { makeState, runPromise, test, WEB } from "./t3.ts";
11 +
12 +const SettingsJson = Schema.fromJsonString(Schema.Record(Schema.String, Schema.Unknown));
13 +const decodeSettings = Schema.decodeEffect(SettingsJson);
14 +const encodeSettings = Schema.encodeEffect(SettingsJson);
15 +
16 +// A token from `auth session issue` acts at most in approval-required mode, so the thread must too.
17 +const approvalRequiredThreads = Effect.gen(function* () {
18 + const fs = yield* FileSystem.FileSystem;
19 + const settingsPath = (yield* Path.Path).join(T3_HOME, "userdata/settings.json");
20 + const original = yield* fs.readFileString(settingsPath);
21 + const settings = yield* decodeSettings(original);
22 + return {
23 + apply: fs.writeFileString(
24 + settingsPath,
25 + yield* encodeSettings({
26 + ...settings,
27 + defaultRuntimeMode: "approval-required",
28 + }),
29 + ),
30 + restore: fs.writeFileString(settingsPath, original),
31 + };
32 +});
33 +
34 +/** Archives a thread as an outside agent does: `t3_thread_organize` on the server's MCP endpoint. */
35 +const archiveOverMcp = Effect.fn("scenario.archiveOverMcp")(function* (
36 + baseUrl: string,
37 + threadId: string,
38 +) {
39 + const { cli } = makeState(T3_HOME);
40 + const { stdout } = yield* cli([
41 + "auth",
42 + "session",
43 + "issue",
44 + "--subject",
45 + "mcp-client",
46 + "--scope",
47 + "orchestration:read",
48 + "--scope",
49 + "orchestration:operate",
50 + "--token-only",
51 + ]);
52 + const client = yield* HttpClient.HttpClient;
53 + let sessionId: string | null = null;
54 + const send = Effect.fnUntraced(function* (message: object) {
55 + const response = yield* client.execute(
56 + HttpClientRequest.post(`${baseUrl}/mcp`).pipe(
57 + HttpClientRequest.setHeaders({
58 + accept: "application/json, text/event-stream",
59 + authorization: `Bearer ${stdout.trim()}`,
60 + ...(sessionId === null ? {} : { "mcp-session-id": sessionId }),
61 + }),
62 + HttpClientRequest.bodyJsonUnsafe({ jsonrpc: "2.0", ...message }),
63 + ),
64 + );
65 + sessionId = response.headers["mcp-session-id"] ?? sessionId;
66 + const body = yield* response.text;
67 + if (response.status >= 300) {
68 + return yield* new ScenarioError({ message: `MCP ${response.status}: ${body}` });
69 + }
70 + return body;
71 + });
72 + yield* send({
73 + id: 1,
74 + method: "initialize",
75 + params: {
76 + protocolVersion: "2025-06-18",
77 + capabilities: {},
78 + clientInfo: { name: "scenario", version: "1" },
79 + },
80 + });
81 + yield* send({ method: "notifications/initialized" });
82 + const result = yield* send({
83 + id: 2,
84 + method: "tools/call",
85 + params: { name: "t3_thread_organize", arguments: { threadId, action: "archive" } },
86 + });
87 + if (result.includes('"isError":true')) {
88 + return yield* new ScenarioError({ message: `Archive failed: ${result}` });
89 + }
90 +}, Effect.provide(FetchHttpClient.layer));
91 +
92 +test(
93 + "Settings Archived lists a thread archived elsewhere while it is open",
94 + WEB,
95 + async ({ t3, app, screen }) => {
96 + const settings = await runPromise(approvalRequiredThreads);
97 + try {
98 + await runPromise(settings.apply);
99 + const project = await t3.project("demo");
100 + const thread = await t3.thread({ project, title: "Archived elsewhere", messages: ["first"] });
101 + await t3.open("/settings/archived");
102 + await expect(screen.getByText("No archived threads")).toBeVisible();
103 +
104 + await runPromise(archiveOverMcp(app.baseUrl ?? "", thread.threadId));
105 +
106 + await expect(screen.getByRole("button", "Unarchive Archived elsewhere")).toBeVisible();
107 + await app.screenshot("archived-list");
108 + } finally {
109 + await runPromise(settings.restore);
110 + }
111 + },
112 +);