Skip to content

Compile exact integer ratios before floating-point division - #362

Draft
seyoung4503 wants to merge 5 commits into
fix/benchmark-selection-countfrom
fix/exact-integer-ratio
Draft

seyoung4503 wants to merge 5 commits into
fix/benchmark-selection-countfrom
fix/exact-integer-ratio

Conversation

@seyoung4503

@seyoung4503 seyoung4503 commented Nov 26, 2026 •

Copy link
Copy Markdown
Collaborator

An observed percentage query divides before multiplying by100, creating an extra floating-point rounding step. With integer-valued REAL counts, 1.0/3.0*100 differs from the nearest binary64 value of100/3. Add integer_ratio_sql: a deterministic SQLite compiler that scales exact integer quantities before one REAL division. It does not rewrite submitted SQL or infer which quantities/units the user intended.

Callers supply ratio_input(group_id,numerator,denominator) and an explicit positive integer multiplier (1 for a fraction,100 for percent). Generated SQL accepts INTEGER or exactly integral REAL inputs, checks the shared binary64 exact-integer bound before scaling, and preserves every input row. NULL, nonnumeric/fractional input, unsafe magnitudes and zero denominators produce explicit statuses and NULL results. No rounding or casting away source fractions is permitted. The result remains REAL, not an exact decimal; requested decimal-place policies are separate.

The existing fixed-decimal compiler remains for rounded AVG/SUM; using it for an unrounded ratio would require inventing an output scale. Reuse its exact-integer bound, ToolPort/registry, normal and tool-only composition, shared Codex MCP allowlist, and run_sql execution gate. One compiler plus a thin tool adapter; net +80 production lines. No DB changes, grading changes, case-specific constants, environment settings or duplicate I/O/retry path. Initial user prompts stay unchanged. After tool-only trials demonstrated non-adoption, one existing numeric instruction is extended to use the verified compiler for exact integer ratios and retain separately requested components.

Validation: 4,000 seeded signed/boundary fractions against Fraction, integral REAL and scaling-order cases, NULL/zero/fractional/text/BLOB/overflow checks, argument rejection, and actual stdio compilation → execution. Root tests: 384 passed, 1 skipped; scoped Ruff and diff checks pass. No CODE MAP generator exists.

A failure-only pilot will rerun bird007, which is an official failure in the frozen106-case snapshot of the ongoing full500 validation. Original question/context/model stay unchanged, and no previous answer, grade, counterfactual or analyst hints enter inference. Merely making a correct tool available does not guarantee model use; results will be retained either way. No full-accuracy or regression-free claim and no merge.

Principle Result Evidence
Reuse O Existing bounds, registry, composition, MCP allowlist, execution gate; +80 production lines.
Cause only O Guarded integral ratio scaling removes intermediate division rounding; no semantic inference.
Logging O Existing MCP start/done/failed logs carry tool/call IDs; raw benchmark calls preserved.
Errors O Invalid compiler arguments raise via registry; data errors retained as statuses without dropped rows.
Environment N/A No new environment reads/variables.
Issue comments O No issue IDs or benchmark-specific literals in production.
Verification O Rational reference checks, stdio, root suite, Ruff, diff; no CODE MAP generator.
Authorization O Draft PR, no merge/release.
Request path O External/internal agent → compiler tool → generated CTEs → existing run_sql gate.
Async O Pure synchronous compiler with existing async ToolPort adapter; no blocking I/O.
Constants/deployment O Shared mathematical bound, explicit requested multiplier, no deployment/env changes.

Pilot outcome: bird007 0→1, but the model made zero integer_ratio_sql calls and directly wrote multiply-before-divide SQL. Initial prompt bytes match baseline. This is a recorded repair, not evidence that the compiler caused it or that performance is repeatably improved. The passed case will not be rerun during development. Raw evidence and validated comparison are archived under integer-ratio (16 verified hashes).

A second tool-only pilot, bird120, remained 0/1 and also made zero compiler calls. Its complete negative trace is preserved under integer-ratio-difference (16 verified hashes). After these tool-first checks, a short generic extension to the existing numeric instruction requests guarded ratio compilation and separately requested component calculations. No question ID, source value, reference SQL or grader convention appears in the instruction. A fresh failure-only pilot will test that changed condition; no success claim yet.

Guidance-stage verification repeats the384-test root suite after the code change. The prompt-file Ruff check ignores only the pre-existing BLE001 exception warning; other changed files use normal scoped Ruff.

Guidance-stage result: bird120 0→1, with one actual compiler call and its generated CTEs present verbatim in the final executed SQL. The model computes both year-specific percentages, inspects them, then subtracts. This follows the tool-only0/1 result, and initial task bytes remain identical. Tool adoption and component-stage preservation both changed; no isolated attribution or full accuracy/repeatability claim. All evidence is preserved under integer-ratio-guidance (16 verified hashes). Passed cases are not rerun in development; broad regression validation is still 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