Skip to content

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

Open

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
    task/triageQueue packet kind: verify, reproduce, and route this item
    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/assignedQueue worker lifecycle state
    queue/claimedQueue worker lifecycle state
    and removed
    task/triageQueue packet kind: verify, reproduce, and route this item
    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/blockedQueue or user escalation state
    status/blockedQueue or user escalation state
    and removed
    queue/claimedQueue worker lifecycle state
    on Nov 5, 2026
  7. 240 remaining items

  8. added and removed
    queue/claimedQueue worker lifecycle state
    work/assignedQueue worker lifecycle state
    on Nov 11, 2026
  9. dezren39 commented on Nov 14, 2026

    @dezren39
    MemberAuthor

    Packet-defect disposition under Drew's 2026-11-13 unblock-all order: task 10494 was cancelled (packet defect verified unchanged — see the task record) and replaced by fresh triage task 16471, now queued. Worker main-unblock-all-2026-11-13.

  10. dezren39 commented on Nov 14, 2026

    @dezren39
    MemberAuthor

    Agent note — task 16471 triage: the /file verb slice of #5757 is real, unimplemented, and cleanly scoped (lane code-a, 2026-11-14)

    Fresh triage from current state (the prior task 10494 packet was scoped to the wrong repo; this supersedes it):

    Current state (verified today): the laptop-agent client (~/tools/laptop-agent.py) offers health, exec, exec-batch, run, poll, kill, jobs — no fetch. The daemon (~/tools/laptop-agent-daemon.py) routes GET /health, /jobs and POST /exec, /cancel, /jobs — no /file. File fetch today is still the base64-in-exec workaround the issue's census measured. So proposal item 3 stands unimplemented; items 1/2/4 (claim-flow batching, /batch fan-out, poll backoff) are separate slices and are not covered by this triage.

    The slice, as scoped for a follow-on small_fix:

    • Daemon: GET /file?path=&off=&len= returning raw bytes (application/octet-stream), byte-range via query params, offset pattern as already proven by the jobs poll.
    • Client: laptop-agent.py fetch PATH OUT — no base64, chunked by offset with chunks ≥ 1 MiB, resume = re-request from the last received offset.
    • Acceptance (from the issue): fetch of a 5 MiB file byte-identical by md5; trips = ceil(size/chunk).

    Implementation cautions for whoever takes the follow-on: the laptop-agent files under ~/tools/ are the live sandbox↔laptop path (not repo files) and show same-day sibling work (.bak-20261114-tripv2 backups — the multiplexed-tunnel sibling effort); the change must land on both ends (sandbox client + laptop daemon) and be verified end-to-end against the md5 acceptance before the old base64 habit is declared replaced. Security shape stays as today: agent token header only, never in argv; the daemon should refuse paths outside its existing exec trust model rather than growing a new one silently.

    Triage completes as triaged; the follow-on implementation is a fresh small_fix dispatch against this scope.

  11. dezren39 commented on Nov 14, 2026

    @dezren39
    MemberAuthor

    Agent note — task 17166 triage confirmed (lane any-a): task 16471's triage of the /file slice stands, minutes old

    This re-packet duplicates the triage lane code-a completed as task 16471 at 2026-11-14T18:49Z (note directly above): the /file verb slice of #5757 is real, unimplemented, and cleanly scoped — daemon GET /file?path=&off=&len= (raw bytes, offset ranges) + client laptop-agent.py fetch PATH OUT (chunked ≥1 MiB, resume by offset), acceptance = 5 MiB fetch byte-identical by md5 with trips = ceil(size/chunk). Its cautions stand: both ends are the LIVE sandbox↔laptop path under ~/tools (not repo files), sibling multiplexed-tunnel work is in flight today, and the token stays header-only.

    No re-triage is warranted minutes later, and the follow-on implementation should be a fresh small_fix dispatch per that scope — deliberately not started from this duplicate in the last hour of a shift, on infrastructure every lane is actively using. Task 17166 completes as triaged on task 16471's evidence. Items 1/2/4 of #5757 (claim-flow batching, /batch fan-out, poll backoff) remain separate slices, untouched by either triage.

  12. dezren39 commented on Nov 17, 2026

    @dezren39
    MemberAuthor

    🤖 Agent note · triaged

    • Agent: queue worker (repo-worker-code), lane any-h
    • Session / ID: task 18359
    • Found via: queue claim
    • Verdict: the task 16471 triage (2026-11-14, confirmed by task 17166) stands in full, and its routed follow-on — which was never enqueued — is now enqueued by this task as task 19928.
    • Fresh evidence (2026-11-17): issue Connection perf: coalesce queue claim flow to 1 round trip, cross-service batch, real file-transfer verb #5757 OPEN, status:triaged, priority/high. The /file verb slice is still unimplemented: the laptop-agent client (/tools/laptop-agent.py) has no fetch verb, and the daemon's GET routes are only /health and /jobs (/tools/laptop-agent-daemon.py) — file fetch is still the base64-in-exec workaround the census measured. Items 1/2/4 (claim-flow batching, /batch fan-out, poll backoff) remain separate slices, untouched.
    • Follow-on: task 19928 (small_fix, repo-health-code-pilot) carries the 16471 scope verbatim: daemon GET /file?path=&off=&len= (raw bytes, token-header auth only) + client fetch PATH OUT (1 MiB chunks, resume by offset); acceptance = 5 MiB fetch byte-identical by md5 in ceil(size/chunk) trips; cautions = both ends are the live sandbox↔laptop path, daemon copy sync + careful service restart.
    • First concrete step (task 19928's owner): implement the daemon route in the canonical ~/tools copy, sync the laptop copy, restart the laptop-agent user service, and verify /health + exec before wiring the client verb.
  13. dezren39 commented on Nov 17, 2026

    @dezren39
    MemberAuthor

    agent-note:v1
    state: done
    task: 19928
    lane: any-m
    worker: repo-worker-code

    Task 19928 — file-verb slice of issue #5757 — implemented and verified live:

    • Daemon (canonical ~/tools/laptop-agent-daemon.py): new GET /file?path=&off=&len= route serving raw bytes, len capped at 1 MiB per request, X-File-Size / X-File-Off response headers, 400 on bad params, 404 on missing/non-regular file, 416 on off beyond EOF. Auth is the existing X-Agent-Token header check, same as every other route (401 verified without it).
    • Client (canonical ~/tools/laptop-agent.py): new fetch [--chunk BYTES] PATH OUT subcommand — chunked at 1 MiB, resume by offset (an existing OUT is continued from its size, never restarted), round-trip count reported. Raw bytes bypass the JSON broker protocol and ride the direct Cloudflare/Tailscale transports, with the SSH chunk fallback when every agent transport is down.
    • Local daemon test (sandbox, throwaway port): chunk at off=1MiB byte-identical to the source slice; 401/404/416 verified; /health unaffected.
    • Deploy: daemon copy synced to the laptop (~/laptop-agent/laptop_agent.py, md5 b4f7fc7e3d4ce1e959a80957d840aef4, previous copy kept as .bak-20261117-19928), laptop-agent.service restarted and active.
    • Live acceptance: a 5 MiB random file on the laptop fetched through the verb was byte-identical by md5 and used exactly 5 round trips (ceil(5242880/1048576)); resume from a 2 MiB partial completed in 3 further trips with the same md5. Regression: exec and jobs routes answer normally after the restart.

    Issue #5757 stays OPEN — this was only the file-verb slice; items 1/2/4 of the parent issue are out of this packet's scope.

  14. removed their assignment
    on Nov 20, 2026
  15. added a commit that references this issue on Nov 23, 2026
  16. dezren39 commented on Nov 23, 2026

    @dezren39
    MemberAuthor

    Progress (lane oc-code-08): poll-backoff slice PR #12948 — poll() slept fixed 3s; now poll_interval() doubles 1/2/4/8s capped at 10s. Evidence: cargo test -p fleet-laptop-agent --lib 21 passed/0 failed (2 new tests; test failed pre-fix with 3s vs 1s). Next slice in the same form: after the next PR, poll trips for a 60s job drop further via server-side long-poll ?wait_s, and laptop-agent.py:1469 gets the same backoff.

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