feat: add per-agent compaction and contextPruning config overrides#52751
feat: add per-agent compaction and contextPruning config overrides#52751jjjj-lgtm wants to merge 3 commits into
Conversation
- Add compaction and contextPruning fields to AgentConfig type - Export ContextPruningSchema and CompactionSchema from zod-schema.agent-defaults - Add compaction and contextPruning to AgentEntrySchema Fixes openclaw#52732
Greptile SummaryThis PR enables per-agent overrides for
Confidence Score: 2/5
Prompt To Fix All With AIThis is a comment left during a code review.
Path: src/config/zod-schema.agent-runtime.ts
Line: 14-17
Comment:
**Circular module dependency introduced**
This import creates a circular dependency:
- `zod-schema.agent-runtime.ts` → imports `ContextPruningSchema`, `CompactionSchema` from `zod-schema.agent-defaults.ts`
- `zod-schema.agent-defaults.ts` → already imports `HeartbeatSchema`, `AgentSandboxSchema`, `AgentModelSchema`, `MemorySearchSchema` from `zod-schema.agent-runtime.ts`
In both Node.js CJS and ESM, a circular dependency like this means that when one module is being evaluated and the other hasn't finished loading yet, the importing module receives `undefined` for the not-yet-exported bindings. Depending on which module is evaluated first, either:
- `AgentDefaultsSchema` is built with `HeartbeatSchema`/`AgentSandboxSchema`/etc. as `undefined`, or
- `AgentEntrySchema` is built with `CompactionSchema`/`ContextPruningSchema` as `undefined`
Either scenario silently corrupts schema validation at runtime.
**Recommended fix:** Extract `ContextPruningSchema` and `CompactionSchema` into a new dedicated file (e.g., `src/config/zod-schema.compaction.ts`) that has no dependency on either `zod-schema.agent-runtime.ts` or `zod-schema.agent-defaults.ts`. Both files can then safely import from the new module without a cycle.
How can I resolve this? If you propose a fix, please make it concise.Reviews (1): Last reviewed commit: "feat: add per-agent compaction and conte..." | Re-trigger Greptile |
| import { | ||
| ContextPruningSchema, | ||
| CompactionSchema, | ||
| } from "./zod-schema.agent-defaults.js"; |
There was a problem hiding this comment.
Circular module dependency introduced
This import creates a circular dependency:
zod-schema.agent-runtime.ts→ importsContextPruningSchema,CompactionSchemafromzod-schema.agent-defaults.tszod-schema.agent-defaults.ts→ already importsHeartbeatSchema,AgentSandboxSchema,AgentModelSchema,MemorySearchSchemafromzod-schema.agent-runtime.ts
In both Node.js CJS and ESM, a circular dependency like this means that when one module is being evaluated and the other hasn't finished loading yet, the importing module receives undefined for the not-yet-exported bindings. Depending on which module is evaluated first, either:
AgentDefaultsSchemais built withHeartbeatSchema/AgentSandboxSchema/etc. asundefined, orAgentEntrySchemais built withCompactionSchema/ContextPruningSchemaasundefined
Either scenario silently corrupts schema validation at runtime.
Recommended fix: Extract ContextPruningSchema and CompactionSchema into a new dedicated file (e.g., src/config/zod-schema.compaction.ts) that has no dependency on either zod-schema.agent-runtime.ts or zod-schema.agent-defaults.ts. Both files can then safely import from the new module without a cycle.
Prompt To Fix With AI
This is a comment left during a code review.
Path: src/config/zod-schema.agent-runtime.ts
Line: 14-17
Comment:
**Circular module dependency introduced**
This import creates a circular dependency:
- `zod-schema.agent-runtime.ts` → imports `ContextPruningSchema`, `CompactionSchema` from `zod-schema.agent-defaults.ts`
- `zod-schema.agent-defaults.ts` → already imports `HeartbeatSchema`, `AgentSandboxSchema`, `AgentModelSchema`, `MemorySearchSchema` from `zod-schema.agent-runtime.ts`
In both Node.js CJS and ESM, a circular dependency like this means that when one module is being evaluated and the other hasn't finished loading yet, the importing module receives `undefined` for the not-yet-exported bindings. Depending on which module is evaluated first, either:
- `AgentDefaultsSchema` is built with `HeartbeatSchema`/`AgentSandboxSchema`/etc. as `undefined`, or
- `AgentEntrySchema` is built with `CompactionSchema`/`ContextPruningSchema` as `undefined`
Either scenario silently corrupts schema validation at runtime.
**Recommended fix:** Extract `ContextPruningSchema` and `CompactionSchema` into a new dedicated file (e.g., `src/config/zod-schema.compaction.ts`) that has no dependency on either `zod-schema.agent-runtime.ts` or `zod-schema.agent-defaults.ts`. Both files can then safely import from the new module without a cycle.
How can I resolve this? If you propose a fix, please make it concise.There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: c897f6849d
ℹ️ 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".
| import { | ||
| ContextPruningSchema, | ||
| CompactionSchema, | ||
| } from "./zod-schema.agent-defaults.js"; |
There was a problem hiding this comment.
Remove the new zod schema import cycle
Importing ContextPruningSchema/CompactionSchema here creates a direct cycle with src/config/zod-schema.agent-defaults.ts:3-8, which already imports HeartbeatSchema, AgentSandboxSchema, and MemorySearchSchema from this module. src/config/zod-schema.agents.ts:2-9 loads both modules during normal config parsing, so one side now has to read the other side's top-level const exports before they are initialized; in ESM that can throw a ReferenceError and prevent startup/config validation entirely.
Useful? React with 👍 / 👎.
| /** Optional per-agent compaction settings (overrides agents.defaults.compaction). */ | ||
| compaction?: AgentCompactionConfig; | ||
| /** Optional per-agent context pruning settings (overrides agents.defaults.contextPruning). */ | ||
| contextPruning?: AgentContextPruningConfig; |
There was a problem hiding this comment.
Wire per-agent compaction and pruning overrides into runtime
These new AgentConfig fields are only typed/validated; the runtime still ignores them. resolveAgentConfig() in src/agents/agent-scope.ts:28-45,130-149 does not return either field, and the embedded Pi paths still read only cfg.agents?.defaults in src/agents/pi-embedded-runner/extensions.ts:37-45,60-93, src/agents/pi-settings.ts:67-77, src/agents/pi-embedded-runner/compact.ts:625-627, and src/agents/pi-embedded-runner/run/attempt.ts:2981-2984. As a result, agents.list[].compaction / agents.list[].contextPruning now parse successfully but are a silent no-op for every agent.
Useful? React with 👍 / 👎.
Extracted ContextPruningSchema and CompactionSchema into a new dedicated file zod-schema.compaction.ts to break the circular import dependency. Fixes code review feedback: circular module dependency between zod-schema.agent-runtime.ts and zod-schema.agent-defaults.ts
Add compaction and contextPruning fields to ResolvedAgentConfig type and resolveAgentConfig() return object so per-agent overrides are actually used at runtime. Fixes code review feedback: per-agent overrides ignored by runtime
|
maintainer review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: f839b37b0d
ℹ️ 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".
| compaction: CompactionSchema, | ||
| contextPruning: ContextPruningSchema, |
There was a problem hiding this comment.
Reject or apply per-agent compaction/pruning overrides
These new schema fields make agents.list[].compaction and agents.list[].contextPruning validate successfully, but runtime compaction/pruning logic still reads only cfg.agents.defaults (for example in src/agents/pi-embedded-runner/extensions.ts:37-74, src/agents/pi-settings.ts:67, src/agents/pi-embedded-runner/compact.ts:626, and src/agents/pi-embedded-runner/run/attempt.ts:2982). Fresh evidence in this commit is that resolveAgentConfig now carries both fields, yet there are still no call sites that consume resolveAgentConfig(...).compaction/contextPruning, so per-agent overrides are silently ignored whenever they differ from defaults.
Useful? React with 👍 / 👎.
|
Hi @codex review This PR has been updated with fixes for the circular dependency issue. The latest commit (48b98e6) extracts Additionally, the Please re-review the latest commit. Thank you! |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: f839b37b0d
ℹ️ 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".
| compaction: CompactionSchema, | ||
| contextPruning: ContextPruningSchema, |
There was a problem hiding this comment.
Apply per-agent compaction overrides in standard run path
Adding these fields to AgentEntrySchema makes agents.list[].compaction and agents.list[].contextPruning valid config, but the normal reply pipeline still runs compaction/pruning from cfg.agents.defaults only. In the non-cron flow, getReplyFromConfig/get-reply-run pass the unmerged config through to runEmbeddedPiAgent, and compaction logic (for example in src/agents/pi-embedded-runner/extensions.ts and src/agents/pi-embedded-runner/run/attempt.ts) reads global defaults rather than per-agent entries; only isolated cron merges per-agent overrides via buildCronAgentDefaultsConfig. This means users can set these new per-agent keys without errors and still get global compaction/pruning behavior.
Useful? React with 👍 / 👎.
|
This pull request has been automatically marked as stale due to inactivity. |
|
Codex review: found issues before merge. What this changes: The PR adds per-agent Maintainer follow-up before merge: This is an open implementation PR with a blocking runtime gap and overlapping open PR #69988; maintainers should choose or request a consolidated canonical branch rather than queue an automated repair on this source branch. Security review: Security review cleared: The PR changes config types, Zod schemas, and resolver plumbing only; it does not add dependencies, workflow changes, secret handling, install hooks, release metadata, or new code-execution surfaces. Review findings:
Review detailsBest possible solution: Land one canonical implementation that accepts both per-agent keys, merges each agent override over Full review comments:
Overall correctness: patch is incorrect Acceptance criteria:
What I checked:
Likely related people:
Remaining risk / open question:
Codex review notes: model gpt-5.5, reasoning high; reviewed against 6516be102392. |
|
Codex review: found issues before merge. What this changes: The PR adds per-agent Maintainer follow-up before merge: This is an open implementation PR with a real feature request, a blocking runtime gap, and an overlapping open PR; the next action is maintainer branch/consolidation judgment rather than an automated repair lane on this source branch. Review findings:
Review detailsBest possible solution: Land one canonical implementation that accepts both per-agent keys, merges each agent override over Full review comments:
Overall correctness: patch is incorrect Acceptance criteria:
What I checked:
Likely related people:
Remaining risk / open question:
Codex review notes: model gpt-5.5, reasoning high; reviewed against e46dccb35374. |
|
Thanks for the per-agent compaction proposal. Closing this stale config feature because compaction/context-pruning policy needs an owner-backed design path. |
Summary
Adds support for per-agent
compactionandcontextPruningconfiguration overrides.Previously, these settings could only be defined at
agents.defaults, applying globally to all agents. This PR allows overriding them per agent inagents.list.Changes
compaction?: AgentCompactionConfigtoAgentConfigtypecontextPruning?: AgentContextPruningConfigtoAgentConfigtypeContextPruningSchemaandCompactionSchemafromzod-schema.agent-defaults.tsAgentEntrySchemafor runtime validationUsage Example
{ "agents": { "defaults": { "compaction": { "mode": "safeguard", "reserveTokens": 8000 } }, "list": [ { "id": "main", "compaction": { "mode": "default", "reserveTokens": 12000 } } ] } }