Skip to content

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

Open
irchelper wants to merge 3 commits intoopenclaw:mainfrom
irchelper:fix/post-compaction-workspace-dir
Open

fix: use per-session workspaceDir instead of process.cwd() for post-compaction context#18914
irchelper wants to merge 3 commits intoopenclaw:mainfrom
irchelper:fix/post-compaction-workspace-dir

Conversation

@irchelper
Copy link

@irchelper irchelper commented Feb 17, 2026

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 Summary

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.

Confidence Score: 3/5

  • 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

Last reviewed commit: 95871a1

Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

2 files reviewed, 1 comment

Edit Code Review Agent Settings | Greptile

@greptile-apps
Copy link
Contributor

greptile-apps bot commented Feb 17, 2026

Additional Comments (1)

src/auto-reply/reply/commands-context-report.ts
Test file not updated for removed features

The test file commands-context-report.test.ts was not updated alongside these changes. Two assertions will fail:

  1. Line 68: expect(result.text).toContain("Bootstrap max/total: 150,000 chars") — this output line was removed from both the "list" and "detail" display paths.
  2. Lines 69-72: the bootstrap truncation warning ("⚠ Bootstrap context is over configured limits", "Causes: ...") was completely removed.

The PR description says "41/41 agent-runner tests pass" but these are in commands-context-report.test.ts, not the agent-runner test suite. The test expectations need to be updated or removed to match the new behavior.

Prompt To Fix With AI
This is a comment left during a code review.
Path: src/auto-reply/reply/commands-context-report.ts
Line: 1:17

Comment:
**Test file not updated for removed features**

The test file `commands-context-report.test.ts` was not updated alongside these changes. Two assertions will fail:

1. Line 68: `expect(result.text).toContain("Bootstrap max/total: 150,000 chars")` — this output line was removed from both the `"list"` and `"detail"` display paths.
2. Lines 69-72: the bootstrap truncation warning (`"⚠ Bootstrap context is over configured limits"`, `"Causes: ..."`) was completely removed.

The PR description says "41/41 agent-runner tests pass" but these are in `commands-context-report.test.ts`, not the agent-runner test suite. The test expectations need to be updated or removed to match the new behavior.

How can I resolve this? If you propose a fix, please make it concise.

@openclaw-barnacle openclaw-barnacle bot added the channel: mattermost Channel integration: mattermost label Feb 17, 2026
@greptile-apps
Copy link
Contributor

greptile-apps bot commented Feb 17, 2026

Got it — thanks for the clarification! Since the commands-context-report.ts changes have been reverted and the current PR only contains the two focused fixes you mentioned, my original review comment is indeed outdated.

I'll mark this resolved. The remaining changes look clean:

  • The agent-runner.ts fix correctly replaces process.cwd() with session-scoped workspaceDir
  • The test fix addresses a race condition in the Mattermost monitor tests

No further concerns on my end. ✅

@irchelper irchelper force-pushed the fix/post-compaction-workspace-dir branch 2 times, most recently from 5f7b346 to eb1b2e0 Compare February 17, 2026 06:06
@irchelper irchelper force-pushed the fix/post-compaction-workspace-dir branch from eb1b2e0 to 8258737 Compare February 22, 2026 12:46
@irchelper irchelper force-pushed the fix/post-compaction-workspace-dir branch from 2b4a073 to c505012 Compare March 7, 2026 05:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

channel: mattermost Channel integration: mattermost size: S

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant