Skip to content

🤖 refactor: clean up workspace runtime contract helpers#3014

Open
ammar-agent wants to merge 2 commits intomainfrom
refactor/workspace-runtime-cleanup
Open

🤖 refactor: clean up workspace runtime contract helpers#3014
ammar-agent wants to merge 2 commits intomainfrom
refactor/workspace-runtime-cleanup

Conversation

@ammar-agent
Copy link
Collaborator

@ammar-agent ammar-agent commented Mar 17, 2026

Summary

Broaden the workspace runtime cleanup so the runtime contract is more consistent across local, worktree, SSH, Docker, and devcontainer flows. This keeps the earlier WorktreeManager / runtimeFactory cleanup from #3014, then adds shared init-hook orchestration, persisted workspace identity plumbing, and consistent directoryName usage for workspace/container path identity.

Background

The first pass of runtime cleanup reduced some local duplication, but the runtime contract still had a few horizontal seams with noticeable drift:

  • several runtimes independently implemented the same initWorkspace() hook-only flow,
  • recreated runtimes did not always receive the persisted workspace root, which especially mattered for devcontainer host-path behavior, and
  • some runtime create paths still treated branch identity and workspace-directory identity as if they were always the same value.

This follow-up keeps those cleanup threads aligned across the runtime layer instead of fixing each runtime in isolation.

Implementation

  • keep the earlier WorktreeManager.deleteWorkspace() / runtimeFactory helper cleanup from this PR
  • add runWorkspaceInitHook(...) in src/node/runtime/initHook.ts and reuse it in LocalRuntime, WorktreeRuntime, SSHRuntime, DockerRuntime, and DevcontainerRuntime
  • preserve runtime-specific preparation and hook execution while centralizing the shared hook gating / error reporting / MUX_* env flow
  • update createRuntimeForWorkspace(...) to pass the persisted namedWorkspacePath, so recreated runtimes start from the stored workspace identity instead of reconstructing it later
  • propagate directoryName through worktree/ssh/devcontainer/docker workspace creation so workspace/container paths follow the persisted workspace entry name while git checkout behavior still follows branchName
  • add regression coverage for the shared init-hook helper and the new workspace-identity expectations

Validation

  • bun test src/node/runtime/initHook.test.ts src/node/runtime/runtimeHelpers.test.ts src/node/runtime/runtimeFactory.test.ts src/node/runtime/SSHRuntime.test.ts src/node/worktree/WorktreeManager.test.ts src/node/runtime/DevcontainerRuntime.test.ts src/node/runtime/DockerRuntime.test.ts src/node/runtime/LocalRuntime.test.ts src/node/runtime/submoduleSyncRuntimes.test.ts
  • make static-check

Risks

Low to moderate. The changes are intended to be behavior-preserving, but they touch shared runtime initialization and workspace path identity, so regressions would most likely show up as init-hook execution differences, recreated-runtime path mismatches, or incorrect workspace/container naming during create flows.


Generated with mux • Model: openai:gpt-5.4 • Thinking: xhigh • Cost: $153.79

Follow up on the submodule workspace work by extracting shared
WorktreeManager cleanup helpers and reusing runtime identity plumbing in
runtimeFactory. This keeps workspace delete/rollback flows easier to
follow without changing behavior.

---

_Generated with `mux` • Model: `openai:gpt-5.4` • Thinking: `xhigh` • Cost: `$79.98`_

<!-- mux-attribution: model=openai:gpt-5.4 thinking=xhigh costs=79.98 -->
@ammar-agent
Copy link
Collaborator Author

@codex review

@chatgpt-codex-connector
Copy link

Codex Review: Didn't find any major issues. Keep them coming!

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@ammar-agent ammar-agent changed the title 🤖 refactor: clean up workspace runtime helpers 🤖 refactor: clean up workspace runtime contract helpers Mar 17, 2026
@ammar-agent
Copy link
Collaborator Author

@codex review

Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 2f41d257c7

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Continue the workspace runtime cleanup by centralizing the shared init-hook
flow, threading persisted workspace identity through runtime recreation, and
using directoryName consistently for workspace/container paths.

---

_Generated with `mux` • Model: `openai:gpt-5.4` • Thinking: `xhigh` • Cost: `$153.79`_

<!-- mux-attribution: model=openai:gpt-5.4 thinking=xhigh costs=153.79 -->
@ammar-agent ammar-agent force-pushed the refactor/workspace-runtime-cleanup branch from 2f41d25 to 1e0a43b Compare March 17, 2026 23:08
@ammar-agent
Copy link
Collaborator Author

@codex review
Please take another look.

@chatgpt-codex-connector
Copy link

Codex Review: Didn't find any major issues. Delightful!

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant