Skip to content

docs(spec): P5 multi-session isolation — per-request subject, no ambient credential (#220) - #228

Merged
pdettori merged 2 commits into
rossoctl:mainfrom
pdettori:docs/220-session-isolation-spec
Sep 8, 2026
Merged

pdettori merged 2 commits into
rossoctl:mainfrom
pdettori:docs/220-session-isolation-spec

Conversation

@pdettori

@pdettori pdettori commented Sep 7, 2026

Copy link
Copy Markdown
Member

Docs only — a spec and an ADR for the concurrency-safety half of #220. No code, no pi-fork
change, and nothing here closes #220.

What this is

docs/specs/2026-09-06-p5-session-isolation-design.md (canonical id P5) plus
ADR-0032, registered in both indexes.

The design makes one property enforceable: a request's upstream identity is determined solely by
that request, and no identity is reachable from process-global state.
Three ordered steps —
per-request subject inflow (X-SH-Subject → inert placeholder), then removing the ambient fallbacks
in applyModelGateway, then a startup scrub. The ordering is forced, not stylistic (see below).

Why the issue's framing needed correcting first

#220 attributes the blockage to five process-global states, four in pi-fork, and proposes threading
a SessionContext through the call chain. Tracing the code at f78081f contradicts that on four of
five rows — spec §2.1 has the full table with citations:

# Issue says Code says
1. ANTHROPIC_API_KEY Showstopper — "sessions corrupt each other" Real, different in kind. Write-once-if-absent, so A's token sticks process-wide and B..N authenticate as A — an identity leak, not mutual corruption
2. stdoutTakeoverState Showstopper Unreachable in server mode — takeOverStdout() is called only from main.ts:511 and rpc-mode.ts:54; the harness enters via createAgentSession
3. sessionResourceCleanups Showstopper — "A tears down B" Largely false — the sole registrant filters by session (openai-codex-responses.ts:769-784) and agent-session.ts:733 passes this.sessionId
4. fileMutationQueues Race — "same promise chain" Wrong mechanism — keyed by realpath, so different files already run in parallel
5. commandResultCache Stale data Low — only caches values beginning with !, which harness config never uses

Two consequences worth reviewing carefully:

Pi is already per-session on the credential path. _getRequiredRequestAuth resolves auth per
request from a per-instance ModelRegistry, and withEnvApiKey (stream.ts:26) consults the
environment only when no explicit key was given. The harness's env seed is what activates that
fallback beneath a mechanism that already worked. So nothing in pi-fork changes, and the four
other globals are pinned by reachability tests rather than refactored — an inert global should be
proven inert and left alone, since refactoring adds fork divergence to fix nothing.

The real prerequisite is unlisted by #220: no per-session credential enters the harness at all.
Every buildConfig() call site reads process.env (server.ts:66-73, leaf-job.ts:13-18,
cli.ts:13), so the pod's environment is the credential, one per deployment. Deleting the seed
alone would leave every session unauthenticated rather than fixing a leak — hence the forced ordering.

The architecture already forbade the obvious fix

Passing a real credential per request contradicts ADR-0011 (secret-free harness), ADR-0012 (injector
holds the keys), and ADR-0026 — whose rejected alternative #3 is literally "bake the credential
into the workload env". So the harness carries an inert placeholder and a subject, never a secret,
and AuthBridge's static-inject swaps it on egress. That invariant was documented prose with nothing
pinning it, which is how #182's spec entry went stale for two months; the spec adds a test for it.

One non-obvious constraint (spec §3.3): ANTHROPIC_API_KEY cannot simply be deleted.
run-turn.ts:150-155 documents that pi resolves the request key by provider name, and
createAgentSession exposes no per-session key seam — so an absent variable throws
No API key found for "anthropic" before any request is attempted. Server mode installs a fixed
non-secret sentinel instead: identical across tenants so it asserts no identity, stripped from
the wire by 'x-api-key': null, and assertable by exact value in a way deletion is not.

What this explicitly does not claim

  • Not the deployment-model change. ScaledJob → elastic pod pool, the 100× density numbers, and
    Sync-path saturation: bounded wait + 503 Retry-After per spec 4.3 #55's overload shift are a separate slice that this unblocks.
  • Not end-to-end multi-tenancy. That also needs per-subject resolution at the injector — Z5's
    deferred per-user / RFC 8693 half, in kagenti-extensions. The harness half is the strict
    prerequisite (the injector cannot key on a subject the harness never sends) and claims no more.
  • No change to the leaf ScaledJob path, which is one pod per leaf and stays ambient by design.

Review notes

Two judgment calls to confirm or overrule: the canonical id P5 on the two-tier P track rather
than a Zx id (it changes the harness tier's process model, same epic as #49), and the pinned caller
contract names X-SH-Subject / SH_SUBJECT_PLACEHOLDERS.

The index diffs look larger than one row each because the new row's cells are the longest in those
tables, so prettier re-pads every separator. git diff -w shows the substantive change is one row
per index.

make fmt and make lint (all hooks, gitleaks included) are clean. Refs #220.


Assisted-By: Claude (Anthropic AI) [email protected]

@cwiklik cwiklik left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Verified the spec's citations rather than its reasoning: every file:line reference in §2–§5 was checked against the tree at f78081f (which is this PR's own base commit) and the pi-fork submodule pinned there at 2c28be5. They all land where claimed, including the load-bearing ones:

  • run-turn.ts:310-312 is genuinely write-once-if-absent (if (authToken && !process.env.ANTHROPIC_API_KEY)), so row 1's "identity leak, not mutual corruption" re-framing is correct.
  • stream.ts:26 short-circuits on an explicit key before getEnvApiKey at :27, so §2.2's "pi is already per-session" — the finding the whole design rests on — holds.
  • takeOverStdout() has exactly two call sites repo-wide, main.ts:511 and rpc-mode.ts:54 (row 2's "unreachable in server mode").
  • registerSessionResourceCleanup has exactly one registrant repo-wide, openai-codex-responses.ts:786, and agent-session.ts:733 passes this.sessionId (row 3's "largely false").
  • file-mutation-queue.ts keys on the realpath-derived value at :35, leaving registrationQueue as the only true global (row 4's "wrong mechanism").
  • output-guard.ts:91's process.exit(1) sits in an unhandled-rejection catch, supporting §4's point that the module hides a worse hazard than the one #220 lists.

Three suggestions below, none blocking. They cluster on one theme: the design is consistently tighter than the artifacts meant to pin it — the sentinel test omits the variable that outranks the one it asserts, the lock-down invariant is asserted in-process while the manifest still mounts the real key, and step 2 touches leaf-shared code without saying why the leaf survives.

Two nits, not worth inline comments: the commit subject is 89 characters against the 72-char advisory, and agent-session.ts:353-355 is cited as "a per-instance field" where it is actually the accessor for one (the claim itself is right — this._modelRegistry).

On the two judgment calls put up for confirmation: P5 on the P track reads correct, since the slice changes the harness tier's process model and sits in epic #49 rather than the credential plane. X-SH-Subject as a dedicated header is well argued in §3.2 — that Authorization will mean may this caller use the harness once ADR-0011's lock-down lands, and that identity should not ride in a body persisted to Redis, both hold.


Author: pdettori (MEMBER — maintainer)
Areas reviewed: Docs (spec + ADR + 2 indexes); security §3.5/§3.5a; commit conventions; citation accuracy vs f78081f and pi-fork@2c28be5
Agent/IDE config (.claude/.vscode): none
Commits: 1 commit, all signed-off: yes
CI status: passing (12/12, DCO included)


Assisted-By: Claude (Anthropic AI) [email protected]

Placeholder derivation is a **pure, non-secret mapping** from subject → placeholder, from mounted
non-secret configuration. It contains no credentials, so it may be logged and asserted on in tests.

**Step 2 — remove the ambient fallbacks.** In `harness/src/run-turn.ts::applyModelGateway`, delete

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

suggestion — step 2 edits code the leaf path shares, and the safety argument given is turn-path-only.

applyModelGateway runs from both runTurn and runLeaf — the comment at run-turn.ts:307-309 says so explicitly, and warns against "cleaning it up" — but "Only safe after step 1" refers to per-request subject inflow in server.ts, which the leaf never receives. So a reader implementing this stops here and asks whether deleting the :310-312 seed leaves leaf pods with no ANTHROPIC_API_KEY for the provider-name lookup that §3.3 shows is load-bearing.

It doesn't: deploy/knative/leaf-scaledjob.yaml:65 mounts ANTHROPIC_API_KEY from llm-credentials directly, so the leaf never depended on the seed at all. Worth one sentence here or in §8 — §8 exists to stop a fresh session rediscovering mechanics, and this is the dual-path check most likely to be re-derived from scratch.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Recorded in step 2 — with two independent reasons rather than the one raised.

leaf-scaledjob.yaml:65-66 mounts ANTHROPIC_API_KEY from llm-credentials, so the :310-312 seed never fires in a leaf pod at all: its !process.env.ANTHROPIC_API_KEY guard is already false there, and the by-provider-name lookup §3.3 shows to be load-bearing still resolves. Separately, the :306 deletion is harmless for a different reason — leaf-job.ts:18 populates anthropicAuthToken from process.env.ANTHROPIC_AUTH_TOKEN itself, so the leaf's token reaches applyModelGateway through config, never through that fallback. The leaf never depended on either.

Kept in §3.2 step 2 rather than §8, since it is the step-2 reader who stops to ask. 791d11b

| Two-tenant interleaved turns | Each upstream request carries its own subject's placeholder | No per-request subject exists |
| Fail-closed: no subject | 401 before a session is created, **and no upstream request made** | Ambient env silently supplies one |
| Ambient-absence | With a real tenant token in `ANTHROPIC_API_KEY` before startup, a subject-less session still fails rather than borrowing it | This is the leak (`run-turn.ts:310`) |
| Sentinel identity (§3.3) | After startup `ANTHROPIC_API_KEY` equals the sentinel **exactly**, and is byte-identical across two differently-subjected turns | No scrub exists |

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

suggestion — this row pins ANTHROPIC_API_KEY, but not the variable that outranks it.

env-api-keys.ts:96-98 returns ["ANTHROPIC_OAUTH_TOKEN", "ANTHROPIC_API_KEY"] — in that order, under the comment "ANTHROPIC_OAUTH_TOKEN takes precedence over ANTHROPIC_API_KEY". §3.2 step 3 does delete ANTHROPIC_OAUTH_TOKEN, so the design is right; the test is the part that's narrower than the design.

If a regression reintroduced ANTHROPIC_OAUTH_TOKEN, or the scrub quietly stopped deleting it, this assertion stays green while a real credential takes precedence over the sentinel — precisely the failure the sentinel exists to make loud. Since §3.3's argument #3 is that the sentinel is assertable where deletion is not, it seems worth asserting the deletions too: consider requiring ANTHROPIC_OAUTH_TOKEN and ANTHROPIC_AUTH_TOKEN to be absent in this same row, so the precedence order is pinned rather than just the fallback.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Row widened: it now requires ANTHROPIC_OAUTH_TOKEN and ANTHROPIC_AUTH_TOKEN absent alongside the exact-sentinel assertion, so the precedence order is pinned rather than just the fallback.

Step 3 now also states why that deletion is load-bearing instead of incidental — getApiKeyEnvVars returns the OAuth name first (env-api-keys.ts:96-98), so a leftover OAuth token outranks the sentinel and §3.3's reason-3 argument collapses. That is now the thing the test pins. Citation tightened :96-99 → :96-98, and ADR-0032's sentinel consequence mirrors the addition. 791d11b

| Fail-closed: no subject | 401 before a session is created, **and no upstream request made** | Ambient env silently supplies one |
| Ambient-absence | With a real tenant token in `ANTHROPIC_API_KEY` before startup, a subject-less session still fails rather than borrowing it | This is the leak (`run-turn.ts:310`) |
| Sentinel identity (§3.3) | After startup `ANTHROPIC_API_KEY` equals the sentinel **exactly**, and is byte-identical across two differently-subjected turns | No scrub exists |
| Lock-down invariant | No real provider credential is reachable from the harness process in server mode | Unpinned prose today (§2.4) |

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

suggestion — worth either scoping this claim or widening the slice, because the scrub is in-process only.

§3.2 step 3 replaces the variable at server startup, but the deployment still hands the pod the real thing: deploy/knative/service.yaml:45-49 mounts api-key from llm-credentials into the ksvc, and :56 mounts auth-token. So a test asserting "no real provider credential is reachable from the harness process in server mode" passes after the scrub while the manifest is still delivering a real credential to the harness container — which is the property ADR-0011/0012 assert the harness never has. §8's touched-files list is server.ts + run-turn.ts + tests, with no manifest change, so nothing in this slice closes that.

Two honest options:

  • (a) Make it true of the pod as deployed — set ANTHROPIC_API_KEY to the §3.3 sentinel literal in service.yaml and drop ANTHROPIC_AUTH_TOKEN from the ksvc, then add the manifest to §8. The scrub becomes defence-in-depth rather than the only barrier.
  • (b) Scope the row to "in-process, after the startup scrub" and record the manifest as follow-up.

As written this row reads as (a) but the slice delivers (b) — which matters more than usual here, since this is the test §2.4 says has been missing since ADR-0011 was written.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Taken as (b) — and I want to be explicit that (a) is not merely bigger, it is unavailable: nothing puts an injector in the harness's egress path today. The base kustomization.yaml renders redis + sandbox pool + ksvc + relay with no AuthBridge, and overlays/ocp-authbridge adds only the AB1/AB2 sandbox-egress resources (ibac-stub, echo-target, ab2-config) without patching the ksvc's env. So replacing the ksvc's api-key with the §3.3 sentinel and dropping auth-token would leave the harness unable to reach any model, in every deployment including the AB-gated ones — the scrub would not become defence-in-depth, it would become the only barrier in front of nothing.

So the slice now says (b) where it read (a):

  • New §3.6 records the gap and that reason — the process ends up sentinel-only, the pod does not — and states that §8 carries no manifest for the same reason.
  • §5's row is retitled "Lock-down invariant, in-process" and scoped in the assertion itself: the pod as deployed still receives one.
  • §6 gains the follow-up, owed to the lock-down slice (ADR-0011 · Z2) and injector deployment (ADR-0012 · Z3), not to this one.
  • ADR-0032 no longer claims the invariant is fully pinned — "gains its first test — scoped to the process, not yet to the pod" — plus a matching accepted-cost bullet and follow-up.

791d11b

pdettori added a commit to pdettori/moca that referenced this pull request Sep 8, 2026
…coping

Three suggestions from the review, all verified against the tree at the PR's
base (f78081f) and pi-fork at 2c28be5 before acting.

§3.2 step 2 said "only safe after step 1", but step 1 lands in server.ts and
the leaf never enters it, so a reader implementing the step stops to ask
whether deleting the run-turn.ts:310-312 seed strands the leaf. It does not,
for two independent reasons rather than the one raised: leaf-scaledjob.yaml:65-66
mounts ANTHROPIC_API_KEY from llm-credentials directly, so the seed's
!process.env.ANTHROPIC_API_KEY guard is already false in a leaf pod; and
leaf-job.ts:18 passes anthropicAuthToken through config, so the :306 fallback
was already redundant there. Both recorded in step 2.

The §5 sentinel row asserted the sentinel but not the variable that outranks it.
getApiKeyEnvVars returns ["ANTHROPIC_OAUTH_TOKEN", "ANTHROPIC_API_KEY"] in that
order (env-api-keys.ts:96-98), so an OAuth token left behind would take
precedence while the assertion stayed green — exactly the failure the sentinel
exists to make loud. The row now requires ANTHROPIC_OAUTH_TOKEN and
ANTHROPIC_AUTH_TOKEN absent, and step 3 states the precedence that makes the
deletion load-bearing rather than incidental.

The lock-down row claimed no real provider credential is reachable from the
harness in server mode, while the scrub is in-process and service.yaml:45-49/:56
still mount llm-credentials. Taken as scoping (option b), not as a widened
slice: option (a) is unavailable, because no manifest puts an injector in the
harness's egress path — the base kustomization renders redis + pool + ksvc +
relay with no AuthBridge, and overlays/ocp-authbridge patches only the AB1/AB2
sandbox-egress demo, never the ksvc env. Swapping the ksvc's api-key for the
sentinel would leave the harness unable to reach any model in every deployment.
New §3.6 records the gap and that reason; §6 owes the secret-free pod to the
lock-down slice (ADR-0011 · Z2) and injector deployment (ADR-0012 · Z3); the §5
row is scoped to the process. ADR-0032's consequences and follow-ups mirror it.

Also fixes the review's citation nit: agent-session.ts:353-355 is the
modelRegistry accessor, not the per-instance field declaration.

Docs only. No code, no pi-fork change, and nothing here closes rossoctl#220.

Assisted-By: Claude (Anthropic AI) <[email protected]>
Signed-off-by: Paolo Dettori <[email protected]>
Specs the concurrency-safety half of rossoctl#220. Tracing the code contradicted the
issue's five-blocker framing, so the spec's primary value is the corrected map:

- Pi's request-auth path is already per-session (`_getRequiredRequestAuth` reads
  a per-instance ModelRegistry; `withEnvApiKey` consults env only when no
  explicit key was given). Nothing in pi-fork needs to change.
- Of the other four globals: one is unreachable in server mode, one is already
  session-scoped, two are low. They are pinned by reachability tests rather than
  refactored — an inert global should be proven inert and left alone.
- The real prerequisite is unlisted by rossoctl#220: no per-session credential enters the
  harness at all, since every buildConfig() call site reads process.env. So the
  three steps are strictly ordered — inflow, fallback removal, scrub.
- Per ADR-0011/0012/0026 the harness must carry an inert placeholder and a
  subject, never a secret. That invariant was documented prose with no test
  pinning it; this slice adds one.
- ANTHROPIC_API_KEY cannot simply be deleted: run-turn.ts:150-155 documents that
  pi resolves the request key by provider name, and createAgentSession exposes no
  per-session key seam, so an absent variable throws before any request. Server
  mode sets a fixed non-secret sentinel instead — identical across tenants, so it
  asserts no identity, stripped from the wire by `x-api-key: null`, and
  assertable in a way deletion is not (§3.3).

End-to-end multi-tenancy also needs per-subject resolution at the injector (Z5's
deferred per-user/RFC 8693 half, in kagenti-extensions). The harness half is the
strict prerequisite and claims no more. The deployment-model change is a
separate slice.

Adds ADR-0032 and registers P5 in the spec/ADR indexes.

Assisted-By: Claude (Anthropic AI) <[email protected]>
Signed-off-by: Paolo Dettori <[email protected]>
…coping

Three suggestions from the review, all verified against the tree at the PR's
base (f78081f) and pi-fork at 2c28be5 before acting.

§3.2 step 2 said "only safe after step 1", but step 1 lands in server.ts and
the leaf never enters it, so a reader implementing the step stops to ask
whether deleting the run-turn.ts:310-312 seed strands the leaf. It does not,
for two independent reasons rather than the one raised: leaf-scaledjob.yaml:65-66
mounts ANTHROPIC_API_KEY from llm-credentials directly, so the seed's
!process.env.ANTHROPIC_API_KEY guard is already false in a leaf pod; and
leaf-job.ts:18 passes anthropicAuthToken through config, so the :306 fallback
was already redundant there. Both recorded in step 2.

The §5 sentinel row asserted the sentinel but not the variable that outranks it.
getApiKeyEnvVars returns ["ANTHROPIC_OAUTH_TOKEN", "ANTHROPIC_API_KEY"] in that
order (env-api-keys.ts:96-98), so an OAuth token left behind would take
precedence while the assertion stayed green — exactly the failure the sentinel
exists to make loud. The row now requires ANTHROPIC_OAUTH_TOKEN and
ANTHROPIC_AUTH_TOKEN absent, and step 3 states the precedence that makes the
deletion load-bearing rather than incidental.

The lock-down row claimed no real provider credential is reachable from the
harness in server mode, while the scrub is in-process and service.yaml:45-49/:56
still mount llm-credentials. Taken as scoping (option b), not as a widened
slice: option (a) is unavailable, because no manifest puts an injector in the
harness's egress path — the base kustomization renders redis + pool + ksvc +
relay with no AuthBridge, and overlays/ocp-authbridge patches only the AB1/AB2
sandbox-egress demo, never the ksvc env. Swapping the ksvc's api-key for the
sentinel would leave the harness unable to reach any model in every deployment.
New §3.6 records the gap and that reason; §6 owes the secret-free pod to the
lock-down slice (ADR-0011 · Z2) and injector deployment (ADR-0012 · Z3); the §5
row is scoped to the process. ADR-0032's consequences and follow-ups mirror it.

Also fixes the review's citation nit: agent-session.ts:353-355 is the
modelRegistry accessor, not the per-instance field declaration.

Docs only. No code, no pi-fork change, and nothing here closes rossoctl#220.

Assisted-By: Claude (Anthropic AI) <[email protected]>
Signed-off-by: Paolo Dettori <[email protected]>
@pdettori
pdettori force-pushed the docs/220-session-isolation-spec branch from 791d11b to 2ee9e40 Compare September 8, 2026 18:33
@pdettori

pdettori commented Sep 8, 2026

Copy link
Copy Markdown
Member Author

Both body-level nits are handled as well.

agent-session.ts:353-355 is cited as "a per-instance field" where it is actually the accessor for one

Corrected — §2.2 now reads "a per-instance field, whose modelRegistry accessor is at :353-355".

the commit subject is 89 characters against the 72-char advisory

Amended and force-pushed: the base commit is now docs(spec): P5 multi-session isolation design (#220) (52 chars), and the review-fixup commit is 69. Body, Signed-off-by and Assisted-By trailers unchanged, and git diff 791d11b 2ee9e40 is empty — the rewrite touched messages only.

Head is now 2ee9e40 (c91982b → e316d39 amended, plus 2ee9e40).

@pdettori
pdettori merged commit 02109bc into rossoctl:main Sep 8, 2026
12 checks passed
@pdettori
pdettori deleted the docs/220-session-isolation-spec branch September 8, 2026 18:46
pdettori added a commit to pdettori/moca that referenced this pull request Sep 8, 2026
…edentials

Specs multi-user support as a trusted always-on control plane fronting the
existing scale-to-zero data plane. Tracing the tree at b533d87 shaped three
decisions the requirements did not anticipate:

- The credential path reads the environment in THREE places, not one
  (run-turn.ts:306, :310-311, :313). Removing only the write-once-if-absent
  seed leaves the `||` fallbacks intact, so the /turn path would still fail
  open. All three go, on that path only — a narrow cut.
- Redis is fully ephemeral (redis.yaml has no PVC and no appendonly), so
  credentials cannot live there. Per-user K8s Secrets under envelope
  encryption, in their own namespace, with no `list` verb on the serving path.
- Requirement 4 has no reverse index to read: the lease ZSET is keyed by run
  id, not session id (sandbox-lease.ts:3-6). The harness self-reports its
  runtime record, and that record is display-only — never authz input.

Two things are named rather than glossed. Slice 1 ships a SHARED sandbox pool,
so isolation holds at the API, session store, and inference credential but not
the sandbox; and the control plane holds both identity and credentials, which
diverges from Z1 §2's "orchestrator holds no secrets" and is contained by a
CredentialStore seam plus RBAC scoping until Z3/Z5 retire it.

§3.5 sets the ownership boundary with the P5 session-isolation spec in PR rossoctl#228,
whose implementation is a separate contributor's track on a different timeline.
Z8 is adjacent to it, not blocked on it: Z8 owns /turn, P5 owns the leaf/CLI
paths, the global reachability pins, and the scrub. Both touch run-turn.ts:306-313,
so whichever lands second rebases; neither ordering invalidates the other.
P5 reserves ADR-0032, so this takes ADR-0033.

The tenant partition slice 2 needs is blocked on an already-deferred ADR-0028
decision at server.ts:308-320, where a workload's pool selector is ignored for
kind:'prompt' leaves. Filed as rossoctl#237 rather than decided here, since it also
affects the non-multi-user /runs path.

Assisted-By: Claude (Anthropic AI) <[email protected]>
Signed-off-by: Paolo Dettori <[email protected]>
pdettori added a commit to pdettori/moca that referenced this pull request Sep 8, 2026
…th merged P5

The review asked for this to move to its own track. Rebasing onto main to do it
surfaced that rossoctl#228 had merged in the meantime, and reading the merged P5 spec
contradicted a load-bearing assumption in §3.4 — so this commit is both.

Own track. Z8 becomes MU1, first entry in a new `MU` (multi-user service) track,
with its own registry section and dependency notes. Phase 2 is a security
architecture; this is a product surface with its own consumers and compatibility
obligations. They meet only at the credential. MU2/MU3 are recorded so the
former slice 2/3 have ids.

§3.4 corrected. The draft said "pass the key explicitly and pi's per-session
apiKey does the rest." P5 §3.3 and run-turn.ts:150-155 show there is no such
seam: createAgentSession cannot inject a per-session key, and pi resolves the
key by provider name from ANTHROPIC_API_KEY. What IS per-session is the model
object, rebuilt each turn at :497 by applyModelGateway, which installs
Authorization: Bearer from config and already prefers config over env at :306.
Two consequences: MU1 touches no line of run-turn.ts, and deleting the :310-312
seed without P5's sentinel would break gateway mode outright.

§3.5 rewritten from "ownership boundary on shared files" to composition. P5
step 1 already reserved Authorization for "may this caller use the harness" —
this spec — and carries whose-work-it-is in X-SH-Subject. MU1 adopts that split
unchanged and adds what P5 cannot: making the subject trustworthy instead of
asserted. When a session token is present the subject is token.sub and an
inbound X-SH-Subject is ignored; both present and conflicting is a 400, not a
precedence rule, because a silent winner there is a cross-tenant bug.

Pre-P5, MU1 enforces fail-closed by policy at two points it owns rather than by
construction. §3.5, §8.1 and §9.3 test 1 now state which is in force instead of
implying the stronger one; the test asserts the policy form today and tightens
when the sentinel lands.

Also: run-turn.ts seed cited as :310-312, matching P5 and the closing brace.

Assisted-By: Claude (Anthropic AI) <[email protected]>
Signed-off-by: Paolo Dettori <[email protected]>
@pdettori

pdettori commented Sep 8, 2026

Copy link
Copy Markdown
Member Author

Coordination note for whoever implements this, from the MU1 multi-user control-plane design (#238). Posting here because the issues replacing #220 don't exist yet — worth carrying into whichever implementation issue gets filed.

MU1 is the caller-auth work this spec's §6 deferred ("Caller auth is ADR-0011's lock-down work; §3.2 keeps Authorization free for it"), so the two compose rather than collide. MU1 adopts the header split unchanged. Three interactions are recorded in MU1 §3.6 rather than here, since this design is already merged — but they affect what the P5 implementation should and shouldn't pin:

1. The Bearer payload becomes one-or-the-other. P5 targets Bearer <inert placeholder> swapped by static-inject. MU1's interim direct mode carries Bearer <real token> resolved by the control plane, with no injector in the path. Same field, incompatible contents — so if buildConfig unconditionally sets the placeholder, it silently overwrites MU1's token and the request fails with nothing configured to swap it.

MU1's resolution: TurnConfig carries a tagged credential ({mode: 'placeholder' | 'direct', value}) rather than a bare string, and the control plane declares the mode at exchange time, with placeholder mode winning wherever an injector is configured. Adding an injector then strictly narrows what the harness may hold, and MU3 deletes direct mode. Nothing needed from P5 here beyond not assuming the field is always a placeholder.

2. Direct mode diverges from §5's in-process invariant. §5 asserts that after the startup scrub, no real provider credential is reachable from the harness process in server mode. MU1's direct mode puts one there per turn — accepted in ADR-0033 and named there explicitly so this isn't discovered as a contradiction later.

Suggestion: scope that assertion to the environment (which MU1 never writes) rather than the whole process, or gate it on direct mode being disabled. §5's sentinel and ANTHROPIC_OAUTH_TOKEN/ANTHROPIC_AUTH_TOKEN deletions are unaffected either way, and MU1 depends on them — §3.4 notes that deleting the :310-312 seed without the sentinel would break gateway mode outright, since pi resolves the key by provider name (run-turn.ts:150-155).

3. Inbound X-SH-Subject becomes conditional. Once a session token is present, MU1 derives the subject from token.sub and ignores an inbound X-SH-Subject; both present and conflicting is a 400, not a precedence rule. Reading the header from the request is right for a trusted orchestrator, but it's the spoofable-header pattern Z1 §3.2 warns about once arbitrary users can call the API — MU1's job is making that subject trustworthy rather than asserted.

So please don't pin "inbound X-SH-Subject is always honoured" as an invariant. Operator and leaf paths keep that behaviour; the token-bearing path does not.

Nothing here asks for a change to this merged spec — item 2 is the only one where a small scoping adjustment to §5 would help, and it can just as well live in the implementation.

maia-iyer pushed a commit to maia-iyer/moca that referenced this pull request Sep 16, 2026
… path

Re-verified every file:line in the P5 design against main@02109bc and
pi-fork@2c28be50 ahead of implementation. All 1.0 citations are accurate
except one classification, and that one is load-bearing.

3.5 parked server.ts:174 as a non-turn buildConfig() call site, and 2.3
labelled it "async dispatch". It is neither: :174 sits inside
handleTurnStream (:150), whose only caller is handleTurn:108 via
`if (wantsStream)`, on the POST /turn route (:564) — it is the SSE branch
of the same endpoint. Converting only :111 in step 1 would let any client
bypass the per-request subject by sending `Accept: text/event-stream`,
making 3.1 clause 1 false on a shipped code path while 5's sync-only
two-tenant test passed green.

Also settled here, so an implementer does not decide them silently:

- 3.1 / 3.2 step 2: step 2 adds no enforcement of its own. run-turn.ts:314
  returns the base model unchanged (deliberately pinned by
  model-gateway.test.ts:27), so step 1's 401 is the only thing enforcing
  fail-closed.
- 3.2 step 3: "server entrypoint" resolved to startServer() (:576) rather
  than the isMainModule guard (:592-593), which keeps 5's sentinel-identity
  row assertable in-process; the cost is env save/restore in every test
  that starts a server.
- 3.2 step 1: TurnConfig gains an explicit subject field, so the tenant is
  not knowable only by reverse-mapping the placeholder — that would put the
  logging path in contact with the credential mapping this slice isolates.
- 4: the cwd probe was run. The verdict holds and scope does not grow, but
  the 1.0 pin was too strong: SettingsManager does compute a cwd-derived
  projectSettingsPath (settings-manager.ts:189), read-only from a server
  turn. Two residuals now pinned rather than assumed — projectTrusted
  defaults to true, and the settings lock busy-waits synchronously on the
  read path, stalling every multiplexed session.
- 5: adds the SSE variant of the two-tenant test, and flags the three
  existing model-gateway tests (:50, plus :42/:78 which need splitting
  because the ANTHROPIC_BASE_URL half survives) that assert exactly what
  step 2 deletes.

Refs rossoctl#239, rossoctl#220, rossoctl#228

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

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat: multi-session harness multiplexing — N concurrent sessions per process

2 participants