Skip to content

Secrets broker cold refresh takes ~3-4 min (242 per-secret bws spawns); clients hang instead of falling back while it refreshes #13893

Done

Description

@dezren39

Problem (measured 2026-11-23, BROKER-HEALTH-PERF lane)

The sandbox secrets broker's cold refresh takes ~160–220s (observed 00:00:56Z→00:03:30Z for the refresh that produced serving:true, secrets:242). Cause: the broker shells out to bws secret get <id> once per secret — 242 subprocess spawns per refresh, ~10–14 concurrent, each a network round trip. Refresh runs at startup and every 900s.

Worse, while the local broker is present-but-refreshing, clients do not fall back: fleet secrets get <name> hung >120s (killed by timeout) at 00:00Z even though the laptop tier was healthy. 22 fleet gh/secrets client processes were found piled up behind the refreshing broker. The tiered shape (local → laptop → in-process) only helps if the client gives up on a non-serving local broker promptly.

Proposed fixes

  1. Batch the refresh: bws secret list returns every secret (id, key, value) in ONE call — the heal script already relies on its shape. Replace the 242 per-secret gets with one list call (keep per-secret get as a fallback for any secret missing from list output). Expected cold refresh: seconds, not minutes.
  2. Bound the client wait on a non-serving local broker: if the local broker health is not serving:true within a short bound (~2–5s), fall through to the laptop tier instead of blocking indefinitely. A refreshing broker should be a cache miss, not a wedge.
  3. Consider a parallelism bump as a stopgap if (1) is deferred (10–14 concurrent bws children observed; the wall time is latency-bound).

Context

This is the same incident family as the 2026-11-23 restart loop (heal killing a mid-refresh broker): even with the kill loop fixed, a 3–4 minute non-serving window after every sandbox restart wedges every secrets consumer in the fleet.

{
  "direct_parent": null,
  "links": [],
  "lineage": {
    "design": null,
    "roadmap_item": null,
    "priority": null
  },
  "pm_meta": 1,
  "provenance": {
    "queue_id": null,
    "scheduled_start": null,
    "picked_up_at": null,
    "work_started_at": null,
    "created_at": "2026-11-24T00:16:50Z",
    "session_id": null,
    "lane": null,
    "host": "htch-runtime",
    "worktree": null,
    "model": null,
    "lane_start_issues": [],
    "workspace_ref": null,
    "auth_subject": "archer",
    "stamped_by": "fleet 0.1.0 (native)"
  }
}

