Skip to content

Build: fleet kv phase 2 — central CAS, shared namespaces and session sweep #13316

Open

Description

@dezren39

Phase 2 — shared primary + session sweep + grants (global reads, CAS conflicts, supported auth)

  • Parent issue: Design: fleet kv — namespaced key-value store (local + global), blob offload to content-addressed R2 #10359 (items 2/4/5: central store, sweep survival, five-agent workload).
  • Parent design: reviewed decision record (§1 hybrid central D014, §4 sweep, §5 CAS, §6 five-agent topology D008, §9 auth D011). Stable decision IDs: D003, D004, D005, D006, D007, D008, D011, D014 (D002 reversed/superseded — do not implement row-scopes-only).
  • Prerequisite: design PR docs(fleet): settle namespaced KV storage, sweep and blob design (#10359) #13294 must merge before this phase starts. Depends on: Phase 1 Build: fleet kv phase 1 — local verbs, scoped SQLite and backup #13314 (local verbs + full-identity overlay + durable outbox); its implementation PR must be merged before Phase 2 implementation begins.
  • Scope: shared Turso primary over the queue-style libSQL HTTP pipeline at configurable FLEET_KV_URL (no hardcoded or fake deployed hostname); proposed migrations/handler paths (no code in this issue): pkgs/fleet/crates/fleet-kv/migrations/ for kv_namespaces, kv_heads, kv_versions, kv_conflicts, idem_receipts, kv_grants, and pipeline handlers beside the existing queue HTTP handlers. Central key derivation per write/read: from the explicitly selected scope — the shared scope_id of the namespace for authorized agents, or the private scope_id of the owning (user, context) — resolved via kv_namespaces + kv_grants; no implicit extra fallback scope exists.
  • Scope: shared Turso primary over the queue-style libSQL HTTP pipeline; central key (scope_id, registry_id, namespace, key) with one shared scope per shared namespace (shared-scope tombstones affect all shared readers; private scopes separate); kv_namespaces with designation-only global_flag; kv_grants with explicit-grant group DBs under fail-closed admission/provisioning policy (no default per-session proliferation; group DBs inline-only — no blob refs, ceiling checked before any group-DB write, blob-needing group writes refuse with blob_requires_shared_primary); --global now serves central (authoritative bypass); local-first reads (ordinary cache ≤ 1 s; miss/expiry refreshes or typed unavailable/stale, --allow-stale opt-in with age; overlay reads immediate offline) with local-override + merged list; durable sweep keyed (owner_user_id, context_id, session_id) via outbox + per-key CAS (≤ 5 attempts, jittered exp backoff capped at 1 s), receipts keyed (authenticated_writer, host_incarnation_UUID, outbox_UUID) + immutable fingerprint; tombstones sweep through CAS; five-agent rule (single-writer-per-key CAS; KV CAS is not a queue lease — no leases/expiry/steal); 15-minute archive checkpoint TARGET (unbounded loss when offline/unarchived; archive carries inline payloads only up to the effective threshold — no Phase 3 upload here). Auth: RP/agent JWT or route-scoped service token to the trusted endpoint; secrets-broker fetch path is not request auth; per-user Turso data-plane tokens refused (data_plane_credential_refused). v1 operational integration ships here: migrations, credential wiring, grant-policy implementation, backup/restore runbook, health probes.

Acceptance

  1. --global get/set round-trips against central; plain get merges local + central with stated origin marks and never silently hides the shadowed row; --global bypasses the 1 s cache.
  2. Sweep: session dirty set merges idempotently (re-run safe; retransmit with same key+fingerprint returns the stored result); two sessions racing one key produce one winner + one typed conflict {expected, actual} with both versions retrievable — never silent last-writer-wins, never Turso Sync last-push-wins; rebase after conflict is a new intent/new id, never silent overwrite. CAS-before-ack order: receipt written atomically with CAS, ack after; crash between CAS and ack replays the recorded result, never a spurious new conflict.
  3. Archive carries inline payloads only (≤ effective threshold) via the archive owner command fleet kv backup (equivalently fleet kv sync --archive mode) plus the 15-minute online-checkpoint-target sweeper; over-threshold local-working bytes are reported protection_unavailable_needs_phase3, never uploaded — no blob upload exists before Phase 3. Over-ceiling bytes addressed to central before Phase 3 land typed pending_needs_phase3 (queued intent, not a row), never silently buffered inline. Crash before ack re-sweeps fully.
  4. Grants: a group DB exists iff a kv_grants row authorizes it; unknown group/namespace refuses fail-closed; with no grant, everything lands on the shared primary. No per-session DB is provisioned by default. Group DBs accept inline bytes only: over-ceiling bytes addressed to a group scope refuse with blob_requires_shared_primary (shared-primary placement required, no auto-move), so no unrestricted write bypasses the ceiling.
  5. Data-plane credential presented to the endpoint is refused with the typed rule, not an incidental signature failure; central access reuses the hosted RP/agent JWT or route-scoped service token path only.
  6. Load probe (REQUIRED, correctness-only fixture — not a latency/perf promise, and no billing claim): five writers × ~1–10 keys/min on a ~10k-key namespace all converge; list polling observes at most the documented 1 s staleness.
  7. Done check from repository root: cargo test --manifest-path pkgs/fleet/Cargo.toml -p fleet-kv central runs the proposed central_* model/property/integration suite with a nonzero test count. It must include the five-agent fixture, scope isolation, clear-versus-sweep, same-ID/different-body refusal, duplicate delivery, archive restore, and expired-cache refusal. Also run cargo test --manifest-path pkgs/fleet/Cargo.toml -p fleet-kv to preserve Phase 1 behavior. A zero-match filter is failure, not evidence.

Oracles

  • Property: CAS linearity — concurrent same-key writers serialize; the central head always equals one writer's full intent, never a blend; losers get typed conflicts. (PBT over concurrent CAS attempts.)
  • Property: sweep idempotence — sweeping the same outbox twice changes central once. (PBT over duplicate deliveries.)
  • Property: tombstone sweep convergence — delete-vs-write races resolve to a retrievable conflict or a tombstoned head, never resurrection-by-replay.
  • Model: central head machine (version, parent_version, writer) against a sequential CAS oracle; sweep as an outbox-draining refinement of it.
{
  "direct_parent": null,
  "links": [],
  "lineage": {
    "design": null,
    "roadmap_item": null,
    "priority": null
  },
  "pm_meta": 1,
  "provenance": {
    "queue_id": null,
    "scheduled_start": null,
    "picked_up_at": null,
    "work_started_at": null,
    "created_at": "2026-11-23T13:22:18Z",
    "session_id": "ses_e5df79277fdffep9u8FJIv4AqN",
    "lane": null,
    "host": "amd",
    "worktree": "/home/user/.local/share/opencode/worktree/7c7733/lane-any-n-12892-fleet-kv-design",
    "model": null,
    "lane_start_issues": [],
    "workspace_ref": {
      "kind": "worktree",
      "id": "/home/user/.local/share/opencode/worktree/7c7733/lane-any-n-12892-fleet-kv-design",
      "repo": "developing-today/code",
      "branch": "lane-any-n/12892-fleet-kv-design",
      "sha": "5ac3ddcec60017b05b655b8fe665b06c61369ec3"
    },
    "auth_subject": "oc-code-06",
    "stamped_by": "fleet 0.1.0 (native)"
  }
}

Related program: #10359

Activity

  1. added
    kind/feature
    priority/normal
    effort/l
    on Nov 23, 2026
  2. developing-today commented on Nov 23, 2026

    @developing-today
    Contributor
  3. dezren39 commented on Nov 23, 2026

    @dezren39
    MemberAuthor

    Filed by lane any-n under #10359, design task 21123 / parent 20571. Same-pass pilot coverage: repo-health-code-pilot task 21317 (queued); do not implement before design PR #13294 and the phase prerequisites are merged. This run publishes design/build handoffs only.

  4. dezren39 commented on Nov 23, 2026

    @dezren39
    MemberAuthor

    Triage verdict (task 21317, lane oc-code-02): valid build handoff, not yet implementable.

  5. dezren39 commented on Nov 23, 2026

    @dezren39
    MemberAuthor

    Triage verdict (lane code-g, queue task 21320, 2026-11-23): valid phased build handoff under #10359 with concrete acceptance + oracles. NOT startable now: gate design PR #13294 is OPEN/unmerged, and phase-1 prerequisite #13314 is OPEN. Per the issue's own prerequisite clause, phase-2 implementation must wait for both. Parking the queue task with a ready-condition on #13294 merge; re-validate #13314's implementation PR at resume before any code work. No code changes made.

  6. added a commit that references this issue on Nov 23, 2026
  7. dezren39 commented on Nov 23, 2026

    @dezren39
    MemberAuthor

    Triage refresh (queue task 21320, lane agent-next-22-local, 2026-11-23): valid Phase 2 build handoff; still not startable.

    This updates the earlier triage note that said design PR #13294 was open; the design gate has cleared, but Phase 1 has not.

  8. dezren39 commented on Nov 23, 2026

    @dezren39
    MemberAuthor

    Related program: #10359. This phase delivers one of the three implementation stages from the accepted fleet-kv design.

  9. dezren39 commented on Nov 23, 2026

    @dezren39
    MemberAuthor

    Triage refresh (queue task 21320, lane xaltha, 2026-11-23 ~14:30 UTC): valid Phase 2 build handoff; still not startable.

  10. dezren39 commented on Nov 24, 2026

    @dezren39
    MemberAuthor

    Triage refresh (queue task 21320, lane code-h, 2026-11-24): valid Phase 2 build handoff; still not startable.

  11. dezren39 commented on Nov 24, 2026

    @dezren39
    MemberAuthor

    Triage refresh (queue task 21320, lane code-i, 2026-11-24): valid Phase 2 build handoff; still not startable. Re-verified fresh: #13316 OPEN, design #13294 MERGED, Phase 1 #13314 OPEN. Only PRs referencing #13314 are #13362 (merged first slice) and #13294 (design) — no new Phase-1 implementation has merged. Phase 1 remainder from the #13314 record still stands. No code touched. Parked until #13314 closes; then revalidate #13316/#13314/#13294 before building.

  12. dezren39 commented on Nov 24, 2026

    @dezren39
    MemberAuthor

    Triage 2026-11-24Z: #13316 OPEN (kind/feature, effort/l). Stated dependency verified: phase 1 #13314 OPEN (unimplemented); design PR #13294 MERGED (design settled, no design gap). Task 21320 blocked on #13314 with dep recheck; no code touched. Unblocks when #13314 closes.

  13. added
    priority/high
    and removed
    priority/normal
    on Nov 24, 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

    effort/lkind/featurepriority/high

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions