Skip to content

fix: share Codex task state across worktrees#492

Open
xzjncu wants to merge 1 commit into
openai:mainfrom
xzjncu:fix/share-codex-state-across-worktrees
Open

fix: share Codex task state across worktrees#492
xzjncu wants to merge 1 commit into
openai:mainfrom
xzjncu:fix/share-codex-state-across-worktrees

Conversation

@xzjncu

@xzjncu xzjncu commented Jul 13, 2026

Copy link
Copy Markdown

Summary

  • use the Git main worktree as the task-state identity so parent sessions can observe rescue tasks launched from isolated worktrees
  • keep /codex:rescue foreground unless the user explicitly requests --background, preserving its stdout-forwarding contract
  • add worktree state-sharing coverage and make the temp-state test independent of a host-provided CLAUDE_PLUGIN_DATA

Test plan

  • node --test tests/commands.test.mjs tests/state.test.mjs
  • npm run check-version
  • git diff --check
  • Manually verified a foreground task returns its final stdout and is visible through /codex:status from the main worktree

Known baseline issue

npm test retains three pre-existing failures in tests/runtime.test.mjs that also fail unchanged on origin/main; they share state through the process environment during parallel execution. The affected new and command-contract tests pass independently.

Rescue tasks launched from isolated worktrees now remain visible to the
parent session, and unspecified rescue runs stay foreground so callers
receive the final Codex output instead of an untracked background job.
@xzjncu xzjncu requested a review from a team July 13, 2026 09:21

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

Copy link
Copy Markdown

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: 0ac71420c7

ℹ️ About Codex in GitHub

Codex has been enabled to automatically 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 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

export function resolveStateDir(cwd) {
const workspaceRoot = resolveWorkspaceRoot(cwd);
let canonicalWorkspaceRoot = workspaceRoot;
const repositoryIdentity = resolveRepositoryIdentity(workspaceRoot);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Cache repository identity lookups

When a task emits progress, paths like upsertJob/saveState and resolveJobFile reach resolveStateDir repeatedly, so this call now synchronously runs the Git identity lookup (including git worktree list) several times per state update. In foreground or background tasks with many progress events, those subprocesses block the Node process and can make status/log updates noticeably slow; compute the repository identity once per command or cache it per workspace/common-dir.

Useful? React with 👍 / 👎.

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