Skip to content

Ensure MCP launch resources are cleaned up - #455

Merged
tninja merged 3 commits into
mainfrom
agent/mcp-launch-resource-cleanup
Jul 26, 2026
Merged

Ensure MCP launch resources are cleaned up#455
tninja merged 3 commits into
mainfrom
agent/mcp-launch-resource-cleanup

Conversation

@tninja

@tninja tninja commented Jul 26, 2026

Copy link
Copy Markdown
Owner

Summary

This PR adds lifecycle management for temporary resources created by ai-code-mcp-agent-prepare-launch.

Claude Code launches create a temporary MCP configuration file, but the previous cleanup function only unregistered the MCP session. The temporary file could therefore remain on disk after the session ended.

Changes

  • Add TDD coverage for Claude MCP temp config cleanup.
  • Add a test proving cleanup is idempotent.
  • Return command metadata with tracked runtime files from backend command injection.
  • Centralize cleanup in an idempotent helper that removes runtime files and unregisters the MCP session exactly once.

Impact

Claude Code MCP temporary configuration files are now removed when the session cleanup function runs. Other MCP-enabled backends keep their existing command behavior.

Validation

  • Added focused ERT tests in test/test_ai-code-mcp-agent.el.
  • The execution environment used to prepare this PR does not include Emacs, so the tests were not run locally; GitHub CI should provide the executable verification.

Follow-up

Startup-failure cleanup in the shared terminal/session infrastructure is intentionally left for a separate focused change, so this PR remains limited to resources owned by ai-code-mcp-agent.

@tninja
tninja marked this pull request as ready for review July 26, 2026 16:04
@tninja
tninja requested a review from Copilot July 26, 2026 16:05

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@tninja
tninja merged commit b403a84 into main Jul 26, 2026
4 checks passed

@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: d35203f90f

ℹ️ 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".

Comment thread ai-code-backends-infra.el
Comment on lines +1547 to +1548
(when cleanup-fn
(funcall cleanup-fn)))

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 Clean the prepared launch when session startup fails

The cleanup added here only covers reuse of a live session. For a fresh Claude Code launch whose process is nil or exits during the initialization delay—for example, when the CLI cannot start—ai-code-backends-infra--create-new-session calls ai-code-backends-infra--handle-session-start-failure without invoking cleanup-fn, and no sentinel was installed to invoke it later. The newly created MCP configuration file is therefore still leaked on this failure path; ensure launch cleanup also runs when session creation fails.

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.

2 participants