interplane.Get Omega
Read in your language

interplane-mv

INTERPLANE: open interoperability protocol between AI models and agent runtimes. Models express intent. Runtimes retain authority.

Brought by drakestapleton

branch main Branches Tags History

interplane-mv / docs / PROVIDER-REPLAY.md

120 lines · 7694 bytes Raw Blame History Rendered
1# Sanitized offline provider replay (issue #98)
2
3Replay lets a dialect or adapter be qualified against provider behaviour with no network, no
4credentials and no live model. A capture records what a provider sent; the replay feeds those
5bytes through the existing Lenshift dialect parsers and compares the result to golden values.
6
7Boundaries: a capture is observed provider behaviour. Parsing is Lenshift. Authorization is the
8runtime. The replay output (`Outcome`) has a closed shape (`class`, `text`, `tool_calls`,
9`rejected`, `partial`) and no decision, approval or grant field. A fixture is never evidence that
10anything was authorized, and "authorization: approved" in model text stays plain text.
11
12## Audit before this change
13
14- `dialects/fixtures/*` hold parse inputs per dialect (one string or message body each). The
15 `openai_stream` ones include SSE bodies, but as ONE pre-joined string: transport chunking,
16 HTTP status, headers and timing are not represented.
17- `qualification/captures/**` hold real request/response bodies from llama.cpp, Ollama and SGLang
18 (body as one string, no status, no chunk boundaries). `rust/crates/interplane-probe` reads live
19 responses through `Transport { get, post } -> HttpResponse { status, body }` and judges them;
20 it has no offline capture-to-fixture path.
21- `rust/crates/interplane-lenshift/tests/dialect_fixtures.rs` and `conformance/` run parsing and
22 core cases only. No secret scanner existed for fixtures.
23
24Not reproducible offline before this change: a tool call split across transport chunk
25boundaries (as opposed to across SSE events); 429 and 5xx handling (no status in any fixture);
26a stream cancelled mid-chunk, mid-JSON; a renamed provider field (schema drift); fixtures
27guaranteed free of credentials, emails and tenant ids; and adversarial text (authorization
28claims, fake tool calls in prose) arriving through a stream.
29
30## Fixture format (`interplane-replay/1`)
31
32Files live in `dialects/replay/*.json`. They are deliberately NOT under `dialects/fixtures/`:
33`dialect_fixtures.rs` and `interplane-corpus validate` glob that tree and expect
34the dialect-fixture shape.
35
36| Field | Meaning |
37|---|---|
38| `format` | `interplane-replay/1` |
39| `name`, `provider`, `model` | identity. Providers: a backend name, or `synthetic-openai-compatible` |
40| `endpoint_kind` | `chat_completions_stream` (SSE, parsed by `openai_stream`) or `chat_completions` (JSON body, `choices[0].message` parsed by `openai`) |
41| `provenance` | `origin` (`synthetic` or `recorded`), `source_commit` (repo commit the fixture was made at), `captured_on`, `note` |
42| `request` | `method`, `path`, `header_names` (NAMES only), `body` (user and tool content replaced by `<USER_CONTENT>` style placeholders) |
43| `response` | `status`, `header_names`, `chunks` (ordered transport chunks, may end mid-event), optional `timing_ms` (informational; replay never sleeps) |
44| `expect` | golden outcome: `class` (`parsed`, `rate_limited`, `server_error`, `client_error`, `unparsable_body`), `text`, `tool_calls` (name, arguments), `rejected` (Lenshift codes), `partial` |
45
46Replay joins `chunks` in order and parses them as live bytes would be. Status 429, 5xx and other
474xx are classified and the body is never parsed for calls.
48
49## Scrubbing and scanning
50
51`interplane_lenshift::replay::scrub_value` runs before a fixture is written: tenant style ids
52become `<ID>`, system, assistant, user and tool request content and a top level `prompt` become placeholders, response `content` and `reasoning` text becomes `<MODEL_TEXT>` or `<REASONING>` (tool-call fragments are kept), and every string is passed
53through `scrub_text`. `scan` runs over every fixture in the test and refuses: bearer or basic
54tokens, authorization / cookie / set-cookie / x-api-key style headers with values, `sk-`,
55`AKIA`, GitHub, Slack and Google style keys, hex runs of 32 or more, base64-looking runs of 40 or
56more, JWTs, PEM blocks, `sk_live_` style payment keys, `hf_` tokens, IP addresses, home, system and
57Windows file paths, `Cookie:` values, emails, `org-`/`ws_`/`tenant-` style ids and tenant/workspace/org/account id keys without a
58placeholder, query-string secrets (`?api_key=`, `token=`, `sig=` ...), header lists that contain a
59value, and unscrubbed user content. The test `scanner_refuses_each_seeded_secret_class` seeds each
60class into a clean candidate and asserts refusal. The scanner is a safety net, not a proof: a
61human still reviews a new fixture.
62
63## Never commit
64
65Raw captures straight from a provider; real user prompts or system prompts (the scrubber replaces
66system, assistant and user content and model reasoning with placeholders, but you still read the
67result); real model output you have not reviewed; API keys, tokens, cookies, certificates or
68private keys; emails, tenant, workspace or account ids; IP addresses, hostnames and local file
69paths; anything the scanner refuses. Tool-call deltas are kept on purpose, they are the golden, so
70check their arguments by hand.
71
72Scan any file or tree before committing, recursively, with no test run needed:
73
74```
75cd rust && cargo run -q -p interplane-lenshift --example replay_scan -- ../dialects/replay <other paths>
76```
77
78## Regenerating a fixture from a live run
79
801. Capture with the live probe workflow, keeping the raw request and the response body as in
81 `qualification/captures/*/` (`name`, `endpoint`, `request`, `response`).
822. `cd rust && cargo run -q -p interplane-lenshift --example replay_scrub -- <capture.json> ../dialects/replay/<name>.json <provider> <git-short-sha> <YYYY-MM-DD>`
833. The tool splits the stream into SSE events, scrubs, scans, and refuses to write if anything is
84 left. The `expect` it writes is bootstrapped from the CURRENT parser: review it by hand, a
85 golden that only mirrors today's bug proves nothing.
864. Run the tests below. Never commit a fixture the scanner refuses.
87
88Hand-written (synthetic) fixtures must say `"origin": "synthetic"` and why in `note`.
89
90## Running in CI
91
92Offline and part of the normal workspace run, no new CI step:
93
94```
95cd rust && cargo fmt --all --check && cargo clippy --all-targets --all-features -- -D warnings && cargo test --all
96cargo test -p interplane-lenshift --test provider_replay # just this suite
97```
98
99## Scenarios covered
100
101Tool call split across transport chunks; non-stream tool call serialization round trip; schema
102drift (renamed `tool_calls`); 429; 503; stream cancelled mid-chunk; finish_reason `length`;
103malformed JSON chunk; authorization claim in text; fake tool call in prose; one recorded Ollama
104Qwen3.5 stream. Mutation tests prove the runner fails on changed bytes, a changed golden and a
105truncated stream.
106
107## Coverage gaps and limitations
108
109- Only the `openai` and `openai_stream` endpoint kinds are replayed (not Qwen text-form,
110 Anthropic, or completions endpoints) and only choice 0.
111- Synthetic scenarios model behaviours; they are not proof any real provider does them. Only the
112 Ollama fixture is recorded (from the repo's own qualification capture).
113- Observed gaps pinned as goldens, not endorsed: schema drift in `tool_calls` yields no call and
114 no rejection; `finish_reason: length` on plain text is not flagged `partial`.
115- Rust only. The repository ships no Python (the Python SDK was removed on 2026-10-15), and the
116 replay needs only the Rust parsers it already feeds.
117- Chunk strings are UTF-8: splits inside a multi-byte character cannot be represented.
118- Timing is recorded but not exercised; no retry, backoff or timeout logic is replayed.
119- The scanner is regex based and can both miss novel secret shapes and flag long identifiers.
120- No production outbound telemetry is added; nothing here opens a socket.