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 flaky backfill restage test on a privacy mode change
Claudec4aa57c51503
diff --git a/CLAUDE.md b/CLAUDE.mdindex 51de1ec2..725786e1 100644--- a/CLAUDE.md+++ b/CLAUDE.md@@ -28,7 +28,7 @@ Do not recreate or depend on removed `asymptote` mirror trees. Keep new work foc- Preserve the local-only default. The public Beacon build must not require a hosted account, remote policy fetch, hosted dashboard, or external network dependency during normal hook execution, and hooks themselves never touch the network.- `beacon login` is the account-identity channel for interactive users and is required by the interactive `beacon endpoint install` wizard. It uses browser PKCE against beacon.sh and stores the scoped CLI token only in `~/.beacon/auth/session.json` (0600 under a 0700 directory). Signing in alone never starts forwarding. User-mode `beacon endpoint connect` may send that token once to `POST /api/cli/enroll/account` to authorize minting a separate device ingest key, and `beacon mcp token create` may send it to `POST /api/cli/mcp/tokens` (scope `mcp:token:create`, listed on the sign-in page) to mint a personal MCP token that is printed once to stdout and never written to a file; never copy the account token into endpoint config, Vector, hook environments, logs, or command output. System/root/package/MDM/CI/piped-stdin/dry-run installs stay noninteractive and account-free.- Beacon Cloud forwarding (`cli/beacon/internal/endpoint/asymptote`, `beacon endpoint connect`, `beacon endpoint asymptote`) is Vector-shaped: Beacon writes local JSONL, Vector ships runtime lines only from the connection point forward and reads inventory from the beginning to establish the endpoint's current baseline, plus the one bounded exception of the session backfill (below), and the `bcn_device_*` key stays only in `<BaseDir>/asymptote/vector-secrets.json` via Vector's secret backend. The onboarding wizard preselects Beacon Cloud, and confirming it connects this endpoint in the same command once the local install has succeeded; an endpoint that is already enrolled is never re-enrolled, because enrollment rotates the device key. Standard mode ships locally sanitized retained content; metadata-only uses local Vector transforms to remove prompts, responses, reasoning, tool arguments/results, command output, raw fields, diffs, inventory content, and MCP definitions before buffering/upload. Keep the ingest URL `https://`, the wire contract aligned with `beacon-ingest` (`/v1/ingest/{runtime,inventory}` and `/v1/ingest/health`), and do not add another endpoint network channel. The cloud-sandbox shuttle is the bounded exception: only with `BEACON_ORIGIN=cloud`, it can upload new runtime lines to GCS, S3, or the same Beacon ingest contract because no Vector/service manager/browser/persistent disk exists there.-- Session backfill (`cli/beacon/cmd/endpoint_backfill.go`; docs in `docs/cli/endpoint-install.mdx#session-backfill` and `docs/cli/endpoint-connect.mdx#session-backfill`): after every successful install (user or system mode), every session-store collector runs once with `CollectOptions.Since` (30 days; `sessionwindow.Recent` keeps those sessions, newest first, and never touches the cursors of the rest) and a shared `writer.Budget` (24 MiB, at most 12 MiB per runtime through `Budget.Sub`; a refused append returns `writer.ErrBudgetSpent`, the collector stops with cursors past only what was written, and a manual sync reads the rest). A new session-store collector takes both fields and joins `endpointBackfillRunners`. Every connect, first or re-connect, user or system, runs the same sweep before enrollment (skipped when install just ran it) and, before the forwarder starts, `asymptote.StageBackfill` copies the window's `harness.collection_method=poll` lines into `cloud-backfill.jsonl` beside the runtime log, which the `beacon_backfill` Vector source (fingerprinted `device_and_inode`, so each atomically restaged copy is a new file) reads from the beginning into the runtime sink through the same privacy transform. Live hook/OTLP/plugin history before the connection point stays local. Re-connects restage, so a resend of already-shipped lines is expected and rests on the deterministic `event.id`; a privacy-mode change deletes the staged file with the checkpoints before restaging, and `disconnect` removes it. System mode runs the collectors under `withUserHome` for the active console user (`activeConsoleUser`), with cursors under the system base directory, and reports a skip when nobody is logged in. The wizard's confirm screen names the upload (`WizardOptions.BackfillDays`). Dry-run, `--no-backfill` and `BEACON_BACKFILL=0` skip all of it; the cmd tests run with `BEACON_BACKFILL=0` set in `TestMain`.+- Session backfill (`cli/beacon/cmd/endpoint_backfill.go`; docs in `docs/cli/endpoint-install.mdx#session-backfill` and `docs/cli/endpoint-connect.mdx#session-backfill`): after every successful install (user or system mode), every session-store collector runs once with `CollectOptions.Since` (30 days; `sessionwindow.Recent` keeps those sessions, newest first, and never touches the cursors of the rest) and a shared `writer.Budget` (24 MiB, at most 12 MiB per runtime through `Budget.Sub`; a refused append returns `writer.ErrBudgetSpent`, the collector stops with cursors past only what was written, and a manual sync reads the rest). A new session-store collector takes both fields and joins `endpointBackfillRunners`. Every connect, first or re-connect, user or system, runs the same sweep before enrollment (skipped when install just ran it) and, before the forwarder starts, `asymptote.StageBackfill` copies the window's `harness.collection_method=poll` lines into `cloud-backfill.jsonl` beside the runtime log, which the `beacon_backfill` Vector source (fingerprinted `device_and_inode`, so each atomically restaged copy is a new file) reads from the beginning into the runtime sink through the same privacy transform. Live hook/OTLP/plugin history before the connection point stays local. Re-connects restage, so a resend of already-shipped lines is expected and rests on the deterministic `event.id`; a privacy-mode change clears the checkpoints and the restage renames the new-mode copy over the old one (kept until then so the copy is always a new inode; deleted instead when nothing restages), and `disconnect` removes it. System mode runs the collectors under `withUserHome` for the active console user (`activeConsoleUser`), with cursors under the system base directory, and reports a skip when nobody is logged in. The wizard's confirm screen names the upload (`WizardOptions.BackfillDays`). Dry-run, `--no-backfill` and `BEACON_BACKFILL=0` skip all of it; the cmd tests run with `BEACON_BACKFILL=0` set in `TestMain`.- `beacon endpoint install` has a full-screen onboarding wizard on interactive user TTYs. It signs in, preselects Beacon Cloud, requires an explicit choice to opt out to Local, and asks Managed users to choose Standard or Metadata-only privacy. Signing in alone still moves no telemetry. Confirming Beacon Cloud does: the confirm screen states that it installs Beacon and starts forwarding, and names what the selected privacy mode sends, so that screen is the consent point. The managed destination is recorded only after enrollment succeeds, so a failed enrollment leaves a working local install, prints `beacon endpoint connect` as the retry, and re-offers the question on the next install. The onboarding record is written only after `lifecycle.Install` returns, because a profile written first left a failed install looking onboarded and silently skipped the wizard on the retry. Explicit `install --connect` is unchanged. The wizard is skipped for system/root/CI/piped-stdin/dry-run or `BEACON_ONBOARDING=0`; those unattended paths must never gain an account or browser dependency. Legacy `BEACON_ONBOARDING_EMAIL`/`USAGE` submissions remain only for fleet compatibility. After the destination, the wizard shows an agent tools screen; every row is preselected (opt-out, space toggles). Beacon Cloud MCP is offered only with Beacon Cloud and runs the `beacon mcp connect` flow (`connectCloudMCP` with `yes`, OAuth, detected harnesses) only after the endpoint is connected (or already was), via `finishCloudSetup`; a failed enrollment skips it and names the retry. The Beacon Agent Skills are offered for either destination and installed user-wide into `~/.agents/skills` and, when Claude Code is set up, `~/.claude/skills` (`cli/beacon/internal/agentskills`, `beacon skills install|uninstall`; a `.beacon-managed` marker decides what Beacon may replace or remove; install and repair refresh only copies Beacon already wrote). Both run after `lifecycle.Install` returns and warn rather than fail. The answers are recorded as `onboarding.cloud_mcp`/`agent_skills`. Implementation lives in `cli/beacon/internal/onboarding`, `cli/beacon/cmd/endpoint_onboarding.go`, `cli/beacon/cmd/endpoint_install.go` and `cli/beacon/cmd/agent_tools.go`; keep `docs/cli/endpoint-onboarding.mdx` and `docs/cli/skills.mdx` in sync.- Do not add dependency vulnerability scanning, OSV/GHSA lookups, package remediation, or other vulnerability-enforcement flows to the public hook path.- Do not add broad runtime enforcement unless explicitly requested. Current control behavior is limited to hook-native approvals/denials exposed by supported agent runtimes.diff --git a/cli/beacon/internal/endpoint/asymptote/backfill_test.go b/cli/beacon/internal/endpoint/asymptote/backfill_test.goindex 70047fca..1a18c736 100644--- a/cli/beacon/internal/endpoint/asymptote/backfill_test.go+++ b/cli/beacon/internal/endpoint/asymptote/backfill_test.go@@ -236,6 +236,32 @@ func TestPrivacyModeChangeRestagesTheBackfillInTheNewMode(t *testing.T) {}}+func TestPrivacyModeChangeWithNothingToRestageDropsTheOldStagedBackfill(t *testing.T) {+ testenv.SetHome(t, t.TempDir())+ isolateVectorDiscovery(t)+ fd := newFakeDashboard(t)+ fwd := &fakeForwarder{supported: true}+ opts := connectOptions(t, fd, fwd, fakeVector(t, "0.56.0", 0))+ writeLines(t, opts.LogPath, backfillTestLine(time.Now().UTC().Format(time.RFC3339), "poll", "fresh"))+ opts.Backfill = &ConnectBackfill{}+ if _, err := Connect(context.Background(), opts); err != nil {+ t.Fatal(err)+ }+ staged := BackfillLogPath(opts.LogPath)+ if _, err := os.Stat(staged); err != nil {+ t.Fatalf("first connect did not stage: %v", err)+ }+ // The window now holds nothing, so no new-mode copy replaces the old one.+ opts.Backfill = &ConnectBackfill{Options: BackfillOptions{Since: time.Now().Add(time.Hour)}}+ opts.PrivacyMode = "metadata-only"+ if _, err := Connect(context.Background(), opts); err != nil {+ t.Fatal(err)+ }+ if _, err := os.Stat(staged); !os.IsNotExist(err) {+ t.Fatal("a privacy mode change left the old-mode staged backfill for the forwarder to ship")+ }+}+func TestDisconnectRemovesTheStagedBackfill(t *testing.T) {testenv.SetHome(t, t.TempDir())isolateVectorDiscovery(t)diff --git a/cli/beacon/internal/endpoint/asymptote/connect.go b/cli/beacon/internal/endpoint/asymptote/connect.goindex 4ad4b968..8d4659be 100644--- a/cli/beacon/internal/endpoint/asymptote/connect.go+++ b/cli/beacon/internal/endpoint/asymptote/connect.go@@ -264,6 +264,7 @@ func Connect(ctx context.Context, opts ConnectOptions) (_ *ConnectResult, err erreturn nil, err}+ dropStaged := falseif previous != nil {previousMode, _ := managedprivacy.Normalize(previous.PrivacyMode)if previousMode != privacyMode {@@ -276,11 +277,11 @@ func Connect(ctx context.Context, opts ConnectOptions) (_ *ConnectResult, err erif err := os.MkdirAll(dataDir, 0o700); err != nil {return nil, err}- // The buffer held lines in the old mode; drop the old staged copy with it. The- // backfill staged below replaces it in the new mode.- if err := RemoveBackfill(logPath); err != nil {- return nil, fmt.Errorf("could not remove the staged session backfill: %w", err)- }+ // The buffer held lines in the old mode; the old staged copy goes with it. It stays+ // linked until the restage below renames the new-mode copy over it, so that copy+ // always gets a new inode for the inode-fingerprinted backfill source. Removing it+ // first would free the inode for the restage to reuse.+ dropStaged = true}}// Staged before the forwarder (re)starts, so on a first connect the runtime source's connection@@ -297,6 +298,12 @@ func Connect(ctx context.Context, opts ConnectOptions) (_ *ConnectResult, err erbackfill = &staged}}+ if dropStaged && (backfill == nil || backfill.Events == 0) {+ // Nothing replaced the old-mode copy, so delete it rather than ship it.+ if err := RemoveBackfill(logPath); err != nil {+ return nil, fmt.Errorf("could not remove the staged session backfill: %w", err)+ }+ }if err := writeFileAtomic(configPath, []byte(rendered), 0o644); err != nil {return nil, err}