⚡ Bolt: optimize context building with safe caching#55
Conversation
- Removed redundant episodic_memory fetch in buildContext - Added 1-min TTL cache for working_memory - Added 5-min TTL cache for knowledge reranking with error-safety - Cleaned up dead context selection functions - Preserved fresh task state for agent loop consistency Co-authored-by: SuvenSeo <263689617+SuvenSeo@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. |
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
There was a problem hiding this comment.
Pull request overview
This PR optimizes agent context construction by removing redundant history fetching and adding short-TTL, error-safe caching around slower-changing context components (working memory + knowledge reranking) to speed up multi-iteration tool loops.
Changes:
- Removed the
episodic_memoryfetch and deleted dead context-selection helpers/constants inbuildContext. - Added TTL-based caching for
working_memory(1 min) and knowledge semantic reranking results (5 min) with “don’t cache on unexpected DB errors” behavior. - Added internal “Jules” learnings docs capturing security/operational lessons around timing-safe comparisons and caching.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| frontend/src/lib/services/context.js | Removes redundant history DB work and introduces TTL caching for working memory + knowledge reranking. |
| .jules/sentinel.md | Adds security/ops lessons documentation (timing attack + cache failure modes). |
| .jules/bolt.md | Adds agent-loop guidance documentation (avoid stale context hoisting; cache expensive reranking). |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| // Use a composite key for knowledge cache based on normalized message and keywords | ||
| const normalizedMsg = userMessage.toLowerCase().trim().replace(/\s+/g, ' '); | ||
| const cacheKey = `knowledge:${normalizedMsg}:${[...keywords].sort().join(',')}`; | ||
| const cached = getCache(cacheKey); | ||
| if (cached) return cached; |
| if (!cachedCore && coreMemory) setCache('core_memory', coreMemory, TTL_5MIN); | ||
| if (!cachedPatterns && patterns) setCache('patterns', patterns, TTL_5MIN); | ||
| if (!cachedIdeas && ideas) setCache('ideas', ideas, TTL_5MIN); | ||
| if (!cachedWorking && workingMemory) setCache('working_memory', workingMemory, TTL_1MIN); |
💡 What:
episodic_memorydatabase fetch inbuildContext(history is already passed via themessagesarray).working_memory(1 min) andknowledge_basesemantic reranking (5 min).tasksremain fresh to support the agent's multi-turn tool execution loop.selectConversationLines,compressVerboseContent,scoreEpisodeForContext, etc.) and unused constants.🎯 Why:
episodic_memorywas being fetched twice per message, doubling IO latency for history retrieval.📊 Impact:
🔬 Measurement:
npm test(34/34 passing).episodic_memoryfetch.PR created automatically by Jules for task 9951101745884560353 started by @SuvenSeo