Skip to content

Commit 8d9d6d0

Browse files
committed
fix(codex): scope trajectory recorder warn dedupe to session
ClawSweeper P2: the host recorder factory returns null for per-session target-mapping conflicts, not only static config, so a process-wide warn-once flag silenced a later distinct session's recorder loss. Warn once per session (bounded set, cleared past 64 entries) so retries stay quiet but each newly affected session records its loss. Regression covers a later distinct session still warning.
1 parent 6129fd3 commit 8d9d6d0

2 files changed

Lines changed: 26 additions & 10 deletions

File tree

‎extensions/codex/src/app-server/trajectory.test.ts‎

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -117,8 +117,8 @@ function createSqliteHostTrajectoryRecorder(params: {
117117
}
118118

119119
describe("Codex trajectory recorder", () => {
120-
it("warns once per process when the SQLite host recorder is unavailable", async () => {
121-
// Import a fresh module instance so the process-wide warn-once flag starts
120+
it("warns once per session when the SQLite host recorder is unavailable", async () => {
121+
// Import a fresh module instance so the process-wide dedupe set starts
122122
// clean without a test-only reset export in production code.
123123
vi.resetModules();
124124
const { createCodexTrajectoryRecorder: createFreshRecorder } = await import("./trajectory.js");
@@ -136,14 +136,22 @@ describe("Codex trajectory recorder", () => {
136136
});
137137

138138
expect(makeRecorder("session-1")).toBeNull();
139-
// Static config condition: repeated attempts must not repeat the warn.
140-
expect(makeRecorder("session-2")).toBeNull();
141-
139+
// Retried attempts for the same session must not repeat the warn.
140+
expect(makeRecorder("session-1")).toBeNull();
142141
expect(warn).toHaveBeenCalledTimes(1);
143142
expect(warn).toHaveBeenCalledWith(
144143
"codex trajectory capture requires the SQLite host recorder",
145144
{ sessionId: "session-1", reason: "sqlite-recorder-unavailable" },
146145
);
146+
147+
// A later distinct session's recorder loss stays visible: the host can
148+
// reject per-session (target-mapping conflicts), not only per-process.
149+
expect(makeRecorder("session-2")).toBeNull();
150+
expect(warn).toHaveBeenCalledTimes(2);
151+
expect(warn).toHaveBeenLastCalledWith(
152+
"codex trajectory capture requires the SQLite host recorder",
153+
{ sessionId: "session-2", reason: "sqlite-recorder-unavailable" },
154+
);
147155
});
148156

149157
it("stores SQLite-backed captures for the canonical session-key target", async () => {

‎extensions/codex/src/app-server/trajectory.ts‎

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,12 @@ function createCodexHostTrajectorySink(params: {
121121
};
122122
}
123123

124-
let warnedSqliteRecorderUnavailable = false;
124+
// The host recorder can be absent per session (target-mapping conflicts), not
125+
// only per process, so dedupe the warn by session: repeated attempts for one
126+
// session stay quiet while a later distinct session still records its loss.
127+
// Bounded: cleared past the cap so a pathological session churn cannot grow it.
128+
const warnedRecorderUnavailableSessions = new Set<string>();
129+
const WARNED_RECORDER_SESSIONS_CAP = 64;
125130

126131
/** Creates a trajectory recorder when trajectory capture is enabled for the environment. */
127132
export function createCodexTrajectoryRecorder(
@@ -138,10 +143,13 @@ export function createCodexTrajectoryRecorder(
138143
// from a session-file string silently drops every capture once the host
139144
// stops emitting the legacy `sqlite:` marker.
140145
if (!params.trajectoryRecorder) {
141-
// A missing host recorder is a static config condition; repeating the warn
142-
// on every attempt buries real diagnostics, so emit it once per process.
143-
if (!warnedSqliteRecorderUnavailable) {
144-
warnedSqliteRecorderUnavailable = true;
146+
// Per-attempt repeats for one session bury real diagnostics; warn once per
147+
// session so retries stay quiet but each newly affected session is visible.
148+
if (!warnedRecorderUnavailableSessions.has(params.attempt.sessionId)) {
149+
if (warnedRecorderUnavailableSessions.size >= WARNED_RECORDER_SESSIONS_CAP) {
150+
warnedRecorderUnavailableSessions.clear();
151+
}
152+
warnedRecorderUnavailableSessions.add(params.attempt.sessionId);
145153
params.warn?.("codex trajectory capture requires the SQLite host recorder", {
146154
sessionId: params.attempt.sessionId,
147155
reason: "sqlite-recorder-unavailable",

0 commit comments

Comments
 (0)