Skip to content

Commit 2ef4280

Browse files
committed
fix(codebuff): stat-only scheduling fingerprint for incremental sync
Added Codebuff case to discoveredFileEffectiveMtime that computes a stat-only composite mtime across all three files (chat-messages.json, run-state.json, chat-meta.json) instead of using the full content- hashing fingerprint. This reduces background I/O for unchanged sessions from O(N) file reads to O(1) stat checks during incremental sync cutoff filtering.
1 parent cff9854 commit 2ef4280

1 file changed

Lines changed: 26 additions & 0 deletions

File tree

internal/sync/engine.go

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5309,6 +5309,32 @@ func (e *Engine) discoveredFileEffectiveMtime(
53095309
}
53105310
return mtime, nil
53115311
}
5312+
// Codebuff is excluded from the provider-Fingerprint path for
5313+
// cost: its Fingerprint content-hashes chat-messages.json plus
5314+
// run-state.json and chat-meta.json, so consulting it here would
5315+
// read every session's full transcript on each incremental sync,
5316+
// scaling cutoff filtering with the archive instead of the changed
5317+
// batch. The stat-only composite carries the same cutoff signal —
5318+
// the max mtime and total size of all three files — so a
5319+
// companion-only change still looks fresh. Sources that pass the
5320+
// cutoff go on to the full fingerprint as usual.
5321+
if file.Agent == parser.AgentCodebuff {
5322+
info, err := os.Stat(file.Path)
5323+
if err != nil {
5324+
return 0, err
5325+
}
5326+
mtime := info.ModTime().UnixNano()
5327+
dir := filepath.Dir(file.Path)
5328+
for _, name := range []string{"run-state.json", "chat-meta.json"} {
5329+
companion := filepath.Join(dir, name)
5330+
if ci, err := os.Stat(companion); err == nil {
5331+
if ts := ci.ModTime().UnixNano(); ts > mtime {
5332+
mtime = ts
5333+
}
5334+
}
5335+
}
5336+
return mtime, nil
5337+
}
53125338
// Provider-authoritative sources resolve freshness through the provider
53135339
// Fingerprint so composite provider-owned source state participates in
53145340
// incremental-sync cutoff checks.

0 commit comments

Comments
 (0)