Skip to content

Commit 53718e2

Browse files
fix: keep fork origins across a concurrent eviction and retry missing child rollouts
Per-commit review findings on list row usage: - A read that waited on its subagents while another read evicted its entry lost the fork origin for good; the read now stores the origin it used again with its usage. - A subagent whose rollout was still missing after a second thread/read stayed cached with its first metadata; it is now read again later. Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent 9419f80 commit 53718e2

1 file changed

Lines changed: 10 additions & 5 deletions

File tree

‎src/SessionUsage.ts‎

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -259,10 +259,11 @@ export class SessionUsageIndex {
259259
const recheckAt = this.recheckTime(thread);
260260
let usage: SessionUsage | null = null;
261261
let originRead = false;
262+
let origin = this.origins.get(thread.id);
262263
if (thread.path !== null) {
263264
try {
264-
if (!this.origins.has(thread.id)) {
265-
const origin = await readForkOrigin(thread.path);
265+
if (origin === undefined) {
266+
origin = await readForkOrigin(thread.path);
266267
if (origin !== undefined) {
267268
this.origins.set(thread.id, origin);
268269
originRead = origin !== null;
@@ -280,8 +281,9 @@ export class SessionUsageIndex {
280281
}
281282
const before = this.usages.get(thread.id);
282283
const evicted = remember(this.usages, thread.id, {updatedAt: thread.updatedAt, path: thread.path, usage, recheckAt});
283-
// The fork origin of a row lives as long as its usage.
284+
// The fork origin of a row lives as long as its usage; another read can have dropped it meanwhile.
284285
if (evicted !== undefined) this.origins.delete(evicted);
286+
if (origin !== undefined) this.origins.set(thread.id, origin);
285287
// Another record can come within the second of `updatedAt` without moving it: read once more after it.
286288
if (recheckAt !== null) this.readLater(subject, Math.max(0, recheckAt - this.nowSeconds()) * 1000);
287289
return originRead || (before === undefined ? usage !== null : JSON.stringify(before.usage) !== JSON.stringify(usage));
@@ -318,8 +320,11 @@ export class SessionUsageIndex {
318320
try {
319321
stamp = await stampOf(child.path);
320322
} catch (again) {
321-
// Codex writes the rollout of a new thread later.
322-
if (isMissingFile(again)) return null;
323+
// Codex writes the rollout of a new thread later: read the thread again then.
324+
if (isMissingFile(again)) {
325+
this.subagents.delete(childId);
326+
return null;
327+
}
323328
throw again;
324329
}
325330
}

0 commit comments

Comments
 (0)