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(endpoint): compact an oversized event instead of failing the sync (#882)
Rudy Mizrahi Celekli90566e61c605
diff --git a/cli/beacon/internal/endpoint/writer/writer.go b/cli/beacon/internal/endpoint/writer/writer.goindex e403be7f..cd2eca78 100644--- a/cli/beacon/internal/endpoint/writer/writer.go+++ b/cli/beacon/internal/endpoint/writer/writer.go@@ -8,6 +8,7 @@ import ("io/fs""os""path/filepath"+ "reflect""strconv""strings"@@ -90,6 +91,17 @@ func AppendEvent(event schema.Event, opts Options) (string, error) {return "", err}}+ if len(data) > opts.MaxBytes {+ // Retained content is the next thing to go after raw, as in the hook adapter and the+ // collector exporter. Each string is capped but their number is not (a multi-edit's+ // arguments, a long todo list), and an error here makes a session sweep stop at the line+ // and meet it again on every later sweep.+ compactRetainedContent(&event)+ data, err = json.Marshal(event)+ if err != nil {+ return "", err+ }+ }if len(data) > opts.MaxBytes {return "", fmt.Errorf("event exceeds maximum size after truncation: %d bytes", len(data))}@@ -115,6 +127,38 @@ func AppendEvent(event schema.Event, opts Options) (string, error) {return opts.Path, nil}+// compactRetainedContent drops an event's retained text and records that it did, so a reader can+// still tell what the event was about and that its content was held back rather than never+// captured. Mirrors the collector exporter's step of the same name.+func compactRetainedContent(event *schema.Event) {+ if event.File != nil {+ event.File.Diff = ""+ }+ if event.Command != nil {+ event.Command.Output = ""+ }+ if event.Prompt != nil {+ event.Prompt.Text = ""+ }+ if event.GenAI != nil {+ event.GenAI.Input = nil+ event.GenAI.Output = nil+ if event.GenAI.Tool != nil && event.GenAI.Tool.Call != nil {+ event.GenAI.Tool.Call.Arguments = nil+ event.GenAI.Tool.Call.Result = nil+ }+ // An event whose only gen_ai content was the turn text drops the object rather than+ // writing "gen_ai":{}, as the exporter does.+ if reflect.ValueOf(*event.GenAI).IsZero() {+ event.GenAI = nil+ }+ }+ if event.Content != nil {+ event.Content.Included = false+ event.Content.Truncated = true+ }+}+// EnsureSystemLogWritable prepares a machine-wide runtime log so the people whose agent sessions// this endpoint captures can append to it, and nobody else can redirect what the privileged// writers do there.diff --git a/cli/beacon/internal/endpoint/writer/writer_test.go b/cli/beacon/internal/endpoint/writer/writer_test.goindex 7349c14a..9df42b36 100644--- a/cli/beacon/internal/endpoint/writer/writer_test.go+++ b/cli/beacon/internal/endpoint/writer/writer_test.go@@ -448,3 +448,78 @@ func TestRetainedLogPathsMatchesWhatRotationKeeps(t *testing.T) {t.Fatalf("RetainedLogPaths(\"\") = %v, want nil", got)}}++// A tool call whose arguments hold many strings (a multi-edit, a long todo list) stays over the size+// limit after raw is dropped and the message is cut, because each string is capped but their number+// is not. The hook adapter and the collector exporter then drop the retained content and keep the+// event; this writer used to fail it, and a session sweep that gets an error stops at that line and+// meets it again on every later sweep.+func TestAppendEventKeepsAnOversizedToolCallWithoutItsRetainedContent(t *testing.T) {+ path := filepath.Join(t.TempDir(), "runtime.jsonl")+ edits := make([]interface{}, 0, 40)+ for i := 0; i < 40; i++ {+ edits = append(edits, map[string]interface{}{+ "old_string": strings.Repeat("a", 3000),+ "new_string": strings.Repeat("b", 3000),+ })+ }+ event := schema.NewEvent(schema.NewEventOptions{+ Action: "tool.invoked",+ Harness: schema.HarnessInfo{Name: "test"},+ Message: "MultiEdit",+ })+ event.GenAI = &schema.GenAIInfo{Tool: &schema.GenAIToolInfo{+ Name: "MultiEdit",+ Call: &schema.GenAIToolCallInfo{ID: "call_1", Arguments: map[string]interface{}{"edits": edits}},+ }}++ if _, err := AppendEvent(event, Options{Path: path}); err != nil {+ t.Fatalf("AppendEvent dropped the event instead of compacting it: %v", err)+ }+ data, err := os.ReadFile(path)+ if err != nil {+ t.Fatalf("read log: %v", err)+ }+ if len(data) > MaxEventBytes+1 {+ t.Fatalf("line is %d bytes, over the %d byte limit", len(data), MaxEventBytes)+ }+ var decoded schema.Event+ if err := json.Unmarshal(data, &decoded); err != nil {+ t.Fatalf("line is not an event: %v", err)+ }+ if !decoded.Truncated {+ t.Fatal("a compacted event must say it was truncated")+ }+ if decoded.GenAI == nil || decoded.GenAI.Tool == nil || decoded.GenAI.Tool.Call == nil || decoded.GenAI.Tool.Call.ID != "call_1" {+ t.Fatalf("the tool call's identity must survive compaction: %+v", decoded.GenAI)+ }+}++// A prompt event whose gen_ai held only the turn's input is left with nothing in gen_ai once the+// input goes, and the line must not carry an empty "gen_ai":{} object.+func TestAppendEventDropsAnEmptiedGenAIObject(t *testing.T) {+ path := filepath.Join(t.TempDir(), "runtime.jsonl")+ parts := make([]interface{}, 0, 40)+ for i := 0; i < 40; i++ {+ parts = append(parts, map[string]interface{}{"type": "text", "content": strings.Repeat("p", 3000)})+ }+ event := schema.NewEvent(schema.NewEventOptions{+ Action: "prompt.submitted",+ Harness: schema.HarnessInfo{Name: "test"},+ Message: "prompt",+ })+ event.GenAI = &schema.GenAIInfo{Input: &schema.GenAIInputInfo{Messages: []interface{}{+ map[string]interface{}{"role": "user", "parts": parts},+ }}}++ if _, err := AppendEvent(event, Options{Path: path}); err != nil {+ t.Fatalf("AppendEvent: %v", err)+ }+ data, err := os.ReadFile(path)+ if err != nil {+ t.Fatalf("read log: %v", err)+ }+ if strings.Contains(string(data), `"gen_ai"`) {+ t.Fatalf("compacted line kept an empty gen_ai object:\n%s", data)+ }+}diff --git a/docs/changelog/cli.mdx b/docs/changelog/cli.mdxindex 7ebe7198..77a2e184 100644--- a/docs/changelog/cli.mdx+++ b/docs/changelog/cli.mdx@@ -12,6 +12,7 @@ Stay up to date with the latest changes to the Agent Beacon CLI.## October 2026- **Codex install, hooks and inventory follow `CODEX_HOME`** · `beacon endpoint install`, `beacon endpoint hooks install --harness codex`, `beacon endpoint discover` and inventory now read and write `$CODEX_HOME/config.toml` and `$CODEX_HOME/hooks.json` when `CODEX_HOME` is set, as Codex does. They previously always used `~/.codex`, so with `CODEX_HOME` set, Codex never saw the OTLP exporter or the SessionStart hook and live capture silently recorded nothing. A per-user install or repair also writes the resolved `CODEX_HOME` into the scheduled inventory job, which launchd and systemd start without your shell's environment. A `CODEX_HOME` that is not an existing directory is now an install error rather than a silent write to `~/.codex`. Project-level `.codex` files are unchanged.+- **Oversized session events no longer stall a sync** · An event still over the 64 KB limit after its raw payload was dropped, such as a tool call with many large edit hunks, made session sync fail at that line on every sweep, so nothing later in that session was recorded. The writer now drops the event's retained content and marks it truncated, as the hook and collector writers already did, keeping the tool name, call ID and file path.### v1.3.40 · October 14, 2026