Skip to content

Epic: P6 async fan-out — replace the KEDA leaf-worker (Archetype A) removed by #691 #686

Closed

Description

@pdettori

Epic: P6 async fan-out — a P6 replacement for the removed KEDA leaf-worker (Archetype A)

Status (2026-11-17): #691 merged; the replacement is largely built. #386 design, #687, #689 and #690 are closed; the spec's M1 (working drain, single tenancy), M2 (turn_exp, grant-at-dequeue, tenancy gate lifted) and M3 (deploy/k8s + smoke, #688) have all landed. See the 2026-11-17 status comment below for what each open child still tracks.

Problem

Async fan-out (Archetype A, docs/concepts/dispatch-archetypes.md) means a deterministic controller submits N leaves with async: true, a consumer drains them from a Redis stream, and the controller collects the result records later. Before #691 the only consumer was packages/knative-server/src/leaf-job.ts running as a KEDA ScaledJob (ADR-0015). It ran only on the deprecated Knative/KEDA path (ADR-0041).

#691 removes all of it:

  • deploy/knative/ (including leaf-scaledjob.yaml, leaf-orchestrator.yaml, leaf-async-smoke.sh and the ocp-async overlay)
  • the KEDA drainer (leaf-job.ts) and harness/src/leaf-job-runner.ts
  • the async-enqueue route: POST /runs with async: true now answers 400 async_removed
  • @moca/work-queue, whose only consumers were that path
  • docs/migrating-from-knative.md

After #691, P6 (deploy/k8s, deploy/vm, deploy/compose) has no async path at all. The supervisor forks only --role=turn workers; --role=leaf is reserved and not implemented. ADR-0041's post-removal note and dispatch-archetypes.md record Archetype A as "Removed … no P6 equivalent yet", an owed follow-up that ADR-0034 had already flagged.

#490 found no respondent depending on async fan-out, so the removal went ahead without a replacement. This epic owns that replacement, as #536 does for Archetype C (cron). It doesn't duplicate #378. It links the issues that already exist (filed under the coding-agent subagents epic, targeting deploy/vm and compose) and fills in what they leave out.

Reference implementation

The removed code stays the reference for parity. Pin to the last main commit before #691 merges, e.g. 38aa2146:

Whether the P6 consumer revives @moca/work-queue or uses a new queue is a #386 design decision. Its removal doesn't settle it either way.

The two async paths after #691

