Skip to content

feat(sandbox-relay): the sandbox_exec audit line carries wid and call_id, and harness Execs get one - #981

Merged
pdettori merged 2 commits into
rossoctl:mainfrom
webchang:pr/relay-audit-wid
Nov 23, 2026
Merged

pdettori merged 2 commits into
rossoctl:mainfrom
webchang:pr/relay-audit-wid

Conversation

@webchang

Copy link
Copy Markdown
Member

Closes #980

The relay's sandbox_exec audit line now joins the worker's record of the same Exec exactly, can carry a client's own correlation id, and covers the harness's Execs too.

  • wid: the id the worker knows the Exec by, which its journal logs as req= (workerReqId for a sandbox token; the req_id itself on the harness path, which forwards it unchanged). It's absent only when the relay refused the Exec before mapping it. Logging it doesn't weaken spec §3.6: a wid reveals nothing about the relay's key.
  • call_id: from gRPC metadata x-moca-call-id, when it matches [A-Za-z0-9._:-]{1,64}. Any other value is dropped and never echoed. It's a label only, never read for auth or routing.
  • Harness Execs (MOCA_RELAY_EXEC_TOKEN) write the same line with caller: "harness", no sub, sbx or cmd, and wid equal to req_id.
  • Unchanged: lines are still written only on a relay with sandbox keys (a relay without them prints nothing, as before), and SH_SANDBOX_AUDIT_COMMANDS behaves as before.
  • Docs: spec §3.5 and the sandbox-service runbook list the new fields.

Tests (packages/sandbox-relay):

  • the line carries wid, equal to the id the fake worker received;
  • a valid x-moca-call-id appears as call_id, and an invalid one is dropped and not echoed;
  • a harness Exec writes one caller: "harness" line with wid = req_id and no command, even with SH_SANDBOX_AUDIT_COMMANDS=1.

Two existing tests asserted the old design (no worker id in the line; no line for a harness Exec) and are updated. All four fail without the change. The package's tests (347) and typecheck pass.

Assisted-By: Claude Code

…_id, and harness Execs get one

A relay audit line could not be joined exactly to the worker's record of the same Exec: the line
held only the caller's req_id, while the worker logs the id the relay mapped it to (workerReqId).
The line now carries that id as wid (absent only when the relay refused the Exec before mapping
it), an optional call_id from gRPC metadata x-moca-call-id (kept only when it matches
[A-Za-z0-9._:-]{1,64}, otherwise dropped and never echoed; never read for auth or routing), and the
harness's own Execs (MOCA_RELAY_EXEC_TOKEN) write the same line with caller=harness, no sub, sbx or
cmd, and wid = req_id, which the relay forwards unchanged. Lines are still written only on a relay
with sandbox keys, and SH_SANDBOX_AUDIT_COMMANDS is unchanged.

Logging wid keeps the spec's rule: a wid reveals nothing about the relay's key, so a sandbox still
cannot predict another sandbox's. Spec §3.5 and the runbook list the new fields.

Assisted-By: Claude (Anthropic AI) <[email protected]>
Signed-off-by: Rong Chang <[email protected]>
…IdFrom's bounds

The relay keeps its own copy of the client's x-moca-call-id pattern (sandbox-client
exec-conn.ts). The test fails if the copy changes, so the two can't drift apart unseen.

Assisted-By: Claude (Anthropic AI) <[email protected]>
Signed-off-by: Rong Chang <[email protected]>
@pdettori pdettori added the ready-for-ai-review Request automated AI code review from clawgenti label Nov 23, 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

The join is done at the right seam. call_id is the client's label and is validated before it is ever echoed (callIdFrom keeps only [A-Za-z0-9._:-]{1,64}, drops everything else — including a Buffer, which it decodes first), wid is set only after the Exec is mapped, so a refusal before mapping has none (as the spec now says), and the harness path is honest about what it cannot know: no sub/sbx/cmd, wid = the req_id the worker received unchanged. The one-line-per-Exec invariant survives on every path I traced: sandboxExec's log() is logged-guarded and called from the expiry/cancel hooks and the finally, and the harness line is written after a pumpExec that cannot throw (it records thrown in the PumpResult rather than rejecting), so a route failure still leaves outcome: "error" rather than no line.

Verified at 370558e:

  • npx tsc --noEmit clean in packages/sandbox-relay.
  • npx vitest run test/audit.transport.test.ts test/sandbox-token.transport.test.ts — 85/85 pass, including the three new tests (worker wid, valid/invalid x-moca-call-id, the harness line with caller=harness and no command even with SH_SANDBOX_AUDIT_COMMANDS=1).
  • Full package suite: 342 passed, 5 skipped. The two integration suites (template-affinity, tier-affinity) fail to collect here because they need a live Redis (ECONNREFUSED 127.0.0.1:6379); nothing in this diff is on those paths.

No findings.

Author: webchang (MEMBER — maintainer)
Areas reviewed: TypeScript (packages/sandbox-relay audit path and tests), spec and runbook docs
Agent/IDE config (.claude/.vscode): none
Commits: 2, all signed off: yes
CI status: passing (k8s-kind-e2e, lint, microvm-gates, proto, shellcheck, trivy-scan)

All checks pass. Ready for human review.

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

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

Review — relay audit joins (wid, call_id, harness)

Approving. wid is captured only once the Exec is mapped (auditWid = wid right after workerReqId), so refusal lines correctly omit it while every later line carries it. call_id is read once per Exec and callIdFrom keeps only [A-Za-z0-9._:-]{1,64}; anything else is dropped and never echoed, and it is a label only.

Harness Execs always get their line (pumpExec returns rather than throws), with caller: "harness", wid = req_id, and no sub/sbx/cmd, even under SH_SANDBOX_AUDIT_COMMANDS=1; a relay without sandbox keys still writes nothing. The two tests that encoded the old design are updated and the new ones fail without the change. CI 18/18; both commits DCO-signed; MEMBER author; no .claude//.vscode/ changes; no injection content.

@pdettori
pdettori merged commit ea08292 into rossoctl:main Nov 23, 2026
18 checks passed
webchang added a commit to webchang/moca that referenced this pull request Nov 23, 2026
Upstream rossoctl#972, rossoctl#977, rossoctl#978, rossoctl#979, rossoctl#981, rossoctl#983, rossoctl#985, rossoctl#988 and rossoctl#990 (44 commits past 49cce28). No conflict.

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

sandbox-relay: a sandbox_exec audit line can't be joined exactly to the worker's record

4 participants