Skip to content

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

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

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

Conversation

@jakepresent

@jakepresent Jake Present (jakepresent) commented Aug 20, 2026

Copy link
Copy Markdown
Collaborator

Problem

ASSERT carried a case_id, but the sandbox path did not propagate and enforce one consistent identity end to end. That made case-bound mocks incomplete, allowed ambiguous rule selection, and left evidence unable to prove which case rule fired.

Fix

  • propagate the effective ASSERT case ID through SandboxedEndpointSession, the stock container environment, and the optional JSON request sent to an already-running sandbox endpoint;
  • preserve the ordinary target.endpoint request shape when no case ID is configured;
  • use one case-ID resolver for mock selection and evidence, and reject conflicting legacy/session IDs before any pass-through tool executes;
  • define rule precedence as exact case ID, matching case glob, generic fallback, argument specificity, then file order;
  • partition built-in scenario state by case while preserving the legacy current_state(scenario) extension contract;
  • serialize matching and state transition so parallel calls cannot consume the same scenario step;
  • include mock_source, replay detail, and matched_case_id in judge-visible evidence; and
  • keep the packaged and example stock servers aligned.

Verification

  • Focused case, endpoint, sandbox, and runtime suites: 124 passed.
  • Full exact-head Python suite: 1461 passed, 23 skipped, 840 subtests passed.
  • Regression coverage includes endpoint payload propagation, exact/glob/generic precedence, conflicting identities, legacy backend transitions, parallel scenario resolution, and judge-visible matched-rule evidence.
  • Branch includes current main, including the merged host-owned egress ledger correction.

Risk

The endpoint case_id field is optional. Existing ordinary endpoints and mock rules without a case binding retain their previous behavior. Legacy custom scenario backends remain usable, but cannot gain per-case state isolation until they adopt the new case-aware contract.

A clean local stock-image rebuild remains blocked by the local Docker builder's external PyPI TLS failure. The final combined correction tree was separately exercised with the exact branch source overlaid onto the existing stock image; clean-image CI is owned by #328.

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.

@changliu2 Chang Liu (changliu2) left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Two blockers on exact head 46d583a:

  1. Endpoint sandbox targets do not receive the per-test-case ID. The endpoint session still posts only message and history, so case-bound mocks cannot vary correctly across an already-running endpoint.
  2. ScenarioBackend.current_state() now accepts an optional case ID, but callers always pass it; legacy subclasses that override the prior one-argument method raise TypeError.

Please also align wildcard/no-case matching and evidence case-ID precedence so mock selection and recorded evidence cannot disagree.

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