Skip to content

fix(ffi): preserve warning severity + robust include handling in load_source - #1463

Merged
robcohen merged 2 commits into
mainfrom
fix/ffi-load-source-followup
Jun 21, 2026
Merged

robcohen merged 2 commits into
mainfrom
fix/ffi-load-source-followup

Conversation

@robcohen

Copy link
Copy Markdown
Member

What

Follow-up to #1462 (the load_source pipeline collapse), addressing Copilot's review — its comments landed just after the auto-merge, so they're handled here.

  1. Warning severity dropped (most impactful). ledger_error_to_ffi hardcoded severity: "error". With load_source now routing through the full pipeline, plugin warnings — e.g. the unrealized plugin's gain/loss notices — flow through ledger.errors and were surfacing to FFI consumers as errors. Now maps ErrorSeverity::Warning → wire "warning".

  2. Glob include paths errored. The empty-VFS-stub approach keyed on the literal include path, which can't match a glob ([ab].bean ≠ literal file [ab].bean) → GlobNoMatch parse error, breaking the "list, don't resolve, don't error" contract. Replaced stubbing with a targeted filter that drops parse-phase resolution failures (file-not-found / glob-no-match) for declared include paths — uniform for literal and glob, and narrow enough never to mask a real syntax error.

  3. Fatal-fallback error mis-tagged. The fatal load/process fallback built a default (parse-phase) Error; a fatal process/plugin failure would then suppress ledger.validate/query. Now tagged validate.

Tests

tests/load_regular_plugins.rs (now 5 tests):

  • load_source_preserves_warning_severity — unrealized notice surfaces as warning, not error.
  • load_source_glob_include_does_not_error — unresolved glob include produces no error.

Verify

All 8 rustledger-ffi-wasi suites + rustledger-ffi-component pass; cargo clippy --all-features --all-targets and cargo fmt --check clean.

🤖 Generated with Claude Code

…_source

Addresses Copilot review on #1462 (the load_source pipeline collapse):

1. Warning severity dropped. `ledger_error_to_ffi` hardcoded `severity:
   "error"`. Now that load_source routes through the full pipeline, plugin
   *warnings* (e.g. the `unrealized` plugin's gain/loss notices) flow through
   `ledger.errors` and were surfacing to FFI consumers as errors. Map
   `ErrorSeverity::Warning` → wire `"warning"`.

2. Glob include paths errored. The previous empty-VFS-stub approach used the
   literal include path as the key, which cannot match a glob pattern
   (`[ab].bean` won't match the literal file `[ab].bean`), producing a
   `GlobNoMatch` parse-phase error that broke the "list includes, don't
   resolve, don't error" contract. Replace stubbing with a targeted filter
   that drops parse-phase resolution failures (file-not-found / glob no-match)
   for declared include paths — uniform across literal and glob includes, and
   narrow enough never to mask a real syntax error.

3. Fatal-fallback error misclassified. The fatal load/process fallback built a
   default (parse-phase) `Error`; a fatal process/plugin failure would then be
   classified as a parse error and suppress `ledger.validate`/`query`. Tag it
   `validate`.

Tests in `tests/load_regular_plugins.rs` cover warning-severity preservation
and glob-include suppression.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
Copilot AI review requested due to automatic review settings June 20, 2026 23:54
@robcohen
robcohen requested a review from a team as a code owner June 20, 2026 23:54
@codecov

codecov Bot commented Jun 20, 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 Jun 20, 2026 •

Copy link
Copy Markdown
Contributor

📊 Benchmark Results

Tool Time Memory
rustledger 32.5ms ± 0.4ms 23.8 MB
beancount 880.4ms ± 3.7ms 50.7 MB
Comparison 27.1x faster 2.1x less

vs main branch (2026-06-20)

Metric main this PR Change
Time 41.3ms 32.5ms -21.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

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

This PR fixes regressions in the rustledger-ffi-wasi string-load surface (load_source) after it was collapsed onto the canonical loader pipeline, ensuring FFI consumers receive accurate severity/phase metadata and that include directives behave consistently without a real filesystem.

Changes:

  • Preserve LedgerError warning severity in the FFI wire errors (Warning → "warning"), instead of hardcoding "error".
  • Make load_source robust to unresolved include directives (including globs) by suppressing include-resolution failures for declared includes while still listing them in the DTO.
  • Tag fatal fallback failures as "validate" phase to avoid incorrectly suppressing validation/query behavior downstream, and add regression tests covering warnings + glob-includes.

Reviewed changes

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

File Description
crates/rustledger-ffi-wasi/src/helpers.rs Preserves warning severity in ledger_error_to_ffi, retags fatal fallback as validate-phase, and filters include-resolution errors for string-loaded ledgers.
crates/rustledger-ffi-wasi/tests/load_regular_plugins.rs Adds regression tests ensuring warnings remain warnings and glob includes don’t surface resolution errors.

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

Addresses Copilot on #1463: the loader renders paths via Path::display(),
which uses backslashes on Windows, while declared include paths use forward
slashes. Normalize both sides to / before matching so the include-resolution
error filter works regardless of platform separator.

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

Copy link
Copy Markdown
Member Author

Good catch — fixed. The filter now normalizes path separators to / on both the error message and the declared include paths before matching, so it works regardless of platform (the loader renders paths via Path::display(), which uses \ on Windows).

@robcohen
robcohen merged commit 6043ea0 into main Jun 21, 2026
40 checks passed
@robcohen
robcohen deleted the fix/ffi-load-source-followup branch June 21, 2026 00:04
@github-actions

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

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