Skip to content

feat: operator fallback on the VM and a curl/git research-turn smoke (#368 phase 2) - #411

Merged
pdettori merged 17 commits into
rossoctl:mainfrom
pdettori:feat/368-phase2-vm-research
Oct 1, 2026
Merged

pdettori merged 17 commits into
rossoctl:mainfrom
pdettori:feat/368-phase2-vm-research

Conversation

@pdettori

@pdettori pdettori commented Oct 1, 2026 •

Copy link
Copy Markdown
Member

Phase 2 of #368 (VM demo C, epic #370), after #366 and #369 merged. Phase 1 was #372.

Summary

The operator-key fallback works on the VM, and it can't be misconfigured silently.

  • Fixed: the fallback was unreachable. createSession refused every subject with no inference credential, so the exchange's fallback branch ran only when a credential was deleted after its session was created. That's exactly what the existing tests did. That path is now closed too (see "Behaviour changes"), and the tests reach the fallback with no credential at all.

    • With SH_ALLOW_OPERATOR_FALLBACK=true and an operator token set, such a subject now gets a session that records no credential name. The exchange spends the operator's key per turn, audited as operator_fallback_used.
    • A session that names a credential never falls back, at creation or at exchange.
  • mocactl used to block before ever calling POST /v1/sessions when the user had no credential. Now it asks the server.

    • If the server refuses with credential_required, the user sees the same "add an inference credential" hint, and the interactive UI still routes to the credentials screen.
  • New SH_OPERATOR_INFERENCE_HEADER (authorization | x-api-key, default authorization).

    • The fallback was Bearer-only, so a raw sk-ant-api… operator key could never work.
    • It's wired into deploy/compose and the deploy/vm env example.
  • The control plane refuses to boot on a fallback that can't work:

    • no token;
    • no default endpoint;
    • an sk-ant-oat… token;
    • an Anthropic key on the Bearer header, or one aimed anywhere but https://api.anthropic.com.

    It also refuses an api.anthropic.com default endpoint with a path (/v1). Messages name settings and key prefixes, never values. Before this, every one of these surfaced to users as "control plane returned 503", per turn.

  • setup-vm.sh loads credentials/operator-inference-token with a LoadCredential= drop-in when the file exists, and removes the drop-in when the file goes. A static line can't do this, because LoadCredential= on a missing file fails the unit.

    • It stops on: the fallback on with no token file; a file that is empty, a dangling symlink, or not mode 0600/0400; or the token as an env line.
    • It never reads the value.
  • operator-fallback is a reserved credential name, so an audit line naming it is always the operator's key.

A live smoke for the research turn: deploy/vm/research-smoke.sh (gated by VM_RESEARCH_SMOKE=1).

  • It runs on the VM as root. It mints a fresh user with the control plane's own signing key, then either stores that user's credential from a one-line key file, or uses the operator fallback.
  • It streams one /v1/turn whose prompt makes the agent git clone --depth 1 rossoctl/moca and curl -o nodejs.org's 330 KB release index. That's past Pi's 50 KB tail, so it exercises the "curl -o, then grep" guidance.
  • It passes only if:
    • both commands appear in the SSE tool_use frames with non-error results;
    • the answer's COMMIT/NODE_VERSION/NODE_DATE equal what the sandbox container's own copy of the files says, read with podman exec;
    • the control plane's audit shows the intended credential was spent.
  • A model answering from memory can't pass: HEAD changes with every merge.
  • It refuses to run while a microVM worker is in the pool (no guest network, P4.1: implement microVM egress transport (vsock → shared proxy) #277).
  • Keys never reach an argv, an env var or a written file. Tokens travel in 0700 header files, deleted on exit.

Docs: deploy/vm/README.md gains a "research turn" section.

  • It says plainly that sandbox egress, instance metadata included, is open this round.
  • It carries the demo prompt for the epic's runbook. A test holds it equal to the smoke's.

How MI1 S2 absorbs this

  • The operator fallback becomes a grant whose binding is SH_OPERATOR_INFERENCE_HEADER, and moca-egress injects the token under it.
  • directModeMismatch goes away with direct mode.
  • The token/endpoint/header consistency check stays, since the injector needs the same agreement.
  • The token file and drop-in are already MI1 §6.7's "secrets are files" contract.

Behaviour changes to note

  • Stricter boot. A control plane with SH_ALLOW_OPERATOR_FALLBACK=true but no token or no default endpoint, or with an api.anthropic.com/v1 default, now fails to start. Each such config could not serve a fallback or default-endpoint turn anyway. deploy/knative/control-plane.yaml ships the fallback false.
  • Looser createSession with the fallback on. A credential-less subject gets a session, as spec §6.4 intended.
  • A fallback session keeps the operator's key after its user stores their own. A session's credential is fixed at creation; only a new session picks the new credential up. This is tested and documented.
  • A session that named a credential never falls back, even after that credential is deleted. Before this PR, the exchange gave the operator's key to any session whose recorded credential was gone. Now that session's next turn is refused with credential_required, naming the credential (feat: operator fallback on the VM and a curl/git research-turn smoke (#368 phase 2) #411 review).

Known limits

Test plan

  • New unit tests:

    • control plane: operator-fallback-config.test.ts (the boot checks) and operator-fallback-session.test.ts (credential-less sessions, a deleted named credential never falling back, the reserved name, the message once the fallback is off), plus an x-api-key fallback exchange case; the existing fallback tests now create the session with no credential instead of deleting one;
    • mocactl: session options, headless run, and the New Session overlay.
  • deploy/vm/tests/setup-vm.test.sh: the operator-token section, mutation-checked.

  • deploy/vm/tests/research-smoke.test.sh: VM-free. It mocks curl/podman, mints tokens for real, and covers:

    • the pass, gateway and fallback paths;
    • a microVM in the pool, and no sandbox at all;
    • a model that skipped the tools, fetched without curl, hit a curl error, gave a wrong commit, or ended in an error frame;
    • argv/secret hygiene, cleanup, and README/script prompt parity.

    Mutation-checked.

  • deploy/compose/tests/*: the header reaches the control plane.

  • make lint, make typecheck and make test are green.

  • Live on the KVM rig with a real model: the smoke on a user's own raw Anthropic key (13/13), the smoke on the operator fallback (12/12), mocactl run on the fallback, and the boot refusals, with no key in any journal. See the comment below.

🤖 Generated with Claude Code

…; SH_OPERATOR_INFERENCE_HEADER

The operator fallback was Bearer-only, so a raw Anthropic operator key could never work, and any
mismatch surfaced per turn as a 503 the caller could not act on. The fallback's token, header and
endpoint are all deployment settings: check them at startup, naming settings, never values. Also
refuses an api.anthropic.com default endpoint with a path (rossoctl#368 phase 1 known minor).

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

createSession refused every subject with no inference credential, so the exchange's operator
fallback (spec §6.4) was reachable only when a credential was deleted after its session was created.
With SH_ALLOW_OPERATOR_FALLBACK=true and an operator token, such a subject now gets a session that
records no credential name; the exchange spends the operator's key per turn, audited. An explicitly
named credential never falls back.

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

setup-vm.sh installs a LoadCredential= drop-in for credentials/operator-inference-token when the
file exists (0600, non-empty) and removes it when the file goes, since LoadCredential= on a missing
file fails the unit. SH_ALLOW_OPERATOR_FALLBACK=true without the file, or the token as an env line,
stops the script. The value is never read. control-plane.env.example documents the four settings.

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

One minted user, on its own stored credential or the operator fallback, runs a turn that must
git clone rossoctl/moca and curl -o nodejs.org's release index in a container sandbox, then answer
from them. Passes only if both commands appear in the SSE tool_use frames without error, the answer
equals what the sandbox's own copy of the files says, and the audit shows the intended credential.
Gated by VM_RESEARCH_SMOKE=1; a mock-driven test covers it offline (rossoctl#368).

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

Says plainly that sandbox egress (instance metadata included) is open in this round, gives the
curl/git research prompt the demo runbook will reuse, and documents research-smoke.sh. A test holds
the README's prompt equal to the script's (rossoctl#368).

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

With no inference credential stored, mocactl blocked before ever calling POST /v1/sessions, so a
user on a deployment with SH_ALLOW_OPERATOR_FALLBACK=true could not start a session from mocactl
at all (rossoctl#368 review). The inference field now leaves the choice to the server when there is none;
a credential_required refusal maps back to the same 'add an inference credential' hint and, in the
interactive UI, the same route to the credentials overlay.

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

The control plane now refuses to boot on an Anthropic API key as the operator token unless
SH_OPERATOR_INFERENCE_HEADER=x-api-key, but compose lists the control plane's environment
explicitly and never passed that setting, so a compose operator could not satisfy the check
(rossoctl#368 review). The .env template and README show both fallback shapes.

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

PUT /v1/credentials refuses the name the audit gives the operator's key, so an operator-fallback
audit line is never a subject's own credential. A session started on the fallback keeps it (a
session's credential is resolved at creation, spec §6.4): pinned by a test, documented, and with
the fallback turned off its turns now say to start a new session instead of naming credential ''
(rossoctl#368 review).

Assisted-By: Claude (Anthropic AI) <[email protected]>
Signed-off-by: Paolo Dettori <[email protected]>
…env line and a dangling symlink

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

A key file with a comment line was detected as one kind and sent as a multi-line secret; now it
must be exactly one line. The session delete is retried while the turn's end is still being
reported, and a failure to delete is said, not swallowed. The README says how to re-run the demo
prompt, whose git clone refuses an existing directory (rossoctl#368 review).

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

pdettori commented Oct 1, 2026

Copy link
Copy Markdown
Member Author

Live results on the KVM rig (Amazon Linux 2023, static podman, systemd 252), 2026-10-01

This branch @ 5f9f54f, on the container tier with the sandbox image built from this branch. The published :latest image still has HOME=/workspace, so it predates #372.

The research smoke, real model (Anthropic API, raw sk-ant-api… key):

  • The user's own credential, stored as kind api-key: 13/13.
    • git clone --depth 1 and curl -o …/index.json both ran in sh-sandbox-1.
    • The answer was COMMIT=f8d0e6cf0aac, which equals git ls-remote rossoctl/moca HEAD, plus NODE_VERSION=v26.10.0 and NODE_DATE=2026-09-21. All three were read back from the sandbox's own files.
    • Audit: credential_issued.
    • This also closes feat: per-user inference credential headers and sandbox research tooling (#368 phase 1) #372's open box: a live turn with a real raw Anthropic key, sent as x-api-key.
  • The operator fallback (SH_OPERATOR_INFERENCE_HEADER=x-api-key, default endpoint https://api.anthropic.com, token loaded by the new drop-in): 12/12, same answer. Audit: operator_fallback_used.
  • mocactl run as a user with no credential, on the fallback: it got a session and answered pong. Audit: session_created/operator_fallback_used as operator-fallback. This is the VM demo C: per-user inference credentials and a curl/git research turn in the P6 container sandbox #368-review mocactl fix, live.

Refusals, live:

  • With the fallback off, a credential-less user gets 400 credential_required at POST /v1/sessions.
  • With SH_ALLOW_OPERATOR_FALLBACK=true and no token file, setup-vm.sh stops and names the file. Nothing was touched.
  • With a fabricated gateway token sent as Bearer to api.anthropic.com, the control plane refuses to boot: "…set SH_OPERATOR_INFERENCE_HEADER=x-api-key…". The token appears 0 times in the journal.
  • With the token file removed, a setup-vm.sh re-run removes the drop-in, and the control plane comes back ready.

Hygiene: the key's prefix appears 0 times in the control-plane, supervisor and relay journals. Neither the smoke output nor its evidence contains it.

The rig is restored to #409's setup: that branch is checked out again, microvm-worker is running and the only pool record, the env files are byte-identical to before (sha256), and the key, token, containers, test image and scratch files are removed. The control-plane audit stream keeps this run's entries, by design.

Resolves deploy/vm/README.md (the egress bullet beside rossoctl#403's two isolation bullets) and
deploy/vm/tests/setup-vm.test.sh (the operator-fallback section beside rossoctl#403's
seed_control_plane_env section): both sides kept.

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

@huang195 huang195 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Two must-fixes, both small:

  • The new research-smoke test suite never runs in CI: it SKIPs on the deploy-scripts runner, which has no tsx.
  • setup-vm.sh refuses every symlinked operator token, and the remedy it prints loops.

The control-plane and mocactl changes check out:

  • The boot check and the exchange share directModeMismatch on the same base URL.
  • A fallback session's '' round-trips through the ownership index.
  • credential_required reaches mocactl with its message, and only POST /v1/sessions can raise it there.
  • The smoke's assumptions (SSE frame shapes, audit fields, pool record ids, Redis keys, /v1/turn) match the code.

Not in the diff: deploy/knative/control-plane.yaml:228 still says the fallback needs SH_OPERATOR_INFERENCE_TOKEN. After this PR it also needs SH_DEFAULT_INFERENCE_ENDPOINT, or the control plane won't boot.

Checked locally at 3b22c92:

  • The four touched control-plane vitest files pass (54 tests).
  • research-smoke.test.sh and the setup-vm operator-token cases pass.
  • shellcheck -S warning is clean on the three scripts.
  • The symlink and named-credential findings have repros.

Comment thread deploy/vm/tests/research-smoke.test.sh Outdated
fails=$((fails + 1))
fi; }
command -v node >/dev/null || { echo "SKIP: node not installed"; exit 0; }
[[ -x "$REPO/packages/control-plane/node_modules/.bin/tsx" ]] ||

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

must-fix — this suite never runs in CI. deploy-scripts runs make test-deploy with no pnpm install (by design: ci.yml says those tests need no node or pnpm), and check runs pnpm -r test, not make test. This PR's own run shows it: == deploy/vm/tests/research-smoke.test.sh then SKIP: packages/control-plane has no tsx (run pnpm install), exit 0.

So the argv/secret-hygiene checks, the cleanup checks, the failure scenarios and the README/script prompt parity ("A test holds it equal to the smoke's") are enforced only on a laptop with a built workspace. An edit to either prompt passes CI today.

Options: run this file from check after pnpm install, or install just tsx in deploy-scripts. Either way, the checks that need no tsx (the gate, gw-noep, multi, nokey, the prompt parity) could run above the skip, the way setup-vm.test.sh skips only its one real-genkeys check. Failing instead of skipping under CI=true would keep this from regressing silently.

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.

Fixed in e28f3f2.

  • The checks that need neither node nor tsx now run above the skip, so they also run in deploy-scripts: the gate, the no-key / multi-line / whitespace / gateway-without-endpoint refusals, an unreadable pool, and README/script prompt parity. That's 20 checks.
  • The mint-driven rest runs from a new check step after pnpm install, with MOCA_REQUIRE_WORKSPACE=1. There a missing tsx is a failure, not a skip, so it can't go quiet again.
  • Simulated locally by hiding packages/control-plane/node_modules/.bin/tsx: plain, the early checks pass and the rest is SKIP; with the flag, it fails.

Comment thread deploy/vm/setup-vm.sh Outdated
}

# file_mode <file>: its permission bits in octal (GNU stat, then BSD stat for the macOS test run).
file_mode() { stat -c '%a' "$1" 2>/dev/null || stat -f '%Lp' "$1"; }

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

must-fix — stat -c '%a' and stat -f '%Lp' report the symlink's own mode (777 on Linux), not its target's. So a symlink to a 0600 key is always refused. The message's remedy, sudo chmod 0600 $f, changes the target, so every re-run fails the same way. The dangling-symlink message at :595 tells the operator to "Point it at the operator's inference key", which leads straight here.

Repro: source with SH_SOURCE_ONLY=1 and make the token path a symlink to a 0600 file. The function prints … is mode 755: … must be 0600 or 0400 with rc=1, does the same after the suggested chmod, and writes no drop-in.

LoadCredential= follows symlinks, so stat -L in both forms fixes it. A live-symlink case beside the dangling one in setup-vm.test.sh would hold it. If symlinks are meant to be refused, the :595 message should say so instead.

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.

Fixed in 0b97aa4. file_mode now uses stat -L in both forms, so a symlink is judged by its target, as LoadCredential= reads it.
New case beside the dangling one:

  • a link to a 0600 key passes and gets the drop-in;
  • a link to a 0644 key is refused, reporting mode 644;
  • after the advised chmod 0600, the re-run passes, so the remedy no longer loops.

Comment thread packages/control-plane/src/handlers.ts Outdated
const credentialName = resolveInferenceName(descriptors, requested);
// The operator fallback (spec §6.4) is for a subject with no inference credential of its own: such
// a session records NO credential name, and the exchange resolves the operator's key per turn,
// attributably. An explicitly requested name never falls back -- a typo must 400, not spend the

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

suggestion — "An explicitly requested name never falls back" holds only at creation. At exchange time (exchange.ts:152), any session whose recorded credential is gone takes the operator's key.

A probe: create a session with credentials.inference: 'my-anthropic', delete that credential, exchange. The exchange returns op-gw-token, and the audit reads session_created/my-anthropic, then operator_fallback_used/operator-fallback.

That predates this PR, but it contradicts README.md:317 ("A session's credential is fixed when the session is created"). The case that matters is a user deleting a leaked key mid-session: their session carries on, on the operator's bill.

Now that fallback sessions record '', the exchange could fall back only when !rec.credentialName and refuse otherwise ("no usable inference credential 'X'"). That changes the tests that reach the fallback through delete-after-create (exchange-auth-header.test.ts, including the new x-api-key case). If the current behaviour is intended, it's worth a line next to README.md:317 and a narrower comment here.

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.

Took the stricter version, in d917999. The exchange now falls back only when !rec.credentialName, i.e. a session created on the fallback.

  • A session that named a credential which has since been deleted is refused with credential_required, naming the credential. That's the leaked-key case: the session stops instead of moving onto the operator's bill.
  • New test in operator-fallback-session.test.ts: your probe, asserting no operator_fallback_used audit entry.
  • The fallback tests that reached the fallback by delete-after-create (exchange.test.ts, and three in exchange-auth-header.test.ts including the x-api-key case) now create the session with no credential at all, the way a user reaches it.
  • README.md now says the creation-time binding holds in both directions, and the comment here says so too.

Comment thread deploy/vm/setup-vm.sh
"re-run." >&2
return 1
fi
rm -f "$dropin_dir/$OPERATOR_DROPIN"

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

suggestion — until this PR, main's README (f1435e4, 2026-09-30) told operators to sudo systemctl edit sh-control-plane.service and add this same LoadCredential= line. That writes sh-control-plane.service.d/override.conf, and nothing here looks at it.

While the token exists, the unit carries the line twice. After the new "delete the file and re-run", this removes only 50-…conf, the rmdir below fails silently, and the stale override fails the unit on the missing file (the premise of the comment at :577).

The window is small, but a grep of the drop-in dir for any other SH_OPERATOR_INFERENCE_TOKEN LoadCredential= (refuse, naming the file) closes it.

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.

Fixed in 0b97aa4. ensure_operator_fallback now greps the drop-in dir for any other *.conf with a LoadCredential=SH_OPERATOR_INFERENCE_TOKEN: line, and refuses, naming the file, whether or not the token exists.
It's the operator's file, so the script names it and tells them to drop the line rather than editing it. The README's stop list mentions the old systemctl edit override.conf. Tested with the token both present and absent.

Comment thread deploy/vm/research-smoke.sh Outdated
fi
if [[ -s "$OUT/api.hdr" ]]; then
if [[ -n "$SID" ]]; then
# The worker may still be reporting the turn's end, and the control plane refuses to delete a

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

nit — deleteSession never refuses an in-flight session: it cascade-deletes and answers 202 (handlers.ts:333-344), which this loop already accepts. The retry is harmless for a 5xx or a network error. But this comment, and the test's 409 turn_in_flight mock (research-smoke.test.sh:115), describe a response the control plane doesn't have.

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.

Right, thanks. Fixed in e28f3f2. The comment now says deleteSession cascade-deletes mid-turn (202), so the retry only covers a 5xx or a dropped connection. The mock answers 503 instead of an invented 409 turn_in_flight (MOCK_SESSION_DELETE_FAIL).

# One line, so the kind detected here and the secret node sends below are the same string.
[[ "$(grep -c . "$RESEARCH_CREDENTIAL_FILE")" == 1 ]] ||
die "RESEARCH_CREDENTIAL_FILE must hold exactly one line: the key, and nothing else"
if grep -q '^sk-ant-api' "$RESEARCH_CREDENTIAL_FILE"; then

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

nit — bash detects the kind on the raw line, but node sends its .trim() (:193). A key file with leading whitespace is detected as bearer, so it demands RESEARCH_ENDPOINT, yet stored as api-key for api.anthropic.com. That is not the "same string" the comment at :141 promises. Either refuse surrounding whitespace in the one-line check, or normalise both sides the same way.

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.

Fixed in e28f3f2. The one-line check now also refuses leading or trailing whitespace on the key line, a CR from a Windows editor included. So bash's kind detection and node's trimmed value are the same string. Test: a key with a leading-space line is refused before any request.

Comment thread deploy/vm/research-smoke.sh Outdated
[[ "$boxes" -ge 1 ]] && ok "$boxes running sh-sandbox-* container(s)" || ko "no running sh-sandbox-* container"
# One tier per host (deploy/microvm/P4-ON-P6.md): with a microVM worker attached the turn may land in
# a guest with no network (#277), and this smoke would fail for a reason that is not the one it tests.
others="$(podman exec sh-redis redis-cli HKEYS sh:sandbox:records 2>/dev/null | grep -v '^sh-sandbox-' | grep -v '^$' || true)"

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

nit — this check fails open. If podman exec sh-redis redis-cli fails (stderr is discarded), others is empty and the run reports "every pool record is a container sandbox". The audit check at the end still fails, so this only costs diagnosis. Checking the exec's exit status separately would keep the message honest.

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.

Fixed in e28f3f2. The pool records are read first, checking the exec's exit status, and filtered second. A failed podman exec sh-redis redis-cli now reports "could not read the pool records from sh-redis: …" with its stderr, and no turn runs. Test: MOCK_REDIS_FAIL asserts that message, and asserts the all-container claim is absent.

Comment thread deploy/vm/setup-vm.sh Outdated
fi
return 0
fi
if [[ "$(env_file_value SH_ALLOW_OPERATOR_FALLBACK "$cp")" == true ]]; then

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

nit — env_file_value matches ^KEY= only, while :588 accepts leading whitespace on purpose (systemd's EnvironmentFile= does). An indented SH_ALLOW_OPERATOR_FALLBACK=true with no token file passes here and removes the drop-in, and then the control plane refuses to boot. That's fail-safe thanks to checkInferenceConfig, just inconsistent with :588.

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.

Fixed in 0b97aa4. A new operator_fallback_value reads SH_ALLOW_OPERATOR_FALLBACK with leading whitespace allowed, matching the token-line guard. It strips a matched pair of quotes, as env_file_value does. An indented SH_ALLOW_OPERATOR_FALLBACK=true with no token file now refuses, naming the file. Tested.

rossoctl#411 review)

deploy-scripts has no node or pnpm, so the whole suite skipped there and nothing in CI enforced it.
Its checks that need neither (the gate, the key-file refusals, prompt parity, an unreadable pool)
now run above the skip; the rest runs from the check job, after pnpm install, with
MOCA_REQUIRE_WORKSPACE=1 turning a missing tsx into a failure.

Also from the review: a key line with surrounding whitespace is refused (grep and node's trim
disagreed on it); a failed read of the pool records says so instead of reporting an all-container
pool; the session-delete retry's comment and mock describe the 202/5xx the control plane really
answers.

Assisted-By: Claude (Anthropic AI) <[email protected]>
Signed-off-by: Paolo Dettori <[email protected]>
…e a second drop-in (rossoctl#411 review)

file_mode reported a symlink's own mode (777), so a link to a 0600 key was always refused and the
printed remedy (chmod the path) looped. It now follows the link, as LoadCredential= does. Also from
the review: another drop-in loading SH_OPERATOR_INFERENCE_TOKEN -- the systemctl edit override.conf
the README described before -- is refused, naming it, since it doubles the line and outlives the
token; and an indented SH_ALLOW_OPERATOR_FALLBACK line counts, as systemd's EnvironmentFile= reads it.

Assisted-By: Claude (Anthropic AI) <[email protected]>
Signed-off-by: Paolo Dettori <[email protected]>
…that named no credential (rossoctl#411 review)

The exchange took the operator's key for ANY session whose recorded credential was gone, so a user
who deleted a leaked key mid-session carried on on the operator's bill, contradicting 'a session's
credential is fixed at creation'. Only a session created on the fallback (credentialName '') falls
back now; one that named a credential is refused, naming it. The fallback tests reach it the way a
user does -- no credential at all -- instead of by deleting one after creation.

Also: control-plane.yaml's comment names everything a fallback-on control plane now needs to boot.

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

pdettori commented Oct 1, 2026

Copy link
Copy Markdown
Member Author

Thanks for the thorough review. All eight inline items and the out-of-diff note are addressed, in three commits: e28f3f2, 0b97aa4 and d917999.

Must-fixes:

  • research-smoke.test.sh in CI (e28f3f2): its tsx-free checks run above the skip, so deploy-scripts now enforces 20 of them, prompt parity included. A new check step runs the whole file after pnpm install with MOCA_REQUIRE_WORKSPACE=1, where a missing tsx fails instead of skipping.
  • Symlinked operator token (0b97aa4): it's judged by its target (stat -L), and the remedy no longer loops.

Suggestions:

  • Exchange fallback (d917999): only a session that named no credential falls back. A session whose own credential was deleted is refused, naming it. The fallback tests now reach it with no credential instead of delete-after-create. The README states the binding both ways.
  • Leftover override.conf (0b97aa4): any other drop-in loading the token is refused, naming it.

Nits:

  • In e28f3f2: the delete-retry comment and mock now describe a 202 or 5xx; a key line with surrounding whitespace is refused; an unreadable pool says so.
  • In 0b97aa4: an indented SH_ALLOW_OPERATOR_FALLBACK counts.

Not in the diff: deploy/knative/control-plane.yaml's comment now names everything a fallback-on control plane needs to boot (d917999).

The PR description's "Behaviour changes to note" gains the exchange change. make lint, make typecheck, make test and make test-deploy are green at d917999.

- exchange.test.ts: 'refuses when the fallback is allowed but no operator key is configured' now
  tests that (a fallback session exchanged after the key is gone), not the named-credential gate.
- A deleted named credential's refusal says what to do: store it again, or start a new session.
- setup-vm.sh: the other-drop-in check matches as systemd parses units (whitespace around '=',
  LoadCredentialEncrypted=, the colon-less form); a trailing-spaced SH_ALLOW_OPERATOR_FALLBACK
  counts, as systemd drops the whitespace.
- The key-file rule (one line, the key alone) is documented in the script header and README; the
  CI comment says deploy-scripts lacks a workspace install, not node.

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

pdettori commented Oct 1, 2026

Copy link
Copy Markdown
Member Author

One more commit, fd3a9e6, from a self-review pass over the whole PR. It found no must-fixes; these are the smaller items it turned up:

  • exchange.test.ts: "refuses when the fallback is allowed but no operator key is configured" now really tests that. It creates a session on the fallback, then exchanges it after the key is gone. Since d917999 it had been passing on the named-credential gate instead.
  • Clearer refusal: a deleted named credential's refusal now says to store it again or start a new session.
  • setup-vm.sh, other drop-ins: the check now matches as systemd parses unit files: whitespace around =, LoadCredentialEncrypted=, and the colon-less form.
  • setup-vm.sh, trailing spaces: a trailing-spaced SH_ALLOW_OPERATOR_FALLBACK=true counts, since systemd drops that whitespace.
  • Docs: the key-file rule (one line, the key alone) is in the script header and the README. The CI comment says deploy-scripts lacks a workspace install, not node; ubuntu-latest ships node, it's tsx that's missing.

The PR description's Summary and Test plan are updated to match. Lint and every affected suite are green.

Resolves .github/workflows/ci.yml: rossoctl#409's P4 authenticated-turn step and this PR's
research-smoke step both run in the check job, after pnpm install.

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

@huang195 huang195 left a comment •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Round 2, at fd3a9e6, plus c6c23b6's merge of main. All eight round-1 items and the knative note are fixed. Every fix but one is held by a test that fails when the fix is reverted. The exception, and two smaller items, are inline.

CI: none of the four fix commits had a run, because the PR conflicted with main in ci.yml. c6c23b6, which merged main while I was reviewing, keeps both check steps (#409's and this one) and is green. Its logs show research-smoke.test.sh running 59 checks in check and 20 in deploy-scripts, the rest skipped. Those are the counts I got locally, so the first round-1 must-fix holds on CI too.

Checked locally at fd3a9e6:

  • control-plane vitest: 441 passed.

  • research-smoke.test.sh:

    • 59 checks with the workspace installed;
    • 20 with no tsx, and the same 20 with node off PATH as well (deploy-scripts' shape);
    • with MOCA_REQUIRE_WORKSPACE=1 and no tsx, it fails, as intended.
  • setup-vm.test.sh passes.

  • Each of these reversions makes a test fail:

    • !rec.credentialName dropped from the exchange's fallback branch;
    • stat without -L;
    • no other-drop-in check, no Encrypted form, no colon-less form;
    • no trailing-whitespace strip;
    • no whitespace check on the key line;
    • the pool read failing open.

    The one that survives is the indented-fallback grep (inline).

  • The new rule ("only a session that recorded no credential falls back") has no other reader. credentialName has been stored on every session record since the ownership index was added, so only sessions created on the fallback carry ''.

Comment thread deploy/vm/tests/setup-vm.test.sh Outdated
# An INDENTED fallback line counts too: systemd's EnvironmentFile= accepts it, so the control plane
# would see the fallback on (#411 review).
mv "$OP/credentials/operator-inference-token" "$OP/token.aside"
printf ' SH_ALLOW_OPERATOR_FALLBACK=true\n' >>"$OP/control-plane.env"

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

suggestion: this case passes without the fix. $OP/control-plane.env still holds the unindented SH_ALLOW_OPERATOR_FALLBACK=true appended at :1198, and nothing removes it before the sed at :1295. So the refusal comes from that line, and operator_fallback_value never has to read the indented one.

Mutation: anchor its grep (setup-vm.sh:581) back to ^SH_ALLOW_OPERATOR_FALLBACK=. setup-vm.test.sh still reports all passed. Copy the :1295 sed above this printf and the same mutation fails with an indented SH_ALLOW_OPERATOR_FALLBACK=true with no token file was accepted, while the real code passes. The trailing-spaces case below is sound, since that sed runs before it.

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.

Good catch, thanks. Fixed in 4a2ea9c. The block now deletes every SH_ALLOW_OPERATOR_FALLBACK line first, and checks that a missing token passes with none present. Then it tests each spelling alone: indented, trailing-spaced, =, and = "true".
Your mutation, the grep anchored back to ^SH_ALLOW_OPERATOR_FALLBACK=, now fails with ' SH_ALLOW_OPERATOR_FALLBACK=true' with no token file was accepted.

Comment thread deploy/vm/setup-vm.sh Outdated
return 1
fi
# Leading whitespace too: systemd's EnvironmentFile= accepts it.
if grep -qE '^[[:space:]]*SH_OPERATOR_INFERENCE_TOKEN=' "$cp" 2>/dev/null; then

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

nit: fd3a9e6 made the drop-in check accept whitespace around =, as systemd does. The two control-plane.env reads still don't. systemd's EnvironmentFile= parser (parse_env_file_internal in env-file.c) trims trailing whitespace from the key and skips it after =, so SH_OPERATOR_INFERENCE_TOKEN = sk-… sets the variable.

This grep misses that form. With no token file, ensure_operator_fallback returns 0, and credentialValue falls back to the environment's value. The fallback then runs on a secret written in control-plane.env, which is the case this guard is there to refuse. The same miss in operator_fallback_value (:581) is fail-safe: the boot check refuses a fallback with no token.

Repro, sourced with SH_SOURCE_ONLY=1, no token file:

  • SH_OPERATOR_INFERENCE_TOKEN=x: rc=1.
  • SH_OPERATOR_INFERENCE_TOKEN = x: rc=0.
  • SH_ALLOW_OPERATOR_FALLBACK = true: rc=0.

Fix: use [[:space:]]*= after the key in both greps, and have operator_fallback_value strip leading whitespace after the = too.

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.

Fixed in 4a2ea9c. Both control-plane.env reads now allow whitespace before =:

  • the token-line guard is now ^[[:space:]]*SH_OPERATOR_INFERENCE_TOKEN[[:space:]]*=;
  • operator_fallback_value uses the same form and also strips blanks after =.

Your three repros are now test cases: SH_OPERATOR_INFERENCE_TOKEN = x and =x are refused, and SH_ALLOW_OPERATOR_FALLBACK = true with no token file refuses, naming the file. Each fails when its part of the fix is reverted (the space before = in either grep, or the strip after =).

Comment thread deploy/vm/README.md Outdated
- `SH_ALLOW_OPERATOR_FALLBACK=true` with no token file;
- a token file that is empty, a dangling symlink, or readable by anyone but its owner (not 0600 or
0400; for a symlink, its target's mode);
- the token as a line in `control-plane.env`.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

nit: this item still ends the list (.), but one now follows it. A ;, like the two items above, keeps the new item in the same list.

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.

Fixed in 4a2ea9c. The token-line item ends with ; and now also says it covers any spelling systemd accepts. The drop-in item ends the list, and its remedy moved into the paragraph after.

…aces around '=' (rossoctl#411 round 2)

systemd's EnvironmentFile= parser trims the key and skips blanks after '=', so
'SH_OPERATOR_INFERENCE_TOKEN = sk-...' sets the variable; the token-line guard and
operator_fallback_value missed that spelling. Both now match it. The indented-fallback test also
tested nothing: an earlier unindented line stayed in the file and made it pass alone. Every
spelling is now tested with no other fallback line present, and each test fails when its fix is
reverted. README: the stop list ends where it should.

Assisted-By: Claude (Anthropic AI) <[email protected]>
Signed-off-by: Paolo Dettori <[email protected]>
@pdettori
pdettori merged commit f2ad74c into rossoctl:main Oct 1, 2026
13 checks passed
@pdettori
pdettori deleted the feat/368-phase2-vm-research branch October 1, 2026 15:35
pdettori added a commit to pdettori/moca that referenced this pull request Oct 1, 2026
The epic's walkthrough: P6 and P4 on one VM, two GitHub users logging
in with mocactl, a curl/git research turn on each user's own key,
cross-user session refusals, then the host switched to the microVM tier.

Folds in the B plan's runbook notes (login expiry and
SH_API_TOKEN_TTL_SECONDS, device_flow_disabled, the tenancy caveat) and
orders the acts around one-tier-per-host: container tier first, P4
last, because switching back needs a setup-vm.sh re-run that loses
every session (rossoctl#410).

Drafted, not yet performed end to end; Act 5 is the record to fill in.
The research act uses deploy/vm/README.md's prompt and research-smoke.sh
from rossoctl#411, which must merge first.

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 Oct 1, 2026
The research smoke and prompt are on main now, so drop the
merge-first notes. The login step quotes mocactl's new operator-fix
message (rossoctl#405), and the fix list marks it fixed.

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

2 participants