Path Who submits State after #691 P6 plan
Data-plane POST /runs {async:true} (server.ts) Unauthenticated callers (SH_REQUIRE_AUTH off), e.g. an in-cluster Archetype A controller Removed. Answers 400 async_removed, naming ADR-0041. Not decided (#687): restore on the new consumer, replace with the authenticated path, or leave removed.
Authenticated async on a session A logged-in user or coding agent through the control plane Refused with 501 async_runs_unavailable (MI1 R7, no bearer token in the queue). Unchanged by #691. #386 → #387, #388 → #389

Goal

Everything Archetype A did on Knative has a P6 equivalent on all three P6 deployments:

  • submit N leaves without waiting
  • drain them with bounded concurrency inside supervisor admission
  • survive a worker crash or restart with at-least-once delivery that completes effectively once
  • collect per-leaf results

Where a P6 equivalent isn't built, the decision not to support it is documented (ADR + dispatch-archetypes.md).

Children

Existing (linked, not re-scoped here):

New (filed from this epic):

Acceptance

  • A recorded decision on data-plane /runs {async:true}: restored, replaced, or permanently removed. If it is not restored, async_removed names the replacement.
  • An Archetype A pipeline (N async leaves submitted, drained at a pool cap below N, all results collected) runs end to end on deploy/k8s and on deploy/vm or compose. Coding-agent subagents B4: async leaf worker on P6 (deploy/vm, compose) #389's crash and drain acceptance must hold.
  • ADR-0041's "Still owed" note and dispatch-archetypes.md no longer say "no P6 equivalent" for Archetype A.

Sequencing

#691 merges first; nothing here blocks it. Then #386 (design). #387 and #388 can run in parallel after it. #389 follows, and the deploy/k8s wiring (#688) builds on #389. The data-plane decision (#687) belongs inside #386's review, not after it. #689 can start as soon as #691 merges, using the pinned reference. #537 is decided once a working fan-out exists to measure against. Cron (#536) is likely to build on the same consumer, so its design should reference #386.

Related

#691 (removal PR), ADR-0015, ADR-0028, ADR-0034, ADR-0040, ADR-0041 · docs/concepts/dispatch-archetypes.md · pipeline archetypes spec §2 · #378 (subagents epic), #490 (migration poll, closed by #691), #536 (Archetype C), #380, #360, #391, #17

Activity

  1. added
    enhancement
    on Nov 5, 2026
  2. changed the title [-]Epic: P6 async fan-out — replace the KEDA leaf-worker (Archetype A) before Knative/KEDA removal[/-] [+]Epic: P6 async fan-out — replace the KEDA leaf-worker (Archetype A) removed by #691[/+] on Nov 5, 2026
  3. cwiklik commented on Nov 6, 2026

    @cwiklik
    Contributor

    Status update — 2026-11-06: design phase complete, implementation open

    The gating child is done. #386 closed with docs/specs/2026-11-05-p6-async-fan-out-design.md and ADR-0047, merged as 316056a7 (#696). Everything below it is now unblocked.

    Children

    Child State Note
    #386 — B1 design Closed Spec + ADR-0047 (#696)
    #687 — data-plane async Closed Decided "replaced, not restored" — §4.2
    #689 — parity check Closed §10's sixteen-row table covers every "At minimum" bullet
    #690 — docs and ADR Open Step 1 in review: #697. Step 2 waits for the last implementation child
    #387 — B2 control plane Open Design decisions posted; M1-blocking
    #388 — B3 grants at dequeue Open Design decisions posted; larger than it read — see below
    #389 — B4 the consumer Open Design decisions posted; M1
    #688 — deploy/k8s wiring Open M3
    #537 — /v1/batches Open Decided once a working fan-out exists to measure

    All five downstream children (#387, #388, #389, #390, #391) now carry a comment mapping the spec's decisions onto their scope, per the spec's §12 obligation, so each can be picked up without re-deriving the design. Each comment also corrects what #691 invalidated in the issue body — notably #389's claim that @moca/work-queue and leaf-job-runner.ts "exist and can be reused", which is no longer true: both were deleted, and only harness/src/classify-outcome.ts survived.

    Three findings that change the plan, not just the docs

    1. turn_exp does not exist in code, so #388 is bigger than it reads. MI1 §6.1 specifies it, no TypeScript implements it (grep -rn 'turn_exp\|turnExp' packages harness → nothing outside docs), and expiry today is always exp = iat + ttlSeconds. This is where the M1/M2 split comes from: M1 ships before MI1 S2 using S2's own stated interim (credential resolved from the turn record at dequeue, MOCA_TENANCY=single only), and M2 is gated behind S2. Also: for an async leaf "turn start" is dequeue, not enqueue — a semantic MI1 §6.1 does not pin down, and a correction S2 needs regardless of async fan-out.

    2. A per-owner fan-out quota is new scope, and it ships in M1. MOCA_ASYNC_QUEUED_PER_OWNER (default 50), enforced in the control plane before the enqueue with 429 async_quota_exhausted. It is the only containment against unbounded fan-out from the LLM orchestrator §3 assumes, so it ships with the path it protects rather than after. It is distinct from SH_TURNS_PER_SUBJECT (#360), not a duplicate: per deployment vs. per worker, waiting vs. executing — an in-process counter cannot bound a queue it does not hold. Both apply.

    3. #390's heartbeat scope narrows. For queue-backed turns the liveness signal already exists one layer down (the 30 s claim heartbeat against a 90 s minIdleMs), and lost has exactly one author — the reaper. A second heartbeat on the turn record would be two liveness signals that can disagree.

    Acceptance, restated

    Unchanged, and worth repeating because the design phase closing is easy to mistake for progress against it: a reviewed spec and ADR close #386, not this epic. #686 closes when an Archetype A pipeline runs end to end on deploy/k8s and on deploy/vm or compose — M1 plus M3 — with #389's crash and drain acceptance holding. The first two acceptance bullets are now partly discharged: the data-plane decision is recorded (#687, "replaced"), and #697 removes "no P6 equivalent" from dispatch-archetypes.md and ADR-0041 in favour of "designed, not yet built". The third bullet — dropping "removed" from the Archetype A row — waits for the path to run.

    Sequencing from here

    Unchanged from the epic body, now with #386 done: #387 and #388 in parallel → #389 → #688 (M3). #690 step 2 lands with or after the last of those. #537 after a working fan-out exists. Cron (#536) should build on this consumer and cite ADR-0047; §11 of the spec states what it inherits (the identity answer and the whole queue-and-drain substrate — it adds the schedule).

  4. added a commit that references this issue on Nov 7, 2026
  5. self-assigned this
    on Nov 12, 2026
  6. added this to the v0.12.0 milestone on Nov 17, 2026
  7. cwiklik commented on Nov 17, 2026

    @cwiklik
    Contributor

    Status update — 2026-11-17: M1, M2 and M3 have all landed

    The epic has had no status update since the design-phase comment above (2026-11-06), and it reads as "designed, not built" when the opposite is now true. All three of the spec's milestones are implemented, verified against main @ 4da5dbfe. What is left under the open children is smaller than their state suggests, and in two cases it is only an unrecorded landing.

    What landed since 2026-11-06

    Milestone (§9) State Where
    M1 — working drain, MOCA_TENANCY=single Done #704 (submission, turn record, idempotency, audit, MOCA_ASYNC_QUEUED_PER_OWNER), #713 (POST /internal/turn-credentials), #717 (@moca/work-queue and leaf-job-runner.ts restored, leaf-drain-loop.ts in the turn worker, crash redelivery, reaper)
    M2 — multi-tenant Done #807 (both grants minted and refreshed), #788 (model and sandbox tier pinned to the record), #822 (turn_exp built, grant-at-dequeue, the inference listener that redeems it, tenancy gate lifted — async_tenancy_unsupported is gone from CP_ERROR_CODES)
    M3 — deploy/k8s Done #765 — the pod wiring (SH_ASYNC_DRAIN, the supervisor env ref, setup.sh's sticky validation) shipped with #389; #765 proved it drains on a real cluster and answered #688's capacity question (no HPA, no metrics adapter, by design — the drain shares one admission budget with interactive turns, so queue depth is the wrong signal for the front door)
    Docs Done #697 then #764 — dispatch-archetypes.md and ADR-0041 record Archetype A's P6 equivalent as shipped
    #390 — turn state, results, artifacts, retention Closed 2026-11-17 #840 — per-turn artifacts, a bounded status read, seven-day retention, and the sh:cp:session:<sid>:turns index that closes §9.2's deletion gap

    The acceptance criteria, re-read against that

    All three are now discharged:

    1. A recorded decision on data-plane /runs {async:true} — P6 async fan-out: decide the fate of data-plane /runs {async:true} (unauthenticated Archetype A controllers) #687, "replaced, not restored" (§4.2), and the async_removed refusal names this route.
    2. An Archetype A pipeline end to end on deploy/k8s and on deploy/vm or compose — feat(knative-server): async leaf worker on P6 (#389 M1) #717 on vm and compose, test(k8s): prove the async leaf consumer on deploy/k8s, and document its capacity #765 on a live cluster. Coding-agent subagents B4: async leaf worker on P6 (deploy/vm, compose) #389's crash and drain acceptance holds, including the env-gated live kill -9.
    3. ADR-0041 and dispatch-archetypes.md no longer say "no P6 equivalent" — docs: record archetype A's P6 equivalent as shipped (#690) #764.

    This epic is close to closable. What holds it open is #391 and one deferred item in #389, not the fan-out path itself.

    What each open child still tracks

    Child What is actually left
    #387 — B2 control plane M1 landed in #704 and is recorded there. §9's M2 line for this number — "control-plane turn record and submission API complete" — has no landing note, and the M2 control-plane work since #704 went in under #388's and #390's numbers (#788, #822, #840). Needs a confirm-or-close, not more building.
    #388 — B3 grants Both slices have landed. #713 recorded M1; M2 (#822) was never recorded here — it is the PR that built turn_exp, minted both grants at dequeue and lifted the tenancy gate, i.e. this issue's scope items 1 and 2. One open policy question remains (ADR-0047: whether refresh past turn_exp is refused outright, MI1 §6.2's current rule, or whether a still-running turn may extend). Closable once that is answered or split out.
    #389 — B4 the consumer M1 items 1–4 landed in #717 — also never recorded here. Item 5, retiring #380's interim contract, is the one genuinely deferred piece (§5.5).
    #391 — B13 budgets, quotas, cancel The real remaining implementation work, in progress on feat/391-turn-budgets-cancel. The queue-depth half already shipped as MOCA_ASYNC_QUEUED_PER_OWNER (#704); the per-subject concurrency half (#360, SubjectCounter) and per-turn budgets/cancel are what is left.
    #537 — /v1/batches Unstarted and correctly so: it is decided once a working fan-out exists to measure against. That fan-out now exists, so this is ready to be decided.

    One doc inconsistency worth fixing with the next PR

    ADR-0047's status line is stale. Line 3 still reads "M1 and M3 implemented by #704, #713, #717, #765; M2 … owed", while the body of the same ADR (§ "Delivery in three milestones") already describes M2 in the past tense — "M2 implemented turn_exp, completed grant-at-dequeue, and lifted the gate". #822 updated the gate section but not the header. A reader who checks the status line concludes multi-tenant async is unavailable, which is no longer true.

    Sequencing from here

    #391 is the last implementation child. #387, #388 and #389 need landing notes and a confirm-or-close pass rather than code (modulo #389 item 5 and #388's refresh-past-turn_exp question). #690 step 2 is already discharged by #764. Then #537 is decided, and this epic closes. Cron (#536) should build on this consumer and cite ADR-0047.

  8. cwiklik commented on Nov 18, 2026

    @cwiklik
    Contributor

    Closing: Archetype A has a P6 equivalent, end to end, on every P6 deployment

    #856 merged 2026-11-18 (aeff414b), which was the last implementation child. Every child of this epic is now closed, and all three acceptance criteria are discharged.

    Acceptance

    1. A recorded decision on data-plane /runs {async:true} — P6 async fan-out: decide the fate of data-plane /runs {async:true} (unauthenticated Archetype A controllers) #687: replaced, not restored (async spec §4.2). The route answers 400 async_removed and names the replacement; async_runs_unavailable is gone from the codebase entirely.
    2. An Archetype A pipeline end to end — deploy/vm and compose in feat(knative-server): async leaf worker on P6 (#389 M1) #717, a live cluster in test(k8s): prove the async leaf consumer on deploy/k8s, and document its capacity #765. deploy/k8s/smoke.sh claim 13 fans five leaves over a stack that runs two at a time and requires all five to reach a result; claim 14 deletes the supervisor pod under a running leaf and requires it to finish on a second delivery (attempts ≥ 2), which is Coding-agent subagents B4: async leaf worker on P6 (deploy/vm, compose) #389's redelivery acceptance. CI runs both on every k8s-kind-e2e with SH_ASYNC_DRAIN=1.
    3. ADR-0041 and dispatch-archetypes.md no longer say "no P6 equivalent" — docs: point Archetype A at ADR-0047 instead of "no P6 equivalent" (#690 step 1) #697, then docs: record archetype A's P6 equivalent as shipped (#690) #764.

    Children

    Child Closed by
    #386 — B1 design the ADR-0047 + spec PR
    #687 — data-plane async decision "replaced, not restored"
    #688 — deploy/k8s wiring #765, which also answered its capacity question: no HPA and no metrics adapter, by design — the drain shares one admission budget with interactive turns, so queue depth is the wrong signal for the front door
    #689 — Archetype A parity check fed back into #386
    #690 — docs and ADR #697, #764
    #387 — B2 control plane 2026-11-18, landing note; M1 in #704, the rest under #788/#822/#840
    #388 — B3 grants 2026-11-18, landing note; M2 in #807 and #822
    #389 — B4 the consumer 2026-11-18, landing note; items 1–4 in #717, deploy/k8s in #765, item 5 in #878
    #380 — the interim /runs contract #878, which made it permanent and tested rather than retiring the behavior
    #537 — /v1/batches decided 2026-11-17, once a working fan-out existed to measure against
    #391 — B13 budgets, quotas, cancel #856 merged; the issue stays open, re-scoped to cluster-wide per-subject bounding and per-session spend attribution. Its parent for the remainder is #378, and two shipped docs (docs/api/CHANGELOG.md:50, docs/operations/sizing-and-scaling.md:43) already point there by number

    What shipped, in one paragraph

    The KEDA ScaledJob is replaced by no new workload at all: with SH_ASYNC_DRAIN=1, each of the supervisor's ordinary --role=turn workers also runs a drain loop that claims one queued turn at a time and runs it through the same runLeaf a synchronous /v1/runs uses, inside the same admission budget (ADR-0047). A turn is submitted to the control plane, which writes an owner-scoped turn record and queues the turn id alone — no bearer token in the queue. At dequeue the worker exchanges that id for the turn's two grants, minted from the record with turn_exp anchored at the claim. Crash redelivery, a heartbeat-aware reaper, dead-lettering past maxAttempts, per-owner queue depth, per-turn token and wall-clock ceilings and running-turn cancel are all in place, with per-subject fairness bounding mixed load within a worker.

    Cron (#536) should build on this consumer and cite ADR-0047.

    Assisted-By: Claude Code

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

enhancement

Type

No type

Projects

Relationships

None yet

Development

No branches or pull requests

Issue actions