context-engine: pass runtime context to ContextEngineFactory#67243
context-engine: pass runtime context to ContextEngineFactory#67243jarimustonen wants to merge 15 commits intoopenclaw:mainfrom
Conversation
Greptile SummaryPasses a new Confidence Score: 5/5Safe to merge — no P0/P1 issues; all findings are style and docs suggestions. The implementation is clean, backward-compatible, and covered by three targeted unit tests. The two comments are both P2: a minor type inconsistency in an injected dep signature and missing doc examples for the new context parameter. Neither blocks correct runtime behavior. No files require special attention; the minor dep-type inconsistency in src/agents/subagent-registry.ts (lines 80–83 and 109–112) is the only thing worth a second look.
|
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 8dba5fb7cb
ℹ️ About Codex in GitHub
Codex has been enabled to automatically 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 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
7728db5 to
07df597
Compare
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 07df5971f6
ℹ️ About Codex in GitHub
Codex has been enabled to automatically 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 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
f06a50f to
361c0f0
Compare
361c0f0 to
6ae3ec4
Compare
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 6ae3ec4500
ℹ️ 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".
| const factoryCtx: ContextEngineFactoryContext = { | ||
| config, | ||
| agentDir: options?.agentDir, | ||
| workspaceDir: options?.workspaceDir, | ||
| }; |
There was a problem hiding this comment.
Pass an isolated factory context to fallback engine
resolveContextEngine constructs one factoryCtx object and reuses that same object when invoking both the configured engine factory and the default fallback factory. On fallback paths, a failing non-default factory can mutate ctx in place (for example while normalizing paths) before throwing/returning invalid data, and the default engine will then initialize from those mutated values instead of the original runtime context. This affects recovery scenarios directly, so each factory invocation should get its own immutable/independent context object.
Useful? React with 👍 / 👎.
Summary
ContextEngineFactoryreceives no parameters — plugins must use fragile workarounds (capture from first tool call, global mutable state, hardcoded fallback paths) to obtain runtime context like config, agentDir, and workspaceDir.ContextEngineFactorynow receives aContextEngineFactoryContextwithconfig?,agentDir?, andworkspaceDir?.resolveContextEngine()accepts optionalResolveContextEngineOptionsand forwards them to the factory. All three resolution call sites (run, compact, subagent-registry) pass available context.ContextEngineinterface and its method signatures are unchanged. Existing no-arg factories continue to work because TypeScript permits assigning functions with fewer parameters to wider signatures.Change Type (select all)
Scope (select all touched areas)
Linked Issue/PR
None.
Root Cause (if applicable)
N/A — this is a new feature.
Regression Test Plan (if applicable)
src/context-engine/context-engine.test.tsContextEngineFactoryContextwith correct config, agentDir, workspaceDirresolveContextEngine()cover the factory invocation contract without requiring full agent runtime.User-visible / Behavior Changes
None — this is a plugin API addition. No user-facing behavior changes.
Diagram (if applicable)
Security Impact (required)
Repro + Verification
Environment
Steps
ContextEngineFactoryContextresolveContextEngine(config, { workspaceDir: "/some/path" })Expected
{ config, workspaceDir: "/some/path" }Actual
Evidence
3 new tests in
src/context-engine/context-engine.test.ts:passes ContextEngineFactoryContext to factories that accept a parameterno-arg factories still work when context is passedpasses undefined config when resolveContextEngine is called without configAll 39 tests pass.
Human Verification (required)
workspaceDiris received correctly at factory construction time, no regression in existing behavior.Review Conversations
Compatibility / Migration
Risks and Mitigations
ContextEngineFactoryContext, updatedContextEngineFactorysignature)