⚡ Bolt: Remove N+1 query when fetching thread context for Agent - #641
⚡ Bolt: Remove N+1 query when fetching thread context for Agent#641schmug wants to merge 1 commit into
Conversation
Replaced the N+1 pattern in `workers/agent/index.ts` where we fetched the email list for a thread and then issued N calls to `stub.getEmail`. Instead we now use the `getFullThread` helper from `workers/lib/email-helpers.ts` which does a 2-query fetch (emails + attachments) and maps out the `body_text` inline, severely reducing latency for long threads. Co-authored-by: schmug <38227427+schmug@users.noreply.github.com>
|
👋 Jules, reporting for duty! I'm here to lend a hand with this pull request. When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down. I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job! For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with New to Jules? Learn more at jules.google/docs. For security, I will only act on instructions from the user who triggered this task. |
Deploying with
|
| Status | Name | Latest Commit | Preview URL | Updated (UTC) |
|---|---|---|---|---|
| ✅ Deployment successful! View logs |
ais-hub | 96977bc | Commit Preview URL Branch Preview URL |
Jul 22 2026, 05:29 AM |
Deploying with
|
| Status | Name | Latest Commit | Updated (UTC) |
|---|---|---|---|
| ✅ Deployment successful! View logs |
agentic-inbox | 96977bc | Jul 22 2026, 05:30 AM |
💡 What: Refactored
workers/agent/index.tsto usegetFullThread()when rendering context for LLM agents, instead of astub.getEmails()followed by aPromise.all(stub.getEmail(...)).🎯 Why: Long threads caused the Durable Object to process an N+1 query, locking the DO thread momentarily while dispatching many separate SQL statements for individual emails.
📊 Impact: Reduces SQL roundtrips in the DO from N+1 to 2 queries per thread context setup.
🔬 Measurement: Verify agent tests still pass via
npm run testand check latency on long thread interactions.PR created automatically by Jules for task 3171690880336653470 started by @schmug