Skip to content

feat: mint turn grants at dequeue and redeem them at the inference listener (#388) - #822

Merged
cwiklik merged 15 commits into
rossoctl:mainfrom
cwiklik:feat/388-m2-grant-redemption
Nov 16, 2026
Merged

cwiklik merged 15 commits into
rossoctl:mainfrom
cwiklik:feat/388-m2-grant-redemption

Conversation

@cwiklik

@cwiklik cwiklik commented Nov 16, 2026

Copy link
Copy Markdown
Contributor

Summary

Closes the ADR-0047 gate: an async turn can now run under MOCA_TENANCY=multi, because the dequeue
has something to return that is not a secret. The control plane mints MI1 §6.1's two grants when a
worker claims a turn (mode: 'grant'), and redeems the inference one at its own listener, so a
worker in multi-tenant async mode holds a capability scoped to one turn and never a credential it
could spend anywhere else. Slice M2 of #388 (epic #686 P6 async fan-out); MI1 §6.1–§6.7, §7.2, §8.6;
ADR-0047 gate section marked closed rather than deleted.

What changed, in order:

  • dda06deb the redeemer — swaps an moca-inference grant for the credential its cred claim
    names, sets whichever header that credential's binding wants, forwards upstream.
  • 885460c7 the listener — a second HTTP listener in the control-plane process
    (MOCA_INFERENCE_ADDR / MOCA_INFERENCE_URL); checkGrantRedemption makes multi without a
    redeemer a boot refusal, which is where ADR-0047's async_tenancy_unsupported refusal now lives.
  • 91420a25 grantsForTurn — both grants from the turn record, turn_exp = dequeue + min(caps.wallClock, MOCA_TURN_MAX_S),
    the inference grant minted with exp == turn_exp so nothing refreshes mid-turn.
  • 4b14dbad the dequeue branch — under multi, exchangeTurnCredential returns grants and the
    listener's URL and reads no credential at all (§6.6); async_tenancy_unsupported is gone from
    CP_ERROR_CODES, and the submission-time refusal with it. The single-tenant path is unchanged.
  • 938f94b4 the worker side — grant accepted as a third UpstreamCredential mode, and the
    MOCA_TENANCY=multi early return deleted from the leaf drain loop.
  • 115ff62d the acceptance test — a full async turn over HTTP under multi: grant at dequeue,
    verified against the grant ring, spent at the listener, real credential seen only by the fake
    upstream, and no secret on the queue entry, the turn record or the audit stream. It passed without
    any further production change.
  • 1c22cfc8 docs — openapi 1.24.0 (mode: grant, sandboxGrant, turnExp, the two 501s that no
    longer exist), CHANGELOG, change-policy, configuration reference, the two deploy READMEs and
    env examples, the MI1 spec's §14/§15 rows, and the ADR's closing note.

Notes for review:

  • The grant is a capability, never a secret: no response, audit entry or log line carries a
    credential value, and the grant branch has no resolveInference above it by design.
  • The interactive exchange still returns a real key under multi — pre-existing, out of this slice,
    marked with a shortcut: comment.
  • 938f94b4's scope reads feat(knative-server); the package is packages/server after the
    upstream rename. Cosmetic, happy to reword if you want the history tidy.

Checklist

  • Commits are signed off (git commit -s).
  • make lint and the tests for the touched packages pass. control-plane 1854 passed / 3 skipped,
    packages/server 577 passed, harness 871 passed. make lint is clean except hadolint-docker,
    which needs a Docker daemon I do not have running locally. Three pre-existing failure clusters
    on this macOS box (harness/test/context-overlay.test.ts permission, packages/supervisor
    real-worker integration, packages/mocactl sbx/TUI) reproduce unchanged on main without this
    branch.
  • Docs: changed behavior, flags and environment variables are reflected in
    docs/reference/configuration.md, docs/reference/http-api.md, docs/api/openapi.yaml,
    deploy/k8s/README.md and deploy/vm/README.md.
  • Docs: make check-links passes (211 files, 0 broken links).
  • A new spec or ADR is registered — n/a, no new spec or ADR; the existing MI1 spec and ADR-0047
    are amended in place.

Assisted-By: Claude Code

@cwiklik
cwiklik requested a review from pdettori as a code owner November 16, 2026 16:01
Comment thread packages/control-plane/src/main.ts Fixed
cwiklik added a commit to cwiklik/moca that referenced this pull request Nov 16, 2026
…lines

CodeQL on rossoctl#822: one high and two medium alerts on the new redemption path.

The high one was mine from the previous commit -- the bind-failure line
interpolated `env.MOCA_INFERENCE_ADDR`, and that `env` is the copy holding
resolved secrets, so nothing read out of it belongs in a log. Node's listen
error already names the address and port.

The two mediums are log injection: a credential NAME reaches two plain-text
operator lines (the unreachable-upstream error, the non-primary-KEK warning),
and on this path the name comes from a grant claim rather than from a validated
request body. `JSON.stringify` already protects the audit lines; these are
plain text, so strip CR/LF with one shared `forLog` helper.

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

@clawgenti clawgenti 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.

"### Summary\n\n(Note: an earlier version of this summary posted with backtick-quoted terms stripped; this is the corrected text.)\n\nLarge, well-executed slice of #388 (M2): under MOCA_TENANCY=multi, dequeue now mints two Ed25519 grants (inference + sandbox) instead of handing the worker a real credential, and a new second-port listener inside the control plane redeems the inference grant per request, re-reading the credential from the store (rotation/deletion honored, 3 s read cache) and proxying upstream SSE-safely. Boot contract is strong — multi without the ring or a derivable listener URL refuses to boot. Test coverage is thorough (grant hygiene, path traversal, SSE, tombstones, e2e with secret-absence assertions). No must-fix findings; the inline notes are suggestions on acknowledged shortcut trade-offs.\n\nAuthor: cwiklik (CONTRIBUTOR — returning external)\nAreas reviewed: Frontend (TS), YAML (OpenAPI), Docs, Security\nAgent/IDE config (.claude/.vscode): none\nCommits: 10 commits, all signed-off: yes\nCI status: passing\n\nGenerated by RepoMan github-pr-review@235a7f7 (https://github.com/rossoctl/agent-skills/blob/235a7f7620139ee3e4ab0872b8439591fe52e8c1/skills/github-pr-review/SKILL.md).\n"

* mutate live request headers, and it would buy nothing: the redeemer re-reads the session and
* the credential on EVERY request, so a deleted session or a rotated key takes effect at once
* rather than within MOCA_GRANT_TTL_S.
* shortcut: a grant stolen from a worker is replayable until `turn_exp` rather than for one TTL

@clawgenti clawgenti Nov 16, 2026 •

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 full-turn replay window (exp == turn_exp, up to MOCA_TURN_MAX_S, no revocation list) is acknowledged here and in configuration.md. Session tombstoning and credential rotation both cut it short at the next redemption, which is good defense-in-depth. Worth tracking a follow-up for a per-turn nonce or jti allowlist once M3 lands, so a leaked grant can be revoked even when its session stays live. Not blocking — MI1 §6.2 builds no revocation list on purpose.

Generated by RepoMan github-pr-review@235a7f7 (https://github.com/rossoctl/agent-skills/blob/235a7f7620139ee3e4ab0872b8439591fe52e8c1/skills/github-pr-review/SKILL.md).

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.

Deliberate for this slice, and agreed as a follow-up. §6.2 builds no revocation list on purpose, so what keeps the window honest is that both live checks run on EVERY redemption rather than once per grant: the session (tombstone and owner, from Redis) and the credential (re-read from the store). Each half already carries its own jti, so an allowlist has something to key on when M3 adds the token endpoint and a redeemer that is not in this process — that is the slice where it buys something, since today the only holder of a grant is the worker the control plane just handed it to.

One correction to the comment you quoted: it said a rotated credential takes effect "at once". With the read cache added in this round (K8sSecretStore, 3s per subject) that is now "at once on this replica, within 3s on another". Both the mint site and the redeemer say so (b5c3ee7, ba8cfab).

// Node's 300 s default requestTimeout would kill a long completion mid-stream, and a completion
// legitimately runs for minutes. `turn_exp` (at most MOCA_TURN_MAX_S) and the worker's own turn
// deadline are what bound it instead.
// shortcut: no per-request upstream timeout at all, so a wedged provider holds a socket until the

@clawgenti clawgenti Nov 16, 2026 •

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 — No per-request upstream timeout (requestTimeout = 0, no AbortSignal on the fetch). With MOCA_TURN_MAX_S bounding the turn, the worker gives up eventually, but a wedged provider still pins a socket. The comment's own plan (AbortSignal.timeout on the fetch) is the right one — consider landing it when the listener faces callers other than the deployment's own workers, or as a MOCA_INFERENCE_TIMEOUT_S defaulting generously.

Generated by RepoMan github-pr-review@235a7f7 (https://github.com/rossoctl/agent-skills/blob/235a7f7620139ee3e4ab0872b8439591fe52e8c1/skills/github-pr-review/SKILL.md).

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.

Keeping the shortcut: as written. The trigger it names — this listener facing callers that are not the deployment own workers — is also the trigger for the source allowlist in your next comment, and the two want to land together as one hardening change rather than as an env knob now that nobody would tune. In the meantime the worker turn deadline and turn_exp (≤ MOCA_TURN_MAX_S) bound the pinned socket, and headersTimeout is 60s, so a provider that wedges before answering headers is already cut.

// shortcut: no per-request upstream timeout at all, so a wedged provider holds a socket until the
// worker gives up. Add one (AbortSignal.timeout on the fetch) when this listener faces callers
// that are not this deployment's own workers.
server.requestTimeout = 0;

@clawgenti clawgenti Nov 16, 2026 •

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 listener is a credential boundary with only operator discipline (loopback / sandbox-network bind) protecting it; nothing in code restricts who may connect. That's documented loudly in configuration.md and the env example, and the boot contract refuses a wildcard bind without an explicit MOCA_INFERENCE_URL, which is a nice touch. If the listener later sits on a shared network, a source allowlist (or at minimum a startup warning when binding non-loopback) would harden this.

Generated by RepoMan github-pr-review@235a7f7 (https://github.com/rossoctl/agent-skills/blob/235a7f7620139ee3e4ab0872b8439591fe52e8c1/skills/github-pr-review/SKILL.md).

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.

Took the minimum you offered: warnIfExposed now says it at boot when the bind is not loopback, naming what the listener redeems and what the network therefore has to be (cb24ed8), and docs/reference/configuration.md records that the warning exists. A source allowlist stays with the per-request timeout above, for the slice where this listener stops being reachable only by this deployment own workers.

// Placeholder mode WINS whenever the deployment has an injector, so adding one strictly narrows
// what the harness may hold; direct mode is reachable only when none is configured, and MU3 deletes
// it outright (spec §3.6).
// shortcut: under MOCA_TENANCY=multi this still returns a real key, which MI1 §6.6 forbids --

@clawgenti clawgenti Nov 16, 2026 •

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 — The interactive /internal/credentials exchange still returns a real key under multi (MI1 §6.6), marked as out of scope. Fine for this slice; just flagging so the residual gap isn't lost once the async path is the reviewed surface.

Generated by RepoMan github-pr-review@235a7f7 (https://github.com/rossoctl/agent-skills/blob/235a7f7620139ee3e4ab0872b8439591fe52e8c1/skills/github-pr-review/SKILL.md).

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.

Agreed, and it is held by the shortcut: comment at that line rather than only by this PR thread. It is the interactive path own slice of §6.6 — the async half is what ADR-0047 gated, and that gate is what this PR closes.

Comment thread deploy/k8s/README.md
MI1 §6.1 grants and the worker spends the inference one at the control plane's inference listener.
It costs three control-plane settings — `MOCA_GRANT_SIGNING_KEY`, `MOCA_INFERENCE_ADDR`, and
`MOCA_INFERENCE_URL` when the bind is a wildcard — and the boot refuses without them. These
manifests wire none of them: no ConfigMap key and no Service port ship for the listener, so

@clawgenti clawgenti Nov 16, 2026 •

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 — Good that the k8s gap is stated this plainly and the boot refusal makes it loud rather than silent. Follow-up for M3: ship the ConfigMap key + Service port for the listener, since a multi k8s deployment currently needs hand-rolled manifests to boot at all.

Generated by RepoMan github-pr-review@235a7f7 (https://github.com/rossoctl/agent-skills/blob/235a7f7620139ee3e4ab0872b8439591fe52e8c1/skills/github-pr-review/SKILL.md).

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.

That is decision D5 for this slice: env-example rows only, no deployment wiring, so a multi k8s deployment fails its boot contract loudly instead of coming up half-wired on manifests nobody tested. Agreed the ConfigMap key and the Service port belong in M3, alongside the listener moving to moca-egress (§8.6).

@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.

Summary

This lifts ADR-0047's multi gate for async turns. The dequeue now mints the MI1 §6.1 grant pair from the turn record (turn_exp is anchored at the claim, exp == turn_exp), and a new control-plane inference listener redeems the inference grant. That redemption re-checks the session owner and tombstone on every request and then forwards upstream with the binding's header. The single-tenant path is a pure refactor (the shared sandbox block is hoisted), and the worker-side changes are minimal. The K8sSecretStore read cache coalesces in-flight reads, never caches failures, and invalidates on local writes.

One must-fix: the listener's .. check runs on the raw path, but fetch normalizes percent-encoded dot segments. So /%2e%2e/... climbs out of the credential endpoint's prefix, and the real secret goes to another path on the gateway host. That is the exact case the comment says the check prevents (inline). One suggestion: the boot contract accepts multi with only MOCA_INFERENCE_URL set, which means no listener runs in this process (inline).

The remaining CodeQL log-injection alert on inference-proxy.ts:116 looks like a false positive now that forLog wraps both caller-supplied values. Worth dismissing it with that reason once it's confirmed.

Author: cwiklik (MEMBER — maintainer)
Areas reviewed: TypeScript (control-plane, server, harness), tests, Docs/OpenAPI, deploy env examples
Agent/IDE config (.claude/.vscode): none
Commits: 10 commits, all signed-off: yes
CI status: passing (all 17 checks green)

// carrying a prefix (`https://gw/anthropic`) keeps it -- `new URL(path, endpoint)` would discard
// the prefix and aim the secret at the gateway's root. That makes a `..` a way to climb out of the
// prefix, so refuse one; no legitimate client sends it.
if (!path.startsWith('/') || path.includes('..')) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

must-fix — path.includes('..') checks the raw req.url, which Node does not decode, but fetch(target) parses target with the WHATWG URL parser, and that parser treats %2e/%2E as a dot when it resolves dot segments. Verified with Node 26:

new URL('https://gw.example/anthropic' + '/%2e%2e/admin').href  // https://gw.example/admin
new URL('https://gw.example/anthropic' + '/.%2E/admin').href    // https://gw.example/admin
new URL('https://gw.example/anthropic' + '/%2e./x').href        // https://gw.example/x  (no literal '..' at all)

So a grant holder can still climb out of the endpoint prefix, and the real secret is attached on the way out (L90-91). The comment above names this as the case being prevented. Suggest validating the resolved URL rather than the input string:

const base = new URL(cred.baseUrl);
const basePath = base.pathname.replace(/\/+$/, '');
const u = new URL(`${base.origin}${basePath}${path}`);
if (u.origin !== base.origin || (basePath && !u.pathname.startsWith(basePath + '/'))) {
  throw new CpError('invalid_request', 'the inference path must stay under the credential endpoint');
}
// then fetch(u) / fetch(u.href)

Please also add the %2e%2e and .%2E cases to inference-proxy.test.ts.

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.

Confirmed and fixed in 9ad2508. Your three cases reproduce exactly as written, and the third is the one that shows why an input-string check cannot work: %2e./x climbs a level with no .. in it anywhere.

Took your approach -- validate the RESOLVED url rather than the string that arrived -- with two differences. The origin is compared as well as the prefix, because the prefix test alone would pass a path that somehow moved the request to another host, and that is the one outcome that must never happen with the secret attached. And cred.baseUrl is parsed with URL.parse rather than new URL, so an endpoint that does not parse keeps the 503 credential_unavailable the unreachable case gives instead of becoming an unhandled 500 (refuseMisdirectedSecret tolerates an unparseable endpoint, so it can reach here).

The target string is still built by concatenation and fetched as before, so a credential endpoint carrying userinfo is unaffected -- base.origin drops it on both sides of the compare.

Tests: the literal .. case and both encoded ones are in inference-proxy.test.ts, sent through rawPost because fetch resolves them client-side. Verified against the pre-fix file: /%2e%2e/admin reaches the fake upstream with a 200 there, so the test fails without the change.

Comment thread packages/control-plane/src/main.ts Outdated
'than a credential (MI1 §6.6), and nothing can mint one without the ring',
);
}
if (!config.inferenceUrl) {

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 — this checks config.inferenceUrl, which inferenceUrlFromEnv fills from MOCA_INFERENCE_URL alone. So MOCA_TENANCY=multi + grant key + MOCA_INFERENCE_URL with no MOCA_INFERENCE_ADDR boots cleanly, while main() (L828) starts no listener. Every dequeue then hands out a URL nothing in this process serves, which is the failure the bind-error process.exit(1) comment at L832 says must not happen (nothing else implements the redeemer yet). The error text also implies ADDR is required. Consider requiring addrSet under multi as well (e.g. if (!addrSet || !config.inferenceUrl)), and adding the URL-only case to the checkGrantRedemption test in main.test.ts.

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.

Right, and fixed in e73483f: checkGrantRedemption now requires addrSet under multi too, as you suggested, with the message changed from "or MOCA_INFERENCE_URL" to "plus MOCA_INFERENCE_URL when the bind address is a wildcard" so the text matches what is actually required. main.test.ts gains the URL-only case (checkGrantRedemption(multi, true, false) throws).

Your reading of the intent is the right one: ADDR is never optional under multi, the URL only becomes necessary when the bind cannot be dialled.

cwiklik added a commit to cwiklik/moca that referenced this pull request Nov 16, 2026
… non-loopback bind

Review comments on rossoctl#822.

`forLog` used a `[\r\n]+` class, which CodeQL's js/log-injection does not
recognise as a sanitiser, so both alerts stayed open on code that was already
safe. `/\n|\r/g` is the form the query models -- same behaviour, and the scanner
keeps working on this path.

The listener is a credential boundary whose only caller check is the grant it
redeems, so the bind address is the access control (MI1 §8.6). An operator now
meets that in the boot log when the bind is not loopback, not only in the
configuration reference, which says so too.

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

@clawgenti clawgenti 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.

Summary

Impressive slice — the grant lifecycle is coherent end to end (mint at dequeue from the turn record, redeem at a dedicated listener, exp == turn_exp so nothing refreshes mid-turn), and the test coverage is unusually thorough: tampered/expired/wrong-audience grants, no-secret assertions across the queue entry, turn record and audit stream, raw-socket path-traversal probe, and the non-loopback bind warning. The single-tenant path is genuinely untouched apart from hoisting the shared sandbox object, and the interactive-exchange shortcut: is clearly marked pre-existing.

No must-fix issues; one suggestion and one nit inline. The stale knative-server commit scope you already flagged in the body — no need to rewrite history for it.

Author: cwiklik (CONTRIBUTOR — returning external)
Areas reviewed: TypeScript (control-plane, server/worker, harness), Tests, Docs/deploy/openapi
Agent/IDE config (.claude/.vscode): none
Commits: 13 commits, all signed-off: yes
CI status: passing on all completed checks (codeql, k8s-kind-e2e pending at review time)

Generated by RepoMan github-pr-review@235a7f7 (https://github.com/rossoctl/agent-skills/blob/235a7f7620139ee3e4ab0872b8439591fe52e8c1/skills/github-pr-review/SKILL.md).

Comment thread docs/reference/configuration.md Outdated
| `SH_SANDBOX_NAMESPACE` | `default` | Used on Kubernetes paths | Sandbox namespace |
| `SH_MODEL_CATALOG_HOSTS` | empty | Comma-separated bare hostnames, case-insensitive; a URL, port or path refuses to boot | Extra hosts the model catalog may contact |
| `MOCA_ASYNC_QUEUED_PER_OWNER` | `50` | Non-negative integer or boot fails. `0` refuses every async submission (429). Distinct from the worker's `SH_TURNS_PER_SUBJECT`: that counts turns executing, this counts turns waiting | Non-terminal async turns one owner may hold (ADR-0047) |
| `MOCA_TENANCY` | `single` | `single` or `multi`; **a near-miss spelling of the name throws**, here as in the worker. Async turns are refused with `501` under `multi` until M2. Must match the worker's | Tenancy mode |

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 — This row still says "Async turns are refused with 501 under multi until M2", but this PR is M2 and deletes exactly that refusal (async_tenancy_unsupported is gone from CP_ERROR_CODES, submitTurn and the dequeue, and the rewritten MOCA_INFERENCE_ADDR rows describe the new contract). Every other doc in the PR was updated; this one sentence contradicts them and the code.

Suggested fix: drop the sentence (e.g. end the row after "here as in the worker."). Worth fixing now so the configuration reference doesn't tell operators multi-tenant async is still gated after this merges.

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 e73483f. Dropped the sentence from that row, and from the WORKER MOCA_TENANCY row higher up (line 61), which carried the same claim in different words ("the control plane ... refuses async turns under multi until M2") -- it now says the control plane hands an async turn its grants rather than a key. grep "until M2" docs/ is clean apart from the two dated specs, where the phrase is their own planning text about when M2 arrives rather than a claim about current behaviour.

}

const out: Record<string, string> = {};
upstream.headers.forEach((v, k) => {

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 — out[k] = v collapses repeated response headers into a single , -joined entry (the Headers forEach contract). For headers where comma-joining isn't equivalent to repetition (set-cookie is the classic case) the client sees a lossy transcription. Unlikely to matter for Anthropic SSE responses, but since this is a transparent proxy it may be worth a getSetCookie() special case someday — no action needed now.

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.

Agreed on both counts, and leaving it. set-cookie is the only header where the comma-join is lossy rather than equivalent, and an inference endpoint that sets cookies is not a case this listener has: it forwards one POST per completion, holds no cookie jar, and pi sends none back. Adding a getSetCookie() branch now would be code with no caller.

Worth saying what the limit is rather than just agreeing: if this listener ever fronts something session-oriented, the fix is res.writeHead with set-cookie as an array from upstream.headers.getSetCookie(), everything else as today.

@clawgenti clawgenti 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.

State marker for the review queue (full review posted separately on this SHA):

Generated by RepoMan github-pr-review@235a7f7 (https://github.com/rossoctl/agent-skills/blob/235a7f7620139ee3e4ab0872b8439591fe52e8c1/skills/github-pr-review/SKILL.md).

…names

MI1 §6.3's ordered checks, in-process: verify the grant, confirm the session is
alive and owned, resolve the credential name the grant pins, refuse a misdirected
secret. The operator fallback is the one redemption that is audited. rossoctl#388

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

operatorInferenceHeader was left unset, so the prior assertion passed by
coincidence (default equals the asserted value). Set it explicitly so the
test proves the value is read from config.

Assisted-By: Claude (Anthropic AI) <[email protected]>
Signed-off-by: cwiklik <[email protected]>
A worker spends its inference grant here (MI1 §6.3): verify, resolve, swap in the
header the credential's binding names, stream through. In-process rather than in
moca-egress (decision D1), so there is no second shared bearer to steal, and the
boot contract refuses MOCA_TENANCY=multi without a ring and a redeemer. rossoctl#388

Assisted-By: Claude (Anthropic AI) <[email protected]>
Signed-off-by: cwiklik <[email protected]>
grantsForTurn takes the credential name and bundle the turn pinned at
submission, anchors turn_exp to the dequeue, and mints exp == turn_exp so a
worker needs no mid-turn refresh (decision D4). rossoctl#388

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

The async dequeue exchange had one answer under MOCA_TENANCY=multi:
async_tenancy_unsupported (501), because MI1 §6.6 forbids returning a real
key there and there was nothing else to return. There is now -- M1 landed
the grant mint -- so the gate is replaced by a third credential mode.

  - turn-exchange.ts gains a `grant` branch: two signed grants (MI1 §6.1)
    plus MOCA_INFERENCE_URL, and no resolveInference above it, so the path
    reads no credential at all. turn_exp is anchored to the DEQUEUE and
    clamped by caps.wallClock (async §5.4).
  - everything that is NOT the credential -- bundle, tier, template, seed,
    pinned build, model -- is hoisted into one `sandbox` object spread by
    both branches, so a templated session's async turn still lands on its
    template's workers instead of running untemplated.
  - turn-handlers.ts drops the submission-time tenancy refusal; multi now
    admits async, and errors.ts drops the code with its 501.

openapi.yaml still lists async_tenancy_unsupported, so
openapi-contract.test.ts fails until the docs commit removes it.

Refs: rossoctl#388, MI1 §6.1/§6.5/§6.6, async fan-out §5.4, ADR-0047

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

The worker side of the dequeue grant. Two deletions and one widened check:

  - turn-auth.ts accepts `grant` alongside `direct` and `placeholder`. The
    six fields it already validates are exactly the ones that matter in
    grant mode -- a non-empty token (the grant) and a resolved endpoint
    (the inference listener). sandboxGrant and turnExp are deliberately
    NOT validated: nothing in the worker reads either yet.
  - leaf-drain-loop.ts no longer refuses to arm under MOCA_TENANCY=multi.
    That block existed because the exchange answered 501 there, so arming
    meant claiming and refusing forever; the exchange now mints grants.
  - harness's UpstreamCredential already carries the `grant` arm, so the
    grant reaches runLeaf as the upstream credential unchanged.

Refs: rossoctl#388, MI1 §6.1, async fan-out §5.4

Assisted-By: Claude (Anthropic AI) <[email protected]>
Signed-off-by: cwiklik <[email protected]>
Submit, drain with the blind fake worker, verify both grants, then spend the
inference grant through the listener at a fake upstream. Asserts the upstream
saw the real key under the credential's own path prefix, and that the queue
entry, the turn record and the audit stream saw none of it. Replaces the test
for the 501 the slice deleted.

Refs: rossoctl#388, rossoctl#387

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

The dequeue exchange's documented response gains grant mode, sandboxGrant and
turnExp; async_tenancy_unsupported leaves the Error enum and both 501s. Every
place that told an operator async needs MOCA_TENANCY=single now names what multi
costs instead: the grant ring, the inference listener, and the sandbox grant's
still-missing redeemer. MI1 gets a dated amendment for the listener living in the
control plane rather than in moca-egress; ADR-0047 records its gate's criterion
as met. Contract version 1.22.0.

Refs: rossoctl#388, rossoctl#387

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

Review findings on the grant-redemption slice.

- The inference listener forwarded upstream's `content-encoding` while `fetch`
  had already decoded the body, so a worker gunzipped plain text and every
  compressed (that is, every non-streamed) provider answer failed. Dropped on
  the way back, as `content-length` already was.
- `K8sSecretStore` forked a `kubectl get secret` per read, and a worker redeems
  its grant on EVERY request to the provider -- a process fork per completion.
  Reads now go through a 3 s per-subject cache that holds the in-flight promise,
  so concurrent redemptions collapse into one fork; a write on this replica
  invalidates at once, and a failed read is never cached.
- `server.listen` resolves a bracketed `[::1]` as a hostname and dies ENOTFOUND,
  so `MOCA_INFERENCE_ADDR=[::1]:9100` could never bind. Brackets stripped for
  the bind, kept for `inferenceUrlFromEnv`. A bind failure now exits 1 instead
  of serving grants for a listener that is not there.
- The SIGTERM handler moved from `startInferenceProxy` to its one call site, so
  tests no longer accumulate a process listener per server.
- Dropped a stale comment about the 501 a `multi` deployment used to answer.

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

CodeQL on rossoctl#822: one high and two medium alerts on the new redemption path.

The high one was mine from the previous commit -- the bind-failure line
interpolated `env.MOCA_INFERENCE_ADDR`, and that `env` is the copy holding
resolved secrets, so nothing read out of it belongs in a log. Node's listen
error already names the address and port.

The two mediums are log injection: a credential NAME reaches two plain-text
operator lines (the unreachable-upstream error, the non-primary-KEK warning),
and on this path the name comes from a grant claim rather than from a validated
request body. `JSON.stringify` already protects the audit lines; these are
plain text, so strip CR/LF with one shared `forLog` helper.

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

Review comments on rossoctl#822.

`forLog` used a `[\r\n]+` class, which CodeQL's js/log-injection does not
recognise as a sanitiser, so both alerts stayed open on code that was already
safe. `/\n|\r/g` is the form the query models -- same behaviour, and the scanner
keeps working on this path.

The listener is a credential boundary whose only caller check is the grant it
redeems, so the bind address is the access control (MI1 §8.6). An operator now
meets that in the boot log when the bind is not loopback, not only in the
configuration reference, which says so too.

Assisted-By: Claude (Anthropic AI) <[email protected]>
Signed-off-by: cwiklik <[email protected]>
The same stale 'at once' claim the redeemer's step 2 carried: a credential
rotated on another replica now takes effect within the credential store's read
window, not instantly.

Assisted-By: Claude (Anthropic AI) <[email protected]>
Signed-off-by: cwiklik <[email protected]>
CodeQL js/clear-text-logging on the warning added a commit ago: the host comes
out of the env copy that also carries resolved secrets, and nothing read from
there belongs in a log line. The operator set MOCA_INFERENCE_ADDR, so naming the
setting is enough to act on.

Assisted-By: Claude (Anthropic AI) <[email protected]>
Signed-off-by: cwiklik <[email protected]>
@cwiklik
cwiklik force-pushed the feat/388-m2-grant-redemption branch from fc7e9bc to 515d61a Compare November 16, 2026 17:59

@clawgenti clawgenti 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.

Summary

Well-structured slice: the grant-at-dequeue design holds together, the secret-never-leaves-the-control-plane invariant is enforced and tested at every layer (queue entry, turn record, audit stream, logs), and the acceptance test exercises the full path over real HTTP. Two suggestions below, neither blocking: a gap in the new boot contract (MOCA_INFERENCE_URL without MOCA_INFERENCE_ADDR under multi), and a docs/code mismatch on the MOCA_INFERENCE_ADDR format.

Author: cwiklik (CONTRIBUTOR — returning external)
Areas reviewed: TypeScript (control-plane, server, harness), docs/OpenAPI, tests, security (secrets, supply-chain)
Agent/IDE config (.claude/.vscode): none
Commits: 13 commits, all signed-off: yes
CI status: pending at review time

Verified locally (head 515d61a): the eight touched control-plane suites pass — 212 tests, 0 failures (errors, grant-exchange, grant-redeem, inference-proxy, k8s-secret-store, main, turn-exchange, turn-handlers). The two touched packages/server suites could not be collected in this environment: harness/src/run-turn.ts imports the private @earendil-works/pi-coding-agent, which is not installable here — an environment limitation, not a PR defect. A throwaway probe against checkGrantRedemption (deleted afterwards) confirmed finding 1 below.

Generated by RepoMan github-pr-review@235a7f7 (https://github.com/rossoctl/agent-skills/blob/235a7f7620139ee3e4ab0872b8439591fe52e8c1/skills/github-pr-review/SKILL.md).

Comment thread packages/control-plane/src/main.ts Outdated
'than a credential (MI1 §6.6), and nothing can mint one without the ring',
);
}
if (!config.inferenceUrl) {

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 — Under multi, MOCA_INFERENCE_URL set without MOCA_INFERENCE_ADDR passes this boot check but the listener never binds (main only starts the proxy if (addr)), so the deployment boots, every dequeue hands out a grant aimed at inferenceUrl, and each turn fails at its first completion — exactly the failure mode the inference.on('error') exit path says failing the boot is for. The PR's own framing ("a deployment either has a grant ring and somewhere to redeem, or it does not boot") is violated by this configuration.

Verified empirically on head: checkGrantRedemption({ tenancy: 'multi', inferenceUrl: 'http://cp:3129' }, /* hasGrantRing */ true, /* addrSet */ false) does not throw (throwaway vitest probe, deleted afterwards).

Suggested fix: under multi, also require addrSet (or fold the URL and the bind into one check), so a URL with no listener refuses at boot like the other two misconfigurations. Why now: this is the slice that introduces the boot contract, so closing its last configuration-shaped hole belongs here rather than in the redeemer's follow-up.

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 e73483f -- if (!addrSet || !config.inferenceUrl), which is what you and @ingpaolodettori-dev both suggested, plus the URL-only case in the checkGrantRedemption test. Agreed on the timing: the hole is in the boot contract this slice introduces, so it belongs here.

Comment thread docs/reference/configuration.md Outdated
| `MOCA_GRANT_PUBLIC_KEYS` | empty | `<kid>:<base64 SPKI>`, comma-separated; the signer's own public half is always added. Only needed during a grant-key rotation. Verified on every request the inference listener is handed, so a rotation must list the retiring key here until the last grant signed by it has expired. Listing a key from `SH_SESSION_TOKEN_PUBLIC_KEYS` (or the session signer's own) refuses to boot | Extra grant verification keys |
| `MOCA_GRANT_TTL_S` | `300` | Blank or invalid falls back. With no revocation list (MI1 §6.2 builds none on purpose), this IS the revocation latency and a stolen grant's replay window; the holder refreshes at half-life. It governs the INTERACTIVE `/internal/turn-grants` pair only: at dequeue an async turn's grant is minted for the whole turn (`exp == turn_exp`), because the worker has no refresh loop | How long one grant lives |
| `MOCA_TURN_MAX_S` | `1800` | Blank or invalid falls back. An absolute cap: a refresh carries it forward unchanged and is refused once it passes, so no number of refreshes extends a turn. A turn's caps may ask for less and never more -- more is clamped at mint. A fresh ISSUE does start a new window, so on the interactive path this caps one turn's refresh chain rather than a session. For an ASYNC turn it is anchored at the dequeue and clamped to `caps.wallClock` when the submission named one | Deployment-wide ceiling on one turn |
| `MOCA_INFERENCE_ADDR` | unset | `host:port` or `port` for the inference listener -- a SECOND HTTP server in the control-plane process, not a route. Required under `MOCA_TENANCY=multi`, where the boot refuses without it. Unset means one port and no redemption, which is correct for `single`. Bind it to loopback or to the sandbox network only: a caller holding a valid grant gets the session's credential spent on its behalf, so this port is a credential boundary -- the control plane warns at boot when the bind is not loopback | The inference listener's bind address |

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 row says MOCA_INFERENCE_ADDR accepts "host:port or port", but inferenceAddrFromEnv (main.ts:192) throws on a port-only value: no : means at === -1, so the parse fails with "must be host:port, got '3129'". An operator following this row verbatim gets a boot refusal whose message contradicts the documented format.

Suggested fix: either drop "or port" from the row, or make the parser accept a bare port (binding all interfaces' default host) — whichever matches the intent. Docs accuracy matters here specifically because this setting is new in this release and the READMEs point operators at it as one of the three deliberate edits for enabling multi.

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 e73483f, the docs way: the row now says host:port only. The parser is the intent -- a bare port would have to invent a default host, and the two sensible defaults (loopback, or every interface) differ in exactly the way this setting must be explicit about, since the bind is a credential boundary. Nothing in the repo set a port-only value.

@clawgenti clawgenti 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.

Marker for the review-queue tracker (same review as above, id 5924938516): reviewed at head 515d61a — 2 suggestions, 0 must-fix.

Generated by RepoMan github-pr-review@235a7f7 (https://github.com/rossoctl/agent-skills/blob/235a7f7620139ee3e4ab0872b8439591fe52e8c1/skills/github-pr-review/SKILL.md).

`path.includes('..')` looked at `req.url`, which Node hands over undecoded,
while the WHATWG parser `fetch` uses resolves `%2e%2e`, `.%2E` and `%2e.` as
dot segments too. A grant holder could therefore send `/%2e%2e/admin` and climb
out of the credential endpoint's own path prefix, with the real provider secret
attached on the way out.

The check now runs on the RESOLVED url: same origin, and under the endpoint's
prefix. An endpoint that does not parse keeps the 503 the unreachable case
gives, rather than surfacing as an unhandled 500.

The test covers the literal spelling and two encoded ones; without the fix the
encoded cases reach the fake upstream with a 200.

Reported in review of rossoctl#822.

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

`MOCA_INFERENCE_URL` satisfied the `multi` boot check on its own, but the
listener binds only when `MOCA_INFERENCE_ADDR` is set, so that one combination
booted a deployment whose every dequeue hands out a grant aimed at a port
nothing in the process serves -- the failure the bind-error `process.exit(1)`
exists to prevent. `multi` now requires ADDR as well.

Two rows in the configuration reference, both flagged in review:

  - `MOCA_INFERENCE_ADDR` claimed to accept a bare `port`, which
    `inferenceAddrFromEnv` refuses ("must be host:port"). The parser is the
    intent, so the row drops the second form.
  - both `MOCA_TENANCY` rows still said async turns are refused with 501 under
    `multi` until M2. This IS M2 and it deletes that refusal.

Reported in review of rossoctl#822.

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

@clawgenti clawgenti 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.

Summary

Re-review of the two commits since 515d61a (9ad2508, e73483f), which close out the two open findings — and both hold up.

  1. Path traversal (was the must-fix): the check moved from the raw req.url string to the URL the parser actually resolves, and now enforces both the origin and the endpoint prefix on resolved.pathname. That covers every encoded spelling (/%2e%2e/, /.%2E/, /%2e.) the old literal .. scan missed, and the origin comparison closes the "move to another host" case the prefix test alone would not. The new test seeds a prefixed credential and asserts all three spellings get 400 with nothing reaching the upstream — exactly the probe the previous review ran by hand, now pinned.
  2. Boot-contract gap (was the suggestion): checkGrantRedemption now requires addrSet as well as inferenceUrl, so MOCA_INFERENCE_URL alone no longer boots a multi deployment handing out grants aimed at a port nothing serves. The main.test.ts case covers it, and the two stale MOCA_TENANCY rows in configuration.md ("refuses async turns under multi until M2") are corrected to describe the grant hand-off.

No new findings. One small nicety in the unparseable-baseUrl branch: the credential_unavailable 503 vs invalid_request 400 split is well-reasoned (the endpoint is the credential's problem, not the caller's) and the comment says so.

Author: cwiklik (CONTRIBUTOR — returning external)
Areas reviewed: TypeScript (control-plane), tests, docs
Agent/IDE config (.claude/.vscode): none
Commits: 15 commits, all signed-off: yes
CI status: passing (all checks green on head)

Verified locally (head e73483f): the three touched suites pass — 73 tests, 0 failures (inference-proxy, main, grant-redeem). No throwaway probes needed this time; the traversal cases are now first-class tests.

Generated by RepoMan github-pr-review@235a7f7 (https://github.com/rossoctl/agent-skills/blob/235a7f7620139ee3e4ab0872b8439591fe52e8c1/skills/github-pr-review/SKILL.md).

@clawgenti clawgenti 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.

Marker for the review-queue tracker (full review posted separately, id 5925549081): reviewed at head e73483f — 0 must-fix, 0 suggestions.

Generated by RepoMan github-pr-review@235a7f7 (https://github.com/rossoctl/agent-skills/blob/235a7f7620139ee3e4ab0872b8439591fe52e8c1/skills/github-pr-review/SKILL.md).

@cwiklik

cwiklik commented Nov 16, 2026 •

Copy link
Copy Markdown
Contributor Author

@ingpaolodettori-dev re-requesting review — both findings from your review on c67cdf40 are fixed, and the head is now e73483f4.

must-fix, the .. check on the raw path → 9ad25088. Reproduced all three of your cases; the check now runs on the RESOLVED url (same origin and under the endpoint path prefix) rather than on the undecoded req.url. cred.baseUrl is parsed with URL.parse, so an endpoint that does not parse keeps the 503 credential_unavailable the unreachable case gives instead of becoming an unhandled 500. Tests cover the literal spelling plus %2e%2e and .%2E, sent over a raw socket because fetch resolves them client-side — against the pre-fix file /%2e%2e/admin reaches the fake upstream with a 200, so they fail without the change.

suggestion, multi with only MOCA_INFERENCE_URL → e73483f4. checkGrantRedemption now requires addrSet as you proposed, the message reads "plus MOCA_INFERENCE_URL when the bind address is a wildcard", and main.test.ts asserts the URL-only case throws.

On the CodeQL log-injection alert: it was not a false positive — forLog used /[\r\n]+/g, which the query does not model as a sanitiser. Rewriting it to the recognised /\n|\r/g form closed it properly in 3435f9bc, so there is nothing left to dismiss. No js/* alert is open on this ref.

Also rebased onto upstream/main (aba41dbe) to clear a docs conflict, which force-pushed once — review comments anchored to the old SHAs may show as outdated. 17/17 checks green.

Assisted-By: Claude Code

@cwiklik cwiklik self-assigned this Nov 16, 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.

Follow-up at e73483f. Thanks, both items from our c67cdf4 review are fixed:

  • %2e%2e escape: the check now runs on the resolved URL (same origin, and under prefix + '/'). Because fetch uses the same WHATWG parser, the URL that gets checked is the URL that gets sent. I checked /%2e%2e/, /.%2E/, /%2e./ and /..\ (all refused), and /..%2f, //host and /@host (they stay under the prefix on the same origin). The new test covers the encoded forms.
  • ADDR under multi: now required, with a test.

Two small inline items, neither blocking: addrSet should use the parsed ADDR, so that an empty MOCA_INFERENCE_ADDR= can't slip past the check you just tightened. Also, the forLog comment is stale.

Author: cwiklik (MEMBER — maintainer)
Areas reviewed: TypeScript (inference-proxy.ts, main.ts, tests), Docs (configuration.md)
Agent/IDE config (.claude/.vscode): none
Commits: 15, all signed-off: yes
CI status: passing (17/17)

// Named for the same reason, and checked before anything connects: a deployment that cannot mint
// or redeem a grant must not reach the first request under `multi`.
const grantRing = grantRingFromEnv(env, verifyKeys);
checkGrantRedemption(config, grantRing !== undefined, env.MOCA_INFERENCE_ADDR !== undefined);

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 — addrSet is env.MOCA_INFERENCE_ADDR !== undefined, but inferenceAddrFromEnv treats an empty value as unset (if (!raw) return undefined), and the listener starts only if (addr) (L832). So under multi, MOCA_INFERENCE_ADDR= (empty, e.g. a blank env-file line) together with MOCA_INFERENCE_URL still boots with no listener. That's the same hole e73483f closes. The reverse case also misfires: under single with no grant ring, an empty ADDR refuses to boot with "ADDR is set". Passing inferenceAddrFromEnv(env) !== undefined (or !!env.MOCA_INFERENCE_ADDR) makes the check and the bind agree.

*
* `/\n|\r/g` verbatim, not a `[\r\n]+` class: this exact form is the one CodeQL's js/log-injection
* recognises as a sanitiser, and a helper it cannot see through leaves the alert open on every call
* site (#822). Same behaviour, and the scanner stays useful.

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 — "Same behaviour" is no longer accurate. The old class replaced CR/LF with a space, and this deletes it, so a\nb now logs as ab. Something like "CR/LF are deleted rather than spaced" would be accurate.

@cwiklik
cwiklik merged commit 42e5dc6 into rossoctl:main Nov 16, 2026
17 checks passed
@pdettori pdettori added this to the v0.11.0 milestone Nov 17, 2026
webchang added a commit to webchang/moca that referenced this pull request Nov 17, 2026
Takes upstream main at 1a7f41e (19 merges since 032c8f6): the sandbox
idle lifetime across docs, control plane, clients and deploy (rossoctl#820, rossoctl#837,
rossoctl#842, rossoctl#843), grant redemption (rossoctl#822), the lease-check log line (rossoctl#824),
egress fixes (rossoctl#829, rossoctl#834), the mock wait (rossoctl#828), the deadline timer
(rossoctl#835), the create rollback (rossoctl#832), multi refusals and the rossoctl#363 leftovers
(rossoctl#833, rossoctl#838), the identity near-miss check (rossoctl#827), mocactl login errors
(rossoctl#836), the ghostunnel probes (rossoctl#830), refusal-burst deferral (rossoctl#831), a
sandbox-worker change (rossoctl#841) and the v0.11 doc truth (rossoctl#821).

Conflicts (one):

- deploy/sbx/README.md, the "Optional inputs" table. Upstream (rossoctl#843)
  rewrote the SBX_LIFETIME_DAYS row (the default idle lifetime, at most
  SBX_MAX_LIFETIME_DAYS) and added the SBX_MAX_LIFETIME_DAYS and
  SBX_LOWER_WORKSPACE_IDLE rows, which widened the table; the fork had
  added an SBX_GATE_RECORD_SCHEMA row at its end. Resolved by taking
  upstream's table whole and appending the fork's SBX_GATE_RECORD_SCHEMA
  row after SBX_PROFILE, then re-padding the table with prettier. The
  fork's env-file example line for SBX_GATE_RECORD_SCHEMA merged cleanly.

Merged without markers, checked: setup.sh keeps the fork's
SBX_GATE_RECORD_SCHEMA validation and its sbx-settings write (so it stays
in the settings hash) beside upstream's SH_SANDBOX_MAX_LIFETIME_SECONDS;
both ocp-sbx and ocp-combined patch-control-plane.yaml keep the optional
SH_GATE_RECORD_SCHEMA from sbx-settings beside the new optional
SH_SANDBOX_MAX_LIFETIME_SECONDS; setup.test.sh keeps the fork's cases
beside upstream's. The fork's RUNBOOK, README and template-onboarding
docs say nothing about sandbox lifetime, refusal bursts, login errors or
the create rollback, so none needed a correction; GUIDE.md is unchanged
and GUIDE.pdf is not regenerated.

Assisted-By: Claude (Anthropic AI) <[email protected]>
Signed-off-by: Rong Chang <[email protected]>
cwiklik added a commit to cwiklik/moca that referenced this pull request Nov 17, 2026
The queue is one FIFO stream, so an entry's owner is unknowable until it is
claimed: the worker reads the claimed entry's `owner` (one HGET) and, when that
owner already holds SH_TURNS_PER_SUBJECT of this worker's slots, hands the entry
back unrun and backs off as it does on an empty queue. One owner's fan-out can
no longer sit in front of another owner's single turn.

The hand-back is XCLAIM ... JUSTID RETRYCOUNT <before this delivery>, not an
XACK and re-XADD: it keeps the entry in the PEL (so nothing can lose it) and
leaves the delivery counter where it was, so a defer is invisible to
maxAttempts. Without that, an owner at their cap would have their own turns
dead-lettered for having been deferred three times -- a refusal dressed up as a
failure. `WorkQueue` also deliberately exposes no `enqueue` to consumers.

The check runs BEFORE the claim handshake, so a turn that may not run yet mints
no credential, does not flip to `running` and writes no audit issuance. The slot
is released in one `finally` around the whole run, and the counter is the SAME
SubjectCounter instance the sync /turn route holds -- two counters would let one
subject hold 2x its cap.

Known limit, recorded in spec §12 and ADR-0047: the defer resets the entry's
idle timer, so a deferred turn waits up to minIdleMs (90 s) before any worker
may reclaim it. Leaving IDLE high instead would have this worker's own next
claim reclaim the same entry (XAUTOCLAIM leads every claim), defer it again, and
never reach the entries behind it -- the starvation the defer exists to prevent.
Per-owner streams are the upgrade.

`async_deferred_subject` joins §7's counters, plumbed through the stats row to
the admin /metrics. It is counted separately from `async_claims`, because a
defer read an entry and put it straight back: counting it as a claim would show
throughput rising while the queue made no progress.

ADR-0047's status header also said M2 was owed while its own milestones section
described M2 in the past tense; rossoctl#822 shipped it.

Assisted-By: Claude (Anthropic AI) <[email protected]>
Signed-off-by: cwiklik <[email protected]>
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.

5 participants