Skip to content

perf: warm-deploy agent loop — drive < 4 s rebuild+verify+reconnect budget #114

Closed

Description

@zackees

Goal

Warm rebuild + deploy + monitor reconnect on ESP32-S3 should complete end-to-end in under 4 000 ms when:

  1. No source / config / toolchain changes since the last build.
  2. The device already holds the exact firmware image (verify-flash MD5 match).
  3. The serial monitor is expected to reattach and receive the first JSON-RPC byte.

"Auto-research" is the SerialMonitor.auto_reconnect behaviour — the monitor reattaching after a deploy preempts the serial session.

Budget tree (total: 4 000 ms)

Phase Budget
CLI → daemon handshake 200 ms
Daemon lock + dispatch 100 ms
Warm-build fingerprint hit (no compile, no link) 500 ms
Verify-flash MD5 match (3 regions) 1 500 ms
Serial port re-open + WebSocket reattach 700 ms
TTFB (first JSON-RPC byte from device) 1 000 ms
Slack 0 ms

Agent loop

The full spec — test matrix, per-iteration procedure, decision rules, outputs — lives at LOOP.md in the repo root (landed in #113 / `cacba6f`). It is invokable with the `/loop` skill:

```
/loop @./LOOP.md
```

Every iteration appends a row to `tasks/loop-runs/RESULTS.csv` and the agent judges each capture against the budget tree. On three consecutive green T1–T3 iterations, the loop writes `tasks/loop-runs/SUMMARY.md` and terminates; on five attempts without improvement, it files a follow-up issue and stops.

Known suspects (from existing investigation)

From docs/PERF_WARM_BUILD.md (issue #91):

  • First warm build after a daemon restart spends ~68 s in the ESP32 orchestrator even with the fingerprint populated.
  • Second warm build still takes ~1.3 s because `fp-watches-collect` walks thousands of files and zccache re-verifies.
  • Fix direction: split the fast-path fingerprint into in-memory + on-disk layers.

From #66:

Deliverables

  • `LOOP.md` committed (docs(perf): LOOP.md — warm-deploy agent loop spec #113)
  • First pass of the loop against real ESP32-S3 hardware to confirm or tune budgets
  • Follow-up issues for any phase that consistently breaches its budget
  • Close when T1–T3 land inside the total budget for three consecutive iterations

Related: #91 (warm-build investigation), #66 (espflash migration).

Activity

  1. zackees commented on Apr 18, 2026

    @zackees
    MemberAuthor

    Phase (b) landed in #116 (8858dda). The session-trusted verify-skip is now opt-in via FBUILD_TRUST_DEVICE_HASH=1.

    Status of the 4 s budget tree:

    • Warm build (T1): AVR reference measured at 211 ms on tests/platform/uno — the fingerprint fast-path is already well inside the 500 ms budget slot.
    • Verify-skip deploy (T2): with FBUILD_TRUST_DEVICE_HASH=1, the server-side cost drops from ~1.5 s (espflash MD5 round-trip) to ~50 ms (SHA-256 compute + cache lookup + early return). Plus the USB re-enum poll is now skipped on VerifySkip outcome, recovering another 100–3000 ms on the warm path.
    • Deploy + monitor reconnect (T3): end-to-end hardware measurement on the attached ESP32-S3 (COM13) was attempted but blocked — the ESP32 cold bring-up stalls mid-Arduino-framework-library compile with no active compiler processes, staying operation in progress for 15+ minutes. Unrelated to this work; filing a follow-up issue for the orchestrator stall.

    Remaining on this tracker:

  2. zackees commented on Apr 18, 2026

    @zackees
    MemberAuthor

    Sub-1 s best-case follow-up landed in #118 (c01ad5d). Two micro-optimizations on top of the trust-skip:

    • ImageHashMemo on DaemonContext — keys on (firmware_path, bootloader_mtime, partitions_mtime, firmware_mtime) so warm redeploys skip the 2–4 MB disk read + SHA-256 (~5–15 ms saved).
    • DeviceManager::refresh_devices_if_stale(2s) — avoids the 20–30 ms Windows port enumeration on back-to-back deploys.

    Net server-side cost on a warm trust-skip deploy: ~50 ms → ~1–2 ms. Remaining non-trivial slice in the 1 s budget is the warm-build fingerprint (~100–300 ms) — tracked against #91. Once that lands, the full warm fbuild deploy --monitor path should hit sub-1 s in the cached-device / persistent-monitor best case.

  3. zackees commented on Apr 18, 2026

    @zackees
    MemberAuthor

    Warm-build fingerprint cache landed in #120 (1316fe0).

    Budget breakdown now:

    Follow-ups filed from the #120 self-review:

    Remaining on this tracker:

  4. zackees commented on May 10, 2026

    @zackees
    MemberAuthor

    First-pass loop result on real hardware (ESP32-S3-DevKitC-1, native USB-CDC, Windows 10, fbuild release build from feat/114-warm-deploy-loop-first-pass):

    iter full loop wall-clock budget margin
    1 3.587 s 4.000 s +413 ms
    2 3.590 s 4.000 s +410 ms
    3 3.697 s 4.000 s +303 ms
    4 3.585 s 4.000 s +415 ms
    5 3.605 s 4.000 s +395 ms

    5/5 inside 4 s; mean 3.613 s, max 3.697 s, lowest margin 303 ms. Deploy-only (no monitor) is ~2.6 s steady-state. The ~1 s extra is the test sketch's delay(500)×2 loop period (next Serial.println cadence), not deploy/reconnect cost.

    All sub-budgets cleared without any phase consistently over, so no follow-up perf issues filed. Loop spec (LOOP.md) retired — it was already .gitignore'd after #115; local copy removed.

    Acceptance criteria from the OP:

    Closing notes + table land in docs/PERF_WARM_DEPLOY.md via #230.

  5. added a commit that references this issue on May 10, 2026
  6. zackees commented on May 11, 2026

    @zackees
    MemberAuthor

    All acceptance criteria met — closing.

    • LOOP.md committed (docs(perf): LOOP.md — warm-deploy agent loop spec #113)
    • First pass against real ESP32-S3 hardware (5/5 iterations 3.585–3.697 s, all inside 4 000 ms budget)
    • No follow-up perf issues needed — no phase consistently breached its sub-budget
    • T1–T3 inside total budget for three consecutive iterations — five consecutive, lowest margin 303 ms

    Results captured in docs/PERF_WARM_DEPLOY.md via #230 (merged).

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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions