Skip to content

fix(entry): support EC account sets in entry listing query#706

Closed
HonestMajority wants to merge 7 commits into
mainfrom
fix-ec-account-set-list
Closed

fix(entry): support EC account sets in entry listing query#706
HonestMajority wants to merge 7 commits into
mainfrom
fix-ec-account-set-list

Conversation

@HonestMajority
Copy link
Copy Markdown
Contributor

@HonestMajority HonestMajority commented Apr 13, 2026

Summary

The list_for_account_set_id_by_created_at query in the entry repo joined through cala_balance_history, which is never populated for eventually-consistent (EC) account sets during normal posting. This meant cala.entries().list_for_account_set_id(...) always returned empty results for EC sets.

The fix introduces a dual-path query strategy based on the account set's eventually_consistent flag:

  • EC sets query via cala_account_set_member_accounts with a LEFT JOIN cala_account_sets ... IS NULL filter to resolve leaf accounts — the same pattern used in balance/repo.rs for fetch_batch_member_history and fetch_member_account_mappings
  • Non-EC sets keep the original cala_balance_history join, which remains correct and well-tested

An integration test (ec_account_set_entry_listing) covers EC entry listing with pagination and DESC ordering.

🤖 Generated with Claude Code


Note

Medium Risk
Changes the DB query path used to list entries for account sets based on the eventually_consistent flag, which could affect correctness/performance of pagination and ordering for entry listings.

Overview
Fixes entries.list_for_account_set_id returning empty results for eventually-consistent (EC) account sets by switching to a new listing query that resolves leaf member accounts via cala_account_set_member_accounts (and filters out nested sets), while keeping the existing cala_balance_history join for non-EC sets.

Adds an integration test ec_account_set_entry_listing that validates EC entry listing returns results and that pagination cursors and descending ordering behave as expected. Regenerates sqlx query metadata files for the updated queries.

Reviewed by Cursor Bugbot for commit b5cb31e. Bugbot is set up for automated code reviews on this repo. Configure here.

HonestMajority and others added 4 commits April 13, 2026 14:10
…listing

Replace cala_balance_history join with cala_account_set_member_accounts
in list_for_account_set_id_by_created_at so it returns entries for
eventually_consistent account sets. The old query returned empty results
because cala_balance_history is only populated during synchronous posting
(non-EC path).

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Look up the eventually_consistent flag internally in the repo so the
public API is unchanged. Only EC sets use the new member_accounts-based
query; non-EC sets continue to use the original balance_history query.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
The UNIQUE(account_set_id, member_account_id) constraint on
cala_account_set_member_accounts guarantees each account appears at
most once per set, so the join cannot produce duplicate entry rows.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Apr 13, 2026

📊 Performance Report

Commit: b5cb31e
Updated: 2026-04-14 13:07:04 UTC

Cala Performance Benchmark Results (non-representative)

Criterion Benchmark Results (single-threaded)

Benchmark Time per Run Throughput % vs Baseline
post_simple_transaction 6.545ms 152 tx/s 0 (baseline)
post_and_recalculate_ec_account_set 17.817ms 56 tx/s -172.0%
post_and_batch_recalculate_ec_account_set 12.804ms 78 tx/s -95.0%
post_multi_layer_transaction 9.032ms 110 tx/s -38.0%
post_simple_transaction_with_effective_balances 9.614ms 104 tx/s -46.0%
post_simple_transaction_with_skipped_velocity 6.529ms 153 tx/s -0.0%
post_simple_transaction_with_velocity 9.047ms 110 tx/s -38.0%
post_simple_transaction_with_hit_velocity 4.118ms 242 tx/s +37.0%
post_simple_transaction_with_one_account_set 6.780ms 147 tx/s -3.0%
post_simple_transaction_with_five_account_sets 8.105ms 123 tx/s -23.0%
post_simple_transaction_with_ec_account_set 6.400ms 156 tx/s +2.0%

Load Testing Results (parallel-execution)

Scenario tx/s
1 parallel 93.50
2 parallel 138.90
5 parallel 152.07
10 parallel 160.71
20 parallel 155.83
2 contention 123.32
5 contention 126.03
2 acct_sets 118.93
5 acct_sets 122.10

Note: Performance results may vary based on system resources and database state.

Last updated by commit b5cb31e

HonestMajority and others added 3 commits April 13, 2026 15:24
The membership-based query returned entries from all journals, unlike
the original balance_history query which was implicitly journal-scoped.
Look up the journal_id from cala_account_sets alongside the EC flag
and filter entries to the correct journal.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
The journal_id is only needed for the EC query path. Keep the shared
lookup lightweight — only fetch the eventually_consistent flag for all
callers, and defer the journal_id lookup to the EC branch.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
The eventually_consistent prelude used fetch_one, which errors with
RowNotFound if the account set does not exist. This changed the
error surface for the non-EC path, which previously returned an
empty list for unknown ids via an empty JOIN.

Switch to fetch_optional and short-circuit with an empty result
when the id is absent, restoring prior semantics for both paths.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@HonestMajority HonestMajority marked this pull request as ready for review April 14, 2026 12:57
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