Skip to content

Deepen Fleet Run metrics source capture #2090

Description

@JacobStephens2

What to build

Deepen the Fleet Run metrics module so one Console Metrics request or explicit Fleet metrics CLI invocation observes saved sources once. Default view selection, machine choices, chosen-machine validation and report loading should agree on those observations, including when a saved file changes during the operation.

Keep existing metrics results, machine ordering, access rules and saved formats. This is one standalone Ticket: the discovery and fallback implementation, both callers, and their verification fit one fresh session. It requires no release or host migration.

Acceptance criteria

  • The Console and CLI use one operation-owned Fleet metrics capture. Default selection, machine choices, chosen-machine validation, retired sources and configured-peer saved fallback use that capture's observations; obsolete independent discovery entry points are removed.
  • Each capture lists the snapshot directory at most once and reads/decodes each distinct candidate path at most once, including missing, unreadable, malformed and unsupported-version results. Directory discovery and exact configured-slot reads share observations without changing their different eligibility rules.
  • Retain personal-read and reported slots separately. Link-only configured machines use only their exact reported slot; unavailable paired machines choose the newest eligible exact personal-read or reported slot; refused and incompatible peers never use saved fallback. Retired machines use the newest eligible discovered snapshot. Preserve existing timestamp ties and choose the slot before choosing a compatible view.
  • Preserve person isolation, reported visibility, configured order followed by sorted retired/reporting names, local-machine exclusions at their existing projections, unknown-machine errors, status/age/error metadata, view retention, other-window substitution and regrouping, comparison omission and failure-window trimming.
  • Keep live transport credential/destination revalidation and locked writer reloads independent of the read capture. A successful live result still displays when saving fails; concurrent writes still retain their views. Local metrics and the local HTTP metrics route do not fetch peers or construct an unnecessary Fleet capture.
  • Tests cross the capture's interface with native and counting/scripted filesystem adapters. Joint projections demonstrate one listing and one observation per exact path, stable positive and negative observations after file edits, and freshness in a new capture. Include directory-list failure with readable exact slots, unexpected filenames, both slot types, equal timestamps, and a newer slot lacking the requested view.
  • Existing CLI/Console Fleet, offline/retired, reported, person-isolation and local-route regressions pass. Add caller-level coverage that ensures the Console reuses its capture for choices and loading, rather than constructing another one between projections.
  • Update the domain-to-code index for the owning module and tests. The change introduces no new domain concept or persistent decision requiring a glossary entry or ADR.
  • Run focused Fleet metrics and Console metrics/report/person-isolation checks during implementation, then the repository's affected-test selector against main for final validation.

Blocked by

None (can start immediately).

Decisions

The design tree is settled in three rounds: scope and lifetime; source observations, eligibility and execution; tests and delivery. Each decision below follows from those before it; no human choice remains.

  1. Scope: deepen saved-source ownership, preserving behavior. Concentrate discovery, slot eligibility and saved fallback selection inside the existing Fleet Run metrics module. Keep aggregation and rendering as their current projections. Reason: repeated source observations are the demonstrated friction; adding signal groups, remote History or filters would bring unrelated product decisions into this Ticket.
  2. Lifetime and interface: one capture per operation. Capture the already-loaded configuration, local machine name and optional viewing person for one Console Metrics request or explicit Fleet CLI read. Expose default-view selection, other-machine names and loading through that same object; hide saved records and slot policy inside its implementation. Reason: the interface should own the shared observations and their lifetime, rather than require callers to coordinate independent functions. No process-wide cache or sharing between people is introduced.
  3. Keep local reads direct. The local CLI path, single-Command metrics inspection and local HTTP metrics route retain their direct local reading path. The Console creates the capture only when its HTML machine choices or Fleet result need it. Reason: ADR 0026 keeps owning-machine reads local, and a local result needs no peer snapshot discovery.
  4. Capture both discovery and exact-slot facts. Enumerate candidate JSON paths once, retaining enumeration order/membership, and union them with the expected personal-read and reported paths for configured machines. Observe/decode each distinct path once, retaining failures as well as successes. Reason: later projections must not re-read a changed file, while configured fallback must still work when directory enumeration fails but an exact slot is readable. The observation is per file, not a promise of an atomic filesystem-wide instant.
  5. Preserve the two eligibility rules. Directory discovery continues to consider only enumerated JSON entries and their existing version/person/reported checks; an unexpected filename can remain discoverable as today. Configured-peer fallback continues to require the expected digest pathname plus matching machine and slot payload. Reason: substituting a directory-discovered payload for an exact slot would expand which data configured-peer fallback accepts. Extra exact-path observations do not become discovered retired machines.
  6. Retain slots until the projection selects them. Keep eligible personal reads and reports separately, rather than reducing each machine to one winner during capture. Link-only peers use their exact report even when a personal read is newer; unavailable peers compare both exact slots; retired machines use the discovered winner. Reason: early reduction loses information required by these existing rules. Unavailable ties retain the report; discovery ties retain the first enumerated eligible entry. Preserve selection of the newest slot even if an older slot happens to contain a more useful view.
  7. Keep discovery presentation stable. Preserve configured machine order, append sorted discovered retired/reporting names, and apply the existing local-name and configured-name exclusions in the projections that currently own them. Keep the current default predicate, including its tolerant credential lookup and eligible-snapshot test. Reason: changing inventory ownership should not change default choice, selectable names or duplicate counting.
  8. Keep execution fresh where required. Read capture does not authorize requests or retain bearer tokens for later use. Existing transport selection still reloads credentials and validates the destination before sending them; link-only peers still send no probe. Preserve the current credential-error classification, including unavailable fallback. Refused or incompatible live reads never fall back. Reason: stable saved observations do not replace fresh access checks.
  9. Keep writes outside the capture. Successful live reads return their live summary and independently save it; report reception and saves still lock their slot, reload its current file, merge views and atomically replace it. Never use a captured file as the basis of a write. Reason: read reuse must not lose a concurrently saved view or convert a convenience-save failure into a failed live result. A later operation sees new writes through a new capture.
  10. Retain existing view interpretation. Run saved-view lookup, same-filter other-window substitution, daily-to-weekly regrouping, comparison checks and window trimming against the selected captured slot. Materialize the selected summary internally without exposing mutable saved state. Reason: source capture must not alter metrics calculations, compatibility or missing-view diagnostics.
  11. Use a private filesystem seam with two adapters. Supply native filesystem observations in production and a counting/scripted adapter in tests, through an internal constructor. Do not expose filesystem methods or reuse the unrelated Command/Session Log inventory. Reason: listing, reads and negative observations genuinely vary here; keeping that seam internal provides test leverage without enlarging the callers' interface.
  12. The interface is the test surface. Exercise default choice, names, validation and load together, mutate fixture files between projections, then repeat with a fresh capture. Cover successful, absent and invalid observations; duplicate paths; projection-specific filename eligibility and slot precedence; and a live refusal despite available snapshots. Keep existing end-to-end CLI/Console tests and replace redundant private discovery tests when the interface tests cover their behavior. Reason: isolated parsing/selection tests cannot establish that callers share observations. Count read-side observations separately from intentional writer reloads.
  13. One Ticket, no retained-data or domain migration. Deliver the module and both caller changes together, with the code-navigation update and final affected checks. Reason: this is a bounded internal refactor; Fleet, Run metrics and their existing definitions already name the work. Its transient capture is an implementation choice, so neither a new glossary term nor an ADR is warranted. ADR 0016/0026 remain satisfied.

Architecture review

Strength: Strong · Dependencies: local-substitutable

Files: src/logs/metrics/fleet.rs, src/logs/metrics.rs, src/console/metrics.rs, src/logs/metrics/fleet/tests.rs, tests/console/metrics.rs, tests/console/metrics_report.rs, tests/console/fleet_control.rs, docs/code-navigation.md

Before

flowchart LR
  C[Console Metrics] --> D[Default choice]
  C --> N[Machine choices]
  C --> L[Fleet metrics load]
  K[CLI Metrics] --> L
  L --> N
  L --> R[Peer fallback]
  D -.-> S[Saved snapshots]
  N -.-> S
  L -.-> S
  R -.-> S
  classDef leak stroke:#dc2626,stroke-width:2px;
  class D,N,L,R leak
Loading

After

flowchart LR
  C[Console Metrics] --> F
  K[CLI Metrics] --> F
  subgraph F[Captured Fleet metrics module]
    D[Default choice] --> I[Captured source facts]
    N[Machine choices] --> I
    L[Fleet metrics load] --> I
    L --> R[Peer fallback]
    R --> I
  end
  I --> S[Saved snapshots]
  classDef deep stroke-width:3px;
  class F deep
Loading

Problem: default choice, machine choices, selected-machine validation and fallback repeatedly observe saved snapshots, spreading source eligibility and precedence across their implementations.

Evidence:

Solution: deepen the Fleet metrics module with one captured-source interface and an internal filesystem seam, retaining existing transport and writer adapters.

Deletion test: deleting the deep capture would redistribute discovery, negative observations and slot-selection knowledge across the callers; retaining the shallow independent functions would lose that depth.

Wins

  • Locality: one source-policy implementation
  • Leverage: CLI and Console projections
  • Tests cross one captured interface
  • One observation per saved path

Coverage: all 176 open issue titles and bodies were checked, then refreshed before publication; none covers this deepening. #2087 concerns additional Fleet metrics features. This internal refactor preserves ADR 0016/0026 and their existing access rules.

Activity

  1. added
    needs-triage
    ready-for-agent
    architect-plan
    in-progress
    and removed
    needs-triage
    ready-for-agent
    in-progress
    on Nov 12, 2026
  2. removed
    in-progress
    on Nov 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    architect-plan

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions