Skip to content

docs(537): decide against /v1/batches — a fan-out is the caller's loop - #861

Merged
cwiklik merged 2 commits into
rossoctl:mainfrom
cwiklik:docs/537-batch-decision
Nov 17, 2026
Merged

cwiklik merged 2 commits into
rossoctl:mainfrom
cwiklik:docs/537-batch-decision

Conversation

@cwiklik

@cwiklik cwiklik commented Nov 17, 2026

Copy link
Copy Markdown
Contributor

Closes #537.

#537 asked whether P6 needs a batch resource now that a working async fan-out exists to measure a
caller-side loop against. It does not. This is the recorded decision the issue's acceptance asks
for — docs only, no code and no API change.

The decision

A fan-out is the caller's loop: N leaves are N sessions, each holding one async turn, submitted in a
loop and collected by N status reads. Everything /v1/batches would own already lives somewhere
better:

  • Bounded concurrency is admission, not a submission parameter — the per-worker slot cap and
    MOCA_ASYNC_QUEUED_PER_OWNER. A concurrency field on a batch would be a third number free to
    disagree with those two.
  • Per-item state, retry and cancel are per-turn already: the turn record, at-least-once delivery
    with dead-lettering, and DELETE on the turn.
  • Grouping identity, when a caller needs one, is Ambiguity between "run" and "session" — clarify or eliminate the term #279's parentSessionId — a tree, which Coding-agent subagents B16: design — durable orchestration (declarative continuations vs re-entrant leaves) #401's
    declarative continuations own. A flat batch is that graph's degenerate case, so shipping it first
    would commit /v1 to the special case of a general shape nobody has designed.
  • One call instead of N is what remains, and it is a convenience: the caller already holds the N
    items it chose, and leaf runtime dominates N submission round trips.

Evidence beyond the design: #279's resolution left /v1/batches conditional on "a real batch"
appearing; the #490 migration responses named no batch dependency (nor an async fan-out one at all);
and the archetype requirements already assign batching by rule or class, batch size and locality
grouping to the external orchestrator
(docs/specs/2026-06-26-pipeline-archetypes-requirements.md §7.3).

The one real gap is collecting N results without N polls — there is no list-turns route and no
owner-scoped stream today. Its answer is #392's owner-scoped event stream, not a batch noun. What
would reopen this: a group-level operation that cannot be written as a loop (one cancel for the
group, or one read of every result), or a caller whose wall clock is set by submission round trips
rather than by leaf runtime.

What the loop costs, stated so a caller can size it

A session create per leaf, because idempotencyKey defaults to the session id and a session
therefore holds one async turn in flight; 429 async_quota_exhausted at
MOCA_ASYNC_QUEUED_PER_OWNER non-terminal turns, answered by waiting for one to finish rather than
by retrying; a fan-out width of SH_WORKERS × replicas, raised by hand since queue-depth scaling was
dropped; and collection inside LEAF_RESULT_TTL_SECONDS, after which only the record's terminal
state remains.

Where the decision is recorded

Each edit sits where the deferral was originally written, so no "decided once measurable" placeholder
survives:

File Change
docs/adrs/0047-p6-async-fan-out-in-worker-drain.md new rejected alternative, A batch resource (/v1/batches); removed from the follow-up-owed list
docs/specs/2026-11-05-p6-async-fan-out-design.md §4.4 closing amendment with the decision, the evidence and the loop's costs; the "what this is not" note, §4.4's goal-4 sentence, §5.5's collection sentence and §12's owed item all flipped
docs/specs/2026-09-08-multi-user-control-plane-design.md the #279 amendment's "/v1/batches is deferred until a working fan-out can measure whether it is needed" now records the answer
docs/concepts/dispatch-archetypes.md Archetype A step 2 gains N leaves are N sessions — the guide never said it, and the idempotencyKey-defaults-to-the-session-id dedup silently punishes a caller who assumes one session can hold the whole fan-out

Verification

Docs only: no .ts, no OpenAPI document and no contract version touched, so there is nothing to
typecheck or test and no changelog entry to bump (grep -rn "v1/batches" over packages, harness,
scripts and .github finds nothing). Prettier reports all four files conformant.

Assisted-By: Claude Code

rossoctl#537 asked whether P6 needs a batch resource now that a working async
fan-out exists to measure a caller-side loop against. It does not.

