#22845: Pass agentDir through cron and followup embedded runs
size: S
Cluster:
Cron Session Enhancements
## Summary
- Pass `agentDir` into `runEmbeddedPiAgent` in cron and follow-up runner execution paths.
- Add focused regression tests for agentDir forwarding.
## Type
- [x] Bug fix
- [ ] Feature
- [ ] Refactor
- [ ] Docs
- [ ] Chore
## Scope
- [x] Targeted bugfix (small, non-breaking)
- [ ] Broad behavior change
- [ ] New feature surface
## Changes
- `src/cron/isolated-agent/run.ts`: pass `agentDir` into `runEmbeddedPiAgent` when running cron jobs.
- `src/cron/isolated-agent.uses-last-non-empty-agent-text-as.test.ts`: add regression test asserting `agentDir` is forwarded for cron runs.
- `src/auto-reply/reply/followup-runner.ts`: pass `queued.run.agentDir` into `runEmbeddedPiAgent`.
- `src/auto-reply/reply/followup-runner.test.ts`: add regression test for the follow-up path.
## Why
`runEmbeddedPiAgent` resolves provider credentials from `agentDir` and defaults to `main` when missing. In these paths, the directory was not being passed, causing non-default jobs to potentially use the wrong auth store and fail with provider key errors.
## Security impact
- **Low**: The change is additive parameter threading only.
- It reduces cross-agent auth cross-usage risk by explicitly using the job/queue-owned agent directory.
## Verification
Could not run the test suite in this environment because project dependencies are not installed in this container.
- PR scope is limited to auth-path threading plus regression tests.
- Recommended command for maintainers:
- `pnpm test src/cron/isolated-agent.uses-last-non-empty-agent-text-as.test.ts src/auto-reply/reply/followup-runner.test.ts`
## Human verification
- Confirmed local behavioral expectation by tracing run flow around:
- `runCronIsolatedAgentTurn` (cron path)
- `createFollowupRunner` (queued follow-ups)
## Failure recovery
- Revert this PR if any unexpected auth-path behavior is observed; the changes are isolated and can be dropped safely.
## Issue
Closes #22842
<!-- greptile_comment -->
<h3>Greptile Summary</h3>
This PR fixes a bug where `agentDir` was resolved but not passed through to `runEmbeddedPiAgent` in two code paths: the followup runner (auto-reply) and the cron isolated-agent runner. In both cases, `agentDir` was already being passed to `runWithModelFallback` but was missing from the inner `runEmbeddedPiAgent` call, meaning embedded agent runs would not respect per-agent directory configuration.
- Adds `agentDir: queued.run.agentDir` to the `runEmbeddedPiAgent` call in `src/auto-reply/reply/followup-runner.ts`
- Adds `agentDir` to the `runEmbeddedPiAgent` call in `src/cron/isolated-agent/run.ts`
- Removes unused `formatXHighModelHint` import from `src/cron/isolated-agent/run.ts`
- Adds test coverage for both paths verifying `agentDir` propagation
<h3>Confidence Score: 5/5</h3>
- This PR is safe to merge — it fixes a missing parameter propagation with proper test coverage.
- The changes are minimal and focused: two one-line additions passing an already-resolved `agentDir` variable through to `runEmbeddedPiAgent`, one unused import removal, and two well-structured tests. The `agentDir` parameter is already typed as optional in `RunEmbeddedPiAgentParams`, the variable is already in scope at both call sites, and both tests verify correct propagation. No logic changes, no new dependencies, no security implications.
- No files require special attention
<sub>Last reviewed commit: 732ebc9</sub>
<!-- greptile_other_comments_section -->
<sub>(4/5) You can add custom instructions or style guidelines for the agent [here](https://app.greptile.com/review/github)!</sub>
<!-- /greptile_comment -->
Most Similar PRs
#12310: cron: pass agentDir to embedded runner for isolated sessions
by magendary · 2026-02-09
91.1%
#21646: fix(cron): pass agentDir to runEmbeddedPiAgent for correct auth res...
by zhangjunmengyang · 2026-02-20
89.0%
#22707: fix: pass agentDir to runEmbeddedPiAgent in cron isolated sessions
by mrlerner · 2026-02-21
88.9%
#11816: fix(cron): forward agent-specific exec config to isolated cron sess...
by AnonO6 · 2026-02-08
85.9%
#19385: fix: pass authProfileId from cron session to runEmbeddedPiAgent
by gigi-trifle · 2026-02-17
85.6%
#13638: fix: pass delivery context to cron isolated agent subagents
by dario-github · 2026-02-10
83.7%
#16390: fix(cron): jobs land in wrong agent session when agentId isn't in a...
by yinghaosang · 2026-02-14
81.8%
#6522: fix(cron): deliver original message when agent response is heartbea...
by sidmohan0 · 2026-02-01
77.9%
#16303: fix: apply cron payload.model override to session entry and pass au...
by superlowburn · 2026-02-14
77.8%
#22719: fix(agents): make subagent announce timeout configurable (restore 6...
by Valadon · 2026-02-21
77.8%