Skip to content

The cross-harness, self-improving memory layer for AI agents. Join our community: https://discord.com/invite/zdNChS2fBu

fix: prevent transient open failure from resetting Grok session cursor

Cursor Agentd0ed91284f59
diff --git a/cli/beacon/internal/groksession/collect.go b/cli/beacon/internal/groksession/collect.go
index d4734f23..f117412d 100644
--- a/cli/beacon/internal/groksession/collect.go
+++ b/cli/beacon/internal/groksession/collect.go
@@ -190,11 +190,11 @@ func collectSession(store *Store, ref SessionRef, state *State, opts CollectOpti
// cursor would read an ordinary malformed line as a rewrite and re-emit the whole file.
minChat := cursor.ChatLine
minLifecycle := cursor.LifecycleLine
- if data.ChatLines < cursor.ChatLine {
+ if data.ChatLines >= 0 && data.ChatLines < cursor.ChatLine {
minChat = 0
cursor.ChatLine = 0
}
- if data.LifecycleLines < cursor.LifecycleLine {
+ if data.LifecycleLines >= 0 && data.LifecycleLines < cursor.LifecycleLine {
minLifecycle = 0
cursor.LifecycleLine = 0
}
diff --git a/cli/beacon/internal/groksession/store.go b/cli/beacon/internal/groksession/store.go
index cedb02a8..dfa6dc38 100644
--- a/cli/beacon/internal/groksession/store.go
+++ b/cli/beacon/internal/groksession/store.go
@@ -135,10 +135,13 @@ func readJSONFile[T any](path string) (*T, error) {
// blank or unparseable line advances the count without producing a record. The collector compares
// the count against its line cursor to notice a file that was rewritten shorter, and using the
// record count there would read a single malformed line as a rewrite.
+//
+// When the file cannot be opened the line count is -1, distinguishing a transient read failure from
+// a genuinely empty or truncated file. The collector must skip the shrink check for that file.
func readJSONLines[T any](path string) ([]T, int, int) {
f, err := os.Open(path)
if err != nil {
- return nil, 0, 0
+ return nil, -1, 0
}
defer f.Close()
var out []T