carlos / platform Public

plans: fleet box first reconcile speed (phase 1, measure)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
claude agent, operated by paul@keymail.dev pushed by paul@keymail.dev 7c811738f34578473a80028ad90a98922ff34b8b parent ba3a6d6
1 file changed, +108 −0
  • docs/superpowers/plans/2026-11-15-fleet-first-reconcile.md +108 −0

Intent

Human

<paseo-system version="1" kind="agent-message" source-agent-id="adb7ef27-32da-41af-8f54-24ccba176e2e" message-id="ede39e46-55f8-4db7-894a-a5f86ab168bb"> From platform-a9, a fact for step 2: r10r box-1 SERVES shop and railsdemo, the shared dev tenants, so never restart it for measurement. Use a temporary box-2 (ask 8a3d302 for GO and a #421 window) or the local two-box harness. The witness added box-2 the same way twice today; see witness-v0.36.2.md, deviations and method. </paseo-system>

Attributed to this commit: 19.0 g CO₂e (1,284,382 tokens). This is an attribution, not a measurement — usage counted from this commit's own marker forward to the next one on fleet-first-reconcile-speed, never backward from it. A turn that produced more than one commit books all of its tokens to the last one, and a concurrent session on this branch can add to the same figure. Some of it was priced using the shared default rate, because no model-specific factor row exists yet for at least one model involved. The Carbon view has the repo total, which is never derived from this attribution.

diff --git a/docs/superpowers/plans/2026-11-15-fleet-first-reconcile.md b/docs/superpowers/plans/2026-11-15-fleet-first-reconcile.md
new file mode 100644
index 000000000..890eccf66
--- /dev/null
+++ b/docs/superpowers/plans/2026-11-15-fleet-first-reconcile.md
@@ -0,0 +1,108 @@
+# Fleet box first reconcile: from ~17 s to a few seconds
+
+Source: `.superpowers/sdd/2026-11-15-fleet-first-reconcile/HANDOFF.md` (release
+manager 8a3d302, 2026-11-15) and the two witness reports beside it. No design
+spec: this is a latency fix under existing rules. Binding rules the fix must
+keep: the R1 stale-wake fence, R2 restore-required, lease and serving rules,
+region HA (spec §25 and §7.5 of the region HA design; CI must run the
+grouproll tests and the region_ha boundary test), moves spec §9.4 (an unbuilt
+moves hold view freezes every host), the offline keep view rule
+(movesoffline.go), and S3 cost (no new per-box polling).
+
+Review round limit: at most three cross-model rounds per task and for the
+branch.
+
+## Measured (dev r10r box-2, v0.36.2)
+
+Agent start → tunnel +0.2 s → "fast converge loop armed" +9.4 s → first fast
+tick ~2.3 s later → first pass reconcile stage ~9 s (the mint lands ~5 s into
+it, +17 s) → moves stage ~4 s. Nothing logged between tunnel and armed.
+
+## Global constraints
+
+- Fleet boxes read the deployment store through the store door
+ (`internal/fleetapi` client, `internal/edge/storedoor.go` server): every
+ Get/List/ListDirs is one HTTPS round trip over the tunnel.
+- Timing logs must stay quiet in steady state: first pass and startup only,
+ no flag, no per-tick lines after the first full pass.
+- No new periodic store reads. Reordering or parallelizing existing reads is
+ fine; adding reads is not, unless they replace more than they add.
+- Targeted tests only (`go test ./internal/host -run 'X|Y'`), never the full
+ suite locally. Socket-binding packages need `TMPDIR=/tmp/g` with the
+ sandbox off.
+
+## Phase 1: measure
+
+### Task 1: startup timing instrumentation
+
+Goal: one journal line per step from agent start to the end of the first
+full pass, each with its duration, its offset from agent start, and (where
+the step reads the deployment store) the store op counts and summed latency.
+
+1. A process-start instant for the agent (set at the top of `RunAgent`, or the
+ earliest point the agent's own code runs) and a small helper, new file
+ `internal/host/startuptiming.go`:
+ - `countingStore`: a `release.Store` wrapper with atomic counters per op
+ (Get, Put, List, ListDirs, Delete) and summed wall time per op, and a
+ cheap snapshot/diff so a step can report only its own ops. It must pass
+ through any optional interfaces the wrapped store implements that
+ callers type-assert on (check `release` and `internal/host` for
+ type assertions on a Store, e.g. ETag listing, indexed stores); if a
+ pass-through is impractical, do not wrap that call site and log time
+ only.
+ - a step logger: `agent: startup: <step> took <d> at +<since start>
+ (store: get N/<t>, list N/<t>, dirs N/<t>)`, op part omitted when zero
+ or not counted.
+2. In `fastConvergeLoop` (internal/host/agent.go, around lines 3740-3855):
+ log the loop's entry offset, then time each pre-arm step: `heldHolds`
+ setup, `restartSeed`, `armRestartLegs`, `sidecarWakeSeed`,
+ `refreshMovesHolds`, `refreshOfflineView`, `runRunsBootPass`,
+ `sd.converge`, `systemLeg.observe`, and anything else between them that
+ can block on I/O. Pass the counting wrapper as the store argument for the
+ steps that take one. Also log what RunAgent does between "tunnel
+ connected" and starting `fastConvergeLoop` if any of it is synchronous
+ and could block (find out; report it).
+3. The first fast tick: log the sleep before it and time each part of the
+ first `fastTick` that reads the store (observeIndex, moved reader, box
+ role reader, restartGain, ReadSerial, the full pass).
+4. The first full pass (`passLegs.run`, internal/host/changeindex.go): log
+ every stage unconditionally with store op counts for the first run only
+ (later runs keep today's `logSlow` behaviour). Use a counting wrapper on
+ the store for that run only.
+5. Inside reconcile, on the first pass only: an optional trace hook (nil by
+ default, e.g. a `Trace func(stage string)` on `provision.ReconcileConfig`
+ or on reconcileSerialized's path) that the first pass sets, so the journal
+ shows reconcile's own sub-stages (record listing, record reads, policy
+ reads, mint, whatever the code's real phases are) with offsets. Keep the
+ hook's call sites few and coarse.
+6. Tests: the counting store counts and diffs correctly (unit test); the
+ first-pass-only rule holds (a second `run` logs nothing when fast). Use a
+ captured logger, no sleeps.
+
+### Task 2: local measurement with a slow door
+
+Goal: the per-step op counts and a latency model, without a dev box.
+
+1. A test in `internal/host`, skipped unless `CARLOS_MEASURE_STARTUP=1`, that
+ builds a realistic fleet store using the two-box harness
+ (`internal/host/fleettwobox_e2e_test.go`, `newFleetWorld`) or the lighter
+ fixtures it uses: one fleet, two boxes, ~20 instances placed on the box
+ under test, with policies, moves and the rest a drill fleet carries.
+2. Wrap the box's store in a fake door: each op sleeps a fixed latency
+ (default 60 ms, env-overridable) then counts. Run the same startup steps
+ Task 1 instruments, in production order, through the same helpers, then
+ one full pass, and write a table (step, ops by kind, wall time) to the
+ report file.
+3. Report which steps' op counts grow with the number of instances or
+ records (run at 5 and 20 instances), and which reads are serial and
+ independent (candidates to parallelize).
+
+## Phase 2: fix (tasks written after Phase 1's numbers)
+
+Levers named by the handoff, to be chosen from the numbers: arm the loop
+and run the first pass before seeds that do not gate it; run the first pass
+on arming rather than after a tick's sleep; parallelize or batch the store
+door reads inside reconcile and the moves pass, with S3 cost flat; mint
+already-owned records before the moves stage. Deterministic witnesses:
+barrier or fake-clock tests showing the first reconcile is not gated by the
+seeds or the moves pass.