Skip to content

feat: session carries ledger options over the WIT boundary (3.7.0) - #1805

Merged
robcohen merged 3 commits into
mainfrom
feat/wit-session-options
Jul 18, 2026
Merged

robcohen merged 3 commits into
mainfrom
feat/wit-session-options

Conversation

@robcohen

Copy link
Copy Markdown
Member

What

Closes the #1766 design debt for the query surface: entries-accepting functions ran with default ledger options because the contract had no way to carry them.

  • WIT 3.7.0: session.from-entries-with-options(entries, options) — the session becomes the canonical options carrier. query classifies accounts with the ledger's own name-* roots (the L5 POSSIGN/ACCOUNT_SORTKEY note in convert.rs), info() echoes what was provided, and future entry-consuming methods inherit the held options for free. from-entries keeps its shape and documents the default; the builder.query-entries/filter/clamp free functions are doc-soft-deprecated in favor of the session.
  • API_VERSION → 3.7 in lockstep (enforced by the parity test + wit-version-gate).
  • Tests: SessionState unit tests pin the POSSIGN sign flip under renamed roots and the info() echo; a wasmtime parity test drives the same observable through the real component boundary.

Deliberate scope reductions (recorded on #1766)

  • session.format is not added: the rendering pipeline has no display-precision/render-commas machinery anywhere (CLI included), so it would ignore the options it advertises — exactly the debt WIT contract: entries-accepting surfaces classify/render with default ledger options #1766 describes, one layer deeper. format-loaded's docs now state this honestly.
  • ops::clamp's Equity:Opening-Balances hardcoding turned out to be a global pre-existing gap (all callers, CLI included), not an entries-surface asymmetry — it needs an ops-level config, tracked separately.

How to test

cargo test -p rustledger-ffi-component -p rustledger-ffi-component-tests. rustfava adoption (passing its load-time options into the filtered-query path) rides the next release train together with the ingest backend.

Part of #1766.

🤖 Generated with Claude Code

https://claude.ai/code/session_013gJH7uBBF9Xw9et9QFRcsU

Closes the #1766 design debt for the query surface: every
entries-accepting function ran with default ledger options because the
contract had no way to carry them alongside an entry list.

- WIT 3.7.0 adds session.from-entries-with-options(entries, options):
  the session becomes the canonical options carrier, so query builds
  its account classifier from the ledger own name-* roots (the L5
  POSSIGN/ACCOUNT_SORTKEY note) and info() echoes what was provided;
  new entry-consuming methods inherit the held options for free.
- from-entries keeps its shape and documents the default; the
  builder.query-entries/filter/clamp free functions are
  doc-soft-deprecated in favor of the session.
- format-loaded documents honestly that display-precision and
  render-commas are not honored ANYWHERE yet (the rendering pipeline
  has no precision machinery, CLI included) - options-aware rendering
  stays tracked in #1766 rather than shipping a session.format that
  ignores the options it advertises.
- API_VERSION 3.7 in lockstep (parity test + wit-version-gate).
- Tests: SessionState unit tests pin the POSSIGN sign flip under
  renamed roots and the info() echo; a wasmtime parity test drives the
  same observable through the real component boundary.

Scope notes recorded on #1766: ops::clamp hardcoding of
Equity:Opening-Balances is a GLOBAL pre-existing gap (CLI included),
not an entries-surface asymmetry, and needs an ops-level config.

Part of #1766.
@codecov

codecov Bot commented Jul 18, 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 Jul 18, 2026 •

Copy link
Copy Markdown
Contributor

📊 Benchmark Results

Tool Time Memory
rustledger 36.6ms ± 0.9ms 23.8 MB
beancount 772.7ms ± 5.9ms 50.7 MB
Comparison 21.1x faster 2.1x less

vs main branch (2026-07-18)

Metric main this PR Change
Time 35.6ms 36.6ms +2.8% ✅
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

Extends the rustledger:ledger WIT/component embedding surface so a session reconstructed from host-held entries can retain and use the originating ledger options (notably renamed name_* account roots), fixing entries-based query behavior to match load-time classification semantics across the WIT boundary.

Changes:

  • Bumped WIT package to rustledger:[email protected] and runtime API_VERSION to 3.7, adding session.from-entries-with-options(entries, options).
  • Implemented the new session constructor in the component guest and plumbed options into SessionState so session.query classifies with ledger-specific roots.
  • Added unit + component-boundary parity tests covering POSSIGN behavior under renamed roots and info() option echoing.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.

File Description
crates/rustledger-ffi-component/wit/world.wit WIT 3.7.0 bump; adds from-entries-with-options and clarifies default-options behavior for entries-based surfaces.
crates/rustledger-ffi-component/src/lib.rs Bumps API_VERSION to 3.7 and exposes the new GuestSession::from_entries_with_options entrypoint.
crates/rustledger-ffi-component/src/convert.rs Adds options-carrying SessionState::from_entries_with_options, wires options into session.query, and adds unit tests for renamed-root classification + info() echo.
crates/rustledger-ffi-component-tests/tests/parity.rs Adds a wasmtime parity test that drives the renamed-root POSSIGN observable through the real component boundary.

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

@github-actions

Copy link
Copy Markdown
Contributor

✅ Compatibility Test Results

Metric Result
Check Compatibility 100%
BQL Compatibility 100%
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
  • Files: ~800 test files downloaded from 10+ beancount repositories

Full results available in workflow artifacts

- parity test fixture: the backslash-newline continuations stripped
  posting indentation, making the ledger unparsable - the sole
  end-to-end test failed whenever the component wasm existed (verified
  by building the wasm and running it; the local pass was the skip
  path). Rebuilt with concat! and real indentation; both branches now
  assert errors-empty, use first()/expect, and assert the POSITIVE
  value alongside the negative (drift-guard rule)
- from_entries_with_options sanitizes host options: empty name-* roots
  fall back to defaults (a zero-initialized guest record would silently
  break every classification); duplicates documented as host-owned
- WIT and rustdoc scope the "canonical carrier" claim to what the held
  options DO today (classification + info echo); booked-time options
  cannot re-apply and clamp/rendering do not consume options yet
- API_VERSION doc history gains the 3.7 entry; README steers held-entry
  queries at from-entries-with-options instead of the soft-deprecated
  query-entries
@robcohen

Copy link
Copy Markdown
Member Author

Deep review (21 agents, adversarial verification): 9 findings, all addressed in f8f8f95.

The merge-blocker: the parity test's fixture used backslash-newline string continuations, which strip posting indentation — the ledger was unparsable and the sole end-to-end test of from-entries-with-options failed whenever the component wasm actually existed. The reviewer proved it by building the wasm and executing; my local pass was the skip path. Fixed with concat! and real indentation, and I've now verified the test against the real component (passes in 3.5s of genuine instantiation). Lesson absorbed: availability-gated tests get verified with the gate OPEN before pushing.

The rest:

  • Options sanitization: empty name-* roots now fall back to defaults — a zero-initialized record from a guest language would have silently broken every classification with no diagnostic anywhere. Duplicated roots are documented as host-owned (exact-match, first wins). Pinned by a new unit test.
  • Doc precision: the WIT/rustdoc 'canonical carrier' claim is scoped to what the held options do TODAY (query classification + info echo) — booked-time options can't re-apply to booked entries, and clamp/rendering don't consume options yet (both tracked in WIT contract: entries-accepting surfaces classify/render with default ledger options #1766).
  • Test hardening: both test branches assert errors-empty, index via first()/expect, and assert the positive value alongside the negative (the drift-guard rule — a bare negative passes vacuously on an error cell).
  • Doc sweep: the API_VERSION history gains its 3.7 entry, and the README now steers held-entry queries at from-entries-with-options instead of the soft-deprecated query-entries.

Component + parity suites green (parity run against the built wasm this time), clippy/doc clean.

@robcohen
robcohen enabled auto-merge (squash) July 18, 2026 16:05
Copilot review: debug-substring contains("-100") also matches -1000
and passes vacuously on non-numeric cells; both the unit and parity
tests now pattern-match query-value::number and assert_eq the exact
value. API_VERSION history was already updated in f8f8f95.
@robcohen
robcohen merged commit 563b6d5 into main Jul 18, 2026
61 checks passed
@robcohen
robcohen deleted the feat/wit-session-options branch July 18, 2026 16:38
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