Skip to content

fix(0215): make the two-pivot guard runnable, and warn when a reference narrows - #304

Merged
karczuRF merged 3 commits into
developfrom
fix/0215_peg-pivot-step-plan-is-testable
Sep 10, 2026
Merged

fix(0215): make the two-pivot guard runnable, and warn when a reference narrows#304
karczuRF merged 3 commits into
developfrom
fix/0215_peg-pivot-step-plan-is-testable

Conversation

@karczuRF

Copy link
Copy Markdown
Collaborator

Closes the code half of task 0215. The defect itself was fixed on 2026-08-21; this arms the guards that were meant to stop it recurring.

The gap

0215 asked for a test "so a silently-narrowed pivot set fails the suite instead of the quote leg."

The end-to-end coverage already existed — narrow pivot_ids() to [xlm] and usdt_quoted_candles_pivot_on_the_measured_rate_not_a_dollar_peg goes red; narrow it to [usdt] and enrich_fills_close_usd_across_oracle_peg_and_pivot_tiers goes red.

But those tests have never run. Every test in ch_enrich_it.rs is #[ignore] (they need a live ClickHouse), CI runs cargo test --workspace which skips them, and no workflow provides a database. Every CI run has printed 19 ignored for months. The guard was written and never armed. Filed as 0275.

What this PR does

Splits planning from sending. enrich_peg_pivot_step now calls a pure plan_peg_pivot_step returning Vec<StepStatement>; the executor matches and binds. The two variants take different bind sequences, which is why it's an enum rather than Vec<String>. No behaviour change.

Adds plan_issues_one_peg_and_two_pivots — a unit test that runs in CI today. It asserts one peg, two pivots, refs [5, 7] in order, a total of 3, and that each pivot's SQL carries its ref id as the literal that made this defect readable in system.query_log at all.

Warns when a reference does not resolve. resolve_reference_ids now names the absent code. stable_ids()/pivot_ids() flatten a None away, so a missing USDT silently issues one statement where two belong and still reports success — the exact shape of the defect. Partial sets stay legal (bootstrap discovers assets in arbitrary order), so this warns rather than fails; what it must not do is happen quietly.

Verified by inducing, not assumed

induced defect reference_ids_helpers (existing) plan_issues_one_peg_and_two_pivots (new)
pivot_ids() narrowed to [xlm] 🔴 fails 🔴 fails
pivot_ids() correct, break after first pivot 🟢 passes 🔴 fails

The second row is the point: an emission defect is invisible to a set-level assertion. Both inductions were run and reverted; the working tree carries neither.

  • cargo test -p enrichment-worker76 passed, 0 failed (was 75).
  • cargo clippy clean, cargo fmt --check clean.

Prod state, re-verified today

The fix has held for three weeks, and 0111 moved it further out of reach:

check 2026-08-21 baseline now
USDT pivot absent from every scheduled run 4,263 runs / 7 days, 1:1:1 with peg and XLM pivot
XLM pivot duration 45.6 s, client cut at 30.0 s max 3.28 s
oracle duration p95 28.7 s, max 37 s max 1.34 s
BadResponse("") 3/hour for 26 days 0 in 7 days
Lambda timeouts every invocation 0 in 7 days

All prod reads were read-only — ClickHouse as dev_read (readonly = 1), AWS as ReadOnlyAccess.

…ce narrows

A peg-pivot step must issue one peg and TWO pivots (XLM, USDT). Nothing that
runs in CI asserted that. The end-to-end coverage exists — the 0172 and
all-tiers integration tests would both go red on a narrowed pivot set — but
every test in ch_enrich_it.rs is #[ignore] and needs a live ClickHouse, and no
workflow provides one, so `cargo test --workspace` skips all 19. The guard was
written and never armed. Wiring ClickHouse into CI is task 0275.

Split the statement planning out of enrich_peg_pivot_step into a pure
plan_peg_pivot_step returning Vec<StepStatement>. The two variants carry
different bind sequences, so this is an enum rather than Vec<String>. The
executor now matches and binds; no behaviour changes.

plan_issues_one_peg_and_two_pivots asserts one peg, two pivots, refs [xlm,
usdt] in order, and that each pivot's SQL carries its ref id as the literal
that made the defect visible in system.query_log at all.

Verified by inducing, not assumed. Narrowing pivot_ids() to [xlm] fails it.
Leaving pivot_ids() correct but adding a `break` to the loop ALSO fails it,
while the existing reference_ids_helpers stays green — the new test covers the
emission, which the set-level test cannot see.

Also: resolve_reference_ids now warns, naming the absent code, when a reference
does not resolve. Partial sets stay legal — bootstrap discovers assets in
arbitrary order — but a narrowed pass must not happen quietly, which is what
cost 26 days.
…test comment

Two documentation defects introduced by the previous commit, both found in
review.

The StepStatement block was inserted between peg_sql's doc comment and peg_sql
itself. Rust merges consecutive /// blocks, so that comment silently became the
enum's documentation and peg_sql was left with none — losing its bind-order
contract, which is precisely what the executor's .bind(watermark).bind(batch_size)
arm depends on and what a future editor of that arm would go looking for. Move
the enum and plan_peg_pivot_step above the comment so it reattaches.

The no-USDC assertion's comment claimed the step "degrades to the peg alone"
while the assertion beneath it requires the plan to be empty. The assertion is
right: task 0172 made USDC the only peg member, so no USDC means stable_ids()
is empty and peg_sql returns None — nothing to peg and nothing to pivot
against. A reader trusting the comment would have "fixed" the assertion, in the
one test that is currently the only armed guard on this path.
Task 0268 landed ~475 lines of external-tier tests in ch_enrich.rs while this
branch was open. The single conflict sat entirely inside `mod tests` and was
purely additive on both sides — 0268's external-tier block against 0215's
`plan_issues_one_peg_and_two_pivots`. Both are kept.

No production code conflicted: 0268 did not touch `enrich_peg_pivot_step`,
`peg_sql` or `pivot_sql`, so the plan/executor split merges unchanged.

Verified on the resolved tree: cargo test --workspace 903 passed / 0 failed,
`plan_issues_one_peg_and_two_pivots` green, clippy --all-targets and
fmt --check clean.
@karczuRF
karczuRF merged commit b7496dd into develop Sep 10, 2026
3 checks passed
karczuRF added a commit that referenced this pull request Sep 10, 2026
PR #304 merged (b7496dd): the two-pivot guard now runs in CI, and a missing
reference asset is named in the logs.

The "fails loudly" AC is amended to "named in the logs", with the reasoning
recorded. A hard failure would refuse to start on a fresh registry — bootstrap
discovers assets in arbitrary order, so partial reference sets are legal. What
turned this defect into a 26-day outage was the silence, not the tolerance, and
the warn removes exactly that.

`max_execution_time` records the scope decision (the scheduled worker only, not
the operator CLIs) and why 120 s is not a load-bearing number after 0111. Left
unticked: the induction against prod is outstanding.
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