🐛 fix: reduce agent document context latency#15436
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## canary #15436 +/- ##
===========================================
- Coverage 89.70% 70.94% -18.76%
===========================================
Files 862 3225 +2363
Lines 105731 320651 +214920
Branches 10246 28223 +17977
===========================================
+ Hits 94841 227475 +132634
- Misses 10714 92999 +82285
- Partials 176 177 +1
Flags with carried forward coverage won't be shown. Click here to find out more.
🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 01eae69a0c
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
|
@codex review latest code |
|
Codex Review: Didn't find any major issues. Nice work! ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
72187e2 to
0f9c5d1
Compare
0f9c5d1 to
c347f24
Compare
|
@codex review it |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: a4e2df9a99
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| "payload"."provider", | ||
| "payload"."parent_id", | ||
| ${this.userId}, | ||
| "resolved_context"."session_id", |
There was a problem hiding this comment.
Preserve group-message scoping in fast-path inserts
When a group chat send takes this simple fast path with both groupId and sessionId, this direct insert persists resolved_context.session_id on the group messages. The regular MessageModel path intentionally clears sessionId whenever groupId is set (packages/database/src/models/message.ts:1691-1692), so these rows can later match ordinary session-scoped queries in addition to group queries, polluting conversation history. Please mirror that normalization for both simple fast paths by writing NULL for session_id when groupId is present.
Useful? React with 👍 / 👎.
- cli-backend-testing: use $CLI shorthand consistently, remove redundant "When Server Restart is NOT Needed" section and Credential Isolation table (already covered by the restart table and cli skill) - zustand: compress "Slices That Don't Need set" from 61 to 22 lines by merging overlapping Rules of thumb / Do-Don't sections
💻 Change Type
🔗 Related Issue
N/A
🔀 Description of Change
This PR reduces chat preparation and send-persistence latency when an agent has many attached documents, while keeping send-time hydration correct.
agentDocument.getContextDocumentsendpoint for chat context hydration.documents.contentfor progressive documents; onlypolicyLoad === 'always'documents keep full content.contentCharCountso progressive index rendering can still show document sizes without requiring full content.hasDocuments.ensureAgentDocumentsremains the correctness fallback.ConversationProviderso SWR refreshes do not re-renderChatList/VirtualizedListand disturb scroll anchoring.MessageModelgroup-message normalization.src/databasetopackages/database.AGENTS.md.Security review: this only changes open-source agent document/context/store/server persistence behavior and does not expose cloud-specific business logic.
🧪 How to Test
Commands run:
bunx vitest run --silent='passed-only' src/server/services/agentDocuments/index.test.ts src/services/agentDocument.test.ts src/services/chat/chat.test.ts src/store/agent/slices/agent/action.test.ts src/store/chat/slices/topic/action.test.ts src/store/chat/slices/aiChat/actions/__tests__/streamingExecutor.test.tsbunx vitest run --silent='passed-only' src/features/Conversation/ConversationProvider.test.tsx src/store/agent/slices/agent/action.test.ts src/services/chat/mecha/contextEngineering.test.ts src/store/agent/slices/knowledge/action.test.ts src/store/agent/slices/plugin/action.test.tsbunx vitest run --silent='passed-only' src/server/services/aiChat/index.test.ts src/server/routers/lambda/__tests__/aiChat.test.ts src/store/chat/slices/aiChat/actions/__tests__/conversationLifecycle.test.tsAlso checked VS Code diagnostics and
git diff --check.📸 Screenshots / Videos
N/A
📝 Additional Information
This does not add a post-runtime document refresh. The optimization is prefetch plus a send-time fallback: if the cache is warm, chat preparation uses it; if not,
ensureAgentDocumentsstill hydrates the required context before sending.For ordinary new-topic sends, the server persistence fast path is intentionally scoped to the simplest case only; other sends keep the existing multi-step flow.