The cross-harness, self-improving memory layer for AI agents. Join our community: https://discord.com/invite/zdNChS2fBu
Go agent-ai-cliagent-harnessesagent-securitybrowser-extensionciclaude-codecloudcodexcursordetection-engineeringjevknowledge-basememorymobile-device-managementobservabilitysecuritysecurity-information-and-event-managementsecurity-toolstelemetrytraces
fix(grok): name the live config path and keep turn zero
Claudef3ecdc2a1724
diff --git a/cli/beacon/internal/endpoint/harness/grok.go b/cli/beacon/internal/endpoint/harness/grok.goindex 2ff2771a..b34fba5b 100644--- a/cli/beacon/internal/endpoint/harness/grok.go+++ b/cli/beacon/internal/endpoint/harness/grok.go@@ -47,7 +47,12 @@ func DiscoverGrok() Harness {// resolving it here would read whatever repository the command happened to run from and report// it as the machine's state. DiscoverQwen, DiscoverCline and DiscoverPi guard the same way.hookStatus := hooks.GrokHookStatus(hooks.GrokOptions{Level: hooks.LevelUser})- if hookStatus.HooksPath != "" {++ // ConfigPath names what is carrying telemetry, which for this runtime depends on which path is+ // live. GrokHookStatus reports the hook path it *would* use whenever home resolves, installed or+ // not, so keying on the path being non-empty would name a file that is not there and hide the+ // session store on a backfill-only machine. Gate it on the install instead.+ if hookStatus.Installed {h.ConfigPath = hookStatus.HooksPath} else {h.ConfigPath = sessionsDirdiff --git a/cli/beacon/internal/endpoint/harness/grok_test.go b/cli/beacon/internal/endpoint/harness/grok_test.goindex 4791f55e..5a182d5c 100644--- a/cli/beacon/internal/endpoint/harness/grok_test.go+++ b/cli/beacon/internal/endpoint/harness/grok_test.go@@ -141,6 +141,12 @@ func TestDiscoverGrokReportsCollectedSessionsAsEnabledWithoutHooks(t *testing.T)if !strings.Contains(h.Message, "all 1 session") {t.Errorf("message = %q", h.Message)}+ // With no hooks installed, the session store is what is carrying telemetry. Naming the hook+ // path here would point at a file that is not on this machine and hide the one that is --+ // GrokHookStatus reports the path it would use whether or not the file exists.+ if want := filepath.Join(home, ".grok", "sessions"); h.ConfigPath != want {+ t.Errorf("ConfigPath = %q, want the session store %q", h.ConfigPath, want)+ }}// Grok that has never run here is not a broken install, and with no hooks the remedy is to installdiff --git a/cli/beacon/internal/groksession/collect_test.go b/cli/beacon/internal/groksession/collect_test.goindex d74309b5..6aca7622 100644--- a/cli/beacon/internal/groksession/collect_test.go+++ b/cli/beacon/internal/groksession/collect_test.go@@ -70,6 +70,15 @@ func TestStoreListsAndMapsGrokSession(t *testing.T) {if _, ok := byAction["session.ended"]; ok {t.Fatal("turn_ended produced a session.ended event")}+ // Grok numbers turns from zero, so the first turn's number has to survive the mapping. Dropping+ // it as a falsy value would report the one turn every session has as having no number.+ turnEnd := rawGrokDetail(t, events, "session.context", "turn_ended")+ if turnEnd == nil {+ t.Fatal("no session.context event for turn_ended")+ }+ if got, ok := turnEnd["turn_number"]; !ok || got != float64(0) {+ t.Fatalf("turn_number = %v (present=%t), want 0", got, ok)+ }if _, ok := byAction["session.started"]; !ok {t.Fatal("no session.started event")}@@ -229,7 +238,7 @@ func writeFixtureSession(t *testing.T, root, workspace, sessionID string) string`{"ts":"2026-05-21T16:49:27.545Z","type":"permission_requested","tool_name":"run_terminal_command"}`+"\n"+`{"ts":"2026-05-21T16:49:27.545Z","type":"permission_resolved","tool_name":"run_terminal_command","decision":"allow","wait_ms":0}`+"\n"+`{"ts":"2026-05-21T16:49:27.552Z","type":"tool_completed","tool_name":"run_terminal_command","duration_ms":6,"outcome":"success"}`+"\n"+- `{"ts":"2026-05-21T16:50:25.814Z","type":"turn_ended","outcome":"success"}`+"\n")+ `{"ts":"2026-05-21T16:50:25.814Z","type":"turn_ended","outcome":"success","turn_number":0}`+"\n")writeFile(t, filepath.Join(sessionDir, "chat_history.jsonl"),`{"type":"user","content":[{"type":"text","text":"run ls token=secret"}]}`+"\n"+`{"type":"assistant","content":"","reasoning":{"text":"Need to inspect files"},"tool_calls":[{"id":"call-abc","name":"run_terminal_command","arguments":"{\"command\":\"ls -la\",\"description\":\"list files\"}"}],"model_id":"grok-build"}`+"\n"+@@ -239,6 +248,33 @@ func writeFixtureSession(t *testing.T, root, workspace, sessionID string) stringreturn sessionDir}+// rawGrokDetail pulls the grok detail map off the first event with the given action whose+// "lifecycle" field matches, going through JSON so it reads the event exactly as the log does.+func rawGrokDetail(t *testing.T, events []MappedEvent, action, lifecycle string) map[string]interface{} {+ t.Helper()+ for _, item := range events {+ if item.Event.Event.Action != action {+ continue+ }+ data, err := json.Marshal(item.Event)+ if err != nil {+ t.Fatalf("marshal event: %v", err)+ }+ var record struct {+ Raw struct {+ Grok map[string]interface{} `json:"grok"`+ } `json:"raw"`+ }+ if err := json.Unmarshal(data, &record); err != nil {+ t.Fatalf("unmarshal event: %v", err)+ }+ if record.Raw.Grok["lifecycle"] == lifecycle {+ return record.Raw.Grok+ }+ }+ return nil+}+func appendLine(t *testing.T, path, line string) {t.Helper()f, err := os.OpenFile(path, os.O_APPEND|os.O_WRONLY, 0o644)diff --git a/cli/beacon/internal/groksession/mapper.go b/cli/beacon/internal/groksession/mapper.goindex f7cd41e1..8a77377a 100644--- a/cli/beacon/internal/groksession/mapper.go+++ b/cli/beacon/internal/groksession/mapper.go@@ -177,8 +177,8 @@ func (m *mapper) consumeLifecycle(ev LifecycleEvent) {if ev.CancellationCategory != "" {detail["cancellation_category"] = ev.CancellationCategory}- if ev.TurnNumber > 0 {- detail["turn_number"] = ev.TurnNumber+ if ev.TurnNumber != nil {+ detail["turn_number"] = *ev.TurnNumber}out.Raw = map[string]interface{}{"grok": detail}m.append(out, SourceLifecycle, ev.Index)diff --git a/cli/beacon/internal/groksession/types.go b/cli/beacon/internal/groksession/types.goindex e8e7f221..6a9619db 100644--- a/cli/beacon/internal/groksession/types.go+++ b/cli/beacon/internal/groksession/types.go@@ -68,10 +68,13 @@ type ToolCall struct {}type LifecycleEvent struct {- Type string `json:"type"`- TS string `json:"ts"`- SessionID string `json:"session_id,omitempty"`- TurnNumber int `json:"turn_number,omitempty"`+ Type string `json:"type"`+ TS string `json:"ts"`+ SessionID string `json:"session_id,omitempty"`+ // TurnNumber is a pointer because Grok numbers turns from zero. As a plain int with omitempty,+ // the first turn's number is indistinguishable from a row that carries no turn number at all,+ // and reporting either as the other invents or drops a fact the source stated.+ TurnNumber *int `json:"turn_number,omitempty"`ModelID string `json:"model_id,omitempty"`ToolName string `json:"tool_name,omitempty"`Decision string `json:"decision,omitempty"`