Skip to content

perf(inbox): read message bodies only for pages that include them - #126

Merged
bompus merged 1 commit into
mainfrom
perf/inbox-skip-bodies
Oct 10, 2026
Merged

bompus merged 1 commit into
mainfrom
perf/inbox-skip-bodies

Conversation

@bompus

@bompus bompus commented Oct 10, 2026 •

Copy link
Copy Markdown
Owner

fetch_inbox and fetch_session_inbox selected body_md for every row of the page and then dropped it unless include_bodies was set, which is off by default. With it off they now select NULL AS body_md, so SQLite no longer reads the body from the message row.

fetch_inbox for a page of 20 messages, in process, p50 of 10,000 calls on this machine:

body size before after
177 bytes 51 µs 47 µs
2 KB 57 µs 48 µs
17 KB 82 µs 52 µs

Output is unchanged: the response builders only read body_md when include_bodies is set, and existing tests cover both cases. bun run check and the full suite (1214 pass, 0 fail) pass.

I did not change the other cost found in the same profile, the UPDATE agents SET last_active_ts that every successful agent call performs. That write is documented behavior (it orders list_agents, shows in who, and un-retires an idle agent), so removing it from fetch_inbox would make a polling agent look idle. It is about 13% of a fetch_inbox request and left as is.

Summary by CodeRabbit

  • Performance
    • Inbox and session inbox requests load more efficiently when message bodies are not requested, which is the default. This can reduce the time needed to display inbox pages, especially when messages contain larger bodies.
    • Message bodies continue to be included when requested.

fetch_inbox and the session inbox selected body_md for every row and then
dropped it unless include_bodies was set. With include_bodies off they now
select NULL instead. fetch_inbox p50 for 20 messages: 57 to 48 us at 2 KB
bodies, 82 to 52 us at 17 KB.
@coderabbitai

coderabbitai Bot commented Oct 10, 2026 •

Copy link
Copy Markdown

Review in Change Stack →Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Repository YAML (base), Organization UI (inherited)
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: c7701176-7f65-40ed-89f2-01d869af82a5

📥 Commits

Reviewing files that changed from the base of the PR and between f280ef2 and a6d7090.


📒 Files selected for processing (2)
  • CHANGELOG.md
  • src/store.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 7 remain after this review.



📝 Walkthrough

Walkthrough

Inbox and session inbox queries now omit message bodies from storage reads unless include_bodies is truthy. The changelog records this behavior and page timings.

Changes

Inbox Body Selection

Layer / File(s) Summary
Conditional query selection
src/store.ts, CHANGELOG.md
A shared helper selects m.body_md when include_bodies is truthy and NULL AS body_md otherwise. Both inbox query paths use the helper. The changelog records the behavior and page timings.

Priority: ⬇️ Low

Merge Risk: ⚪ Minimal · up to a6d70

Inbox requests continue to receive bodies when requested, while default requests avoid loading them. No material merge risk is evident from the reviewed change.

Pre-merge checks | Passed 6
✅ Passed checks (6 passed)
Check name Status Explanation
Title check Passed The title clearly and concisely identifies the main performance change: inbox queries read message bodies only when requested.
Description check Passed The description explains the change, rationale, measured performance impact, unchanged behavior, test results, and the intentionally unchanged agent update. It does not reproduce the template checklis…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Suppressions Explained Passed The pull request changes only CHANGELOG.md and src/store.ts. The changed lines add a performance note, a documented bodyColumn helper, and SQL column selection. No changed line adds or broadens …
Interface Changes Documented Passed The pull request changes only CHANGELOG.md and src/store.ts. The code changes SQL body selection and preserve the existing include_bodies argument. No MCP tool or argument, swarmail command or…


✨ Finishing Touches
📝 Generate docstrings
  • Commit to this branch
  • Create a new PR


🧪 Generate unit tests (beta)
  • Commit to this branch
  • Create a new PR


  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Comment @coderabbitai help to get the list of available commands.

@bompus
bompus merged commit e2e5761 into main Oct 10, 2026
3 checks passed
@bompus
bompus deleted the perf/inbox-skip-bodies branch October 10, 2026 01:55
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