perf(agent-runtime): avoid full thread reads for resume checks - #464
Conversation
|
Caution Review failedThe pull request is closed. ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (13)
📝 WalkthroughWalkthroughChangesThread resume detection now checks for persisted user or assistant messages through an optional Thread resume detection
Node Web Crypto initialization
Estimated code review effort: 3 (Moderate) | ~20 minutes Sequence Diagram(s)sequenceDiagram
participant AgentRuntime
participant AgentStore
participant ObjectStorage
AgentRuntime->>AgentStore: ensureThread(threadId)
AgentStore->>ObjectStorage: inspect metadata and message prefix
ObjectStorage-->>AgentStore: range result or full messages
AgentStore-->>AgentRuntime: isResume boolean
Possibly related PRs
Suggested reviewers: ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Warning There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure. 🔧 ESLint
core/agent-runtime/src/AgentRuntime.tsESLint skipped: missing config or dependency (missing-dependency). The ESLint configuration references a package that is not available in the sandbox. core/agent-runtime/src/OSSAgentStore.tsESLint skipped: the ESLint configuration for this file references a package that is not available in the sandbox. core/agent-runtime/src/OSSObjectStorageClient.tsESLint skipped: the ESLint configuration for this file references a package that is not available in the sandbox.
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
Caution The consumer version of Gemini Code Assist on GitHub has been sunset. All code review activity has officially ceased. |
|
Caution The consumer version of Gemini Code Assist on GitHub has been sunset. All code review activity has officially ceased. |
What changed
AgentStore.hasMessages(threadId)capability for checking whether a thread contains user or assistant messages.AgentRuntime.ensureThread()prefer the lightweight capability while retaining the existinggetThread()fallback for custom stores.ObjectStorageClientand implement them inOSSObjectStorageClient.OSSAgentStore.hasMessages()with a 64 KiB prefix read; fall back to a full object read only when the prefix is inconclusive.Why
AgentRuntime.ensureThread()previously loaded and parsed the entire thread only to evaluatethread.messages.length > 0. For long JSONL histories this adds avoidable object-store transfer, parsing cost, memory pressure, and run-start latency.The new capability lets each store provide its cheapest correct existence check. Existing stores remain source-compatible because the method is optional.
Behavior and compatibility
hasMessages()follows the defaultgetThread()filtering semantics: only user and assistant messages count.AgentNotFoundError.getThread()path.Validation
ut run test --workspace=@eggjs/agent-runtime— 209 passingut run tsc --workspace=@eggjs/agent-runtimeut run tsc:pub --workspace=@eggjs/agent-runtimeut run tsc:pub --workspace=@eggjs/tegg-typesut run lint— 0 errors; 10 pre-existing warnings in unrelated filesCI compatibility
Summary by CodeRabbit
Improvements
Bug Fixes
Documentation