fix(todo-continuation-enforcer): make compaction guard epoch-aware

Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-openagent)

Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
This commit is contained in:
YeonGyu-Kim
2026-03-24 20:36:22 +09:00
parent 733676f1a9
commit 8e239e134c
2 changed files with 97 additions and 1 deletions
@@ -1,8 +1,37 @@
import { COMPACTION_GUARD_MS } from "./constants"
import type { SessionState } from "./types"
export function armCompactionGuard(state: SessionState, now: number): number {
const nextEpoch = (state.recentCompactionEpoch ?? 0) + 1
state.recentCompactionAt = now
state.recentCompactionEpoch = nextEpoch
return nextEpoch
}
export function acknowledgeCompactionGuard(
state: SessionState,
compactionEpoch: number | undefined
): boolean {
if (compactionEpoch === undefined) {
return false
}
if (state.recentCompactionEpoch !== compactionEpoch) {
return false
}
state.acknowledgedCompactionEpoch = compactionEpoch
return true
}
export function isCompactionGuardActive(state: SessionState, now: number): boolean {
if (!state.recentCompactionAt) {
if (state.recentCompactionAt === undefined || state.recentCompactionEpoch === undefined) {
return false
}
if (state.acknowledgedCompactionEpoch === state.recentCompactionEpoch) {
return false
}