Skip to content

fleet gh: four-tier fallback chain with bounded mints (code#16826) - #16833

Merged
developing-today-fleet[bot] merged 1 commit into
mainfrom
feat/gh-fallback-chain
Nov 29, 2026
Merged

developing-today-fleet[bot] merged 1 commit into
mainfrom
feat/gh-fallback-chain

Conversation

@developing-today-fleet

@developing-today-fleet developing-today-fleet Bot commented Nov 29, 2026 •

Copy link
Copy Markdown
Contributor

Part of #16826 — the pkgs/fleet client + daemon half of the gh-daemon resilience programme (Drew's order, 2026-11-29). Design: pkgs/fleet/docs/fleet-gh-fallback-chain-design.md (landed in this PR); agent last-resort runbook: pkgs/fleet/docs/runbook-agent-last-resort.md.

What changed

The chain (T1→T2→T3→T4, immediate failover, bounded per tier)

  • Unified tier list (gh/chain.rs): --cache-addr / FLEET_GH_CACHE / config entries parse into CacheTier::{Tcp, Https}; an https:// entry is the tier-3 Cloudflare endpoint, http:// is a hard parse error, list position is chain position. Config/defaults append [gh] cache_cf_url as the last tier.
  • FleetTokenProvider::via walks tiers per rotation candidate: TCP daemon (connect 2s, whole request 5s — was 60s) → CF GET /token (8s, bearer resolved by broker NAME from [gh] cache_cf_token_name, fleet-App candidates pass ?owner=) → in-process tier 4. A daemon error answer no longer ends the walk. Tier 3 is consumed once per invocation (later candidates skip it rather than re-run gh under the identical token).
  • Failure caching: in-walk memo of transport-failed tiers; cross-invocation stamp file ~/.cache/fleet/gh-tier-failures.json (tier id + class + timestamp only; connect 60s, timeout/http-status/bad-body 30s; a hit clears the entry; corrupt file = empty cache). ALL-DOWN errors name every tier and its failure class.
  • cache-status: one line per tier incl. the CF line (UP http=200 token_ttl=… latency=… / DOWN http=… / NOT-CONFIGURED); exit 3 only when no tier answered.

Daemon side (gh_cache)

  • Single-flight wait bounded at 10s (Condvar wait_timeout): the waiter gets the cached-failure answer while the mint continues on its own thread and populates the cache.
  • Mint/resolution failures cached 30s (new — see deviations).
  • Mint upstream bounded: the shared RawMinter ureq agent goes 60s/10s → 15s total / 5s connect, covering both the daemon mint and tier-4 in-process mint.

Config (fleet-config): [gh] cache_cf_url + cache_cf_token_name (broker NAME only), env overrides FLEET_GH_CACHE_CF_URL / FLEET_GH_CACHE_CF_TOKEN_NAME, blank-field load errors, URL entries pass through gh_cache_addrs unmangled.

Deviations from the patch plan (recorded on #16826)

  • The crate is synchronous (std threads + ureq + Condvar, no tokio/reqwest): bounds are TcpStream read timeouts, a ureq agent timeout, and wait_timeout, not tokio timeouts.
  • The shipped daemon had no failure cache to align from <60s — one was added at the design's 30s.
  • Broker resolution is already bounded in fleet-secrets (BROKER_ATTEMPT_TIMEOUT = 10s); kept per design §5's allowance (design suggested 5s for a new bound).
  • Docs landed in pkgs/fleet/docs/ instead of doc/agents/: the working checkout is sparse (pkgs/fleet only) and three bounded attempts to expand it to doc/ failed on the day's flaky egress. pkgs/fleet/docs/ is the fleet docs home of fleet-gh-credentials.md, which now cross-links both documents.

Tests

New unit tests (oracle-named per house doctrine): tier entry parsing; CF config precedence/blank rules; chain construction order + precedence; CF client contract over loopback (Authorization asserted server-side; 200 HIT, 503 → http-status, hang → timeout within budget); CF body/skew-guard contract; negative-cache TTLs + corrupt stamp; walk failover dead→live daemon; daemon-error continuation + loud ALL-DOWN; hanging-daemon walk reaching tier 4 within the 5s budget; bounded single-flight wait with the mint landing detached; daemon failure caching; hanging-daemon client fetch bound; cache-status exit codes.

Verification evidence (CI / Actions exec results and e2e timings) will be recorded on #16826 as it lands.

{
  "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-29T15:09:30Z",
    "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)"
  }
}

Open in [code]smith · Need help on this PR? Tag @codesmith-bot with what you need.

Implements code#16826 (gh-daemon resilience programme, 2026-11-29): the token-resolution walk is now T1 local daemon -> T2 laptop daemon -> T3 Cloudflare token endpoint (HTTPS, [gh] cache_cf_url + cache_cf_token_name broker name) -> T4 in-process direct, failing over immediately under the design budget (connect 2s, daemon request 5s, CF request 8s, mint upstream 15s, single-flight wait 10s, broker already bounded at 10s in fleet-secrets).

Daemon-side (gh_cache): bounded single-flight wait via Condvar wait_timeout with the cached-failure answer while the mint continues on its own thread; mint/resolution failures cached 30s; client daemon request timeout cut from 60s to 5s.

Client-side (gh + gh/chain + gh/cache_serve): unified CacheTier list (https:// entry kind, http:// hard error, list position = chain position), in-walk failure memo, cross-invocation negative-cache stamp file (~/.cache/fleet/gh-tier-failures.json; connect 60s, other classes 30s; tier ids/classes/timestamps only), ALL-DOWN error naming every tier and failure class, cache-status extended with the CF line (UP/DOWN/NOT-CONFIGURED, counts-only, exit 3 only when no tier answered).

Config (fleet-config): [gh] cache_cf_url + cache_cf_token_name (name only, never a value), FLEET_GH_CACHE_CF_URL / FLEET_GH_CACHE_CF_TOKEN_NAME env overrides, URL entries pass through gh_cache_addrs unmangled.

Docs: design landed at pkgs/fleet/docs/fleet-gh-fallback-chain-design.md with an implementation-status note, agent last-resort runbook at pkgs/fleet/docs/runbook-agent-last-resort.md, cross-linked from fleet-gh-credentials.md.

Tests: tier entry parsing, config precedence + CF keys, chain construction order, CF client contract over loopback (bearer asserted server-side), CF body/skew contract, negative-cache TTLs + corrupt file, walk failover dead->live daemon, daemon-error continuation + loud ALL-DOWN, hanging-daemon walk reaching tier 4 within budget, bounded single-flight wait with detached mint landing, daemon failure caching, hanging-daemon client fetch bound, cache-status exit codes.
@coderabbitai

coderabbitai Bot commented Nov 29, 2026

Copy link
Copy Markdown

Important

Review skipped

Bot user detected.

To trigger a single review, invoke the @coderabbitai review command.

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 757606e6-0062-46f3-b30f-8daf928a8990

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • Trigger review
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

0 participants