Activity

  1. developing-today commented on Nov 24, 2026

    @developing-today
    Contributor
  2. dezren39 commented on Nov 24, 2026

    @dezren39
    MemberAuthor

    Direction update (Drew, 2026-11-23 ~19:12 CST) — design filed as #13948

    Drew has set the direction for the secrets plane, and it changes what "fixed" means for this issue. The full design is #13948; the dated record lands in doc/ alongside it. In substance:

    1. Delta refresh. Don't just batch the refresh — capture what changed. bws secret list returns a per-secret revisionDate (verified live by the filing lane: one call, 244 secrets, values + timestamps), so a refresh pulls/applies only secrets updated since just before the last refresh started.
    2. Broker-to-broker peer sync. A broker checks its trusted peer (sandbox ↔ laptop): if the peer refreshed within the window, pull the changes as a delta directly from the peer. A hash over the whole set is the sync proof — equal hashes mean synced. V1 simplification Drew explicitly allows: the peer payload is the full set; namespaces and selective pull-back come later if requirements diverge. Consequence: the sandbox broker needs a full upstream refresh only if the laptop is down AND it restarted with no cache.
    3. Client surface. fleet secrets get gains --upstream and --no-cache flags; fleet secrets refresh and fleet secrets put are added (verified at filing: fleet secrets today has only get and list — it is read-only).
    4. Put propagation. A put commits to the primary store first, then the value is pushed directly to the peer broker and the mirror store so neither has to re-fetch; a node holding only one store escalates the put upstream to the laptop, which always has both.
    5. Dual-store, always in sync. Puts go to BOTH Bitwarden Secrets and 1Password. One store is designated primary so sync direction is unambiguous — the design recommends Bitwarden Secrets primary, 1Password mirror (against Drew's initial lean, on evidence: the broker stack already runs headless on Bitwarden machine tokens, and Bitwarden's list is the only one-call delta source; 1Password's list is metadata-only and its service accounts are rate-limited). Ratification is an open question on design: secrets plane — delta refresh, broker peer sync, dual-store puts #13948, decider Drew.
    6. Two companion to-dos filed as future work: to-do: embed 1Password + Bitwarden Secrets access in the fleet binary (configurable feature) #13950 (embed both stores in the fleet binary as a configurable feature) and to-do: fleet init — one-time-token bootstrap as a fleet command #13952 (fleet init one-time-token bootstrap command; the token-generation command's name is an open question).

    Supersession, precisely: this issue's fix 1 (one-call batch list) is absorbed into #13948 as the full-refresh mechanism inside Slice 1/2 — batching alone is no longer the end state. Fix 2 (bound the client wait on a non-serving broker) survives unchanged as part of #13948 Slice 1. Fix 3 (parallelism stopgap) is dropped: delta + one-call list make it moot. This issue stays open until Slice 1 lands its evidence, per the acceptance criteria on #13948.

  3. dezren39 commented on Nov 24, 2026

    @dezren39
    MemberAuthor

    S1 closure evidence (task 21621, lane oc-code-03): merged-ready PR #14021 replaces the 242 per-secret bws spawns with one bws secret list call — measured cold refresh 244 secrets in 2.52s (was 160-220s) — and get-during-refresh now fast-fails (503 in 0.0005s) instead of hanging beyond ~5s. Tests green; full record on #13948.

  4. dezren39 commented on Nov 24, 2026

    @dezren39
    MemberAuthor

    Status note (lane oc-code-03, task 21621 done): S1 evidence is in place — merged-ready PR #14021 (one-call refresh 2.52s, get-during-refresh fast-fail) plus evidence comment 7120154259 above and the S1 record on #13948. Direct closure from this lane is refused by the fleet close-guard (it requires a bound task completion record, which this lane does not hold for this issue). Request: the secrets-plane orchestrator or Archer to execute the closure from the record, citing the evidence above. No further action pending from oc-code-03.

  5. dezren39 commented on Nov 24, 2026

    @dezren39
    MemberAuthor

    Boundary record — Drew's client ruling (2026-11-23 ~21:05 CST) vs S1 (lane CLIENT-FALLBACK-FIX, premise check)

    Drew's ruling, in substance: clients fall back after a regular timeout; if the local broker says it's not serving, go somewhere else and ask them; clients must never hang. Plus the cold-start direction: a cold broker should pull the whole set from a peer broker when that helps; a full upstream cold refresh stays legal but rare.

    Premise-check finding: the client-side half of this ruling is already implemented — by S1 (task 21621, PR #14021, merge-ready and awaiting Archer's merge). This lane is therefore NOT building a second implementation. The mapping, verified against the S1 branch code (pkgs/fleet/crates/fleet-secrets/src/lib.rs) and the S1 evidence already on this issue:

    • Not-serving answer → fall through at once. resolve_with_retry fast-fails the broker's 503 "secrets not loaded yet" answer (including the refresh-failing variant, whose detail carries the same error string), so the resolver chain moves to the next tier immediately instead of spending the restart budget. Measured live by S1: a get issued during refresh returns 503 in 0.0005s and falls through; the refresh itself is now one bws secret list call — cold refresh 2.52s for 244 secrets, was 160–220s — so the wedge window is nearly gone as well.
    • A broker that never answers is bounded, by named constants. BROKER_ATTEMPT_TIMEOUT = 10s per attempt (an accept-but-silent broker fails the attempt; test broker_silent_peer_fails_each_attempt_on_the_attempt_timeout), BROKER_RETRY_BUDGET = 120s total for the budget-owning leg, then the chain falls through to the next tier. Tests also cover the not-serving shape at unit and scripted-broker level (cold_refresh_unavailable_fails_over_without_spending_restart_budget, broker_cold_refresh_response_returns_within_client_bound).
    • One deliberate exception, kept: transient 503/502 answers from the session-broker path during a broker+tunnel restart are retried on the same leg (the 2026-11-15 shape, pinned by broker_retries_unavailable_statuses_then_resolves) — that is path noise, not the broker saying it isn't serving, and it is bounded by the same budget.

    What remains of the ruling, and whose it is:

    1. Merge + deploy PR secrets S1: one-call refresh + client bound (#13948) #14021 (Archer). Until it lands, the running brokers and clients are pre-S1 builds and the ruling is not yet live in the estate. Note for the merge: main has not touched S1's two files since its base, so no content conflict is expected.
    2. Cold-start peer pull = design: secrets plane — delta refresh, broker peer sync, dual-store puts #13948 S4 (with S3's set-hash + peer-status as its prerequisite). That is the broker-side build that makes a cold broker pull the whole set from a peer; there is no peer-status verb in the broker yet for a client-side lane to wire to, so nothing on the client side can be built ahead of S3/S4 without duplicating them. S3/S4 are designed but not yet queued.
    3. Two named residuals (recorded here so they are gaps on paper, not silent ones):
      • The 120s budget is the effective "regular timeout" for a leg that never answers at all. It is sized to span observed broker+tunnel restart windows; Drew's ~2–5s figure in design: secrets plane — delta refresh, broker peer sync, dual-store puts #13948 §5.4 was for the answered not-serving case, which is now immediate. If Drew wants the unanswered case tightened too, it is a one-constant change (BROKER_RETRY_BUDGET) with a real tradeoff against riding out genuine restarts.
      • The fallback tiers' subprocess waits have no timeout: bws / op children are spawned via Command::output() (and the bws --version runnability probe via .status()), so a wedged child would hang the last tier indefinitely. Not part of the measured defect on this issue; named as a follow-up gap for the "clients never hang" ruling.

    Part of #13893. No closing action from this lane: with S1's evidence already recorded here, closure follows Archer's merge of PR #14021 per the S1 acceptance on #13948.

  6. developing-today-fleet commented on Nov 24, 2026

    @developing-today-fleet
    Contributor

    Deployment evidence — S1 live (lane S1-DEPLOY, 2026-11-24)

    This issue was closed 2026-11-24T03:12:34Z on the S1 merge record. The deployment leg of S1's acceptance completed after that closure; this comment supplies it so the record is complete.

    • Artefact: fleet-static-74eee89 (sha256 27eedcf9e0d6a1c251d6bc9ddf41212747f47cbce6d0cfe2cf96ea820708085d, source rev 74eee892e18e…, contains merge 35e5d56b); bootstrap pin PR chore(bootstrap): pin fleet-static-74eee89 — secrets S1 (#13948) #14053 merged b56bdd7.
    • Flips: sandbox seat bcc8043 → 74eee89; laptop CLI f56dc7f → 74eee89; queue broker generation 8 → 9 (activated 2026-11-24T03:45:34Z); secrets broker generation 2 → 3 (activated 2026-11-24T03:47:38Z, flipped at a serving, non-refreshing moment, no live bws children); sandbox-local secrets broker restarted onto the flipped binary. Rollbacks retained at every step.
    • Measured live, post-flip: cold refresh ≈ 2 s (one bws secret list, 257 secrets; laptop broker ≤ ~2.0 s, sandbox broker 1.84 s) vs ~160–220 s pre-S1. Get during a periodic refresh: 14–22 ms, rc=0 ×6 — the broker keeps serving while refreshing. Warm get: 4–5 ms (laptop), median 7 ms / p95 12 ms (sandbox, n=289). Gets issued into a broker restart window took 11.7–15.1 s and one exceeded a 30 s probe cap, bounded by the 120 s retry budget — that residual is tracked on secrets client never-hang residuals: 120s unanswered-leg budget (decision) + unbounded fallback subprocess waits #14040; nothing reproduced the unbounded hang this issue reported.

    Full rollout record: the S1 deployment comment on #13948.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions