Skip to content

impl(039): Bedrock rank, part b, the rules and Bedrock swap test - #424

Merged
bartekus merged 1 commit into
mainfrom
impl/039-bedrock-swap
Oct 31, 2026
Merged

bartekus merged 1 commit into
mainfrom
impl/039-bedrock-swap

Conversation

@bartekus

Copy link
Copy Markdown
Contributor

Spec 039, Bedrock rank increment (owner decision A-49), part b: the swap test. Stacked on #422 (part a, the admission).

One definition (pointwise rank over a filtered pool, select k 2 backfilled from the pool's exact order, backfill_all) runs through rustev-runtime with capture twice: with spec 005's rules backend (3.14) and with the Bedrock adapter answering from documented-shape SYNTHETIC fixtures on a loopback Converse endpoint (fixtures/rank/swap-answers.json). No network, no paid call.

  • One authority path: identical definition and policy, plans differing only by the binding; every case proposes recommend through the same rule with the same policy trace. Per-position origins are asserted, including a case where every Bedrock answer lacks score, so backfill_all fills both positions from the exact order.
  • Comparable reports: the captured bundles are evaluated with rustev eval under one dataset (gold relevance), adapter and configuration: the spec 004 report, spec 041's ranking measures (precision@2, ndcg@2, mrr, backfill@p1, backfill@p2) under rustev.evaluator-config/3, and spec 029 repeat reports (replay, n 2).
  • rustev eval --repeat-config evaluates each run without the adapter's measures (crates/rustev-cli/src/repeat.rs calls evaluate_with_cases, not evaluate_measured_with_cases), so it refuses a version 3 configuration with Adapter. The repeat here runs under the same configuration at version 2; the gap is recorded in 039's record and left to its owner, outside this lane.

Spec: 039 implementation record gains a dated paragraph; RANKING_ACCEPTANCE.md maps the swap row.

Verification (local): cargo test -p rustev-bedrock --locked (all suites), cargo clippy -p rustev-bedrock --all-targets -- -D warnings, cargo fmt --check, make gate.

@github-actions

Copy link
Copy Markdown

AI review (no-findings)

Reviewing the four changed paths for bugs, security issues, and inconsistencies.

integrations/rustev-bedrock/fixtures/rank/swap-answers.json
The fixture is internally consistent: a-* and b-* entries carry score; c-* entries carry only rating (no score), which is what the test's backfill_all branch relies on. The provenance field correctly marks the shape as "documented-shape; synthetic".

integrations/rustev-bedrock/tests/rank_swap.rs

Loopback server (fixture_endpoint): Listener is bound to 127.0.0.1:0 and both the local address and each accepted peer are asserted to be loopback before any data is processed. Acceptable for test code.

Hardcoded credential strings: "HOST_TEST_KEY" / "HOST_TEST_SECRET" are synthetic AWS credential types used only against the loopback fixture; the fixture endpoint ignores them. Not real credentials.

Fixture lookup answers[id]: If a presented id is absent from the answers map, serde_json::Value indexing returns null and the response carries "input": null. Whether the Bedrock adapter treats that as malformed is not exercised here—all nine candidate IDs in CASES have matching entries in swap-answers.json, so this path is never reached.

Hit count assertion assert_eq!(hits, 9): 3 cases × 3 candidates in pointwise mode = 9 individual loopback calls. Correct.

Selection assertions: Verified against the rules formula 2 − 0.1 × price and the Bedrock fixture scores:

  • r-1: rules order a-1(1.5) > a-3(1.2) > a-2(0.8); Bedrock order a-1(0.9) > a-3(0.6) > a-2(0.2). Both pick [a-1, a-3]. ✓
  • r-2: rules order b-2(1.7) > b-3(1.0) > b-1(0.0); Bedrock order b-2(0.8) > b-1(0.7) > b-3(0.1). Rules picks [b-2, b-3], Bedrock picks [b-2, b-1]. ✓ (intentionally different, testing that reports remain comparable across backends)
  • r-3: rules order c-3(1.9) > c-1(1.6) > c-2(1.4); Bedrock all-rating → ranking failure → backfill_all → pool input order [c-1, c-2, c-3] → [c-1, c-2] as Backfill. ✓

backfill@p1 share: 1 of 3 cases is entirely backfilled (r-3); assertion (share − 1/3).abs() < 1e-12 is consistent.

config-v2 downgrade for --repeat-config: The comment explains correctly that rustev eval --repeat-config evaluates without adapter measures and refuses a v3 config; the v2 clone strips measures and ranking metric before writing. Consistent with the prose in spec.md.

specs/039-model-backed-rank/spec.md
The new prose block is inserted in the correct location (before ## Decisions at approval) and accurately describes what rank_swap.rs demonstrates. No status/implementation frontmatter fields are changed (absent from the diff), so no lifecycle inconsistency is introduced.

crates/rustev-core/tests/RANKING_ACCEPTANCE.md
The previously deferred row now points to bedrock, tests/rank_swap.rs, swapping_rules_for_bedrock_fixtures_keeps_one_authority_path_and_comparable_reports. The test name and path match the new file exactly. The parenthetical (spec 004 reports, spec 041 ranking measures, spec 029 repeat reports) maps onto the three evaluation sections in rank_swap.rs.

No concrete defects found.

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

Subject: a46ccf7...21278a2, diff digest 15ae1be067b22aceb878d5cdad941efa36d7632d44db1cbe568b0fd8f875a502, 1 call(s). An AI comment is not an approval.

Base automatically changed from impl/039-bedrock-rank to main October 30, 2026 23:54
@bartekus
bartekus force-pushed the impl/039-bedrock-swap branch from 21278a2 to 686b68c Compare October 30, 2026 23:54
@github-actions

Copy link
Copy Markdown

AI review (no-findings)

Reading through the four changed files:

crates/rustev-core/tests/RANKING_ACCEPTANCE.md — The deferred row is replaced with a concrete test reference that matches the new test function name and path. Consistent.

integrations/rustev-bedrock/fixtures/rank/swap-answers.json — Correctly annotated as documented-shape; synthetic; not a live recording. The c-* entries intentionally lack score (only rating) to trigger backfill_all. All nine candidate ids referenced in CASES are present in the fixture, so no silent null lookups will occur at runtime.

integrations/rustev-bedrock/tests/rank_swap.rs — Reviewed the test carefully:

  • The loopback server correctly asserts peer.ip().is_loopback() and serves one pointwise candidate per request. hits == 9 (3 cases × 3 candidates) is the right expected count for pointwise mode.
  • Arithmetic on rules backend scores is consistent: a-1 (price 5 → 1.5) > a-3 (price 8 → 1.2) > a-2 (price 12 → 0.8); b-2 (price 3 → 1.7) > b-3 (price 10 → 1.0) > b-1 (price 20 → 0.0); c-3 (price 1 → 1.9) > c-1 (price 4 → 1.6) > c-2 (price 6 → 1.4). All rules_chosen assertions match.
  • Bedrock scores from fixture: case r-1 produces same ranking as rules (a-1 > a-3 > a-2); case r-2 differs (b-2 > b-1 > b-3); case r-3 all lack score, so backfill_all fills from pool order [c-1, c-2, c-3] → ["c-1:Backfill", "c-2:Backfill"]. All bedrock_chosen assertions match.
  • assert_eq!(rt, bt, "the policy trace differs") checks only the policy rule firing sequence (same "present" rule fires via when: always in both cases), not the parameter values that differ between backends. Plausible and consistent.
  • backfill@p1 assertions: rules has 0/3 = 0.0; bedrock has 1/3 (only r-3 position-1 is backfill). Correct.
  • The config_v2 downgrade for the repeat path is explicit and documented, consistent with the spec note that v3 config is refused in repeat mode until that path passes measures.
  • The write_inputs dataset gold relevance is internally consistent with the case definitions.

specs/039-model-backed-rank/spec.md — The narrative accurately reflects what the test implements. References to spec 004/041/029 and acceptance items A-49 match the RANKING_ACCEPTANCE.md update.

No bugs, security issues, or governance inconsistencies found.

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

Subject: f94b716...686b68c, diff digest 15ae1be067b22aceb878d5cdad941efa36d7632d44db1cbe568b0fd8f875a502, 1 call(s). An AI comment is not an approval.

@bartekus
bartekus added this pull request to the merge queue Oct 31, 2026
Merged via the queue into main with commit 7a9625f Oct 31, 2026
30 checks passed
@bartekus
bartekus deleted the impl/039-bedrock-swap branch October 31, 2026 00:46
bartekus added a commit that referenced this pull request Oct 31, 2026
Amends approved spec 039's Verification section now that the Bedrock `rank` increment has landed. For the owner to ratify before this is armed.

- The paragraph "Externally blocked until spec 030 is complete" is reworded: the offline Bedrock items owner decision A-49 moves to the Bedrock `rank` increment (section 5's `structured_output: none` row, the fixtures on both wires for the three modes, the swap test, 3.18 item 1) are delivered by #422 and #424 and declared.
- The `verify:cli` block gains `cargo test -p rustev-bedrock --locked --test ranking --test rank_swap`.
- The optional paid live Bedrock `rank` smoke (Decision 18) stays outside declared verification; no live call is part of it.

Nothing else in the approved text changes. Derived shards refreshed.

Verification (local): `cargo test -p rustev-bedrock --locked --test ranking --test rank_swap`, `spec-spine verify 039`, `make gate`, `scripts/check-authored-content.sh`, `spec-spine couple`.
bartekus added a commit that referenced this pull request Oct 31, 2026
Amends approved spec 039's Verification section now that the Bedrock `rank` increment has landed. For the owner to ratify before this is armed.

- The paragraph "Externally blocked until spec 030 is complete" is reworded: the offline Bedrock items owner decision A-49 moves to the Bedrock `rank` increment (section 5's `structured_output: none` row, the fixtures on both wires for the three modes, the swap test, 3.18 item 1) are delivered by #422 and #424 and declared.
- The `verify:cli` block gains `cargo test -p rustev-bedrock --locked --test ranking --test rank_swap`.
- The optional paid live Bedrock `rank` smoke (Decision 18) stays outside declared verification; no live call is part of it.

Nothing else in the approved text changes. Derived shards refreshed.

Verification (local): `cargo test -p rustev-bedrock --locked --test ranking --test rank_swap`, `spec-spine verify 039`, `make gate`, `scripts/check-authored-content.sh`, `spec-spine couple`.
bartekus added a commit that referenced this pull request Oct 31, 2026
Amends approved spec 039's Verification section now that the Bedrock `rank` increment has landed. For the owner to ratify before this is armed.

- The paragraph "Externally blocked until spec 030 is complete" is reworded: the offline Bedrock items owner decision A-49 moves to the Bedrock `rank` increment (section 5's `structured_output: none` row, the fixtures on both wires for the three modes, the swap test, 3.18 item 1) are delivered by #422 and #424 and declared.
- The `verify:cli` block gains `cargo test -p rustev-bedrock --locked --test ranking --test rank_swap`.
- The optional paid live Bedrock `rank` smoke (Decision 18) stays outside declared verification; no live call is part of it.

Nothing else in the approved text changes. Derived shards refreshed.

Verification (local): `cargo test -p rustev-bedrock --locked --test ranking --test rank_swap`, `spec-spine verify 039`, `make gate`, `scripts/check-authored-content.sh`, `spec-spine couple`.
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