Skip to content

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

Backfill sessions on every install and connect, in system mode too

Claudea891af2628a3
diff --git a/CLAUDE.md b/CLAUDE.md
index 446625f5..51de1ec2 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 a successful user-mode install, 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`. A first user-mode connect 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 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 never stage, a privacy-mode change deletes the staged file with the checkpoints, and `disconnect` removes it. The wizard's confirm screen names the upload (`WizardOptions.BackfillDays`). System-mode, dry-run, `--no-backfill` and `BEACON_BACKFILL=0` skip all of it, so unattended paths are unchanged; 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 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`.
- `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/cmd/endpoint_backfill.go b/cli/beacon/cmd/endpoint_backfill.go
index 67da413c..afffe268 100644
--- a/cli/beacon/cmd/endpoint_backfill.go
+++ b/cli/beacon/cmd/endpoint_backfill.go
@@ -51,8 +51,11 @@ var (
// endpointBackfillRun is what one runtime's sweep needs from the orchestrator.
type endpointBackfillRun struct {
LogPath string
- Since time.Time
- Budget *writer.Budget
+ // UserMode picks the endpoint's own cursor files and log permissions. A system endpoint keeps
+ // its cursors under the system base directory while it reads the console user's stores.
+ UserMode bool
+ Since time.Time
+ Budget *writer.Budget
}
// endpointBackfillRunner is one session-store collector.
@@ -66,63 +69,63 @@ type endpointBackfillRunner struct {
}
// endpointBackfillRunners lists every session-store collector, a seam for tests. Each one runs with
-// the same user-mode defaults its own sync command uses.
+// the same defaults its own sync command uses for the endpoint's mode.
var endpointBackfillRunners = func() []endpointBackfillRunner {
return []endpointBackfillRunner{
{Name: "Claude Code", Sync: "beacon endpoint claude sync", Run: func(r endpointBackfillRun) (int, error) {
- s, err := claudesession.CollectOnce(claudesession.CollectOptions{Write: true, UserMode: true, LogPath: r.LogPath, StatePath: resolveClaudeStatePath("", true), Since: r.Since, Budget: r.Budget})
+ s, err := claudesession.CollectOnce(claudesession.CollectOptions{Write: true, UserMode: r.UserMode, LogPath: r.LogPath, StatePath: resolveClaudeStatePath("", r.UserMode), Since: r.Since, Budget: r.Budget})
return s.EventsEmitted, err
}},
{Name: "Codex CLI", Sync: "beacon endpoint codex sync", Run: func(r endpointBackfillRun) (int, error) {
- s, err := codexsession.CollectOnce(codexsession.CollectOptions{Write: true, UserMode: true, LogPath: r.LogPath, StatePath: resolveCodexStatePath("", true), Since: r.Since, Budget: r.Budget})
+ s, err := codexsession.CollectOnce(codexsession.CollectOptions{Write: true, UserMode: r.UserMode, LogPath: r.LogPath, StatePath: resolveCodexStatePath("", r.UserMode), Since: r.Since, Budget: r.Budget})
return s.EventsEmitted, err
}},
{Name: "Cursor", Sync: "beacon endpoint cursor sync", Run: func(r endpointBackfillRun) (int, error) {
- s, err := cursorsession.CollectOnce(cursorsession.CollectOptions{Write: true, UserMode: true, LogPath: r.LogPath, StatePath: resolveCursorStatePath("", true), Since: r.Since, Budget: r.Budget})
+ s, err := cursorsession.CollectOnce(cursorsession.CollectOptions{Write: true, UserMode: r.UserMode, LogPath: r.LogPath, StatePath: resolveCursorStatePath("", r.UserMode), Since: r.Since, Budget: r.Budget})
return s.EventsEmitted, err
}},
{Name: "OpenCode", Sync: "beacon endpoint opencode sync", Run: func(r endpointBackfillRun) (int, error) {
- s, err := opencodesession.CollectOnce(opencodesession.CollectOptions{Write: true, UserMode: true, LogPath: r.LogPath, StatePath: resolveOpenCodeStatePath("", true), Since: r.Since, Budget: r.Budget})
+ s, err := opencodesession.CollectOnce(opencodesession.CollectOptions{Write: true, UserMode: r.UserMode, LogPath: r.LogPath, StatePath: resolveOpenCodeStatePath("", r.UserMode), Since: r.Since, Budget: r.Budget})
return s.EventsEmitted, err
}},
{Name: "GitHub Copilot CLI", Sync: "beacon endpoint copilot sync", Run: func(r endpointBackfillRun) (int, error) {
- s, err := copilotsession.CollectOnce(copilotsession.CollectOptions{Write: true, UserMode: true, LogPath: r.LogPath, StatePath: resolveCopilotStatePath("", true), Since: r.Since, Budget: r.Budget})
+ s, err := copilotsession.CollectOnce(copilotsession.CollectOptions{Write: true, UserMode: r.UserMode, LogPath: r.LogPath, StatePath: resolveCopilotStatePath("", r.UserMode), Since: r.Since, Budget: r.Budget})
return s.EventsEmitted, err
}},
{Name: "Cline", Sync: "beacon endpoint cline sync", Run: func(r endpointBackfillRun) (int, error) {
- s, err := clinesession.CollectOnce(clinesession.CollectOptions{Write: true, UserMode: true, LogPath: r.LogPath, StatePath: resolveClineStatePath("", true), Since: r.Since, Budget: r.Budget})
+ s, err := clinesession.CollectOnce(clinesession.CollectOptions{Write: true, UserMode: r.UserMode, LogPath: r.LogPath, StatePath: resolveClineStatePath("", r.UserMode), Since: r.Since, Budget: r.Budget})
return s.EventsEmitted, err
}},
{Name: "Factory Droid", Sync: "beacon endpoint factory sync", Run: func(r endpointBackfillRun) (int, error) {
- s, err := factorysession.CollectOnce(factorysession.CollectOptions{Write: true, UserMode: true, LogPath: r.LogPath, StatePath: resolveFactoryStatePath("", true), Since: r.Since, Budget: r.Budget})
+ s, err := factorysession.CollectOnce(factorysession.CollectOptions{Write: true, UserMode: r.UserMode, LogPath: r.LogPath, StatePath: resolveFactoryStatePath("", r.UserMode), Since: r.Since, Budget: r.Budget})
return s.EventsEmitted, err
}},
{Name: "Pi", Sync: "beacon endpoint pi sync", Run: func(r endpointBackfillRun) (int, error) {
- s, err := pisession.CollectOnce(pisession.CollectOptions{Write: true, UserMode: true, LogPath: r.LogPath, StatePath: resolvePiStatePath("", true), Since: r.Since, Budget: r.Budget})
+ s, err := pisession.CollectOnce(pisession.CollectOptions{Write: true, UserMode: r.UserMode, LogPath: r.LogPath, StatePath: resolvePiStatePath("", r.UserMode), Since: r.Since, Budget: r.Budget})
return s.EventsEmitted, err
}},
{Name: "Prime Agent", Sync: "beacon endpoint prime sync", Run: func(r endpointBackfillRun) (int, error) {
- s, err := primesession.CollectOnce(primesession.CollectOptions{Write: true, UserMode: true, LogPath: r.LogPath, StatePath: resolvePrimeStatePath("", true), Since: r.Since, Budget: r.Budget})
+ s, err := primesession.CollectOnce(primesession.CollectOptions{Write: true, UserMode: r.UserMode, LogPath: r.LogPath, StatePath: resolvePrimeStatePath("", r.UserMode), Since: r.Since, Budget: r.Budget})
return s.EventsEmitted, err
}},
{Name: "Hermes Agent", Sync: "beacon endpoint hermes sync", Run: func(r endpointBackfillRun) (int, error) {
- s, err := hermessession.CollectOnce(hermessession.CollectOptions{Write: true, UserMode: true, LogPath: r.LogPath, StatePath: resolveHermesStatePath("", true), Since: r.Since, Budget: r.Budget})
+ s, err := hermessession.CollectOnce(hermessession.CollectOptions{Write: true, UserMode: r.UserMode, LogPath: r.LogPath, StatePath: resolveHermesStatePath("", r.UserMode), Since: r.Since, Budget: r.Budget})
return s.EventsEmitted, err
}},
{Name: "DeepSeek Harness", Sync: "beacon endpoint dsh sync", Run: func(r endpointBackfillRun) (int, error) {
- s, err := dshsession.CollectOnce(dshsession.CollectOptions{Write: true, UserMode: true, LogPath: r.LogPath, StatePath: resolveDshStatePath("", true), Since: r.Since, Budget: r.Budget})
+ s, err := dshsession.CollectOnce(dshsession.CollectOptions{Write: true, UserMode: r.UserMode, LogPath: r.LogPath, StatePath: resolveDshStatePath("", r.UserMode), Since: r.Since, Budget: r.Budget})
return s.EventsEmitted, err
}},
{Name: "fx", Sync: "beacon endpoint fx sync", Run: func(r endpointBackfillRun) (int, error) {
- s, err := fxsession.CollectOnce(fxsession.CollectOptions{Write: true, UserMode: true, LogPath: r.LogPath, StatePath: resolveFxStatePath("", true), Since: r.Since, Budget: r.Budget})
+ s, err := fxsession.CollectOnce(fxsession.CollectOptions{Write: true, UserMode: r.UserMode, LogPath: r.LogPath, StatePath: resolveFxStatePath("", r.UserMode), Since: r.Since, Budget: r.Budget})
return s.EventsEmitted, err
}},
{Name: "Grok Build", Sync: "beacon endpoint grok sync", Run: func(r endpointBackfillRun) (int, error) {
- s, err := groksession.CollectOnce(groksession.CollectOptions{Write: true, UserMode: true, LogPath: r.LogPath, StatePath: resolveGrokStatePath("", true), Since: r.Since, Budget: r.Budget})
+ s, err := groksession.CollectOnce(groksession.CollectOptions{Write: true, UserMode: r.UserMode, LogPath: r.LogPath, StatePath: resolveGrokStatePath("", r.UserMode), Since: r.Since, Budget: r.Budget})
return s.EventsEmitted, err
}},
{Name: "OpenClaw Gateway", Sync: "beacon endpoint integrations openclaw sessions sync", Run: func(r endpointBackfillRun) (int, error) {
- s, err := openclawsession.CollectOnce(openclawsession.CollectOptions{Write: true, UserMode: true, LogPath: r.LogPath, StatePath: resolveOpenClawSessionsStatePath("", true), Since: r.Since, Budget: r.Budget})
+ s, err := openclawsession.CollectOnce(openclawsession.CollectOptions{Write: true, UserMode: r.UserMode, LogPath: r.LogPath, StatePath: resolveOpenClawSessionsStatePath("", r.UserMode), Since: r.Since, Budget: r.Budget})
return s.EventsEmitted, err
}},
}
@@ -147,13 +150,15 @@ type endpointBackfillResult struct {
Bytes int64
Limited bool
Runtimes []endpointBackfillRuntimeResult
+ // Skipped says why nothing was read, such as a system endpoint with no console user to read for.
+ Skipped string
}
-// endpointBackfillEnabled reports whether this install or connect should backfill. Only a user-mode
-// endpoint does: the collectors read the invoking user's home, which for a system install is root's,
-// and the unattended system paths stay exactly as they were.
-func endpointBackfillEnabled(userMode bool) bool {
- if !userMode || endpointOpts.dryRun || endpointOpts.noBackfill {
+// endpointBackfillEnabled reports whether this install or connect should backfill. Every real
+// install and connect does, in user and system mode alike; only a dry run, --no-backfill and
+// BEACON_BACKFILL=0 turn it off.
+func endpointBackfillEnabled() bool {
+ if endpointOpts.dryRun || endpointOpts.noBackfill {
return false
}
return strings.TrimSpace(os.Getenv(endpointBackfillEnv)) != "0"
@@ -162,7 +167,7 @@ func endpointBackfillEnabled(userMode bool) bool {
// endpointBackfillDays is the backfill window in days for an interactive user install, or zero when
// the backfill is off; the onboarding wizard names it on its confirm screen.
func endpointBackfillDays() int {
- if !endpointBackfillEnabled(true) {
+ if !endpointBackfillEnabled() {
return 0
}
return int(endpointBackfillWindow / (24 * time.Hour))
@@ -171,12 +176,34 @@ func endpointBackfillDays() int {
// runEndpointBackfill sweeps every session store once into logPath, newest sessions first, within
// the window and the budget. A runtime that fails is reported and the rest still run: the backfill
// is a convenience on top of a working install and never fails it.
-func runEndpointBackfill(logPath string) endpointBackfillResult {
+//
+// A user endpoint reads the invoking user's stores. A system endpoint runs as root, whose home holds
+// no agent sessions, so it reads the active console user's stores instead, the same person system
+// hook repair and inventory resolve, while its cursors stay under the system base directory. With
+// nobody to read for, it reads nothing and says so.
+func runEndpointBackfill(logPath string, userMode bool) endpointBackfillResult {
+ if userMode {
+ return sweepEndpointBackfill(logPath, true)
+ }
+ info, ok, err := activeConsoleUser()
+ switch {
+ case err != nil:
+ return endpointBackfillResult{Skipped: fmt.Sprintf("could not resolve the console user: %v", err)}
+ case !ok || strings.TrimSpace(info.HomeDir) == "":
+ return endpointBackfillResult{Skipped: "no active console user to read agent sessions for"}
+ }
+ result, _ := withUserHome(info.HomeDir, func() (endpointBackfillResult, error) {
+ return sweepEndpointBackfill(logPath, false), nil
+ })
+ return result
+}
+
+func sweepEndpointBackfill(logPath string, userMode bool) endpointBackfillResult {
result := endpointBackfillResult{Since: endpointBackfillNow().Add(-endpointBackfillWindow)}
total := writer.NewBudget(endpointBackfillMaxBytes)
for _, runner := range endpointBackfillRunners() {
share := total.Sub(endpointBackfillShareBytes)
- events, err := runner.Run(endpointBackfillRun{LogPath: logPath, Since: result.Since, Budget: share})
+ events, err := runner.Run(endpointBackfillRun{LogPath: logPath, UserMode: userMode, Since: result.Since, Budget: share})
runtime := endpointBackfillRuntimeResult{Name: runner.Name, Sync: runner.Sync, Events: events}
if errors.Is(err, writer.ErrBudgetSpent) || share.Refused() {
runtime.Limited = true
@@ -211,6 +238,10 @@ func onlyBudgetSpent(err error) bool {
// per runtime that hit the limit or failed, each naming the command that picks up from there.
func reportEndpointBackfill(out io.Writer, result endpointBackfillResult) {
days := int(endpointBackfillWindow / (24 * time.Hour))
+ if result.Skipped != "" {
+ fmt.Fprintf(out, "Session backfill skipped: %s.\n", result.Skipped)
+ return
+ }
if result.Events == 0 && !result.Limited && len(result.Runtimes) == 0 {
fmt.Fprintf(out, "Session backfill: no new agent session activity from the last %d days.\n", days)
return
@@ -236,11 +267,13 @@ func reportEndpointBackfill(out io.Writer, result endpointBackfillResult) {
}
}
-// endpointConnectBackfill is the backfill a user-mode connect ships, or nil when it ships none.
-// synced says this process has just run the install-time backfill, so connect does not sweep again
-// and spend a second budget; it still stages what the first sweep wrote.
+// endpointConnectBackfill is the backfill a connect ships, or nil when it ships none. Every connect
+// ships one, first or not, user or system: the staged lines keep the deterministic event.id they
+// were written with, so history the forwarder already shipped is the same event to the ingest side
+// rather than a second one. synced says this process has just run the install-time backfill, so
+// connect does not sweep again and spend a second budget; it still stages what the first sweep wrote.
func endpointConnectBackfill(out io.Writer, userMode bool, logPath string, synced bool) *asymptote.ConnectBackfill {
- if !endpointBackfillEnabled(userMode) {
+ if !endpointBackfillEnabled() {
return nil
}
backfill := &asymptote.ConnectBackfill{Options: asymptote.BackfillOptions{
@@ -249,7 +282,7 @@ func endpointConnectBackfill(out io.Writer, userMode bool, logPath string, synce
}}
if !synced {
backfill.Sync = func() error {
- reportEndpointBackfill(out, runEndpointBackfill(logPath))
+ reportEndpointBackfill(out, runEndpointBackfill(logPath, userMode))
return nil
}
}
diff --git a/cli/beacon/cmd/endpoint_backfill_test.go b/cli/beacon/cmd/endpoint_backfill_test.go
index 5aea3c5a..d4b49e34 100644
--- a/cli/beacon/cmd/endpoint_backfill_test.go
+++ b/cli/beacon/cmd/endpoint_backfill_test.go
@@ -67,7 +67,7 @@ func TestEndpointBackfillGivesEachRuntimeAShareAndNamesWhereToContinue(t *testin
writingRunner("Absent", 0, nil),
)
logPath := filepath.Join(t.TempDir(), "runtime.jsonl")
- result := runEndpointBackfill(logPath)
+ result := runEndpointBackfill(logPath, true)
if want := time.Date(2026, 9, 5, 12, 0, 0, 0, time.UTC); !since.Equal(want) {
t.Fatalf("collectors were given since=%s, want %s", since, want)
@@ -114,7 +114,7 @@ func TestEndpointBackfillGivesEachRuntimeAShareAndNamesWhereToContinue(t *testin
func TestEndpointBackfillReportsAnEmptyMachinePlainly(t *testing.T) {
stubBackfill(t, 4000, 2500, writingRunner("Absent", 0, nil))
var out strings.Builder
- reportEndpointBackfill(&out, runEndpointBackfill(filepath.Join(t.TempDir(), "runtime.jsonl")))
+ reportEndpointBackfill(&out, runEndpointBackfill(filepath.Join(t.TempDir(), "runtime.jsonl"), true))
if got := strings.TrimSpace(out.String()); got != "Session backfill: no new agent session activity from the last 30 days." {
t.Fatalf("report = %q", got)
}
@@ -163,8 +163,41 @@ func TestEndpointInstallBackfillsAfterTheInstallSucceeds(t *testing.T) {
}
t.Setenv(endpointBackfillEnv, "")
}
- if endpointBackfillEnabled(false) {
- t.Fatal("a system install backfills root's home")
+}
+
+func TestSystemEndpointBackfillReadsTheConsoleUsersStores(t *testing.T) {
+ home := t.TempDir()
+ var sawHome string
+ var sawUserMode bool
+ stubBackfill(t, 1<<20, 1<<20, endpointBackfillRunner{Name: "Codex", Sync: "beacon endpoint codex sync", Run: func(r endpointBackfillRun) (int, error) {
+ sawHome, _ = os.UserHomeDir()
+ sawUserMode = r.UserMode
+ return writingRunner("Codex", 2, nil).Run(r)
+ }})
+ stubConsoleUser(t, consoleUserInfo{Username: "alice", HomeDir: home}, true, nil)
+ before, _ := os.UserHomeDir()
+
+ var out strings.Builder
+ reportEndpointBackfill(&out, runEndpointBackfill(filepath.Join(t.TempDir(), "runtime.jsonl"), false))
+ if sawHome != home || sawUserMode {
+ t.Fatalf("system backfill read home=%q userMode=%t, want the console user's home %q in system mode", sawHome, sawUserMode, home)
+ }
+ if after, _ := os.UserHomeDir(); after != before {
+ t.Fatalf("system backfill left HOME at %q, want %q", after, before)
+ }
+ if !strings.Contains(out.String(), "Session backfill: 2 events from the last 30 days (Codex 2).") {
+ t.Fatalf("report = %q", out.String())
+ }
+
+ stubConsoleUser(t, consoleUserInfo{}, false, nil)
+ sawHome = ""
+ out.Reset()
+ reportEndpointBackfill(&out, runEndpointBackfill(filepath.Join(t.TempDir(), "runtime.jsonl"), false))
+ if sawHome != "" {
+ t.Fatal("a system backfill with no console user read root's home")
+ }
+ if got := strings.TrimSpace(out.String()); got != "Session backfill skipped: no active console user to read agent sessions for." {
+ t.Fatalf("report = %q", got)
}
}
diff --git a/cli/beacon/cmd/endpoint_connect.go b/cli/beacon/cmd/endpoint_connect.go
index 14cb230b..e058438c 100644
--- a/cli/beacon/cmd/endpoint_connect.go
+++ b/cli/beacon/cmd/endpoint_connect.go
@@ -73,7 +73,7 @@ func init() {
endpointConnectCmd.Flags().StringVar(&connectOpts.dashboardURL, "dashboard-url", "", "Beacon service URL (defaults to "+auth.DefaultDashboardURL+", or "+auth.DashboardURLEnv+")")
endpointConnectCmd.Flags().BoolVar(&connectOpts.noBrowser, "no-browser", false, "System mode: print the device approval URL instead of opening a browser")
endpointConnectCmd.Flags().StringVar(&connectOpts.vectorBin, "vector-bin", "", "Vector binary to run (defaults to "+asymptote.VectorBinEnv+", "+asymptote.PackagedVectorPath+", Homebrew, then PATH)")
- endpointConnectCmd.Flags().BoolVar(&endpointOpts.noBackfill, "no-backfill", false, "On a first connect, do not upload the last 30 days of agent sessions read from their local session stores (also "+endpointBackfillEnv+"=0)")
+ endpointConnectCmd.Flags().BoolVar(&endpointOpts.noBackfill, "no-backfill", false, "Do not upload the last 30 days of agent sessions read from their local session stores (also "+endpointBackfillEnv+"=0)")
endpointConnectCmd.Flags().StringVar(&connectOpts.privacyMode, "privacy-mode", "", "Beacon Cloud forwarding privacy: standard or metadata-only (defaults to onboarding choice)")
endpointDisconnectCmd.Flags().BoolVar(&connectOpts.keepCredentials, "keep-credentials", false, "Keep the enrollment record and device key so a later connect can reuse this device")
endpointCmd.AddCommand(endpointConnectCmd)
diff --git a/cli/beacon/cmd/endpoint_install.go b/cli/beacon/cmd/endpoint_install.go
index 49402742..b16d1bef 100644
--- a/cli/beacon/cmd/endpoint_install.go
+++ b/cli/beacon/cmd/endpoint_install.go
@@ -186,8 +186,8 @@ func runEndpointInstall(cmd *cobra.Command, args []string) error {
// in it before any agent runs again. Local only, bounded, and never a reason to fail the
// install; a connect below ships what it wrote rather than sweeping again.
backfilled := false
- if endpointBackfillEnabled(endpointUserMode()) {
- reportEndpointBackfill(cmd.OutOrStdout(), runEndpointBackfill(result.LogPath))
+ if endpointBackfillEnabled() {
+ reportEndpointBackfill(cmd.OutOrStdout(), runEndpointBackfill(result.LogPath, endpointUserMode()))
backfilled = true
}
finishCloudSetup(cmd, onboarded, connectAfterInstall, func() error {
diff --git a/cli/beacon/internal/endpoint/asymptote/backfill.go b/cli/beacon/internal/endpoint/asymptote/backfill.go
index 1f3b7ba7..f65e30c2 100644
--- a/cli/beacon/internal/endpoint/asymptote/backfill.go
+++ b/cli/beacon/internal/endpoint/asymptote/backfill.go
@@ -14,7 +14,7 @@ import (
"github.com/asymptote-labs/agent-beacon/cli/beacon/internal/endpoint/writer"
)
-// BackfillLogName is the file a first connect stages the session backfill in, beside the runtime
+// BackfillLogName is the file every connect stages the session backfill in, beside the runtime
// log.
const BackfillLogName = siempack.BackfillLogName
@@ -22,7 +22,7 @@ const BackfillLogName = siempack.BackfillLogName
// a hand-run pack and the managed forwarder agree on it.
func BackfillLogPath(logPath string) string { return siempack.BackfillLogPath(logPath) }
-// BackfillOptions bounds what a first connect ships from before the connection point.
+// BackfillOptions bounds what a connect ships from before the connection point.
type BackfillOptions struct {
// Since drops events older than it.
Since time.Time
@@ -49,9 +49,11 @@ type BackfillResult struct {
// OTLP and plugin events from before the connection stay local. The lines are copied byte for
// byte, so the forwarder's privacy transforms apply to them exactly as to live lines.
//
-// It runs before the forwarder starts and only on a first connect: a re-connect resumes from
-// Vector's checkpoints and would otherwise ship the same history twice. The file is replaced
-// atomically, 0600, so a reader never sees half of it.
+// It runs before the forwarder starts, on every connect. The file is replaced atomically, 0600, so
+// a reader never sees half of it, and the replacement is a new inode, which the backfill source
+// (fingerprinted by inode) reads from the beginning. A re-connect can therefore send lines the
+// forwarder shipped before; they carry the deterministic event.id they were written with, so they
+// name the same events rather than new ones.
func StageBackfill(logPath string, opts BackfillOptions) (BackfillResult, error) {
result := BackfillResult{Path: BackfillLogPath(logPath)}
if logPath == "" {
@@ -99,8 +101,8 @@ func StageBackfill(logPath string, opts BackfillOptions) (BackfillResult, error)
return result, nil
}
-// RemoveBackfill deletes the staged backfill file. Disconnect calls it so a later first connect
-// stages a fresh one rather than shipping a stale copy.
+// RemoveBackfill deletes the staged backfill file. Disconnect calls it so nothing is left staged
+// for a forwarder that no longer exists.
func RemoveBackfill(logPath string) error {
if logPath == "" {
return nil
diff --git a/cli/beacon/internal/endpoint/asymptote/backfill_test.go b/cli/beacon/internal/endpoint/asymptote/backfill_test.go
index e1887a2e..70047fca 100644
--- a/cli/beacon/internal/endpoint/asymptote/backfill_test.go
+++ b/cli/beacon/internal/endpoint/asymptote/backfill_test.go
@@ -115,7 +115,7 @@ func TestVectorConfigReadsTheStagedBackfillFromTheBeginningInEveryPrivacyMode(t
if err != nil {
t.Fatal(err)
}
- source := "[sources.beacon_backfill]\ntype = \"file\"\ninclude = [\"/tmp/beacon/" + BackfillLogName + "\"]\nread_from = \"beginning\""
+ source := "[sources.beacon_backfill]\ntype = \"file\"\ninclude = [\"/tmp/beacon/" + BackfillLogName + "\"]\nread_from = \"beginning\"\nfingerprint.strategy = \"device_and_inode\""
if !strings.Contains(got, source) {
t.Fatalf("%s config has no backfill source:\n%s", mode, got)
}
@@ -141,7 +141,7 @@ func TestVectorConfigReadsTheStagedBackfillFromTheBeginningInEveryPrivacyMode(t
}
}
-func TestFirstConnectStagesTheBackfillBeforeTheForwarderStartsAndReconnectDoesNot(t *testing.T) {
+func TestEveryConnectStagesTheBackfillBeforeTheForwarderStarts(t *testing.T) {
testenv.SetHome(t, t.TempDir())
isolateVectorDiscovery(t)
fd := newFakeDashboard(t)
@@ -154,11 +154,17 @@ func TestFirstConnectStagesTheBackfillBeforeTheForwarderStartsAndReconnectDoesNo
opts.Backfill = &ConnectBackfill{
Sync: func() error {
synced++
- // The sweep runs before any key exists.
- if _, err := ReadDeviceKey(true); err == nil {
+ // On a first connect the sweep runs before any key exists.
+ if _, err := ReadDeviceKey(true); synced == 1 && err == nil {
t.Error("backfill sync ran after the device key was stored")
}
- writeLines(t, opts.LogPath, backfillTestLine(time.Now().UTC().Format(time.RFC3339), "poll", "fresh"))
+ now := time.Now().UTC().Format(time.RFC3339)
+ lines := []string{backfillTestLine(now, "poll", "fresh")}
+ if synced > 1 {
+ // Written while the endpoint was connected or not; the re-connect stages it too.
+ lines = append(lines, backfillTestLine(now, "poll", "later"))
+ }
+ writeLines(t, opts.LogPath, lines...)
return errors.New("one runtime could not be read")
},
}
@@ -176,23 +182,30 @@ func TestFirstConnectStagesTheBackfillBeforeTheForwarderStartsAndReconnectDoesNo
t.Fatalf("synced=%d backfill=%+v staged-before-load=%d", synced, result.Backfill, loadsAtStage)
}
- // A re-connect resumes from the forwarder's checkpoints: no sweep, no new stage.
- if err := os.Remove(staged); err != nil {
+ // A re-connect sweeps and stages again, as a new file the backfill source reads from the
+ // beginning, so history written while the endpoint was not connected still arrives.
+ first, err := os.Stat(staged)
+ if err != nil {
t.Fatal(err)
}
+ loadsAtStage = 0
again, err := Connect(context.Background(), opts)
if err != nil {
t.Fatal(err)
}
- if synced != 1 || again.Backfill != nil {
- t.Fatalf("re-connect synced=%d backfill=%+v", synced, again.Backfill)
+ if synced != 2 || again.Backfill == nil || again.Backfill.Events != 2 || loadsAtStage != 1 {
+ t.Fatalf("re-connect synced=%d backfill=%+v staged-before-load=%d", synced, again.Backfill, loadsAtStage)
+ }
+ second, err := os.Stat(staged)
+ if err != nil {
+ t.Fatal(err)
}
- if _, err := os.Stat(staged); !os.IsNotExist(err) {
- t.Fatal("re-connect staged the backfill again")
+ if os.SameFile(first, second) {
+ t.Fatal("re-connect rewrote the staged backfill in place; the inode-fingerprinted source would resume at the old offset")
}
}
-func TestPrivacyModeChangeDropsTheStagedBackfillWithTheCheckpoints(t *testing.T) {
+func TestPrivacyModeChangeRestagesTheBackfillInTheNewMode(t *testing.T) {
testenv.SetHome(t, t.TempDir())
isolateVectorDiscovery(t)
fd := newFakeDashboard(t)
@@ -205,15 +218,21 @@ func TestPrivacyModeChangeDropsTheStagedBackfillWithTheCheckpoints(t *testing.T)
t.Fatal(err)
}
staged := BackfillLogPath(opts.LogPath)
- if _, err := os.Stat(staged); err != nil {
+ first, err := os.Stat(staged)
+ if err != nil {
t.Fatalf("first connect did not stage: %v", err)
}
opts.PrivacyMode = "metadata-only"
- if _, err := Connect(context.Background(), opts); err != nil {
+ result, err := Connect(context.Background(), opts)
+ if err != nil {
t.Fatal(err)
}
- if _, err := os.Stat(staged); !os.IsNotExist(err) {
- t.Fatal("a privacy mode change kept a staged backfill whose checkpoint it cleared")
+ second, err := os.Stat(staged)
+ if err != nil || result.Backfill == nil || result.Backfill.Events != 1 {
+ t.Fatalf("a privacy mode change did not restage the backfill: %v %+v", err, result.Backfill)
+ }
+ if os.SameFile(first, second) {
+ t.Fatal("a privacy mode change kept the old staged backfill")
}
}
diff --git a/cli/beacon/internal/endpoint/asymptote/connect.go b/cli/beacon/internal/endpoint/asymptote/connect.go
index cfbc0a96..4ad4b968 100644
--- a/cli/beacon/internal/endpoint/asymptote/connect.go
+++ b/cli/beacon/internal/endpoint/asymptote/connect.go
@@ -49,15 +49,15 @@ type ConnectOptions struct {
InstallID string
// PrivacyMode controls the Vector-side transform before managed upload.
PrivacyMode string
- // Backfill, when set, ships recent session history on a first connect. Nil ships nothing
- // recorded before the connection point.
+ // Backfill, when set, ships recent session history on this connect, first or not. Nil ships
+ // nothing recorded before the connection point.
Backfill *ConnectBackfill
Out io.Writer
// Now is injectable for tests.
Now func() time.Time
}
-// ConnectBackfill is the bounded session backfill a first connect ships. Neither step can fail
+// ConnectBackfill is the bounded session backfill a connect ships. Neither step can fail
// the connect: a backfill that could not be staged leaves a working forwarder, and says so.
type ConnectBackfill struct {
// Sync reads the agents' session stores into the runtime log, so the backfill covers what
@@ -185,7 +185,7 @@ func Connect(ctx context.Context, opts ConnectOptions) (_ *ConnectResult, err er
// The session-store sweep is local and can take a while on a machine with a lot of history,
// so it runs here, after every check that could refuse the connect and before a key exists.
- if opts.Backfill != nil && opts.Backfill.Sync != nil && !reconnect {
+ if opts.Backfill != nil && opts.Backfill.Sync != nil {
if err := opts.Backfill.Sync(); err != nil {
fmt.Fprintf(out, "Session backfill: %v\n", err)
}
@@ -276,18 +276,20 @@ func Connect(ctx context.Context, opts ConnectOptions) (_ *ConnectResult, err er
if err := os.MkdirAll(dataDir, 0o700); err != nil {
return nil, err
}
- // Clearing the checkpoints would have the backfill source read the file staged by
- // the first connect from the beginning again, shipping that history twice.
+ // 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)
}
}
}
- // Staged after the config is written and before the forwarder starts, so the runtime source's
- // connection point falls after every line staged here and nothing is shipped twice. Only a
- // first connect stages: a re-connect resumes from the forwarder's checkpoints.
+ // Staged before the forwarder (re)starts, so on a first connect the runtime source's connection
+ // point falls after every line staged here. A re-connect stages too: the runtime source resumes
+ // from its checkpoint, and the backfill source reads the restaged file as a new one, so history
+ // the agents wrote while the endpoint was not connected, or before a system endpoint could read
+ // it, still arrives. Lines the forwarder already shipped carry the same deterministic event.id.
var backfill *BackfillResult
- if opts.Backfill != nil && !reconnect {
+ if opts.Backfill != nil {
staged, err := StageBackfill(logPath, opts.Backfill.Options)
if err != nil {
fmt.Fprintf(out, "Session backfill was not staged: %v\n", err)
diff --git a/cli/beacon/internal/endpoint/asymptote/pack/README.md b/cli/beacon/internal/endpoint/asymptote/pack/README.md
index 06a674f5..2e5c8756 100644
--- a/cli/beacon/internal/endpoint/asymptote/pack/README.md
+++ b/cli/beacon/internal/endpoint/asymptote/pack/README.md
@@ -13,7 +13,7 @@ and Vector has been started.
Every line of `runtime.jsonl` written after the forwarder starts, every line
of `inventory_state.jsonl`, and every line of `cloud-backfill.jsonl` (the
-bounded session backfill `beacon endpoint connect` stages on a first connect;
+bounded session backfill each `beacon endpoint connect` stages;
absent otherwise), exactly as Beacon wrote them locally. Local
redaction, retention and size limits apply before a line is written, so they
apply to what is forwarded. The ingest service adds a `tenant` block
diff --git a/cli/beacon/internal/endpoint/asymptote/pack/vector.toml.tmpl b/cli/beacon/internal/endpoint/asymptote/pack/vector.toml.tmpl
index 1f4a6805..641ac1fc 100644
--- a/cli/beacon/internal/endpoint/asymptote/pack/vector.toml.tmpl
+++ b/cli/beacon/internal/endpoint/asymptote/pack/vector.toml.tmpl
@@ -26,12 +26,17 @@ include = ["{{LOG_PATH}}"]
# Nothing recorded before the device was approved is shipped.
read_from = "end"
-# The bounded session backfill a first connect stages from the agents' own
-# session stores, so the dashboard shows recent history at once. Read once.
+# The bounded session backfill every connect stages from the agents' own
+# session stores, so the dashboard shows recent history at once. Each connect
+# replaces the file atomically; fingerprinting by inode makes every restaged
+# copy a new file read from the beginning, where a content checksum could take
+# a restaged copy that starts with the same event for the old one and resume
+# at a stale offset. Lines already shipped carry the same event.id as before.
[sources.beacon_backfill]
type = "file"
include = ["{{BACKFILL_LOG_PATH}}"]
read_from = "beginning"
+fingerprint.strategy = "device_and_inode"
[sources.beacon_inventory]
type = "file"
diff --git a/cli/beacon/internal/endpoint/siempack/siempack.go b/cli/beacon/internal/endpoint/siempack/siempack.go
index 95ec6ab5..35264cad 100644
--- a/cli/beacon/internal/endpoint/siempack/siempack.go
+++ b/cli/beacon/internal/endpoint/siempack/siempack.go
@@ -13,7 +13,7 @@ const logPathToken = "{{LOG_PATH}}"
const inventoryLogPathToken = "{{INVENTORY_LOG_PATH}}"
const backfillLogPathToken = "{{BACKFILL_LOG_PATH}}"
-// BackfillLogName is the file Beacon Cloud's first connect stages the bounded session backfill in,
+// BackfillLogName is the file every Beacon Cloud connect stages the bounded session backfill in,
// beside the runtime log. Its name does not start with the runtime log's, so readers of the runtime
// log and its archives never see it.
const BackfillLogName = "cloud-backfill.jsonl"
diff --git a/docs/changelog/cli.mdx b/docs/changelog/cli.mdx
index eaffe971..750842f5 100644
--- a/docs/changelog/cli.mdx
+++ b/docs/changelog/cli.mdx
@@ -11,6 +11,7 @@ Stay up to date with the latest changes to the Agent Beacon CLI.
## October 2026
+- **Session backfill on every install and connect** · The 30-day [session backfill](/cli/endpoint-connect#session-backfill) now runs for system, package and MDM installs and connects too, reading the active console user's session stores, and every `beacon endpoint connect` stages it again rather than only the first one, so history written while an endpoint was disconnected still reaches Beacon Cloud. Re-sent events keep their deterministic event id, which the dashboard collapses. `--no-backfill` and `BEACON_BACKFILL=0` still turn it off.
- **Model-visible MCP tool descriptions on Claude Code** · With `--claude-capture-model-context`, the collector also keeps the name and description of each MCP tool a Claude Code request advertises, and records one `mcp.tool_listed` per tool per session, again only when its description changes. The `claude_api_body` processor sends each destination that same once-per-session list as `beacon.mcp.tools`, in place of the body. Install also raises Claude Code's inline content limit to 256 KB unless you set one, because MCP tools come last in a request body, and the local OTLP receiver accepts gRPC messages up to 32 MiB. Independently, `gen_ai.tool.description` now keeps up to 4 KB on every event rather than 2 KB, so a padded description cannot hide its instructions from `mcp-poisoned-tool-description`.
- **Model-visible MCP tool descriptions on Oh My Pi** · The Oh My Pi extension reads the MCP tool routes from the same system prompt as the skill index and records one `mcp.tool_listed` per described tool, with the description the model was shown in `gen_ai.tool.description`. Each session sends a listing once and again only when it changes. `mcp-poisoned-tool-description` (now version 2) matches these listings as well as `mcp.tool_invoked`, so a poisoned description is flagged when the model sees it rather than only once the tool runs. Metadata-only managed forwarding removes `gen_ai.tool.description` and keeps the tool name.
- **Opt-in capture of Claude Code model context** · `beacon endpoint install
diff --git a/docs/cli/asymptote.mdx b/docs/cli/asymptote.mdx
index b78b7e99..a16be3af 100644
--- a/docs/cli/asymptote.mdx
+++ b/docs/cli/asymptote.mdx
@@ -46,7 +46,7 @@ beacon endpoint asymptote [command]
| User mode | `~/.beacon/endpoint/logs/runtime.jsonl` |
| System mode | `/var/log/beacon-agent/runtime.jsonl` |
-The inventory log is the sibling `inventory_state.jsonl` in the same directory. The forwarder also reads the sibling `cloud-backfill.jsonl` once from the beginning: the bounded [session backfill](/cli/endpoint-connect#session-backfill) a first `beacon endpoint connect` stages there. A hand-run forwarder ships it only if that file exists.
+The inventory log is the sibling `inventory_state.jsonl` in the same directory. The forwarder also reads the sibling `cloud-backfill.jsonl` once from the beginning: the bounded [session backfill](/cli/endpoint-connect#session-backfill) each `beacon endpoint connect` stages there, as a new file each time. A hand-run forwarder ships it only if that file exists.
## beacon endpoint asymptote print-config
diff --git a/docs/cli/endpoint-connect.mdx b/docs/cli/endpoint-connect.mdx
index 8558e84c..eef958fa 100644
--- a/docs/cli/endpoint-connect.mdx
+++ b/docs/cli/endpoint-connect.mdx
@@ -9,7 +9,7 @@ description: "Connect a Beacon endpoint to Beacon Cloud ingest, or disconnect it
Forwarding is opt-in and revocable. Runtime telemetry starts at the end of the
existing runtime log, so pre-connect runtime events are not sent, with one bounded
-exception: a first user-mode connect uploads the last 30 days of agent sessions read
+exception: every connect uploads the last 30 days of agent sessions read
from the runtimes' own session stores, so the dashboard shows your recent work at once
(see [Session backfill](#session-backfill)). Inventory starts
at the beginning of `inventory_state.jsonl` so the dashboard receives the endpoint's
@@ -33,10 +33,10 @@ beacon endpoint disconnect [flags]
1. Locates Vector: `--vector-bin`, then `BEACON_VECTOR_BIN`, then `/opt/beacon/bin/vector`, the `beacon-vector` keg in each Homebrew prefix, a linked `vector` in each Homebrew prefix, then `PATH`. The `beacon-vector` keg is tried ahead of any other Homebrew Vector because it is the copy the tap pins at a supported version.
2. Renders the forwarder config for the selected privacy mode into a scratch directory, with a placeholder key, and runs `vector validate` on it. A config Vector rejects stops `connect` here, before anything is sent to the server.
-3. On a first user-mode connect, runs the [session backfill](#session-backfill) sweep into the runtime log. It is local and runs before any key exists.
+3. Runs the [session backfill](#session-backfill) sweep into the runtime log, in user and system mode. It is local and runs before a new key is issued.
4. Uses the signed-in account's `device:enroll` scope to register this machine's hostname, operating system, architecture, Beacon version, install id, and install mode. The server returns a separate `bcn_device_*` ingest key. System mode uses the existing browser PKCE device approval instead.
5. Writes the device key once to `asymptote/vector-secrets.json` with mode `0600`. The account token is not persisted by the endpoint flow.
-6. Renders `asymptote/vector.toml` with the selected privacy mode and runs `vector validate` on the file the service will run. On a first connect, stages the session backfill in `cloud-backfill.jsonl` beside the runtime log. Then installs a service unit and starts it.
+6. Renders `asymptote/vector.toml` with the selected privacy mode and runs `vector validate` on the file the service will run. Stages the session backfill in `cloud-backfill.jsonl` beside the runtime log. Then installs a service unit and starts it.
7. Records the non-secret enrollment, including privacy mode, in `asymptote/enrollment.json` and `config.json`'s `managed_ingest` block.
A first connect that fails at `vector validate` or at loading the service saves no enrollment record, so the endpoint is not connected and `beacon endpoint disconnect` cleans up what was written. After `disconnect --keep-credentials`, status reports not connected and names the kept device id.
@@ -47,10 +47,11 @@ Some steps can only fail after the server has issued the key: storing it, valida
## Session backfill
-A first user-mode connect uploads recent session history so the Beacon Cloud dashboard is not
-empty until an agent runs again. Beacon first runs the same bounded sweep as
-[`beacon endpoint install`](/cli/endpoint-install#session-backfill): the last 30 days of sessions
-from each runtime's own session store, newest first, at most 24 MiB. `endpoint install --connect`
+Every connect, first or not and in user or system mode, uploads recent session history so the
+Beacon Cloud dashboard is not empty until an agent runs again. Beacon first runs the same bounded
+sweep as [`beacon endpoint install`](/cli/endpoint-install#session-backfill): the last 30 days of
+sessions from each runtime's own session store, newest first, at most 24 MiB. A system connect reads
+the active console user's session stores, as a system install does. `endpoint install --connect`
and the onboarding wizard skip that sweep, because the install has just run it. Then, before the
forwarder starts, Beacon copies the events those sweeps wrote (`harness.collection_method=poll`,
timestamped in the last 30 days, newest kept up to 24 MiB) from the runtime log and its archives
@@ -59,11 +60,14 @@ the beginning into the same runtime upload, through the same privacy transform a
Metadata-only strips the backfill exactly as it strips live telemetry. Hook, OTLP and plugin events
recorded before the connection stay local.
-Only a first connect stages the backfill. A re-connect resumes from the forwarder's checkpoints;
-one that changes the privacy mode clears them and deletes the staged file, so nothing is uploaded
-twice. `disconnect` removes the file. The dashboard collapses any re-sent event on its
-deterministic event id. `--no-backfill` or `BEACON_BACKFILL=0` connects without uploading any
-history. System-mode connects never backfill.
+A re-connect stages the backfill again, so sessions the agents wrote while the endpoint was
+disconnected, or before a system endpoint had a console user to read for, still arrive. The runtime
+upload resumes from the forwarder's checkpoints, and the forwarder reads each newly staged file as a
+new file from the beginning (it fingerprints the file by inode). That can resend events the
+forwarder already shipped; every event keeps the deterministic event id it was written with, and
+the dashboard collapses a re-sent event on it. A privacy-mode change clears the checkpoints and
+replaces the staged file, so the backfill is resent in the new mode. `disconnect` removes the file.
+`--no-backfill` or `BEACON_BACKFILL=0` connects without uploading any history.
## Privacy modes
@@ -90,7 +94,7 @@ are not uploaded under the new one.
| Pending-connect marker (only while a connect is unfinished) | `~/.beacon/endpoint/asymptote/connect-pending` (0600, timestamp and reconnect flag only) | `…/Endpoint/asymptote/connect-pending` | `/etc/beacon/endpoint/asymptote/connect-pending` |
| Device key | `~/.beacon/endpoint/asymptote/vector-secrets.json` (0600) | `…/Endpoint/asymptote/vector-secrets.json` | `/etc/beacon/endpoint/asymptote/vector-secrets.json` |
| Vector config | `~/.beacon/endpoint/asymptote/vector.toml` (0644, no secret) | `…/Endpoint/asymptote/vector.toml` | `/etc/beacon/endpoint/asymptote/vector.toml` |
-| Staged session backfill (first connect only) | `~/.beacon/endpoint/logs/cloud-backfill.jsonl` (0600) | not written | not written |
+| Staged session backfill | `~/.beacon/endpoint/logs/cloud-backfill.jsonl` (0600) | `cloud-backfill.jsonl` beside the system runtime log (0600) | `cloud-backfill.jsonl` beside the system runtime log (0600) |
| Buffer and checkpoints | `~/.beacon/endpoint/asymptote/vector-data/` | `…/Endpoint/asymptote/vector-data/` | `/etc/beacon/endpoint/asymptote/vector-data/` |
| Service | `~/Library/LaunchAgents/com.beacon.endpoint.asymptote-forwarder.plist` | `/Library/LaunchDaemons/com.beacon.endpoint.asymptote-forwarder.plist` | `/etc/systemd/system/beacon-asymptote-forwarder.service` (user mode: `~/.config/systemd/user/`) |
@@ -104,7 +108,7 @@ The directory is `0700`. The device key appears only in the secrets file, which
| `--no-browser` | System mode only: print the approval URL instead of opening a browser |
| `--vector-bin <path>` | Vector binary to run |
| `--privacy-mode <mode>` | Override the onboarding choice with `standard` or `metadata-only` |
-| `--no-backfill` | On a first connect, do not upload the [session backfill](#session-backfill). `BEACON_BACKFILL=0` does the same |
+| `--no-backfill` | Do not upload the [session backfill](#session-backfill). `BEACON_BACKFILL=0` does the same |
| `--user` | Use per-user endpoint paths. Enabled by default |
| `--system` | Use system endpoint paths and a LaunchDaemon or system unit. Requires root; the browser opens as the active console user |
| `--log-path <path>` | Runtime JSONL log path |
diff --git a/docs/cli/endpoint-install.mdx b/docs/cli/endpoint-install.mdx
index 044724f4..bd332ebb 100644
--- a/docs/cli/endpoint-install.mdx
+++ b/docs/cli/endpoint-install.mdx
@@ -57,7 +57,7 @@ The `claude` harness writes both Claude Code's OpenTelemetry settings and its us
## Session backfill
-After a successful user-mode install, Beacon reads the last 30 days of agent sessions from each
+After a successful install, user or system mode, Beacon reads the last 30 days of agent sessions from each
runtime's own session store into the runtime log, so the [local dashboard](/cli/dashboard) has
your recent sessions before any agent runs again. It is the same sweep each runtime's sync command
runs (`beacon endpoint claude sync`, `codex sync`, `cursor sync`, `opencode sync`, `copilot sync`,
@@ -76,9 +76,14 @@ left out are not touched, so the runtime's sync command reads the rest; install
for each runtime that hit the limit. A runtime whose store cannot be read is reported as a warning
and never fails the install. Re-running install reads only what changed since the last sweep.
-The backfill runs only for user-mode installs: system, package, MDM and `--dry-run` installs skip
-it. Turn it off with `--no-backfill` or `BEACON_BACKFILL=0`. If this install also connects to
-Beacon Cloud, the same history is [uploaded on the first connect](/cli/endpoint-connect#session-backfill).
+A system, package or MDM install runs as root, whose home holds no agent sessions, so it reads the
+session stores of the active console user instead: the same person system hook repair and the
+scheduled inventory resolve (`SUDO_USER` or the logind seat on Linux, the console owner on macOS,
+the active session on Windows). Its collector cursors stay under the system base directory. When
+nobody is logged in, install says the backfill was skipped and the next connect or manual sync
+reads the sessions. `--dry-run` installs skip it, and `--no-backfill` or `BEACON_BACKFILL=0` turn it
+off. If this install also connects to Beacon Cloud, the same history is
+[uploaded by the connect](/cli/endpoint-connect#session-backfill).
## Interactive onboarding wizard
diff --git a/docs/cli/endpoint-paths.mdx b/docs/cli/endpoint-paths.mdx
index 1c5f9b27..fcf894c1 100644
--- a/docs/cli/endpoint-paths.mdx
+++ b/docs/cli/endpoint-paths.mdx
@@ -12,7 +12,7 @@ Beacon manages different paths depending on whether you install in user mode or
| Config | `~/.beacon/endpoint/config.json` | `/Library/Application Support/Beacon/Endpoint/config.json` | `/etc/beacon/endpoint/config.json` | `%ProgramData%\Beacon\Endpoint\config.json` |
| Base directory | `~/.beacon/endpoint` | `/Library/Application Support/Beacon/Endpoint` | `/etc/beacon/endpoint` | `%ProgramData%\Beacon\Endpoint` |
| Runtime log | `~/.beacon/endpoint/logs/runtime.jsonl` | `/var/log/beacon-agent/runtime.jsonl` | `/var/log/beacon-agent/runtime.jsonl` | `%ProgramData%\Beacon\Endpoint\logs\runtime.jsonl` |
-| Staged Beacon Cloud session backfill (written by a first connect) | `~/.beacon/endpoint/logs/cloud-backfill.jsonl` | not written | not written | not written |
+| Staged Beacon Cloud session backfill (written by each connect) | `~/.beacon/endpoint/logs/cloud-backfill.jsonl` | `/var/log/beacon-agent/cloud-backfill.jsonl` | `/var/log/beacon-agent/cloud-backfill.jsonl` | `%ProgramData%\Beacon\Endpoint\logs\cloud-backfill.jsonl` |
| Rotated runtime archives | `~/.beacon/endpoint/logs/runtime.jsonl.1` through `.5` | `/var/log/beacon-agent/runtime.jsonl.1` through `.5` | `/var/log/beacon-agent/runtime.jsonl.1` through `.5` | `%ProgramData%\Beacon\Endpoint\logs\runtime.jsonl.1` through `.5` |
| Threat rule store | `~/.beacon/endpoint/rules` | `/Library/Application Support/Beacon/Endpoint/rules` | `/etc/beacon/endpoint/rules` | `%ProgramData%\Beacon\Endpoint\rules` |
| Collector config | `~/.beacon/endpoint/otelcol.yaml` | `/Library/Application Support/Beacon/Endpoint/otelcol.yaml` | `/etc/beacon/endpoint/otelcol.yaml` | `%ProgramData%\Beacon\Endpoint\otelcol.yaml` |
diff --git a/docs/log-forwarding/asymptote.mdx b/docs/log-forwarding/asymptote.mdx
index fd216d91..a2fbc9cb 100644
--- a/docs/log-forwarding/asymptote.mdx
+++ b/docs/log-forwarding/asymptote.mdx
@@ -16,7 +16,7 @@ Generate the pack with [`beacon endpoint asymptote`](/cli/asymptote). `beacon en
For runtime telemetry, Standard mode forwards every line written after the
forwarder starts exactly as Beacon wrote it locally. Pre-connect runtime history is
not sent, except the bounded [session backfill](/cli/endpoint-connect#session-backfill)
-a first user-mode connect stages: the last 30 days of events read from the agents'
+each connect stages, in user and system mode: the last 30 days of events read from the agents'
own session stores (at most 24 MiB), which go through the same privacy transform.
Inventory is read from the beginning of `inventory_state.jsonl` so a
newly connected endpoint sends its current inventory baseline, including inventory