Skip to content

impl(fleet): placement sessions to the queue backend (placement_sessions) — centralize decision state, keep placement decentralized #13146

Closed

Description

@dezren39

Context

Drew's directive, 2026-11-23: improve fleet placement dispatch along the
hybrid lines agreed in chat — dispatch stays decentralized (each
seat's fleet binary decides placement locally; that resilience is
deliberate and was proven the same night, when dispatch kept working
while the queue broker's session-proxy leg was down), and only the
decision state gets centralized.

Today the placement session records (the fp_… handles) live only in a
per-seat JSON file, ~/.local/state/fleet-place/sessions.json
(pkgs/fleet/crates/fleet-queue/src/placement.rs). The intake design
(doc/placement-intake/placement.md, absorbed under #5413) labeled
that store a stopgap and carried DDL for a dedicated session table.
The queue backend has since consolidated on Turso behind the
queue-broker, so the table lands there as placement_sessions (the
Supabase agent. schema in the intake DDL is historical). Dispatch
itself was verified end to end on 2026-11-23; the sandbox-seat gap is
#13122. #4986 (placement records on dispatches) is related but
distinct — this issue is the session store only.

Design (slice 1)

Schema — one new table in the Turso queue backend, added to the
SCHEMA set in turso_queue/core.rs so ensure_schema creates it
with CREATE TABLE IF NOT EXISTS on every broker start:

CREATE TABLE IF NOT EXISTS placement_sessions (
  handle       TEXT PRIMARY KEY,   -- 'fp_' || 32 hex chars
  record       TEXT NOT NULL,      -- the full session record JSON;
                                   -- the client record shape is the contract
  state        TEXT,               -- extracted: queued|running|succeeded|failed|cancelled|dispatched
  surface      TEXT,               -- extracted: registry surface id
  submitted_by TEXT,               -- extracted: for list --mine
  run_id       INTEGER,            -- extracted: correlated Actions run
  created_at   TEXT NOT NULL,
  updated_at   TEXT NOT NULL
);
CREATE INDEX IF NOT EXISTS placement_sessions_created
  ON placement_sessions(created_at);

Broker verbs — new turso_queue verbs, dispatched and
authenticated exactly like the existing queue verbs (the broker shell
does not change):

  • /placement-put {record} — upsert by handle (a seat refreshing a
    session's state is the authority for that update).
  • /placement-get {handle} — the stored record, or null.
  • /placement-list {submitted_by?, limit?} — newest first, bounded.
  • /placement-sync {records} — INSERT OR IGNORE batch; the
    migration path. Never overwrites a row the backend already holds.

Client (placement.rs + one transport helper):

  • The local JSON store stays the always-available store and the
    only input to placement decisions: build_ctx and the
    Blacksmith budget reconcile read local state exactly as today.
    Decisions never depend on the backend.
  • Session records additionally mirror to the backend, best-effort,
    through a bounded broker roundtrip (new helper in the client
    transport: same routes as the queue client — direct broker URL /
    broker socket, else the session proxy — with short timeouts, no
    broker auto-spawn, and errors returned, never a process exit).
  • Write path: local commit first (unchanged semantics, unchanged
    lock), then a best-effort /placement-put. Any failure is silent —
    a dispatch can never fail or stall because the backend is down.
  • Read paths (session status / session result, the --followup
    lookup, session list): consult the backend, prefer the record
    with the newer updated_at across the two stores, refresh state
    from GitHub exactly as today, and persist the refreshed record to
    both stores.
  • Migration of existing local sessions: after a successful dispatch
    commit, and on session list, a best-effort /placement-sync
    pushes local records the backend lacks (bounded, most recent
    first). Pre-existing per-seat stores converge into the backend
    without an operator step.
  • Escape hatch: FLEET_PLACE_REMOTE=off disables the remote mirror
    (operator + test use).

Acceptance criteria

  1. Dispatch on seat A; fleet queue session status <fp_ handle> on
    seat B (empty local store) returns the session.
  2. With the broker unreachable, dispatch + status/result/list behave
    exactly as today (local store only).
  3. A pre-existing local sessions.json migrates: after one dispatch
    or list against a reachable backend, its records are readable
    from another seat, and sync never overwrites a backend row.
  4. Placement decisions (dry-run output, Blacksmith budget accounting)
    are unchanged with the backend up, down, or disabled.
  5. Tests name their oracles: backend verb tests against the stub
    pipeline (SQL + reply mapping), client fallback/merge tests
    against a fake remote, and a boundedness test for the transport
    helper.

Breakdown

  • Slice 1 (this issue): schema + broker verbs + client mirror
    with local fallback + opportunistic migration + runbook update
    (the broadcast string gains the binary-acquisition block).
  • Later slice (recorded, not in scope): a fleet-wide Blacksmith
    minute ledger — only if Blacksmith spend grows; the per-seat local
    ledger stays until then.
  • Later slice (recorded, not in scope): hard cap enforcement at
    decision time (admission control against the caps placement
    currently only steers by).

Activity

  1. developing-today commented on Nov 23, 2026

    @developing-today
    Contributor
  2. added a commit that references this issue on Nov 23, 2026
  3. dezren39 commented on Nov 23, 2026

    @dezren39
    MemberAuthor

    Slice 1 landed — PR #13169, merged 15b2ac8

    What shipped (head eca57d1):

    • Backend: placement_sessions added to the SCHEMA set in
      turso_queue/core.rs (created by ensure_schema on broker
      start; no separate migration step). New module
      turso_queue/placement_sessions.rs: session_row extraction
      (the client record is the contract; scalars extracted for
      queries) + the four verbs, routed in stacks_outbox.rs:
      /placement-put (upsert), /placement-get, /placement-list,
      /placement-sync (insert-or-ignore batch).
    • Transport: broker_roundtrip_bounded in
      client/transport.rs — the queue client's routes with a
      caller-set budget on every leg, HTTP errors as Err, no
      session-broker auto-spawn, bad URL degrades to Err.
    • Client: new placement/remote.rs (SessionRemote trait,
      BrokerRemote at a 5 s budget, NullRemote,
      FLEET_PLACE_REMOTE=off escape hatch, pick/merge/sync helpers).
      placement.rs wiring: commit stays local-first, mirror put
      after; refresh re-mirrors; status/result/followup reads take
      the newer of local vs backend by updated_at (a backend hit
      also seeds the local store); session list unions both stores
      and runs the migration sweep; dispatch runs the sweep after the
      local commit.
    • Runbook: session-store paragraph describes the mirror +
      fallback; the broadcast string gained the approved
      binary-acquisition block (bootstrap pin route + the
      release-asset route for non-Muse machines, tag read from the
      FLEET_URL/FLEET_SHA256 pin block in
      scripts/muse/bootstrap.sh, .sha256 verification, post-install
      checks fleet queue dispatch --help + fleet queue surfaces).

    Verification

    • cargo check -p fleet-queue --features client,queue-broker:
      clean.
    • Targeted: placement filter 54 passed, bounded filter 4 passed;
      all 15 new tests pass by name (7 backend verb tests against the
      stub pipeline, 4 remote pick/merge/sync tests, the commit-mirror
      wiring test, 2 bounded-transport tests).
    • Full crate suite: 556 passed, 0 failed (lib 549 incl. the
      new tests; chunked_list 2; person_wait_cli 5; doc-tests 0) —
      run on the laptop worktree. The remote dispatch route was tried
      first (runs 45150362527, 45151395564, 45154863900, 45156432278)
      and is currently unusable for Rust: the fleet-build image has
      no cargo on PATH and no assembled sysroot on a stable path —
      filed as fix(fleet): fleet-command Run step lacks the toolchain on PATH — dispatched cargo commands fail 127 #13170 with probe evidence.
    • Formatting: the crate is not rustfmt-gated (pristine files diff
      identically); the change follows house style.

    Acceptance criteria status

    1. Cross-seat status by handle — PENDING the normal binary
      rollout (broker gains the verbs and seats gain the client
      from main, same as every fleet change; no deploy-profile or
      seat changes were made by this slice). This issue stays open
      for that record.
    2. Backend down = behavior identical to today — covered by the
      mirror-failure wiring test + NullRemote/fake-remote tests.
    3. Pre-existing local stores migrate without overwriting —
      /placement-sync insert-or-ignore + the sync sweep test.
    4. Decisions unchanged — build_ctx and the reconcile read the
      local store exactly as before; full placement suite green.
    5. Tests name their oracles — done (each new test's doc comment
      names its oracle).

    Next slices (unchanged, in order): live cross-seat
    verification once the rollout lands a broker + two seats on the
    new build; then the conditional Blacksmith minute ledger (only
    if spend grows); then hard cap enforcement at decision time.

  4. dezren39 commented on Nov 23, 2026

    @dezren39
    MemberAuthor

    Criterion 1 verified live — cross-seat session status (rollout completion, 2026-11-23)

    Criterion 1: Dispatch on seat A; fleet queue session status <fp_ handle> on seat B (empty local store) returns the session.

    Setup, all on the bcc8043 build (fleet-static-bcc8043, source rev bcc8043b59ab97c20b639db473f2055c9961d43e):

    • Queue broker rolled to generation 6 via deploy.py + --registry (artifact /nix/store/dlvq6vkxhcv9bicjqvv90a6kwpi320rn-fleet-0.1.0, activated 2026-11-23T14:05:46Z; generation 5 kept as rollback). The broker process (MainPID 3065738) runs that artifact's bin/fleet, whose fleet version reports source rev bcc8043b59ab…. Broker /healthz ok; sandbox-seat fleet queue health answers against it.
    • Sandbox seat binary and ~/tools/fleet both updated to the same build via the bootstrap flow (pinned release fetch, sha256 33c1b5d0… verified); fleet-static-3cb241a kept beside them as rollback.

    Evidence:

    1. Seat A (laptop) dispatched: fleet queue dispatch --repo developing-today/code --ref bcc8043b59ab97c20b639db473f2055c9961d43e --command true --dispatch --json → handle fp_0903fa1bd9ebe524ace8f23ade78ecc8, submitted_by: user@amd, created_at: 2026-11-23T14:15:04Z, surface fleet-org-blacksmith, state dispatched.
    2. Seat B (sandbox) local store did not hold the handle: grep -c fp_0903fa1bd9ebe524ace8f23ade78ecc8 ~/.local/state/fleet-place/sessions.json → 0 before the read.
    3. Seat B status read returned the session from the backend: fleet queue session status fp_0903fa1bd9ebe524ace8f23ade78ecc8 --json returned the full record (repo/command/ref, decision reasoning, submitted_by: user@amd, state dispatched).
    4. The read seeded seat B's local store from the backend, as designed: the same grep after the read returns 2.

    Criteria 2–5 were already recorded as covered by the slice-1 landing (PR #13169, comment 7099021294). Criterion 1 was the last open criterion; closing this issue as completed.

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