Repository navigation
Compile exact integer ratios before floating-point division - #362
Draft
seyoung4503 wants to merge 5 commits into
Draft
seyoung4503 wants to merge 5 commits into
seyoung4503 wants to merge 5 commits into
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
An observed percentage query divides before multiplying by100, creating an extra floating-point rounding step. With integer-valued REAL counts,
1.0/3.0*100differs from the nearest binary64 value of100/3. Addinteger_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_sqlexecution 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.
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.