[PR #3475] [MERGED] fix(server): keep Grok CLI scratch cwd outside any git checkout #5956

Closed
opened 2026-10-23 04:05:36 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/Pasta-Devs/Marinara-Engine/pull/3475
Author: @myaiexp
Created: 7/11/2026
Status: ✅ Merged
Merged: 7/11/2026
Merged by: @SpicyMarinara

Base: staging ← Head: feat/grok-cli-scratch-tmpdir


📝 Commits (2)

  • ab862d3 fix(server): keep grok CLI scratch cwd outside any git checkout
  • b184e97 Address CodeRabbit scratch directory review

📊 Changes

1 file changed (+20 additions, -5 deletions)

View changed files

📝 packages/server/src/services/llm/providers/grok-subscription.provider.ts (+20 -5)

📄 Description

Linked issue

Closes #3474

Why this change

The Grok CLI provider spawned grok with DATA_DIR/grok-cli as its working directory. On source installations inside a Git checkout, Grok walks upward to the repository root and indexes the entire Marinara tree for every one-shot chat, tracker, or agent request. Measurements showed 45,000+ file opens and roughly 10 seconds of avoidable startup CPU per call.

Docker and installer deployments generally hide the problem because their data directory has no Git repository above it.

What changed

  • Move the Grok CLI scratch working directory outside the application checkout into the operating-system temporary directory.
  • Create one unpredictable process-local directory with mkdtemp, preventing another local user from pre-creating the path or substituting a symlink.
  • Keep prompt files in their existing protected directory and continue passing them by absolute path and deleting them after each request.
  • Preserve the existing Grok CLI arguments and request behavior.

Alternatives tested by the contributor: --verbatim does not skip discovery; a stub .git directory is not accepted as a repository boundary; git init works but adds an unnecessary Git binary dependency.

Validation

  • pnpm check passes locally
  • Container (Docker / Podman) built and ran without issue
  • Ran the app, clicked through the changes manually
  • Checked edge cases (light + dark mode, mobile viewport, empty states, error paths)
  • Above manual verification completed (describe below)
  • Read and followed CONTRIBUTING.md

Automated validation completed:

  • pnpm check
  • GitHub pnpm-validate
  • GitHub container-build-test

Manual verification notes

Contributor measurements for an identical one-line prompt using Grok 0.2.14 on Linux:

Scenario Wall time
grok -p outside any repository 4.7 s
grok -p from data/grok-cli inside the checkout 15.6 s
Connection test before this fix 12.1 s
Connection test after this fix 5.4 s

Before merging, manually verify chat generation and tracker/agent runs with an authenticated Grok CLI connection and confirm its scratch directory is created under the OS temporary directory.

Docs and release impact

  • No docs changes needed
  • Updated docs (README / CONTRIBUTING / android/README / CHANGELOG) as needed
  • Version/release files updated (only if this PR includes a version bump)

No version bump is included. The implementation is isolated to the Grok subscription provider.

UI evidence (if applicable)

Not applicable; this is a server-only provider performance and security fix.

Ownership: @myaiexp (agent-assisted).


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/Pasta-Devs/Marinara-Engine/pull/3475 **Author:** [@myaiexp](https://github.com/myaiexp) **Created:** 7/11/2026 **Status:** ✅ Merged **Merged:** 7/11/2026 **Merged by:** [@SpicyMarinara](https://github.com/SpicyMarinara) **Base:** `staging` ← **Head:** `feat/grok-cli-scratch-tmpdir` --- ### 📝 Commits (2) - [`ab862d3`](https://github.com/Pasta-Devs/Marinara-Engine/commit/ab862d3c15dbf99989aa4e05d41e4b6cf2498307) fix(server): keep grok CLI scratch cwd outside any git checkout - [`b184e97`](https://github.com/Pasta-Devs/Marinara-Engine/commit/b184e97323dee930c8407c35e846223ad77453ff) Address CodeRabbit scratch directory review ### 📊 Changes **1 file changed** (+20 additions, -5 deletions) <details> <summary>View changed files</summary> 📝 `packages/server/src/services/llm/providers/grok-subscription.provider.ts` (+20 -5) </details> ### 📄 Description ## Linked issue Closes #3474 ## Why this change The Grok CLI provider spawned `grok` with `DATA_DIR/grok-cli` as its working directory. On source installations inside a Git checkout, Grok walks upward to the repository root and indexes the entire Marinara tree for every one-shot chat, tracker, or agent request. Measurements showed 45,000+ file opens and roughly 10 seconds of avoidable startup CPU per call. Docker and installer deployments generally hide the problem because their data directory has no Git repository above it. ## What changed - Move the Grok CLI scratch working directory outside the application checkout into the operating-system temporary directory. - Create one unpredictable process-local directory with `mkdtemp`, preventing another local user from pre-creating the path or substituting a symlink. - Keep prompt files in their existing protected directory and continue passing them by absolute path and deleting them after each request. - Preserve the existing Grok CLI arguments and request behavior. Alternatives tested by the contributor: `--verbatim` does not skip discovery; a stub `.git` directory is not accepted as a repository boundary; `git init` works but adds an unnecessary Git binary dependency. ## Validation - [ ] `pnpm check` passes locally - [ ] Container (Docker / Podman) built and ran without issue - [ ] Ran the app, clicked through the changes manually - [ ] Checked edge cases (light + dark mode, mobile viewport, empty states, error paths) - [ ] Above manual verification completed (describe below) - [ ] Read and followed `CONTRIBUTING.md` Automated validation completed: - `pnpm check` - GitHub `pnpm-validate` - GitHub `container-build-test` ### Manual verification notes Contributor measurements for an identical one-line prompt using Grok 0.2.14 on Linux: | Scenario | Wall time | | --- | ---: | | `grok -p` outside any repository | 4.7 s | | `grok -p` from `data/grok-cli` inside the checkout | 15.6 s | | Connection test before this fix | 12.1 s | | Connection test after this fix | **5.4 s** | Before merging, manually verify chat generation and tracker/agent runs with an authenticated Grok CLI connection and confirm its scratch directory is created under the OS temporary directory. ## Docs and release impact - [ ] No docs changes needed - [ ] Updated docs (README / CONTRIBUTING / android/README / CHANGELOG) as needed - [ ] Version/release files updated (only if this PR includes a version bump) No version bump is included. The implementation is isolated to the Grok subscription provider. ## UI evidence (if applicable) Not applicable; this is a server-only provider performance and security fix. Ownership: @myaiexp (agent-assisted). --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-10-23 04:05:36 +07:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
Pasta-Devs/Marinara-Engine#5956
No description provided.