Skip to content

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

Fix system-mode state path, Windows SQLite URI, and watch mode event dedup

Cursor Agentea0c6dd67ca0
diff --git a/cli/beacon/cmd/endpoint_opencode.go b/cli/beacon/cmd/endpoint_opencode.go
index 53fd93cc..d97fed80 100644
--- a/cli/beacon/cmd/endpoint_opencode.go
+++ b/cli/beacon/cmd/endpoint_opencode.go
@@ -217,9 +217,10 @@ func resolveOpenCodeStatePath(path string, userMode bool) string {
if strings.TrimSpace(path) != "" {
return path
}
- base := filepath.Join("/var", "lib", "beacon", "endpoint", "state")
- if userMode {
- base = filepath.Dir(opencodesession.DefaultStatePath())
+ if !userMode {
+ if dir := filepath.Dir(lifecycle.ResolveRuntimeLog(false, "").EffectiveLogPath); dir != "" && dir != "." {
+ return filepath.Join(dir, "opencode-sessions.json")
+ }
}
- return filepath.Join(base, "opencode-sessions.json")
+ return opencodesession.DefaultStatePath()
}
diff --git a/cli/beacon/internal/opencodesession/collect.go b/cli/beacon/internal/opencodesession/collect.go
index 8ee78c21..7e0a0200 100644
--- a/cli/beacon/internal/opencodesession/collect.go
+++ b/cli/beacon/internal/opencodesession/collect.go
@@ -16,8 +16,9 @@ import (
const StateVersion = 1
type Cursor struct {
- LastOrder int `json:"last_order"`
- UpdatedAtMS int64 `json:"updated_at_ms,omitempty"`
+ LastOrder int `json:"last_order"`
+ UpdatedAtMS int64 `json:"updated_at_ms,omitempty"`
+ Emitted map[string]bool `json:"emitted,omitempty"`
}
type State struct {
@@ -152,33 +153,48 @@ func CollectOnce(opts CollectOptions) (summary Summary, err error) {
func collectTrace(store *Store, ref TraceRef, state *State, opts CollectOptions, summary *Summary) (bool, error) {
cursor := state.cursor(ref)
- if ref.UpdatedAtUnixMS > 0 && ref.UpdatedAtUnixMS <= cursor.UpdatedAtMS {
+ if ref.UpdatedAtUnixMS > 0 && ref.UpdatedAtUnixMS < cursor.UpdatedAtMS {
return false, nil
}
records, err := store.Read(ref)
if err != nil {
return false, err
}
- mapped := MapTrace(ref, records, MapOptions{MinOrder: cursor.LastOrder})
+ mapped := MapTrace(ref, records, MapOptions{})
if len(mapped) == 0 {
- if len(records) > 0 && records[len(records)-1].Order > cursor.LastOrder {
- cursor.LastOrder = records[len(records)-1].Order
- }
cursor.UpdatedAtMS = ref.UpdatedAtUnixMS
return false, nil
}
- for i, item := range mapped {
+ if cursor.Emitted == nil {
+ cursor.Emitted = make(map[string]bool, len(mapped))
+ }
+ changed := false
+ for _, item := range mapped {
+ eid := item.Event.Event.ID
+ if cursor.Emitted[eid] {
+ continue
+ }
if err := emit(item.Event, opts); err != nil {
- if i > 0 {
- cursor.LastOrder = mapped[i-1].SourceOrder
- }
- return true, err
+ return changed, err
+ }
+ cursor.Emitted[eid] = true
+ if item.SourceOrder > cursor.LastOrder {
+ cursor.LastOrder = item.SourceOrder
}
- cursor.LastOrder = item.SourceOrder
summary.EventsEmitted++
+ changed = true
+ }
+ current := make(map[string]bool, len(mapped))
+ for _, item := range mapped {
+ current[item.Event.Event.ID] = true
+ }
+ for eid := range cursor.Emitted {
+ if !current[eid] {
+ delete(cursor.Emitted, eid)
+ }
}
cursor.UpdatedAtMS = ref.UpdatedAtUnixMS
- return true, nil
+ return changed, nil
}
func emit(event schema.Event, opts CollectOptions) error {
diff --git a/cli/beacon/internal/opencodesession/store.go b/cli/beacon/internal/opencodesession/store.go
index 4feb2547..57186f3a 100644
--- a/cli/beacon/internal/opencodesession/store.go
+++ b/cli/beacon/internal/opencodesession/store.go
@@ -634,7 +634,11 @@ func legacyProjectDirectory(path string) string {
}
func openSQLiteReadOnly(path string) (*sql.DB, error) {
- u := url.URL{Scheme: "file", Path: path}
+ uriPath := filepath.ToSlash(path)
+ if !strings.HasPrefix(uriPath, "/") {
+ uriPath = "/" + uriPath
+ }
+ u := url.URL{Scheme: "file", Path: uriPath}
q := u.Query()
q.Set("mode", "ro")
q.Set("_pragma", "query_only(1)")