Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import { dirname, join } from "node:path";
import { readJsonlObjects } from "../jsonl-lines.js";
import { readDirectoryIfExists } from "../read-directory.js";

const ROLLOUT_FILE_SUFFIX = ".jsonl";

export interface CodexSessionFile {
/** Session file path. */
sessionFilePath: string;
Expand Down Expand Up @@ -56,7 +58,7 @@ async function listRolloutFiles(
continue;
}

if (entry.isFile() && entry.name.startsWith("rollout-") && entry.name.endsWith(".jsonl")) {
if (entry.isFile() && isPrimaryRolloutFile(entry.name)) {
const fileStat = await stat(path);
files.push({ path, mtimeMs: fileStat.mtimeMs });
}
Expand All @@ -71,6 +73,12 @@ async function listRolloutFiles(
.map((file) => file.path);
}

function isPrimaryRolloutFile(name: string): boolean {
return name.startsWith("rollout-") &&
name.endsWith(ROLLOUT_FILE_SUFFIX) &&
name.indexOf(ROLLOUT_FILE_SUFFIX) === name.length - ROLLOUT_FILE_SUFFIX.length;
}

async function readFirstCwd(filePath: string): Promise<string | null> {
try {
for await (const record of readJsonlObjects(filePath)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,24 @@ describe("codex source adapter", () => {
]);
});

it("ignores backup copies of rollout files", async () => {
const fixture = createFixture();
const backupPath = `${fixture.rolloutPath}.bak-strip-input-image.jsonl`;
writeFileSync(
backupPath,
JSON.stringify({
timestamp: "2026-05-29T11:00:00.000Z",
type: "session_meta",
payload: { cwd: join(fixture.workspacePath, "backup-copy") }
}),
"utf8"
);

await expect(discoverCodexSessions({ root: fixture.sessionsRoot })).resolves.toEqual([
expect.objectContaining({ sessionFilePath: fixture.rolloutPath })
]);
});

it("redacts large image tool outputs without failing the scan", async () => {
const fixture = createLargeImageFixture();
const adapter = createCodexSourceAdapter({ sessionsRoot: fixture.sessionsRoot });
Expand Down
4 changes: 3 additions & 1 deletion App/backend/src/services/agent-source-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -557,6 +557,7 @@ async function collectSourceMessages(
messages: [],
errors: []
};
const conversationIds = new Set<string>();

emitProgress(scanOptions, {
sourceId,
Expand Down Expand Up @@ -585,7 +586,8 @@ async function collectSourceMessages(
})) {
scanOptions.signal?.throwIfAborted();
collected.messages.push(message);
if (!collected.conversationIds.includes(message.conversationId)) {
if (!conversationIds.has(message.conversationId)) {
conversationIds.add(message.conversationId);
collected.conversationIds.push(message.conversationId);
}
if (collected.messages.length % SCAN_MESSAGE_YIELD_INTERVAL === 0) {
Expand Down