Skip to content

fix(parser): a query refuses tags and links instead of dropping them - #2198

Merged
robcohen merged 2 commits into
mainfrom
fix/query-rejects-tags
Aug 31, 2026
Merged

robcohen merged 2 commits into
mainfrom
fix/query-rejects-tags

Conversation

@robcohen

Copy link
Copy Markdown
Member

Closes #2194.

The gap

query was in neither camp. It did not keep tags and links the way transaction, note and document do, and it did not refuse them the way the other seven directives do — so it took them and discarded them, Query having no field to hold one. Meanwhile the message the refusal arm emits states the very rule its omission broke:

tags and links belong to transactions, and to note and document directives

The direction, now settled

I filed this rather than fixing it because deciding needed bean-check and the compat container would not build here. It does now — nix shell nixpkgs#python3 nixpkgs#uv plus uv pip install beancount — and 3.2.3 answers it:

2024-01-01 query "n" "SELECT date" #qtag
  -> syntax error, unexpected TAG, expecting end of file or EOL

Its Query namedtuple is (meta, date, name, query_string) — nowhere to keep one either. So refusing matches beancount's grammar and its model.

The reason I backed this out before is answered too

A corpus file uses the form, parser-lima/examples_data_full.beancount:111, and I could not tell whether that meant beancount accepted it. It does not. beancount reports TAG syntax errors on that file at lines 15, 19, 28, 31, 65, 68, 96 and 111.

That file is a parser-lima corpus carrying forms lima accepts. Our accepting line 111 was the divergence — not our rejecting it. The single baseline hash that moves is that file.

Verification

  • Both sigils rejected; the tag-free form still parses.
  • The census in parser_integration_test moves query out of its known-gap arm into the refusing set, where every entry is also checked against its tag-free form — a refusal that rejected valid input would satisfy an assertion that only looked for an error.
  • Control: removing the refusal reports query accepted #atag it has no field to hold.
  • Cache versions move because parser output does: loader 33 → 34, wasm 18 → 19, pin 34. A stale blob holds a Query directive for input this build refuses.
  • Workspace green, clippy 1.97 clean, fmt/typos clean, corpus_parity clean against a freshly built wasip2 component.

Remaining in this family

#2190 (MetaValue::Tag/Link unreachable; custom emits a value it errored on) and #2193 (tolerance ignores a second number; a mismatched tolerance currency is erased by format). Both now have a local beancount to settle direction against.

🤖 Generated with Claude Code

https://claude.ai/code/session_012nNGPA44Dt32NyxWem26xr

`query` was in neither camp. It did not keep tags and links the way a
transaction, note or document does, and it did not refuse them the way
the other seven directives do -- so it took them and discarded them,
`Query` having no field to hold one, while the message the refusal arm
emits states the very rule its omission broke.

I filed this rather than fixing it because the direction needed
beancount and the container would not build here. It does now, via
`nix shell nixpkgs#python3 nixpkgs#uv` and `uv pip install beancount`,
and 3.2.3 settles it:

    2024-01-01 query "n" "SELECT date" #qtag
    -> syntax error, unexpected TAG, expecting end of file or EOL

Its `Query` namedtuple is `(meta, date, name, query_string)`, with
nowhere to keep one either. So refusing matches both beancount's grammar
and its model, and joins the seven directives already refusing.

The reason I backed this out the first time is now answered too. A
corpus file uses the form --
`parser-lima/examples_data_full.beancount:111` -- and I could not tell
whether that meant beancount accepted it. It does not: beancount reports
TAG syntax errors on that file at lines 15, 19, 28, 31, 65, 68, 96 and
111. The file is a parser-lima corpus carrying forms lima accepts, and
our accepting line 111 was the divergence, not our rejecting it.

Cache versions move because parser output does: loader 33 -> 34, wasm
18 -> 19, pin 34. A stale blob holds a `Query` directive for input this
build refuses.

The census in `parser_integration_test` moves `query` out of its
known-gap arm and into the refusing set, where each entry is also
checked against its tag-free form -- a refusal that rejected valid input
would satisfy an assertion that only looked for an error. Verified to
fail: removing the refusal reports `query accepted #atag it has no field
to hold`.

Closes #2194
@robcohen
robcohen requested a review from a team as a code owner August 31, 2026 03:49
Copilot AI lite review requested due to automatic review settings August 31, 2026 03:49

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.

🟡 Changes recommended

Several newly updated cache/fixture comments state that tagged query directives are dropped/refused (no directive produced), but the implementation records an error while still producing the directive, so the documentation should be corrected to match actual behavior.

Once you've addressed the issues Copilot identified, you can request another Copilot review.

Pull request overview

Aligns query directive parsing with beancount by diagnosing (rejecting) header tags/links instead of silently accepting and discarding them, and updates caches/tests/baselines to reflect the changed parser output.

Changes:

  • Add tag/link rejection for query during CST→AST conversion.
  • Update integration census test to include query in the “refuses tags/links” set.
  • Bump loader/WASM cache versions and update the parser corpus baseline manifest hash.
File summaries
File Description
tests/baselines/parser-corpus.manifest Updates the stored baseline hash for the affected parser-lima corpus file.
crates/rustledger-wasm/src/cache.rs Bumps WASM cache version and pins the loader cache version.
crates/rustledger-parser/tests/parser_integration_test.rs Moves query into the “refuses tags/links” census and keeps the tag-free control.
crates/rustledger-parser/src/cst/convert.rs Calls reject_tags_and_links for query during conversion.
crates/rustledger-loader/src/cache.rs Bumps loader cache version and updates fixture-version pins/comments.
Review details
  • Files reviewed: 5/5 changed files
  • Comments generated: 4
  • Review effort level: Lite

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread crates/rustledger-wasm/src/cache.rs Resolved
Comment thread crates/rustledger-loader/src/cache.rs Resolved
Comment thread crates/rustledger-loader/src/cache.rs Resolved
Comment thread crates/rustledger-loader/src/cache.rs Resolved
@codecov

