The best way to control Claude Code, Codex and more from any computer or phone
Mirrored from https://github.com/Camo67/t3code.git
Synced Nov 23, 01:45 UTC
fix(server): session import skips Codex subagent sessions (#16662)
Co-authored-by: Julius Marminge <julius0216@outlook.com>
Igor Makowski committed
Oct 19, 2026 at 22:21 UTC
002ef36521c1c57ec6b31c9db47bea1de96cbb2a
2 files changed
+81
-5
apps/server/src/project/AgentSessionScanner.test.ts
+61
@@ -1554,6 +1554,67 @@ it.layer(NodeServices.layer)("AgentSessionScanner", (it) => {
1554
}),
1555
);
1556
1557
+ it.effect("excludes Codex subagents from discovery and the recent-thread budget", () =>
1558
+ Effect.gen(function* () {
1559
+ const path = yield* Path.Path;
1560
+ const nowMs = Date.parse("2026-08-24T12:00:00.000Z");
1561
+ yield* TestClock.setTime(nowMs);
1562
+ const claudeHomePath = yield* makeTempDir("t3code-claude-home-");
1563
+ const codexHomePath = yield* makeTempDir("t3code-codex-home-");
1564
+ const workspace = yield* makeTempDir("t3code-workspace-");
1565
+ const subagentSources = [
1566
+ { subagent: { thread_spawn: { parent_thread_id: "session-100", depth: 1 } } },
1567
+ { subagent: "review" },
1568
+ { subagent: { other: "guardian" } },
1569
+ { subAgent: "compact" },
1570
+ ];
1571
+ // Newer subagents would exhaust the 100-transcript import budget before any parent.
1572
+ const sources = [
1573
+ ...Array.from({ length: 100 }, (_, index) => subagentSources[index % 4]),
1574
+ "vscode",
1575
+ undefined,
1576
+ null,
1577
+ { custom: "launcher" },
1578
+ ];
1579
+ for (const [index, source] of sources.entries()) {
1580
+ yield* writeTranscript({
1581
+ filePath: path.join(
1582
+ codexHomePath,
1583
+ "sessions",
1584
+ "2026",
1585
+ "08",
1586
+ "24",
1587
+ `rollout-${index}.jsonl`,
1588
+ ),
1589
+ contents: [
1590
+ { type: "session_meta", payload: { id: `session-${index}`, cwd: workspace, source } },
1591
+ // A later cwd must not make an excluded rollout eligible again.
1592
+ { type: "turn_context", payload: { cwd: workspace } },
1593
+ {
1594
+ type: "event_msg",
1595
+ payload: { type: "user_message", message: "Import this prompt" },
1596
+ },
1597
+ ]
1598
+ .map((record) => encodeTranscriptRecord(record))
1599
+ .join("\n"),
1600
+ mtimeMs: nowMs - index * 60_000,
1601
+ });
1602
+ }
1603
+
1604
+ yield* Effect.gen(function* () {
1605
+ const scanner = yield* AgentSessionScanner.AgentSessionScanner;
1606
+ const scan = yield* scanner.scan;
1607
+ expect.soft(scan.candidates.map((candidate) => candidate.threadCount)).toEqual([4]);
1608
+ const outcomes = yield* Stream.runCollect(scanner.recentThreads(workspace));
1609
+ expect(
1610
+ outcomes.map((outcome) =>
1611
+ outcome._tag === "Importable" ? outcome.thread.providerSessionId : outcome._tag,
1612
+ ),
1613
+ ).toEqual(["session-100", "session-101", "session-102", "session-103"]);
1614
+ }).pipe(Effect.provide(layerScannerTest({ claudeHomePath, codexHomePath })));
1615
+ }),
1616
+ );
1617
+
1618
it.effect("suppresses duplicate session copies without reporting a skipped import", () =>
1619
Effect.gen(function* () {
1620
const path = yield* Path.Path;
apps/server/src/project/AgentSessionScanner.ts
+20
-5
@@ -525,7 +525,8 @@ function isT3ManagedWorktree(
525
);
526
}
527
528
-function extractCwd(line: string): string | null {
528
+// false stops metadata scanning for an excluded rollout, even if later records contain a cwd.
529
+function extractCwd(line: string, source: AgentSessionSource): string | null | false {
530
let parsed: unknown;
531
try {
532
parsed = JSON.parse(line);
@@ -540,6 +541,17 @@ function extractCwd(line: string): string | null {
541
}
542
const payload = record.payload;
543
if (typeof payload === "object" && payload !== null) {
544
+ if (source === "codex" && record.type === "session_meta") {
545
+ const sessionSource = (payload as Record<string, unknown>).source;
546
+ if (
547
+ typeof sessionSource === "object" &&
548
+ sessionSource !== null &&
549
+ !Array.isArray(sessionSource) &&
550
+ (Object.hasOwn(sessionSource, "subagent") || Object.hasOwn(sessionSource, "subAgent"))
551
+ ) {
552
+ return false;
553
+ }
554
+ }
555
const nested = (payload as Record<string, unknown>).cwd;
556
if (typeof nested === "string" && nested.trim().length > 0) {
557
return nested;
@@ -674,6 +686,7 @@ export const make = Effect.gen(function* () {
686
});
687
688
const readCwd = Effect.fn("AgentSessionScanner.readCwd")(function* (
689
+ source: AgentSessionSource,
690
transcript: TranscriptCandidate,
691
budget: MetadataReadBudget,
692
) {
@@ -710,7 +723,9 @@ export const make = Effect.gen(function* () {
723
};
724
const readLastRecord = () => {
725
const record = remaining + decoder.decode();
713
- return record.length === 0 || !reserveRecord() ? null : extractCwd(record.trim());
726
+ return record.length === 0 || !reserveRecord()
727
+ ? null
728
+ : extractCwd(record.trim(), source);
729
};
730
731
while (bytesRead < maxBytes) {
@@ -737,7 +752,7 @@ export const make = Effect.gen(function* () {
752
753
for (const line of lines) {
754
if (!reserveRecord()) return null;
740
- const cwd = extractCwd(line.trim());
755
+ const cwd = extractCwd(line.trim(), source);
756
if (cwd !== null) return cwd;
757
}
758
}
@@ -986,8 +1001,8 @@ export const make = Effect.gen(function* () {
1001
>();
1002
1003
for (const transcript of transcripts) {
989
- const cwd = yield* readCwd(transcript, budget);
990
- if (cwd === null) continue;
1004
+ const cwd = yield* readCwd(source, transcript, budget);
1005
+ if (cwd === null || cwd === false) continue;
1006
const key = `${transcript.providerInstanceId}\0${cwd}`;
1007
const existing = byOwnerAndCwd.get(key);
1008
if (existing) {