Skip to content

Add deterministic fixed-decimal SQL aggregation compiler - #347

Draft
seyoung4503 wants to merge 4 commits into
feat/calendar-interval-sqlfrom
feat/fixed-decimal-sql
Draft

seyoung4503 wants to merge 4 commits into
feat/calendar-interval-sqlfrom
feat/fixed-decimal-sql

Conversation

@seyoung4503

@seyoung4503 seyoung4503 commented Nov 26, 2026 •

Copy link
Copy Markdown
Collaborator

A prior Spider execution produced 6.47 instead of 6.48 for a requested two-decimal average because ROUND(AVG(...)) rounded a binary floating-point midpoint. Add a reusable SQLite fixed-decimal AVG/SUM compiler. It accepts explicitly scaled integers, uses integer quotient/remainder for half-away-from-zero rounding after aggregation, and emits plain SQL CTEs. Noninteger inputs and conservative overflow bounds invalidate the whole group; NULL inputs follow aggregate exclusion.

The tool is registered in the existing internal and MCP runtimes and read-only benchmark whitelist. It performs no DB access, chooses no source precision/currency conversion, and still requires guarded run_sql execution. After the tool-only attempt failed because the model did not call the tool, the existing numeric-result guidance bullet was updated to route known fixed-scale aggregates to the compiler after source precision checks. Gold references and graders are unchanged. Scales 0–6 and a conservative exact-integer bound are explicit limitations; rounded_units remains integer and rounded_value is its REAL representation.

Validation: 339 root tests passed, 1 skipped. Tests cover grouped seeded comparisons with Decimal for AVG/SUM at five scale combinations, signed midpoint ties, NULLs, invalid types, unsafe magnitude, invalid compiler parameters, and actual MCP stdio execution. Ruff and diff checks pass (the system-prompt module has a pre-existing BLE001 violation excluded from this scoped lint run). No CODE MAP generator exists. The tool-only Astra/high retry of local152 scored 0/1 and did not call fixed_decimal_sql; all failure artifacts and an offline Decimal diagnosis are preserved. The second fresh original-input retry with compiler-use guidance scored 1/1 (local152 0 → 1). It independently checked one-decimal source precision, called fixed_decimal_sql, executed the emitted CTEs to verify all 3,603 director groups had status=ok and zero invalid inputs, then wrote a shorter integer-rounding final SQL for the verified positive ratings. The final SQL was not a verbatim compiler copy. Its two midpoint values changed 6.47→6.48 and 6.22→6.23. Exact prompts, events, SQL, CSV, scores, paired comparisons and SHA-256 indexes for both attempts are archived under bench/accuracy/mcp-review-results/fixed-decimal*. A single successful attempt does not establish repeated reliability or broader regression freedom. Neither is a full benchmark score. Calendar tooling from parent #346 is retained, so changes from the older baseline are not a single-factor ablation. Stacked PR; no merge requested.

# Implementation principle Verdict Evidence
1 Reuse O Existing ToolSpec/ToolResult, runtime registry, MCP logging, guarded run_sql; one new compiler function for both AVG/SUM; product/runtime +132 lines before the single guidance-line replacement
2 Cause/scope O Rounding error, tool wiring, tests, then one evidence-motivated guidance bullet; both attempts preserved
3 Logging O Existing MCP call IDs and start/done/failed logs; no new external I/O
4 Errors O Invalid parameters raise ValueError; invalid/overflow data yield explicit status and NULL, never partial aggregates
5 Environment N/A No environment reads/settings added
6 Issue comments O No issue-number comments
7 Checks O Root pytest, Ruff and diff checks; no CODE MAP script exists
8 Authority O Branch and PR only, no merge
9 Consumers O Internal and MCP registration, real stdio test and benchmark whitelist
10 Sync/async O One pure compiler, async wrapper; no blocking I/O
11 Constants/deployment O Named precision and exact-integer limits; no operational config or deployment changes

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