Skip to content

Connection perf: coalesce queue claim flow to 1 round trip, cross-service batch, real file-transfer verb #5757

Done

Description

@dezren39

Coalesce queue claim flow + add a real file-transfer verb (fewer round trips, WS-C census)

Part of epic #5412. Census evidence: WS-C comment on #5701 (2026-11-04). Every sandbox↔laptop round trip costs ~200–600 ms warm, so round-trip COUNT is the lever until/unless the multiplexed-tunnel work lands.

Round-trip census today (code + logs)

Operation Transport round trips Wall (measured)
Single trivial exec (laptop-agent.py exec -- true) 1 (unix to session proxy + 1 pooled-tunnel HTTP request) wall 346–719 ms; trip p50 369 ms
fleet queue claim (one claim) 1 (call("/claim") → one broker_roundtrip → one unix_roundtrip; repo-queue crate crates/repo-queue/src/main.rs cmd_claim/call) ~1 trip ≈ 0.3–0.6 s warm
Claimant launch flow (claim + lane + bind) 3 separate CLI invocations = 3 round trips (cmd_lane, cmd_bind are separate call()s) ~1–2 s warm, ×3 failure surfaces
Detached job to completion (run + poll loop) 1 + N polls (poll sleeps 3 s client-side and re-requests per iteration, laptop-agent.py poll) grows with job length
Small file fetch from laptop NO file verb exists: fetch = 1 exec round trip with base64 -w0 in a shell string (measured 301 ms wall for /etc/hostname), 1 MiB/stream cap, +33% base64 size, no resume/offsets 1 trip + encoding overhead

