(chain: Message[])
| 2222 | * /share or log-listing chain rebuilds. |
| 2223 | */ |
| 2224 | export function checkResumeConsistency(chain: Message[]): void { |
| 2225 | for (let i = chain.length - 1; i >= 0; i--) { |
| 2226 | const m = chain[i]! |
| 2227 | if (m.type !== 'system' || m.subtype !== 'turn_duration') continue |
| 2228 | const expected = m.messageCount |
| 2229 | if (expected === undefined) return |
| 2230 | // `i` is the 0-based index of the checkpoint in the reconstructed chain. |
| 2231 | // The checkpoint was appended AFTER messageCount messages, so its own |
| 2232 | // position should be messageCount (i.e., i === expected). |
| 2233 | const actual = i |
| 2234 | logEvent('tengu_resume_consistency_delta', { |
| 2235 | expected, |
| 2236 | actual, |
| 2237 | delta: actual - expected, |
| 2238 | chain_length: chain.length, |
| 2239 | checkpoint_age_entries: chain.length - 1 - i, |
| 2240 | }) |
| 2241 | return |
| 2242 | } |
| 2243 | } |
| 2244 | |
| 2245 | /** |
| 2246 | * Builds a filie history snapshot chain from the conversation |
no test coverage detected