refactor: restructure inference context to separate metadata from runtime state#276
Conversation
…time state - Split InferenceContext into InferenceMetadata (persistent) and InferenceContext (runtime) - Move userModelConfigs and runtimeOverrides from state to behavior instance properties - Add credentialsToRuntimeOverrides utility for SDK credential payload conversion - Update all agent behaviors to use getInferenceContext() for runtime context assembly - Migrate legacy inferenceContext field to metadata in state migration
f0ad25d to
2ff0b0f
Compare
|
Claude finished @AshishKumar4's task in 1m 43s —— View job Code Quality & Security Review (Critical Path)Recommendation: APPROVE PR SummaryRefactors the inference context system to separate persistent metadata ( PR Description
Addressed Issues
Code Quality
Positive Observations:
Security
Security Improvements in This PR:
Testing
Architecture NotesThe refactor correctly implements the pattern: Final RecommendationAPPROVE - This PR implements a well-designed security improvement by ensuring API keys and other sensitive runtime data are never persisted to Durable Object storage. The migration path is clean, and the type system now enforces the separation between persistent and ephemeral data at compile time. Minor suggestions (non-blocking):
|
Summary
Refactors the inference context system to separate persistent metadata (agentId, userId) from runtime-only state (API keys, abort signals, model configs), preventing accidental serialization of sensitive data in Durable Object state.
Changes
InferenceContextintoInferenceMetadata(persistent) andInferenceContext(runtime-assembled)InferenceRuntimeOverridestype for BYOK API keys and AI Gateway overridesuserModelConfigsandruntimeOverridesfrom state to behavior instance propertiescredentialsToRuntimeOverrides()utility for SDK credential payload conversiongetInferenceContext()method inBaseCodingBehaviorto assemble runtime context on-demandinferenceContext->metadatawith migration support for legacy stateruntimeOverridesthrough inference pipeline to support BYOK keysMotivation
The previous design persisted runtime-only data (like user API keys and abort signals) in Durable Object state, which was:
This refactor cleanly separates concerns by:
Testing
inferenceContexttometadatafor existing appsBreaking Changes
state.inferenceContextrenamed tostate.metadata(migration handles legacy data)behavior.getInferenceContext()Related Issues