mirror of
https://github.com/stablyai/orca.git
synced 2026-10-22 08:03:37 +00:00
* fix(native-chat): add reconciliation to catch missed transcript updates Periodic reconciliation catches file changes that fs.watch may miss on remote filesystems. Event-driven drains use a bounded max-wait timer to ensure responsiveness. Extracts timer logic into a scheduler module for testability and maintainability. * fix(native-chat): add reconciliation to catch missed transcript updates Detects same-size file rewrites and native watcher failures by reconciling transcript state even when fs.watch events don't fire. Extracts watcher binding into a dedicated module that gracefully degrades to reconciliation-only mode when native watch is unavailable. Adds test coverage for watcher rebind failures, parent-directory replacements, and unsubscribe races. * Document transcript watcher reconciliation contract Clarify that bind() is best-effort with reconciliation fallback, invalidate() detaches from stale identities, and the caller's polling loop owns transcript liveness. Supports resilience on remote filesystems.
31 lines
740 B
TypeScript
31 lines
740 B
TypeScript
import { stat } from 'node:fs/promises'
|
|
|
|
export type TranscriptFileVersion = {
|
|
identity: string
|
|
size: number
|
|
mtimeMs: number
|
|
ctimeMs: number
|
|
}
|
|
|
|
export async function readTranscriptFileVersion(filePath: string): Promise<TranscriptFileVersion> {
|
|
const value = await stat(filePath)
|
|
return {
|
|
identity: `${value.dev}:${value.ino}`,
|
|
size: value.size,
|
|
mtimeMs: value.mtimeMs,
|
|
ctimeMs: value.ctimeMs
|
|
}
|
|
}
|
|
|
|
export function transcriptFileVersionChanged(
|
|
current: TranscriptFileVersion,
|
|
previous: TranscriptFileVersion
|
|
): boolean {
|
|
return (
|
|
current.identity !== previous.identity ||
|
|
current.size !== previous.size ||
|
|
current.mtimeMs !== previous.mtimeMs ||
|
|
current.ctimeMs !== previous.ctimeMs
|
|
)
|
|
}
|