A fan-out is N sessions, each holding one async turn, submitted in a loop
and collected by N status reads. Everything /v1/batches would own already
lives somewhere better: bounded concurrency is admission (the slot cap and
MOCA_ASYNC_QUEUED_PER_OWNER), per-item state, retry and cancel are
per-turn, and a group identity — when a caller needs one — is rossoctl#279's
parentSessionId tree under rossoctl#401, of which a flat batch is the degenerate
case. One call instead of N is all that remains, and leaf runtime
dominates N round trips.

Records the decision where the deferral was written (ADR-0047's
alternatives, the P6AF spec's §4.4, MU1's rossoctl#279 amendment), with the loop's
limits stated so a caller can size it: a session per leaf, the per-owner
429, a fan-out width of SH_WORKERS × replicas, and collection inside
LEAF_RESULT_TTL_SECONDS. The one real gap it names — collecting N results
without N polls — is rossoctl#392's owner-scoped event stream, not a batch noun.
The archetypes guide gains the "N leaves are N sessions" sentence, which
it never said and which an idempotency-key default silently punishes.

Assisted-By: Claude (Anthropic AI) <[email protected]>
Signed-off-by: cwiklik <[email protected]>
@cwiklik
cwiklik requested a review from pdettori as a code owner November 17, 2026 18:12
@cwiklik cwiklik added the ready-for-ai-review Request automated AI code review from clawgenti label Nov 17, 2026

@ingpaolodettori-dev ingpaolodettori-dev left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The decision record is clear, and it's placed where each deferral was originally written. I checked the factual claims against main: the idempotencyKey default to the session id (turn-handlers.ts:131), MOCA_ASYNC_QUEUED_PER_OWNER, LEAF_RESULT_TTL_SECONDS, and archetypes requirements §7.3. All match. Two small suggestions and one nit inline.

Comment thread docs/concepts/dispatch-archetypes.md Outdated
`async: true` answers `202 {sessionId, turnId}`. Over the fan-out quota it answers 429
`async_quota_exhausted`. **N leaves are N sessions**, one async turn each — `idempotencyKey`
defaults to the session id, so a second async turn on a session whose first is still running is
deduplicated onto it rather than queued behind it. There is no batch resource and none is coming

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion: "N leaves are N sessions" reads as a rule, but spec §4.3 explicitly lets one session hold several queued turns when the caller passes distinct idempotencyKeys (turn-result.ts's per-turn result key exists for exactly that). Consider adding "unless you pass distinct idempotencyKeys, in which case ordering is yours", so the guide doesn't contradict §4.3.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Taken, in 7669697. The line now reads "deduplicated onto it rather than queued behind it — unless you pass distinct idempotencyKeys, which does queue several turns on one session and makes their ordering yours to manage, a responsibility the queue does not take (spec §4.3)". That last clause is §4.3's own wording ("takes responsibility for the ordering, which the queue does not promise"), so the guide now points at the exception instead of overriding it.

@@ -606,7 +644,8 @@ Retention beyond 24 h and richer artifacts are out of scope here; §12 lists the
delivered both: seven-day retention, and a base commit plus a diffstat on every captured patch.)

The caller polls the turn record for state, and the result store for the artifact. Whether N-way

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion: The edit leaves "Whether N-way collection needs no /v1/batches: …", which no longer parses. Drop "Whether": "N-way collection needs no /v1/batches: §4.4's closing amendment records …".

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 7669697 — "Whether" dropped, exactly as suggested: "N-way collection needs no /v1/batches: §4.4's closing amendment records #537's decision and what the loop costs."

richer artifacts; per-class concurrency caps, for which `async_claim_denied_full` against
interactive `429`s is the measurement that would justify them; `/v1/batches` (#537) once a working
fan-out exists to measure against; the documentation updates in #690 (ADR-0041's "Still owed" note,
interactive `429`s is the measurement that would justify them; the documentation updates in #690 (ADR-0041's "Still owed" note,

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: Removing the /v1/batches clause left this line ~129 chars, unwrapped against the surrounding ~100-col prose. Cosmetic only (lint passes).

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rewrapped in 7669697 — the paragraph's last three lines are now 99/97/100 chars, matching the surrounding prose. Checked with prettier --check (the repo binary, since this worktree has no node_modules) and scripts/check-doc-links.py: both clean.

- `dispatch-archetypes.md`: "N leaves are N sessions" read as a rule, which contradicted
  spec §4.3 -- distinct `idempotencyKey`s do queue several turns on one session. The
  caveat, and whose problem their ordering is, is now on the line.
- spec §5.4: the removed `/v1/batches` clause left "Whether N-way collection needs no
  `/v1/batches`:", which no longer parsed. Dropped the "Whether".
- ADR-0047: rewrapped the ~129-char line the same removal left, to the surrounding ~100.

Assisted-By: Claude (Anthropic AI) <[email protected]>
Signed-off-by: cwiklik <[email protected]>

@ingpaolodettori-dev ingpaolodettori-dev left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Follow-up to the 82ddf4f review. 7669697 fixes all three items: the dispatch-archetypes caveat for distinct idempotencyKeys (matches spec §4.3), the spec §5.4 sentence, and the ADR-0047 rewrap. Nothing new. CI note: proto failed in "Build and test remote-worker" on this docs-only head (no Go/proto change, and it passed on 82ddf4f), so it looks like the known flake. Please re-run it before merging.

cwiklik added a commit to cwiklik/moca that referenced this pull request Nov 17, 2026
…red test

The second flake blocking an unrelated docs PR's CI (rossoctl#861):

    FAIL test/sandbox-token.transport.test.ts > clears the timer when the Exec ends
    first: no late Abort reaches the worker
    AssertionError: expected 4 to be +0

4 is DEADLINE_EXCEEDED. `exp` is `Math.floor(Date.now() / 1000) + ttlSeconds`, so a ttl
of 1 leaves between 1 ms and 1 s of real budget depending on where in the second the token
is minted -- and this test deliberately runs with `sandboxLeewayS: 0`, so the Exec has to
finish inside whatever that was. A ttl of 2 guarantees at least a second of it.

The assertion is unweakened: the sleep after the Exec is 2.5 s, which is past exp however
much was left, so a timer that was NOT cleared still delivers its late Abort and still
fails the test.

Assisted-By: Claude (Anthropic AI) <[email protected]>
Signed-off-by: cwiklik <[email protected]>
@cwiklik
cwiklik merged commit d3b4e0c into rossoctl:main Nov 17, 2026
21 of 23 checks passed
cwiklik added a commit that referenced this pull request Nov 17, 2026
…erting it

`proto` failed on an unrelated docs PR (#861) with

    burst_test.go:137: Idle() = false after every frame was delivered: the unsent
    accounting leaked

and passed on a re-run: the test asserted Idle() the instant it observed the last frame,
which does not prove the accounting has caught up. The fake stream records a frame INSIDE
Send while `unsent` drops only after Send returns, and the pool goroutine drops `inflight`
only after runOne returns -- the same lag the `settle` helper exists for. The `DeferredNow
== 0` wait just above does not cover either: drainDeferred drops that counter the moment
the frame is handed to outbound.

So it is a wait now, which still fails on a genuine leak -- as a timeout. Verified by
deleting the sender's `unsent.Add(-1)`: the test fails in 3 s with "timed out waiting for
Idle()".

No production code changed. The two other bare `Idle()` asserts in this package are
ordered: both follow Serve returning, and Serve's teardown closes `outbound` and waits for
the sender goroutine before it does.

Assisted-By: Claude (Anthropic AI) <[email protected]>
Signed-off-by: cwiklik <[email protected]>
cwiklik added a commit to cwiklik/moca that referenced this pull request Nov 17, 2026
Conflicts in ADR-0047's "Also owed" paragraph and the spec's §4.4/§4.5
boundary: rossoctl#861 landed rossoctl#537's decision against /v1/batches while this branch
rewrote the same paragraph and renamed §4.5. Kept both — the rossoctl#537 amendment
block, §4.5's new "Cancellation" title (a running leaf is cancellable now),
and rossoctl#391's fairness/rossoctl#859 amendments, with /v1/batches dropped from the owed
list since rossoctl#537 decided against it.

Assisted-By: Claude (Anthropic AI) <[email protected]>
Signed-off-by: cwiklik <[email protected]>
@pdettori pdettori added this to the v0.11.0 milestone Nov 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ready-for-ai-review Request automated AI code review from clawgenti

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Decide whether P6 needs batch execution (/v1/batches) now that KEDA fan-out is going away

3 participants