perf(api/config): use count_sessions() on status + snapshot (audit: list-sessions-decode-on-poll)#5326
Merged
Merged
Conversation
…() on status + snapshot (audit: list-sessions-decode-on-poll) Two routes — /api/status and /api/dashboard/snapshot — computed session_count via substrate.list_sessions().map(|s| s.len()). list_sessions() returns Vec<serde_json::Value> with each row's full rmp-encoded message history decoded, so calling .len() on the vec required decoding every blob just to count rows. The dashboard polls /api/dashboard/snapshot every 5s with refetchIntervalInBackground=false, so every foreground operator hits it continuously. At 100 sessions × 200 KB each, the daemon burnt ~20 MB/s of needless decode + rmp alloc on the hot path — for what is morphologically a SELECT COUNT(*). MemorySubstrate::count_sessions() (indexed SELECT COUNT(*)) already exists in librefang-memory/src/substrate.rs:391; both call sites now use it.
houko
added a commit
that referenced
this pull request
May 20, 2026
Delete the audit doc + INDEX update per the #5265 convention: narrative 119→118, Critical 7→6, Total 120→119, drop the bullet under Critical, and drop the list-sessions-decode-on-poll leg from Pass 1 priority #4 (paired with audit-export-401; the other leg is addressed by a separate PR so this PR only removes its own half).
Delete the audit doc + INDEX update per the #5265 convention: narrative 119→118, Critical 7→6, Total 120→119, drop the bullet under Critical, and drop the list-sessions-decode-on-poll leg from Pass 1 priority #4 (paired with audit-export-401; the other leg is addressed by a separate PR so this PR only removes its own half).
houko
force-pushed
the
fix/audit-list-sessions-count
branch
from
May 20, 2026 13:45
8beb7c7 to
825524b
Compare
Two #[tokio::test] cases against TestServer that seed N sessions via the memory substrate and assert the wire field reflects N — catches the .unwrap_or(0) silent-pin regression class that the dashboard's existing smoke test (only checks status='running') would miss. Required by CLAUDE.md route-test policy and the audit doc. Also: clarify the comment + CHANGELOG figure to '~20 MB per poll (≈ 4 MB/s)' — the original ~20 MB/s number was off by the 5 s poll period.
…ns-count # Conflicts: # openapi.json # xtask/baselines/openapi.sha256
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #5331
Summary
Audit:
docs/issues/list-sessions-decode-on-poll.md(Severity: Critical, Performance).Two routes —
/api/statusand/api/dashboard/snapshot— computedsession_countvia:list_sessions()returnsVec<serde_json::Value>with each row'sfull rmp-encoded message history decoded. Calling
.len()onthe vec therefore decoded every session blob just to count rows.
The dashboard polls
/api/dashboard/snapshotevery 5 s withrefetchIntervalInBackground: false, so every foreground operatorhits it continuously. At 100 sessions × 200 KB each, the daemon
burnt ~20 MB/s of needless decode + rmp allocator pressure for
what is morphologically a
SELECT COUNT(*).Fix
MemorySubstrate::count_sessions()(indexedSELECT COUNT(*))already exists in
crates/librefang-memory/src/substrate.rs:391. Both call sites incrates/librefang-api/src/routes/config.rs(lines 235 + 3009) nowuse it:
Verification
Out-of-scope follow-ups
The audit doc suggests a
criterionbench demonstrating thedelta. I've deferred that — the change is mechanically equivalent
to swapping a
SELECT *for aSELECT COUNT(*), and the existingsession.rsSQL is already an indexed count oversessions. Abench infrastructure scaffold belongs in a separate PR.
Test plan
workspace with ≥50 sessions
curl /api/statusand/api/dashboard/snapshotstill returncorrect
session_count(compare againstSELECT COUNT(*) FROM sessionsdirectly)