Skip to content

fix(agent): unbreak the codex local-tools MCP server ESM bundle#3369

Merged
tatoalo merged 1 commit into
mainfrom
posthog-code/fix-codex-local-tools-mcp-esm
Jul 12, 2026
Merged

fix(agent): unbreak the codex local-tools MCP server ESM bundle#3369
tatoalo merged 1 commit into
mainfrom
posthog-code/fix-codex-local-tools-mcp-esm

Conversation

@tatoalo

@tatoalo tatoalo commented Jul 12, 2026

Copy link
Copy Markdown
Contributor

Problem

Cloud tasks running on a Codex model cannot commit or open PRs: the model reports that git_signed_commit is not available, even though the session config injects the posthog-code-tools MCP server and the agent-server logs hasLocalTools: true.

Root cause: the bundled dist/adapters/codex-app-server/local-tools-mcp-server.js crashes at import time with Dynamic require of "fs" is not supported. noExternal inlines @posthog/git's CJS dependencies (simple-git@kwsites/file-exists) into the ESM bundle, where esbuild's require shim throws. Codex spawns the server, the process dies before answering initialize, codex emits mcpServer/startupStatus/updated {status: "failed"} (which the adapter ignored), and the signed-git tools silently never reach the model. The Claude adapter is unaffected because it registers these tools in-process; only the Codex path uses this standalone bundle.

Changes

  • Add a createRequire banner to the ESM tsup config so inlined CJS require(...) calls resolve when an entry runs directly under node.
  • Add a post-build smoke check (build/verify-local-tools-mcp-server.mjs, wired into pnpm build) that boots the dist server exactly like codex does and asserts tools/list includes the signed-git tools — this fails the build on any future bundling regression.
  • Log a warning when codex reports an MCP server startup failure instead of dropping the notification, so this class of failure is diagnosable from agent logs.

@trunk-io

trunk-io Bot commented Jul 12, 2026

Copy link
Copy Markdown

Merging to main in this repository is managed by Trunk.

  • To merge this pull request, check the box to the left or comment /trunk merge below.

After your PR is submitted to the merge queue, this comment will be automatically updated with its status. If the PR fails, failure details will also be posted here

@github-actions

github-actions Bot commented Jul 12, 2026

Copy link
Copy Markdown

React Doctor found no issues in the changed files. 🎉

Reviewed by React Doctor for commit 9860a3d.

@tatoalo tatoalo self-assigned this Jul 12, 2026
@tatoalo tatoalo added the Stamphog This will request an autostamp by stamphog on small changes label Jul 12, 2026
@tatoalo tatoalo marked this pull request as ready for review July 12, 2026 12:27

@stamphog stamphog 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.

Gates denied this PR because it modifies build toolchain files (tsup.config.ts and the package.json build script), which require human review. These are non-trivial bundler changes — adding a banner shim to inject require into ESM output affects how all entries in that tsup config are bundled, not just the MCP server.

@stamphog stamphog Bot removed the Stamphog This will request an autostamp by stamphog on small changes label Jul 12, 2026
@greptile-apps

greptile-apps Bot commented Jul 12, 2026

Copy link
Copy Markdown
Contributor

Reviews (1): Last reviewed commit: "fix(agent): unbreak the codex local-tool..." | Re-trigger Greptile

Comment thread packages/agent/build/verify-local-tools-mcp-server.mjs
The bundled dist/adapters/codex-app-server/local-tools-mcp-server.js crashed at import time with "Dynamic require of \"fs\" is not supported": noExternal inlines @posthog/git's CJS deps (simple-git -> @kwsites/file-exists) into ESM output, where esbuild's require shim throws. Codex marks the server failed and the signed-git tools (git_signed_commit/merge/rewrite) silently never reach the model, so codex cloud tasks cannot commit or open PRs.

- add a createRequire banner to the ESM tsup config so inlined CJS requires resolve
- add a post-build smoke check that boots the dist server like codex does and asserts tools/list
- log a warning when codex reports mcpServer/startupStatus/updated status=failed instead of dropping it

Generated-By: PostHog Code
Task-Id: 36343001-a2a7-44ac-8f07-bb41262ac179
@tatoalo tatoalo force-pushed the posthog-code/fix-codex-local-tools-mcp-esm branch from b3936ea to 9860a3d Compare July 12, 2026 12:32
@tatoalo tatoalo added the Stamphog This will request an autostamp by stamphog on small changes label Jul 12, 2026

@stamphog stamphog 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.

Gates denied this PR because it modifies build toolchain files (tsup.config.ts and package.json build script), which are on the deny-list and require human review. The bundler banner shim injected into ESM output affects all entries in that tsup config, not just the MCP server fix.

@stamphog stamphog Bot removed the Stamphog This will request an autostamp by stamphog on small changes label Jul 12, 2026
@tatoalo tatoalo enabled auto-merge (squash) July 12, 2026 12:36
@tatoalo tatoalo requested a review from a team July 12, 2026 12:36
@tatoalo tatoalo merged commit 0c94a4b into main Jul 12, 2026
31 checks passed
@tatoalo tatoalo deleted the posthog-code/fix-codex-local-tools-mcp-esm branch July 12, 2026 13:16
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.

2 participants