Repository navigation
Description
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/(includingleaf-scaledjob.yaml,leaf-orchestrator.yaml,leaf-async-smoke.shand theocp-asyncoverlay)- the KEDA drainer (
leaf-job.ts) andharness/src/leaf-job-runner.ts - the async-enqueue route:
POST /runswithasync: truenow answers400 async_removed @moca/work-queue, whose only consumers were that pathdocs/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:
packages/knative-server/src/leaf-job.ts: the drainerpackages/work-queue/: the Redis Streams queue, with XAUTOCLAIM reaper (leaf-worker KEDA ScaledJob never scales to zero: stale pending entries deadlock (no XAUTOCLAIM reaper) #17) and result recordsdeploy/knative/leaf-scaledjob.yaml: the KEDA scaling contract
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):
- Coding-agent subagents B1: design — async leaf turns on sessions for P6 (spec + ADR) #386 — B1 design: async leaf turns on sessions for P6 (spec + ADR). Decides where the consumer runs (managed by the supervisor or
--role=leaf), admission shared with/turn, drain, and the queue (revive@moca/work-queuefrom history or replace it). - Coding-agent subagents B2: control plane — async turn submission and turn records #387 — B2: control plane, async turn submission and turn records
- Coding-agent subagents B3: grants minted at dequeue from the turn record (no bearer in the queue) #388 — B3: grants minted at dequeue from the turn record, with no bearer token in the queue
- Coding-agent subagents B4: async leaf worker on P6 (deploy/vm, compose) #389 — B4: async leaf worker on P6 (
deploy/vm, compose). The drainer that replaces the removedleaf-worker. - Decide whether P6 needs batch execution (/v1/batches) now that KEDA fan-out is going away #537 — decide whether a client-side loop over async sessions is enough for N-way fan-out, or whether
/v1/batchesis needed
New (filed from this epic):
- P6 async fan-out: decide the fate of data-plane /runs {async:true} (unauthenticated Archetype A controllers) #687 — Data-plane async on P6. After chore: remove the deprecated Knative/KEDA deployment path (ADR-0041) #691 the route answers
400 async_removed. Decide whether unauthenticated/runs {async:true}comes back on the new consumer, is replaced by the authenticated path, or stays removed. If it stays removed, the replacement must cover a controller with no interactive user, the same "who does it run as" question P6 scheduled dispatch: replace the cron-dispatch CronJob (Archetype C) removed by #691 #536 raises for cron. - P6 async fan-out: wire the async leaf consumer into deploy/k8s (Kind and OCP overlays) #688 —
deploy/k8swiring for the consumer. Coding-agent subagents B4: async leaf worker on P6 (deploy/vm, compose) #389 coversdeploy/vmand compose only. This one covers manifests, overlays (Kind, OCP),setup.shand a smoke test for queued leaves on P6.1. The removedleaf-async-smoke.shis the starting point for the smoke. - P6 async fan-out: Archetype A parity check — what the KEDA leaf-worker gives that P6 must match or drop #689 — Archetype A parity check. Against the reference implementation above, list what the KEDA path gave that the P6 design must match or explicitly drop: scale-to-zero, queue-depth-driven capacity, the XAUTOCLAIM reaper (leaf-worker KEDA ScaledJob never scales to zero: stale pending entries deadlock (no XAUTOCLAIM reaper) #17), result-record TTL (
LEAF_RESULT_TTL_SECONDS), and per-class concurrency caps (archetypes §2). Feed the gaps back into Coding-agent subagents B1: design — async leaf turns on sessions for P6 (spec + ADR) #386. - P6 async fan-out: point the migration guide and ADR-0041 at the tracking epic #690 — Docs and ADR.
docs/migrating-from-knative.mdis gone with chore: remove the deprecated Knative/KEDA deployment path (ADR-0041) #691, so the targets are now ADR-0041's "Still owed" note, the Archetype A row and section ofdocs/concepts/dispatch-archetypes.md, and theasync_removedentry indocs/reference/http-api.md. Point them at this epic once chore: remove the deprecated Knative/KEDA deployment path (ADR-0041) #691 merges. Rewrite them as usage docs, plus a configuration-reference entry, when the path ships.
Acceptance
- A recorded decision on data-plane
/runs {async:true}: restored, replaced, or permanently removed. If it is not restored,async_removednames 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/k8sand ondeploy/vmor 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.mdno 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
Metadata
Metadata
Assignees
Labels
Type
Projects
- StatusShow more project fieldsDone
Activity
[-]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[/+]docs(readme): drop Knative/KEDA references now that #691 merged
docs: design the P6 async fan-out replacement (#686, #386)
docs: close four gaps in the async fan-out design (#686, #386)
docs: close two gaps found auditing against #686 rather than #386
cwiklik commentedon Nov 6, 2026
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.mdand ADR-0047, merged as316056a7(#696). Everything below it is now unblocked.Children
deploy/k8swiring/v1/batchesAll 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-queueandleaf-job-runner.ts"exist and can be reused", which is no longer true: both were deleted, and onlyharness/src/classify-outcome.tssurvived.Three findings that change the plan, not just the docs
1.
turn_expdoes 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 alwaysexp = 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=singleonly), 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 with429 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 fromSH_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), andlosthas 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/k8sand ondeploy/vmor 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" fromdispatch-archetypes.mdand 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).
Merge upstream/main (316056a) into sbx-template
docs: point Archetype A at its design instead of "no P6 equivalent"
docs: register P6.4 (async fan-out) in the spec milestone registry
fix(control-plane): answer a pathological variable name in linear time
fix(control-plane): decide the async quota by a write, compare every …
feat(control-plane): resolve a turn's credential at dequeue from its …
feat(control-plane): mount the dequeue exchange at POST /internal/tur…
test(control-plane): drain a turn through the real dequeue exchange
docs(api): document the dequeue exchange, and the version the turn ro…
docs: fix the /runs/status claim and the four docs the sweep missed
docs: say what /runs/status actually answers for an async turn
docs: record archetype A's P6 equivalent as shipped (#690)
test(k8s): prove the async leaf consumer on deploy/k8s, and document …
cwiklik commentedon Nov 17, 2026
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
MOCA_TENANCY=singleMOCA_ASYNC_QUEUED_PER_OWNER), #713 (POST /internal/turn-credentials), #717 (@moca/work-queueandleaf-job-runner.tsrestored,leaf-drain-loop.tsin the turn worker, crash redelivery, reaper)turn_expbuilt, grant-at-dequeue, the inference listener that redeems it, tenancy gate lifted —async_tenancy_unsupportedis gone fromCP_ERROR_CODES)deploy/k8sSH_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)dispatch-archetypes.mdand ADR-0041 record Archetype A's P6 equivalent as shippedsh:cp:session:<sid>:turnsindex that closes §9.2's deletion gapThe acceptance criteria, re-read against that
All three are now discharged:
/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 theasync_removedrefusal names this route.deploy/k8sand ondeploy/vmor 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 livekill -9.dispatch-archetypes.mdno 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
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 pastturn_expis refused outright, MI1 §6.2's current rule, or whether a still-running turn may extend). Closable once that is answered or split out.feat/391-turn-budgets-cancel. The queue-depth half already shipped asMOCA_ASYNC_QUEUED_PER_OWNER(#704); the per-subject concurrency half (#360,SubjectCounter) and per-turn budgets/cancel are what is left./v1/batchesOne 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_expquestion). #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.cwiklik commentedon Nov 18, 2026
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
/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 answers400 async_removedand names the replacement;async_runs_unavailableis gone from the codebase entirely.deploy/vmand 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.shclaim 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 everyk8s-kind-e2ewithSH_ASYNC_DRAIN=1.dispatch-archetypes.mdno 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
deploy/k8swiringdeploy/k8sin #765, item 5 in #878/runscontract/v1/batchesdocs/api/CHANGELOG.md:50,docs/operations/sizing-and-scaling.md:43) already point there by numberWhat shipped, in one paragraph
The KEDA
ScaledJobis replaced by no new workload at all: withSH_ASYNC_DRAIN=1, each of the supervisor's ordinary--role=turnworkers also runs a drain loop that claims one queued turn at a time and runs it through the samerunLeafa synchronous/v1/runsuses, 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 withturn_expanchored at the claim. Crash redelivery, a heartbeat-aware reaper, dead-lettering pastmaxAttempts, 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