Skip to content

fix(sandbox): correlate mediation by test case - #327

Open
Jake Present (jakepresent) wants to merge 4 commits into
mainfrom
jake/fix-sandbox-case-correlation
Open

fix(sandbox): correlate mediation by test case#327
Jake Present (jakepresent) wants to merge 4 commits into
mainfrom
jake/fix-sandbox-case-correlation

Conversation

@jakepresent

Copy link
Copy Markdown
Collaborator

Problem

MockCall carried a case_id, but ASSERT never propagated its stable test-case identity into the sandbox. The field was therefore inert: otherwise identical calls in two cases could not intentionally select different mocks, scenario state could be shared by a long-lived host, and action/network evidence lacked direct case correlation.

Fix

  • pass the effective ASSERT test-case ID into SandboxedEndpointSession and the stock container
  • reserve ASSERT_SANDBOX_CASE_ID from target overrides
  • include the case ID in Agent Hooks session context, compact action evidence, host egress evidence, and runtime metadata
  • support optional exact or prefix/suffix-glob case_id: selectors in mocks.yaml
  • partition scenario response cursors and state by case ID
  • preserve compatibility for callers that do not supply a case ID
  • keep the packaged and copyable stock servers identical

Existing ordered retry responses remain supported; this change ensures separate cases each start from their own sequence.

Verification

  • Five focused regressions were written first and all failed against main.
  • 117 passed across sandbox setup, example, hostile-input, and runtime tests.
  • 1375 passed, 24 skipped, 840 subtests passed across tests/.
  • A live stock-container inference produced the same effective case ID in the artifact row, action-mediation evidence, and runtime session metadata.
  • Packaged and copyable stock servers are byte-identical.
  • The live probe left no new sandbox containers or networks.

Risk

The new fields are optional. Existing rules without case_id: and callers without a case ID retain their previous behavior. Case-specific rules count as one additional specificity condition and do not change pass/mock/block policy decisions.

A fresh local rebuild of the stock image was blocked before product execution by the local Docker builder's PyPI TLS handshake failure. The live proof used a no-network derivative of the existing stock image with this branch's package and stock server copied in; PR CI will perform the clean build path.

sandbox-action-mediation resolve built its MockCall with no case_id and
had no way to supply one, so once case-bound mocks existed the tool
reported the uncorrelated-run branch for every call. That is worse than
missing: it confidently prints a mock the run will not use.

  - add --case-id and thread it into both the find() and resolve() calls
  - echo the case being resolved as
  - name the matched rule's case binding when one applies
  - when no --case-id is given but the setup declares case-bound rules,
    say so instead of passing the default branch off as the answer

Also document the case_id precedence rule in the example README. It is a
tier, not another matcher: a case-bound rule outranks every unbound rule
regardless of argument specificity, which is deliberate but surprising if
you assume it just adds a condition.
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.

1 participant