Skip to content

Commit 413aa67

Browse files
wkeythingclaude
andcommitted
fix(memory): preserve cycle-0 dedup compat, deduplicate tests
Addresses Codex review on #66845: - P1: Restore ?? 0 fallback for compactionCount when memoryFlushCompactionCount is set, preserving backward compat for legacy sessions - P2: Remove duplicate test assertions Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
1 parent 8b62e6b commit 413aa67

2 files changed

Lines changed: 4 additions & 29 deletions

File tree

src/auto-reply/reply/memory-flush.ts

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -112,14 +112,7 @@ export function hasAlreadyFlushedForCurrentCompaction(
112112
if (typeof lastFlushAt !== "number") {
113113
return false;
114114
}
115-
// When compactionCount is undefined the session has never been compacted.
116-
// A lastFlushAt of 0 in that state is ambiguous — it may stem from
117-
// zero-initialization rather than an actual flush at cycle 0 — so we
118-
// require compactionCount to be an explicit number before comparing.
119-
if (typeof entry.compactionCount !== "number") {
120-
return false;
121-
}
122-
return lastFlushAt === entry.compactionCount;
115+
return lastFlushAt === (entry.compactionCount ?? 0);
123116
}
124117

125118
/**

src/auto-reply/reply/reply-state.test.ts

Lines changed: 3 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -356,12 +356,12 @@ describe("hasAlreadyFlushedForCurrentCompaction", () => {
356356
).toBe(false);
357357
});
358358

359-
it("returns false when compactionCount is undefined even if memoryFlushCompactionCount is 0 (zero-initialization edge case)", () => {
359+
it("treats missing compactionCount as 0 for backward compat", () => {
360360
expect(
361361
hasAlreadyFlushedForCurrentCompaction({
362362
memoryFlushCompactionCount: 0,
363363
}),
364-
).toBe(false);
364+
).toBe(true);
365365
});
366366

367367
it("returns true when both compactionCount and memoryFlushCompactionCount are explicitly 0", () => {
@@ -373,28 +373,10 @@ describe("hasAlreadyFlushedForCurrentCompaction", () => {
373373
).toBe(true);
374374
});
375375

376-
it("returns false when both compactionCount and memoryFlushCompactionCount are undefined (fresh session)", () => {
376+
it("returns false when both fields are undefined (fresh session)", () => {
377377
expect(hasAlreadyFlushedForCurrentCompaction({})).toBe(false);
378378
});
379379

380-
it("returns false when compactionCount is undefined and memoryFlushCompactionCount is undefined", () => {
381-
expect(
382-
hasAlreadyFlushedForCurrentCompaction({
383-
compactionCount: undefined,
384-
memoryFlushCompactionCount: undefined,
385-
}),
386-
).toBe(false);
387-
});
388-
389-
it("correctly detects flush at cycle 0 when compactionCount is explicit", () => {
390-
expect(
391-
hasAlreadyFlushedForCurrentCompaction({
392-
compactionCount: 0,
393-
memoryFlushCompactionCount: 0,
394-
}),
395-
).toBe(true);
396-
});
397-
398380
it("returns false after compaction advances past last flush", () => {
399381
expect(
400382
hasAlreadyFlushedForCurrentCompaction({

0 commit comments

Comments
 (0)