Also measured: fleet queue health took 2.1 s and 5.8 s in two live probes (vs 0.30 s in the #5701 stage-2 window) — it visibly resolves secrets ("resolved via bitwarden") plus queries, i.e. multiple internal round trips; health should be 1 lightweight trip.

Proposal

  1. Batch endpoint for the claim flow: queue-broker POST /claim-flow {queue, worker, lane, session, launched_by} performing claim+lane+bind server-side (laptop-local, Supabase calls stay on the laptop) and returning the bound row. Client fleet queue claim --bind ... uses it when session info is present; the 3 separate verbs remain for compatibility. 3 trips → 1.
  2. Generic batch already half-exists: the daemon /exec accepts cmds: [...] (exec-batch measured: 10 trivial commands in ONE trip, 483 ms wall total vs ~400 ms EACH singly). Publish this pattern to queue/secrets clients: a /batch on the session-proxy protocol that carries several service requests (mixed ports) in one frame and fans out at the broker. Client libraries coalesce independent calls made in one invocation.
  3. File-transfer verb: daemon GET /file?path=&off=&len= returning raw bytes (Content-Type application/octet-stream, byte-range via query — the jobs poll already proves the offset pattern) + client laptop-agent.py fetch PATH OUT. No base64, chunked by offset, resume = re-request from last offset. Binary framing arrives free if the multiplexed-tunnel work (sibling issue) lands; the verb is useful on today's HTTP path too.
  4. Poll backoff: poll interval 3 s fixed → exponential 1 s → 10 s cap with server-side long-poll option (?wait_s=N holds the request until state change or N s), cutting poll trips for long jobs by ~10×.

Acceptance

  • Claim+lane+bind in 1 round trip (verify in trips/broker logs: exactly 1 trip id per flow).
  • laptop-agent.py fetch of a 5 MiB file: byte-identical (md5), no base64, trips = ceil(size/chunk) with chunk ≥ 1 MiB.
  • Long-job poll trips reduced ≥5× at equal completion-detection latency ≤10 s.

Activity

  1. developing-today commented on Nov 5, 2026

    @developing-today
    Contributor
  2. added
    queue/queued
    task/triage
    on Nov 5, 2026
  3. dezren39 commented on Nov 5, 2026

    @dezren39
    MemberAuthor

    Triage outcome — task 10166 (2026-11-05, lane code-p)

    Verdict: CONFIRMED structurally on current mains — proposal routed as two repo-scoped follow-ups (one set, tracked here). No Drew decision needed; epic #5412 is OPEN.

    Fresh verification (2026-11-05): issue #5757 OPEN, labels task/triage + queue/queued only — no hard-stop labels, one tracking comment only. No duplicate: searches for claim-flow / file-transfer verb return nothing filed.

    Claim-flow (code, pkgs/fleet/crates/fleet-queue/, main 04f78696ab): the client dispatches claim, lane, and bind as three separate commands (client.rs:1328-1330), each its own call() — claim posts to /claim (client.rs:882) — and the broker exposes three separate routes (queue_broker.rs: /claim :382, /lane :393, /bind :402). There is no /claim-flow route. This shift is live evidence: every task worked paid claim + lane as separate round trips. Broker /health is a full handler (:517), consistent with the census's heavyweight-health observation (this shift's health calls also printed the bitwarden resolution line).

    File verb + poll (nix, pkgs/laptop-agent/src/laptop_agent.py, current main): the daemon's GET routes are only /health, /jobs, /jobs/<id> (:420-445) — no /file route exists; POST offers /exec, /jobs, /jobs/<id>/kill. The client poll loop sleeps a fixed 3 s (~/tools/laptop-agent.py:281), matching the census, with no wait_s long-poll parameter on either side.

    Routing (cross-repo set; this issue stays the tracker):

    • Follow-up A (code): POST /claim-flow on the queue-broker performing claim+lane+bind server-side + fleet queue claim --bind client support; the three separate verbs remain. Acceptance = the issue's own: exactly 1 trip id per claim flow in broker logs. This is the fleet's hottest path — every queue task in every lane pays it.
    • Follow-up B (dezren39/darwin-nix): daemon GET /file?path=&off=&len= (raw bytes, offset-chunked) + client fetch (byte-identical, no base64), and poll backoff (exponential 1 s → 10 s cap) with a server-side ?wait_s=N long-poll on the job route. Acceptance = the issue's own md5/≥5× poll-trip criteria.
    • Deferred, explicitly: proposal item 2 (a generic cross-service /batch) — the daemon /exec cmds:[...] batch already exists and no client need beyond the claim flow is demonstrated; revisit only if a second concrete multi-call flow appears. The lightweight-health point folds into follow-up A's broker work as a stretch item, not a separate task.

    agent-note:v1
    {"kind": "triage", "task": 10166, "issue": 5757, "state": "done", "outcome": "confirmed_routed_two_repo_set", "evidence": "client.rs:1328-1330 three separate verbs, broker routes /claim /lane /bind separate, no /claim-flow; nix laptop_agent.py GET routes have no /file; client poll fixed sleep(3) at laptop-agent.py:281"}

  4. added
    work/assigned
    queue/claimed
    status/in-progress
    and removed
    task/triage
    queue/queued
    on Nov 5, 2026
  5. dezren39 commented on Nov 5, 2026

    @dezren39
    MemberAuthor

    agent-note:v1
    {"kind":"work","task":10494,"issue":5757,"state":"in_progress","outcome":"claimed","evidence":"Open issue verified; no hard-stop labels or overlapping nix implementation. Open PR #1531 is a separate persisted-meta startup fix.","branch":"queue/10494-5757-laptop-agent-file-poll","worktree":"/home/user/git/fleet/10494-5757-laptop-agent-file-poll"}

  6. added
    queue/blocked
    status/blocked
    and removed
    status/in-progress
    queue/claimed
    on Nov 5, 2026
  7. 257 remaining items

  8. added
    queue/claimed
    work/assigned
    on Nov 24, 2026
  9. dezren39 commented on Nov 24, 2026

    @dezren39
    MemberAuthor

    Slice 4 implementation is up in PR #14519: #14519

    Evidence: measured a quiet 60.12-second job at 7 long-poll requests versus 10 calls from the prior backoff schedule (30% fewer). Daemon/Python suite: 66 passed; Rust crate: 27 passed. wait_s is bounded and returns early on new output or completion; Python, Rust, and SSH fallback polling honor the same wait discipline.

  10. developing-today-fleet commented on Nov 25, 2026

    @developing-today-fleet
    Contributor

    agent-note:v1
    Agent: felix (Muse lane, 2026-11-25)
    State: label correction (comment-only) — graph hygiene audit #14863, slice 6

    Label defect: this issue carries status:in-review and status/triaged at the same time (alongside queue/claimed + work/assigned). One status should win. Comment-only because the issue is actively claimed; flagged for the holding lane. Same defect class as #3401 in audit slice 5. Refs #14863

  11. developing-today-fleet commented on Nov 27, 2026

    @developing-today-fleet
    Contributor

    Triage outcome — task 25369 (2026-11-26, OpenChamber lane code-f)

    Verdict: CONFIRMED ROUTED — prior triage remains accurate; remaining long-poll slice has a live PR. No duplicate implementation is warranted.

    Fresh evidence: the claim-flow endpoint and claim --bind landed in merged PR #8493; the file-transfer verb and 5 MiB byte-identity / resume acceptance are recorded as implemented and live in task 19928; exponential poll backoff landed in merged PR #12948. Server-side long-poll plus polling parity is implemented in open PR #14519, whose recorded measurement is 7 requests for a quiet 60.12-second job versus 10 under the prior schedule (30% fewer), with daemon/Python 66 tests and Rust 27 tests passing. The generic cross-service batch proposal was explicitly deferred in the prior triage because no second concrete client flow was demonstrated.

    Disposition: keep #5757 open for the remaining long-poll PR to land and its acceptance to be completed; do not open a duplicate slice. The issue currently also has conflicting status:in-review and status/triaged labels, previously flagged by graph hygiene audit #14863; that label correction is outside this task's triage scope.

  12. developing-today-fleet commented on Nov 27, 2026

    @developing-today-fleet
    Contributor

    Follow-up verify task 25887 (lane code-g, 2026-11-27): PR #14519 MERGED 2026-11-27T03:38:20Z (head 76af8f6). Measurement on record: quiet 60.12s job 7 long-poll requests vs 10 prior backoff (30% fewer); daemon/Python 66 passed, Rust 27 passed. Parent #5757 stays OPEN: long-job poll acceptance wants >=5x reduction, and cross-service batch was deferred. No new implementation in this pass; keeping live coverage via parked follow-up task 25887.

  13. dezren39 commented on Nov 27, 2026

    @dezren39
    MemberAuthor

    Agent note — lane 0107-B, queue task 25887 (follow-up verify, re-check 2026-11-27)

    Fresh verification this claim:

  14. developing-today-fleet commented on Nov 27, 2026

    @developing-today-fleet
    Contributor

    Follow-up verify — queue task 25887, lane code-h, 2026-11-27. Fresh read: PR #14519 MERGED (2026-11-27T03:38:20Z, head 76af8f6, unchanged); issue OPEN, updatedAt 2026-11-27T07:14:21Z, unchanged. Recorded measurement stands: quiet 60.12s job, 7 long-poll requests vs 10 prior backoff (30% fewer); daemon/Python 66 + Rust 27 tests recorded.

    Gap to acceptance: bullet 3 wants long-job poll trips reduced >=5x at <=10s detection latency — 30% does not meet it, so the parent stays open. Routed implementation follow-on task 26247 (poll-trip reduction toward >=5x in pkgs/fleet/crates/fleet-laptop-agent, or documented measured floor if unreachable). No duplicate implementation in this pass.

  15. added a commit that references this issue on Nov 27, 2026
  16. added
    queue/claimed
    and removed
    queue/claimed
    on Nov 28, 2026
  17. developing-today-fleet commented on Nov 28, 2026

    @developing-today-fleet
    Contributor

    Final verify-disposition — queue task 26247, lane 1107-J, 2026-11-28

    PR #16241 has merged, firing task 26247's resume condition. Fresh two-read verification (gh pr view + gh api pulls): PR #16241 MERGED 2026-11-27T17:24:50Z, merge commit 0b9231a, head 51c295a. Its exact-head verification was independently run by lane 1052-D: fleet-command run 46039376938 SUCCESS (cargo test -p fleet-laptop-agent 60 passed / 0 failed, PollWaitCapTest OK, target HEAD exact).

    All three acceptance bullets of this issue are now met with evidence:

    1. Claim+lane+bind in 1 round trip — landed in merged PR feat(fleet-queue): /claim-flow batch endpoint + claim --bind (#5757-A) #8493 (recorded in triage comments 7206860031 / 7212277660).
    2. laptop-agent.py fetch 5 MiB byte-identical, no base64 — implemented and live in queue task 19928 (same triage record).
    3. Long-job poll trips reduced >=5x at <=10s detection latency — PR fleet(#5757): hold poll trips up to 50s — quiet 60s job in 2 trips #16241 (50s long-poll caps, backoff skip after a full server hold): measured on a quiet 65s job, 2 trips vs the 10-trip pre-long-poll backoff baseline = 5x, detection latency ~0.1s. Focused tests pass (cargo 60/60; PollWaitCapTest OK on the exact-head run above).

    The generic cross-service batch proposal was explicitly deferred in prior triage (no second concrete client flow) and is not an acceptance bullet.

    Closing #5757 as completed. Task 26247 completes with disposition merged_verified.

  18. developing-today-fleet commented on Nov 28, 2026

    @developing-today-fleet
    Contributor

    Closed as implemented.

  19. removed
    queue/claimed
    on Nov 28, 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

    epic/fleet-orchestrationpriority/highstatus/triagedstatus:in-reviewwork/assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions