Skip to content

fix(query): JOURNAL must read spanned_directives (BQL compat 77%->93%) - #1531

Merged
robcohen merged 2 commits into
mainfrom
fix/journal-query-regression
Jun 22, 2026
Merged

robcohen merged 2 commits into
mainfrom
fix/journal-query-regression

Conversation

@robcohen

Copy link
Copy Markdown
Member

What

Fixes a BQL JOURNAL regression: BQL compatibility dropped 93% → 77% (JOURNAL 90/90 → 12/90, ~78 queries) starting with #1506 (058f3cf5, "resolve filename/lineno columns in the CLI").

Root cause

The Executor has two directive sources — directives and spanned_directives. The source-location-aware constructor new_with_sources (used by the CLI and LSP) stores directives in spanned_directives and leaves directives empty. SELECT, PRINT, and BALANCES were each updated to fall back to spanned_directives — but execute_journal still iterated self.directives directly, so under that constructor (i.e. every CLI query) JOURNAL walked an empty slice and returned zero rows. #1506 switched the CLI to that constructor, exposing the latent bug.

Reproduced on main: JOURNAL 'Assets' → 0 rows while SELECT … WHERE account ~ 'Assets' → 2 rows.

Fix (+ recurrence guard)

This bug had already hit SELECT/PRINT/BALANCES via copy-pasted inline fallbacks — JOURNAL was the one generic walk that was missed. So rather than add a fourth copy:

  • Add one Executor::resolved_directives() accessor that returns the populated source.
  • Use it in execute_journal (the fix) and route SELECT and PRINT through it (collapsing their inline copies). Any future directive-walking command now can't silently regress the same way.

Tests

  • test_journal_via_source_mapped_executor_returns_rows: builds an Executor via new_with_sources and asserts JOURNAL 'Assets' returns the Assets posting (was 0 rows). Fails on the pre-fix code.
  • Manual repro: JOURNAL now returns the expected rows (incl. pad-synthesized rows) via the CLI.

Verification: rustledger-query suite green; clippy --all-features --all-targets -D warnings + fmt clean. CI compat should return to ~93% BQL.

🤖 Generated with Claude Code

@robcohen
robcohen requested a review from a team as a code owner June 22, 2026 22:11
Copilot AI review requested due to automatic review settings June 22, 2026 22:11
@codecov

codecov Bot commented Jun 22, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 98.18182% with 1 line in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
crates/rustledger-query/src/executor/mod.rs 98.11% 1 Missing ⚠️

📢 Thoughts on this report? Let us know!

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Fixes a BQL JOURNAL regression where Executor::new_with_sources (CLI/LSP path) left directives empty, causing JOURNAL to return zero rows by iterating the wrong directive source.

Changes:

  • Added Executor::resolved_directives() to centralize “pick the populated directive source” logic.
  • Updated JOURNAL, BALANCES, and PRINT directive-walking to use resolved_directives().
  • Added a regression test ensuring JOURNAL returns rows when executing via new_with_sources.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
crates/rustledger-query/src/executor/mod.rs Adds resolved_directives() and refactors BALANCES to use it; adds a JOURNAL regression unit test.
crates/rustledger-query/src/executor/execution.rs Switches JOURNAL and PRINT to iterate via resolved_directives() to work under new_with_sources.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@github-actions

github-actions Bot commented Jun 22, 2026 •

Copy link
Copy Markdown
Contributor

📊 Benchmark Results

Tool Time Memory
rustledger 35.7ms ± 0.3ms 23.4 MB
beancount 753.2ms ± 4.3ms 50.5 MB
Comparison 21.1x faster 2.2x less

vs main branch (2026-06-22)

Metric main this PR Change
Time 34.9ms 35.7ms +2.3% ✅
10K transactions · 5 runs, 2 warmup · hyperfine
What do these numbers mean?
  • Time: Wall-clock time to parse and validate the ledger (± std dev)
  • Memory: Peak resident set size (RSS)
  • vs main: Compared to latest nightly benchmark on main branch

@github-actions

github-actions Bot commented Jun 22, 2026 •

Copy link
Copy Markdown
Contributor

✅ Compatibility Test Results

Metric Result
Check Compatibility 100%
BQL Compatibility 100%
Full AST Match 100%
Total Files 792
What's tested
  • Check: Exit codes and error counts match bean-check
  • BQL: Query results match bean-query
  • Files: ~800 test files downloaded from 10+ beancount repositories

Full results available in workflow artifacts

robcohen added a commit that referenced this pull request Jun 22, 2026
Copilot on #1531: avoid the per-call Vec<&Directive> allocation. The two
directive sources are mutually exclusive, so chaining them yields the populated
one with zero allocation; all three callers only iterate.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
@robcohen
robcohen force-pushed the fix/journal-query-regression branch from ea10d4b to bd67a8c Compare June 22, 2026 22:23
robcohen and others added 2 commits June 22, 2026 23:05
execute_journal iterated self.directives directly, but new_with_sources (CLI/LSP)
leaves that empty and stores directives in spanned_directives — so JOURNAL
returned zero rows in the CLI, regressing BQL JOURNAL compat 90/90 -> 12/90 from
#1506. SELECT/PRINT/BALANCES already had inline fallbacks; JOURNAL was missed.
Add a resolved_directives() accessor and route JOURNAL + SELECT + PRINT through it
so it cannot recur. Adds a source-mapped JOURNAL regression test.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
Copilot on #1531: avoid the per-call Vec<&Directive> allocation. The two
directive sources are mutually exclusive, so chaining them yields the populated
one with zero allocation; all three callers only iterate.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
@robcohen
robcohen force-pushed the fix/journal-query-regression branch from bd67a8c to fe2afa7 Compare June 22, 2026 23:05
@robcohen
robcohen merged commit c3ebcd6 into main Jun 22, 2026
44 checks passed
@robcohen
robcohen deleted the fix/journal-query-regression branch June 22, 2026 23:10
robcohen added a commit that referenced this pull request Jun 23, 2026
The executor had ~10 copy-pasted spanned/unspanned dispatch blocks — the pattern
that caused the JOURNAL regression (a walk forgetting the spanned_directives
fallback returns empty under new_with_sources). #1531 fixed 3; collapse the rest
(5 system-table builders, #accounts, 2 transaction collectors, #entries) onto
resolved_directives, which now yields &\x27a Directive so callers can collect.
Add a source-mapped system-table test. Architecture-roadmap item [M/BR5].

Co-Authored-By: Claude Opus 4.8 <[email protected]>
robcohen added a commit that referenced this pull request Jun 23, 2026
#1535)

* refactor(query): route all directive walks through resolved_directives

The executor had ~10 copy-pasted spanned/unspanned dispatch blocks — the pattern
that caused the JOURNAL regression (a walk forgetting the spanned_directives
fallback returns empty under new_with_sources). #1531 fixed 3; collapse the rest
(5 system-table builders, #accounts, 2 transaction collectors, #entries) onto
resolved_directives, which now yields &\x27a Directive so callers can collect.
Add a source-mapped system-table test. Architecture-roadmap item [M/BR5].

Co-Authored-By: Claude Opus 4.8 <[email protected]>

* test(query): exercise a refactored system table (#entries), not BALANCES

Copilot on #1535: BALANCES is a statement on a different path; query #entries (a
system-table builder collapsed onto resolved_directives in this PR) so the test
actually guards the refactored builders under new_with_sources.

Co-Authored-By: Claude Opus 4.8 <[email protected]>

---------

Co-authored-by: Claude Opus 4.8 <[email protected]>
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.

2 participants