← Back to PRs

#18914: fix: use per-session workspaceDir instead of process.cwd() for post-compaction context

by irchelper open 2026-02-17 05:40 View on GitHub →
channel: mattermost size: XS
Fixes the `process.cwd()` issue identified by @steipete in #18049. ## Problem `agent-runner.ts` lines 564 and 599 used `process.cwd()` to resolve the workspace directory for post-compaction context injection and audit. `process.cwd()` is process-global and does not follow per-session workspace context, which can cause: - Post-compaction context injection to miss the correct `AGENTS.md` / bootstrap files - Post-compaction read audit to validate against the wrong workspace ## Fix Replace both `process.cwd()` calls with `followupRun.run.workspaceDir`, which is the per-session workspace path already passed through from `get-reply-run.ts`. ## Verification - `npx tsc --noEmit` — zero type errors - 41/41 agent-runner tests pass - `followupRun` confirmed in scope at both locations <!-- greptile_comment --> <h3>Greptile Summary</h3> This PR replaces `process.cwd()` with per-session `workspaceDir` in two locations within `agent-runner.ts` (post-compaction context injection and read audit), fixing a bug where multi-session setups could resolve the wrong workspace. It also inlines and refactors `resolveContextReport` in `commands-context-report.ts`, applying the same `process.cwd()` → `params.workspaceDir` fix to the `cwd` parameter and removing `bootstrapTotalMaxChars` from the `/context` command output. - **`agent-runner.ts`**: Two clean substitutions of `process.cwd()` → `followupRun.run.workspaceDir` at lines 564 and 599. Type-safe and correctly scoped. - **`commands-context-report.ts`**: Inlines logic from `resolveCommandsSystemPromptBundle`, fixing an additional `process.cwd()` usage in the `cwd` field. Also removes `bootstrapTotalMaxChars` display and bootstrap truncation warnings from `/context` output. - **Broken tests**: `commands-context-report.test.ts` was not updated and has assertions that expect the removed `"Bootstrap max/total"` line and truncation warning text — these tests will fail. <h3>Confidence Score: 3/5</h3> - The agent-runner.ts fix is safe, but the commands-context-report.ts changes break existing tests that were not updated. - The core bug fix in agent-runner.ts is clean and correct. However, the larger refactor in commands-context-report.ts removes functionality (bootstrap truncation warnings) and the corresponding test file was not updated, meaning tests will fail. The PR description claims all tests pass but only references agent-runner tests, not the commands-context-report tests. - `src/auto-reply/reply/commands-context-report.ts` — requires corresponding test updates in `commands-context-report.test.ts` <sub>Last reviewed commit: 95871a1</sub> <!-- greptile_other_comments_section --> <!-- /greptile_comment -->

Most Similar PRs