Skip to content

impl(022): the direct mapping and stage 2's recorded exchanges - #401

Merged
bartekus merged 1 commit into
mainfrom
impl/022-direct-mapping
Oct 30, 2026
Merged

bartekus merged 1 commit into
mainfrom
impl/022-direct-mapping

Conversation

@bartekus

Copy link
Copy Markdown
Contributor

Records spec 022 3.7 stage 2, the owner-authorized live smoke on TypeSafe's direct API (2026-10-29), and the direct mapping it fixes (3.2.3). Stage 3 is not part of this change.

What the live calls showed. There were two runs of spec 012's smoke harness (--transport direct --pin jev-1.13.0), four synthetic cases each:

  • The pin is confirmed: every answer reports model: jev-1.13.0, recorded as served: reported.
  • classify and rubric are answered in the Gateway's shapes.
  • The direct API has no boolean type. A proposition sent as boolean is HTTP 400; it is noul, answered as {"type":"noul","noul":p}.
  • Usage is reported as input_tokens/output_tokens. The Gateway price table did not name those, so every first-run charge was unknown.

Changes

  • DIRECT_MAPPING_VERSION (rustev-jev-mapping/2 (direct shapes of 022 stage 2)) is the only version a direct binding accepts, and JevBinding::direct sets it. A Gateway binding still accepts only /1. It has a guard test.
  • On the direct transport a proposition is asked as noul, and its noul field maps losslessly to {"false": 1 - p, "true": p}. A boolean answer there is malformed_response. The Gateway is unchanged.
  • The price table also names input_tokens/output_tokens at the same rates, so direct charges are estimated.
  • Five recorded fixtures (tests/fixtures/recorded-direct-*): the four answered exchanges and the refused boolean request. tests/direct_recorded.rs replays them on loopback: each recorded request is the body the mapping sends, and each answer replays to the live output, an estimated charge and served jev-1.13.0. The fixtures were checked for the key and carry no headers.
  • The hand-written direct fixtures now answer propositions as noul; their synthetic cost members are kept for the reconciliation mechanics.
  • production_eligible still refuses construction, now naming stage 3.
  • Spec 022: an implementation record for stage 2 with its spend, and a verify:cli line for tests/direct_recorded.rs.

Spend (shared testing journal, nano-USD units): estimated 344,520 to 411,552 and liability 13,001,784 to 13,079,694. That is about USD 0.00015 in total, out of R-29's USD 5.

make code, make gate, spec-spine verify 022, 012 and 044, and the authored-content check pass locally.

@github-actions

Copy link
Copy Markdown

AI review (findings)

Reviewing the diff for bugs, security issues, and inconsistencies.

Mapping and parsing logic (mapping.rs): The Noul variant, its as_str, the step_request upgrade, map_answer's field dispatch, and the extras allowlist addition all look consistent with each other and with the recorded fixtures.

Transport/version gating (binding.rs): mapping_version(transport), JevBinding::direct, and the validation gate are consistent. The BindingError::MappingVersion display change (removing the hardcoded version string) is safe.

Production gate (production.rs): The message update from "stage 2" to "stage 3" and the matching test update are consistent.

Fixture provenance check (common/mod.rs): The relaxed assert! is correct; all new recorded-* fixtures contain "spec 022 3.7 stage 2".

Recorded fixtures: Request bodies, response shapes, and stated probabilities are internally consistent and match test expectations in direct_recorded.rs.

Test logic bug in binding.rs: The new estimate_units assertion includes output_tokens: 49 in the usage map alongside input_tokens: 516, but asserts the result is Ok(21_672) — identical to the preceding test that only has inputTokens: 516. Since price_table now maps both output_tokens and outputTokens at output_usd_per_million, any non-zero output rate in t would make the asserted value wrong. The comment says "a direct exchange is estimated, not unpriced," implying outputs should contribute, but the expected value does not account for output-token cost. If the test fixture t has a zero output rate the assertion passes vacuously and proves nothing about output pricing; if non-zero it fails. Either way the assertion as written is incorrect for its stated purpose.

{"head": "754ed5aa2b7b050d1d9ae41b6abba9dfbdf71b96", "verdict": "findings", "findings": [{"path": "integrations/rustev-jev/src/binding.rs", "line": 601, "summary": "The new `estimate_units` assertion expects `Ok(21_672)` while the usage map contains both `input_tokens: 516` and `output_tokens: 49`; any non-zero `output_usd_per_million` in the test fixture makes the expected value wrong, and a zero rate makes the assertion prove nothing about output-token pricing despite the comment claiming otherwise."}]}

Subject: 6ce5d1d...754ed5a, diff digest d66321a8e59f94a97dfeb7693eb63e3d7fa1aa197b47112aba83aff1bba1442b, 1 call(s). An AI comment is not an approval.

@bartekus
bartekus had a problem deploying to statecraft-review-exception October 30, 2026 02:16 — with GitHub Actions Error
@github-actions

Copy link
Copy Markdown

AI review (no-findings)

The PR records spec 022 stage 2 (the direct-transport mapping), adds the Noul question type, wires DIRECT_MAPPING_VERSION into JevBinding::direct, extends the price table with input_tokens/output_tokens keys, and replays the four recorded exchanges in a new direct_recorded test. I checked each layer:

Binding logic (binding.rs): mapping_version(transport) correctly dispatches per transport; JevBinding::direct now sets DIRECT_MAPPING_VERSION; validation uses the per-transport version; the price table extension is additive and rate-consistent. The MappingVersion error message was generalized — acceptable given the added mapping_version() helper. The new unit test covers both directions of the version cross-check.

Mapping logic (mapping.rs): QuestionType::Noul is correctly routed through the criteria-object branch of request_body (same as Boolean/Choice); map_answer reads "noul" not "probability" for Noul questions; parse_answered whitelists "noul" so it is not logged as an extra field. The test a_direct_proposition_is_asked_and_read_as_noul covers the round-trip and confirms that boolean answers (with probability) are rejected for Noul questions.

Production gate (production.rs): Comment and error string updated to "stage 3"; the gate still returns unconditional Err(Unresolved(...)), consistent with the spec's claim that no binding is yet production-eligible.

Fixtures and provenance: The common::fixture provenance check now accepts "spec 022 3.7 stage 2" in addition to "R-27" for recorded- files. All five new recorded-direct-* fixtures satisfy this. The synthetic-direct-* hand-written fixtures are correctly updated from boolean/probability to noul/noul. The recorded-direct-boolean-hotel-200.json correctly poses the flight-booking question against hotel state and records a low noul value (0.02) — intentional cross-scenario coverage.

Test (direct_recorded.rs): Each fixture in the loop gets its own fixture_gateway, so g.seen()[0] is unambiguous. The the_gateway_boolean_type_was_refused_and_is_no_longer_sent test mutates only the type field and checks equality — valid because the criteria and state shapes are otherwise identical.

Score fixture: Probabilities keyed "0"/"1"/"2" map to "low"/"medium"/"high" = 0.0/0.1/0.9, matching the test expected values.

No defects found.

{"head": "fe2aa1b9c67f0db7fec8362bd333416c18269632", "verdict": "no-findings", "findings": []}

Subject: ca81e1e...fe2aa1b, diff digest 45e8b0fab08af876074823bc5836ed8b4f439718b7ddd85f30eea6815e239f92, 1 call(s). An AI comment is not an approval.

@bartekus
bartekus enabled auto-merge October 30, 2026 02:29
@bartekus
bartekus added this pull request to the merge queue Oct 30, 2026
Merged via the queue into main with commit 54cbcea Oct 30, 2026
30 checks passed
@bartekus
bartekus deleted the impl/022-direct-mapping branch October 30, 2026 03:21
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