← Back to PRs

#8341: feat: add per-job cache control for cron jobs

by vishaltandale00 open 2026-02-03 22:11 View on GitHub →
app: web-ui gateway stale
Fixes #8321 ## Summary Adds optional `contextPruning` config field to cron jobs, allowing per-job overrides of the global `agents.defaults.contextPruning` settings. ## Problem Currently, all isolated cron jobs inherit global context pruning/caching settings. This means every isolated cron session caches context, even simple script-running jobs that don't need LLM continuity. This results in unnecessary token costs: - Nightly migration job: caches 199k tokens but only runs local Ollama scripts - Backup jobs: cache 24-33k tokens each but just run shell commands - Auto-commit, qmd-refresh: cache context they never use **Impact:** ~$40-50/month in unnecessary caching costs for typical setups with 8-12 cron jobs. ## Solution Added `contextPruning?: AgentContextPruningConfig` field to `CronJob` type. When set, it overrides `agents.defaults.contextPruning` for that job's isolated session. ### Example Usage Disable caching for a simple backup job: ```json { "name": "nightly-backup", "schedule": { "kind": "cron", "expr": "0 2 * * *" }, "sessionTarget": "isolated", "payload": { "kind": "agentTurn", "message": "Run backup scripts" }, "contextPruning": { "mode": "off" } } ``` Or use different cache TTL: ```json { "name": "morning-brief", "contextPruning": { "mode": "cache-ttl", "ttl": "5 minutes" } } ``` ## Implementation 1. **Added `contextPruning` field** to `CronJob`, `CronJobCreate`, `CronJobPatch` types 2. **Updated isolated agent runner** (`cron/isolated-agent/run.ts`) to merge per-job contextPruning into agent config before execution 3. **Extracted ContextPruningSchema** from inline definition in `zod-schema.agent-defaults.ts` for reuse 4. **Added TypeBox schema** (`ContextPruningConfigSchema`) to gateway protocol for API validation 5. **Updated protocol schemas** to support contextPruning in `cron.add` and `cron.update` ## Benefits - **Cost savings**: ~$40-50/month for typical setups - **Flexibility**: Keep caching for complex jobs, disable for simple script runners - **Explicit intent**: Makes it clear which jobs need context continuity - **Backward compatible**: Existing jobs continue using global settings ## Changes - `src/cron/types.ts`: Added `contextPruning` field with documentation - `src/cron/isolated-agent/run.ts`: Apply per-job contextPruning override to agent config - `src/config/zod-schema.agent-defaults.ts`: Extracted ContextPruningSchema for reuse - `src/gateway/protocol/schema/cron.ts`: Added TypeBox schema and updated CronJob/Add/Patch schemas 🤖 Generated with [Claude Code](https://claude.com/claude-code) <!-- greptile_comment --> <h2>Greptile Overview</h2> <h3>Greptile Summary</h3> This PR introduces an optional per-cron-job `contextPruning` configuration so isolated cron sessions can override the global `agents.defaults.contextPruning` (e.g., disabling cache-ttl for simple script jobs). The change threads the new field through cron TS types and gateway protocol schemas, and applies the override when building the per-run `agentCfg` in the isolated agent runner. Main thing to double-check is the interaction between this override and any config-default application: `runCronIsolatedAgentTurn` constructs `cfgWithAgentDefaults`, but `resolveCronSession` is still called with `params.cfg`, which can make the override ineffective if defaults are re-applied from the original config. <h3>Confidence Score: 3/5</h3> - This PR is mostly safe to merge, but the new per-job override may not work reliably as implemented. - The change is small and well-scoped (types + schema + a single override assignment), but the isolated runner mixes `cfgWithAgentDefaults` and `params.cfg` in a way that can let default-application logic overwrite a job-level `contextPruning` override. If that happens, the core advertised behavior (disabling caching per job) won’t be achieved in some configurations. - src/cron/isolated-agent/run.ts <!-- greptile_other_comments_section --> <!-- /greptile_comment -->

Most Similar PRs