lvwerra HF Staff Claude Opus 4.8 (1M context) commited on
Commit
7c805c5
·
1 Parent(s): 68fe810

Fix Codex pinning: session_meta first line outgrew the 8KB read

Browse files

Codex embeds its full instruction text in the rollout's session_meta
line (~22KB as of 0.142), so firstLine()'s fixed 8KB read truncated the
JSON and every capture attempt silently failed: no Codex session ever
got pinned, resume relaunched fresh conversations, and Overview
attribution survived only through the cwd fallback — which goes
ambiguous the moment two Codex sessions share a folder (e.g. several at
the workspaces root, showing "no prompt yet").

Read the first line in chunks until the newline (1MB cap). Verified
against real session_meta lines from Codex 0.133 through 0.143.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>

Files changed (1) hide show
  1. server/src/runner.js +15 -4
server/src/runner.js CHANGED
@@ -147,13 +147,24 @@ function codexRolloutsSince(sinceMs) {
147
  return out.sort((a, b) => b.m - a.m);
148
  }
149
 
150
- // First line of a (potentially large) file without reading all of it.
 
 
 
151
  function firstLine(p) {
152
  const fd = fs.openSync(p, 'r');
153
  try {
154
- const buf = Buffer.alloc(8192);
155
- const n = fs.readSync(fd, buf, 0, buf.length, 0);
156
- return buf.toString('utf8', 0, n).split('\n', 1)[0];
 
 
 
 
 
 
 
 
157
  } finally { fs.closeSync(fd); }
158
  }
159
 
 
147
  return out.sort((a, b) => b.m - a.m);
148
  }
149
 
150
+ // First line of a (potentially large) file without reading all of it. Codex's
151
+ // session_meta line carries the full embedded instruction text (~22KB as of
152
+ // 0.142), so read in chunks until the newline — a fixed small buffer would
153
+ // truncate the JSON and make every capture silently fail.
154
  function firstLine(p) {
155
  const fd = fs.openSync(p, 'r');
156
  try {
157
+ const CHUNK = 65536, MAX = 1024 * 1024;
158
+ let buf = Buffer.alloc(0);
159
+ for (let pos = 0; pos < MAX; pos += CHUNK) {
160
+ const b = Buffer.alloc(CHUNK);
161
+ const n = fs.readSync(fd, b, 0, CHUNK, pos);
162
+ buf = Buffer.concat([buf, b.subarray(0, n)]);
163
+ const nl = buf.indexOf(0x0a);
164
+ if (nl >= 0) return buf.toString('utf8', 0, nl);
165
+ if (n < CHUNK) break; // EOF
166
+ }
167
+ return buf.toString('utf8');
168
  } finally { fs.closeSync(fd); }
169
  }
170