ServerContext Accepts Context Param - #162
Conversation
|
Warning Review limit reached
More reviews will be available in 40 minutes and 14 seconds. Learn how PR review limits work. Your organization has run out of usage credits. Purchase more credits in the billing tab to continue. ⌛ How to resolve this issue?After more reviews become available, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans include higher PR review limits than trial, open-source, and free plans. In all cases, reviews become available again over time. During sustained high-volume PR review activity, CodeRabbit may temporarily slow when the next review becomes available. Please see our Fair Usage Limits Policy for further information. ℹ️ Review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (4)
📝 WalkthroughWalkthroughIntroduces a ChangesServerContextComposition Dependency Injection
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Possibly related PRs
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
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 |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #162 +/- ##
=======================================
Coverage ? 87.56%
=======================================
Files ? 40
Lines ? 1664
Branches ? 554
=======================================
Hits ? 1457
Misses ? 207
Partials ? 0 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
src/core/server/server-context.composition.test.ts (1)
54-70: ⚡ Quick winConsider splitting unrelated assertions into separate tests.
Line 69 creates a new
ServerContextinstance unrelated to the one tested in lines 57-67. While both assertions are correct, testing two different construction scenarios in a single test case may reduce clarity.♻️ Suggested split
- it('constructs with suggestionFlowSeed and no config without throwing', () => { + it('constructs with suggestionFlowSeed and no config without throwing', () => { expect( () => new ServerContext(undefined, { suggestionFlowSeed: [ { namespace: 'wg21', recommended_tool: 'fast', suggested_fields: ['title'], user_query: 'contracts', }, ], }) ).not.toThrow(); + }); - expect(() => new ServerContext(undefined, {}).getConfig()).toThrow(/Missing Pinecone API key/); + it('throws when getConfig is called without Pinecone API key', () => { + expect(() => new ServerContext(undefined, {}).getConfig()).toThrow(/Missing Pinecone API key/); });🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@src/core/server/server-context.composition.test.ts` around lines 54 - 70, Split the test into two separate test cases. The first test should verify that ServerContext constructs successfully with suggestionFlowSeed and no config without throwing (keep the existing assertion for this). Create a second separate test that verifies ServerContext with undefined config throws the Pinecone API key error when getConfig() is called. Each test should focus on a single scenario to improve clarity.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@src/core/server/server-context.ts`:
- Around line 91-95: The namespaceCacheSeed.data and
suggestionFlowSeed[*].suggested_fields payloads are currently stored by
reference, which allows external mutations of these seed objects to affect
multiple contexts that reuse the same seed instance. Clone these injected seed
payloads (both the data structures in namespaceCacheSeed and suggested_fields
arrays in suggestionFlowSeed) to create independent copies that prevent state
aliasing between contexts. Use appropriate deep cloning for nested arrays and
objects to ensure complete isolation.
---
Nitpick comments:
In `@src/core/server/server-context.composition.test.ts`:
- Around line 54-70: Split the test into two separate test cases. The first test
should verify that ServerContext constructs successfully with suggestionFlowSeed
and no config without throwing (keep the existing assertion for this). Create a
second separate test that verifies ServerContext with undefined config throws
the Pinecone API key error when getConfig() is called. Each test should focus on
a single scenario to improve clarity.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 75f6d175-3796-4204-8a9b-07e4e10e718f
📒 Files selected for processing (7)
CHANGELOG.mdsrc/alliance/config.tssrc/core/config.tssrc/core/index.tssrc/core/server/server-context.composition.test.tssrc/core/server/server-context.tssrc/core/server/tools/test-helpers.ts
Summary
Adds a typed composition API to
ServerContextso embedders can inject pre-built dependencies (Pinecone client, URL generators, namespace cache seed, suggest-flow seed) at construction time — without relying on process-global facades likesetPineconeClient()orgetDefaultServerContext().This resolves Issue #1 (Phase 4: Setup/Composition API) from the June week 3 plan and addresses the dual-ownership problem identified in eval §5.2.
What changed
New public API
ServerContextComposition— optional injectables forServerContext/ factory helpersNamespaceCacheSeed,SuggestionFlowSeedEntry— minimal public seed types (internalNamespaceInfois not exported)createIsolatedContext(config, composition?)— multi-tenant factory with no process-global side effectscreateServer(config, composition?)— now accepts an optional composition object (singleton path unchanged)ServerContextconstructor (breaking, pre-1.0)Second argument changed from
client?: PineconeClienttocomposition?: ServerContextComposition.Composition seeds are applied directly in the constructor:
registerUrlGeneratormarkSuggestedto avoid config reach-through when no config is supplied)Singleton path
pendingCompositionwired into lazygetDefaultServerContext()materializationpendingConfiginteardownDefaultServerContext()andcreateServer()Docs & helpers
resolveConfigandresolveAllianceConfigdocumenting the{ config, composition }pairing patterncreateTestServerContext()extended with optionalcompositionfieldMigration
Multi-tenant embedders:
Suggest-flow gate settings (
disableSuggestFlow,cacheTtlMs) remain onServerConfig— not duplicated on composition.Test plan
npm run cipasses (typecheck, lint, format, build, coverage)server-context.composition.test.ts(9 tests): composition seeding,createIsolatedContextvscreateServerisolation, cache expiry refetch,setConfigpreserves URL generators but clears cache/flow, seed validation,AsyncDisposablecleanupserver-context.test.ts,server-context.lifecycle.test.ts,setup-multi-instance.test.tsFiles changed
src/core/server/server-context.tspendingCompositionsrc/core/index.tscreateIsolatedContextsrc/core/config.ts,src/alliance/config.tssrc/core/server/tools/test-helpers.tscompositionoptionsrc/core/server/server-context.composition.test.tsCHANGELOG.md[Unreleased]entryRelated Issue
Summary by CodeRabbit
New Features
createIsolatedContext()factory for creating server contexts without process-level side effectsBreaking Changes
ServerContextconstructor now accepts optional composition parameter instead of clientcreateServer()signature updated to accept optional composition parameterresolveConfig()now requires explicit Pinecone index name; root defaults removedexperimentalobjectDocumentation