codecov Bot commented Aug 31, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@github-actions

github-actions Bot commented Aug 31, 2026 •

Copy link
Copy Markdown
Contributor

📊 Benchmark Results

🔴 Slower than base on: simple

Shape rustledger beancount Speedup RSS (rledger / beancount)
simple 50.2ms ± 5.8ms 798.5ms ± 3.5ms 15.9x 55.1 MB / 50.1 MB
investment 69.4ms ± 4.4ms 3002.2ms ± 12.1ms 43.2x 59.0 MB / 58.0 MB
fifo 66.6ms ± 3.8ms 15571.7ms ± 295.8ms 233.9x 61.1 MB / 57.9 MB

vs base, measured in this run

Shape base this PR Change RSS base → PR
simple 46.7ms ± 3.0ms 50.2ms ± 5.8ms +7.5% 🟡 slower 55.0 MB → 55.1 MB (+0.1%)
investment 69.6ms ± 4.2ms 69.4ms ± 4.4ms -0.2% ✅ within noise 59.1 MB → 59.0 MB (-0.1%)
fifo 67.6ms ± 4.2ms 66.6ms ± 3.8ms -1.5% ✅ within noise 61.1 MB → 61.1 MB (-0.1%)

A difference counts only when it clears the combined spread of the two measurements, per shape (2σ: simple 2.9ms, investment 2.7ms, fifo 2.5ms), and is at least 5%.
10,000 transactions per shape · 20 runs, 3 warmup · hyperfine

What do these numbers mean?
  • simple — Two-posting transfers, one currency. The historical workload — keep as the floor, not as the benchmark.
  • investment — Cost specs, per-unit prices and lot reductions. Exercises booking and inventory, which simple leaves at 0.3%.
  • fifo — Bare {} reductions against a FIFO account — how FIFO sells are normally written. The other four shapes reach the ordered-selection path twice in 2k transactions between them, so it was effectively unprofiled until it turned out to be quadratic (plan_ordered scans every lot per reduction: FIFO ledgers are quadratic (8.8s at 20k transactions) #2083).
  • vs base: the PR and the base-branch commit it is built on, built and measured in the same job
  • RSS: peak resident set size, a single sample — reported without a verdict because there is no spread to test it against
  • A shape with no beancount column is one bean-check reports errors on; it is timed for rledger only

@github-actions

Copy link
Copy Markdown
Contributor

✅ Compatibility Test Results

Metric Result
Check Compatibility 100%
BQL Compatibility 100% (raw 93%, 170 masked)
Full AST Match 100%
Total Files 811
What's tested
  • Check: Exit codes and error counts match bean-check
  • BQL: Query results match bean-query
    The headline is the EFFECTIVE rate, after pairs where beanquery
    itself is wrong are masked. raw is the same run with nothing
    masked. A widening gap means the registry grew, not that rledger
    changed.
  • Files: ~800 test files downloaded from 10+ beancount repositories

Full results available in workflow artifacts

Review caught three comments claiming a tagged `query` is "refused
outright" and "produces no directive". It is not, and it does.
`reject_tags_and_links` records an error and conversion still emits the
`Query`, exactly as it does for the other seven directives that refuse
tags. What moves is the error list, not the archived data.

That is still enough to need the bump, and "enough" deserved measuring
rather than asserting. A file with a tagged query used to parse clean
and was therefore cacheable, so a v33 blob exists for it, and replaying
that blob skips the parse that would now complain. Run against a
pre-#2194 binary's cache:

    without the bump   0 parse errors   <- diagnostic silently hidden
    with the bump      2 parse errors

So the bump is load-bearing rather than precautionary, and the comments
now say which of the two things it protects.
@robcohen
robcohen force-pushed the fix/query-rejects-tags branch from 6b35f2b to d0e65df Compare August 31, 2026 11:40
@robcohen

Copy link
Copy Markdown
Member Author

Good catch, and it was wrong in three places, not one.

You're right that reject_tags_and_links records an error and conversion still emits the Query — verified, and the same holds for event and balance, so all eight refusing directives behave that way. It's a diagnostic, not a rejection. The comments claiming "refused outright" and "produces no directive" are corrected in d0e65df.

Your reading of the actual hazard is right too, and I measured it rather than just rewording. A file with a tagged query used to parse clean and was therefore cacheable, so a v33 blob exists for it; replaying that blob skips the parse that would now complain. Against a cache written by a pre-#2194 binary:

without the bump   0 parse errors   <- diagnostic silently hidden
with the bump      2 parse errors

So the bump is load-bearing rather than precautionary, and that is now what the comments say.

One thing your comment surfaced indirectly: cargo test caught my first attempt at the rewrite, because a blank line followed by an indented paragraph inside a doc comment reads as a Rust code block and rustdoc tried to compile query "n" "SELECT date" #qtag as source.

@robcohen
robcohen merged commit 6545ade into main Aug 31, 2026
68 of 69 checks passed
@robcohen
robcohen deleted the fix/query-rejects-tags branch August 31, 2026 13:08
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.

query accepts tags and links and silently drops them

2 participants