Skip to content

fix(engram): make Antigravity plugin registration recoverable#1602

Closed
dnlrsls wants to merge 2 commits into
Gentleman-Programming:mainfrom
dnlrsls:fix/797-antigravity-mcp-recovery
Closed

fix(engram): make Antigravity plugin registration recoverable#1602
dnlrsls wants to merge 2 commits into
Gentleman-Programming:mainfrom
dnlrsls:fix/797-antigravity-mcp-recovery

Conversation

@dnlrsls

@dnlrsls dnlrsls commented Jul 21, 2026

Copy link
Copy Markdown
Contributor

Closes #797

Summary

  • Make the Antigravity Engram plugin the sole MCP registration owner.
  • Migrate legacy global registration while preserving unrelated configuration.
  • Recover deterministically from atomic-write failures and recognize the stable Linuxbrew path.

Changes

File Change
internal/components/engram/inject.go Reconcile global/plugin registration, preserve configuration, and handle partial atomic-write outcomes.
internal/components/engram/inject_test.go Cover migration, idempotency, malformed input, and write-failure recovery.
internal/components/golden_test.go Assert plugin-owned Antigravity MCP output.
testdata/golden/engram-antigravity-mcp.golden Expect the agent tool profile in plugin MCP configuration.

Test Plan

  • go test -count=1 ./internal/components/engram ./internal/components
  • Four-lens bounded review completed with zero findings.
  • go test -count=1 ./... — incomplete because the repository-wide suite exceeded the execution timeout after 23 packages passed.

Contributor Checklist

Summary by CodeRabbit

  • New Features

    • Improved Antigravity integration with a dedicated Engram plugin installer and end-to-end MCP config reconciliation.
    • Added support for stable Linuxbrew Engram executable paths.
    • Standardized Antigravity MCP tool exposure and plugin command/args handling.
  • Bug Fixes

    • Added more robust recovery/rollback when MCP config writes fail.
    • Prevented updates when existing Antigravity global configuration is malformed.
    • Improved synchronization between Antigravity global MCP state and the Engram plugin.
  • Tests

    • Expanded convergence, rollback, and malformed-config coverage, plus updated golden assertions for the plugin-scoped config location.

@coderabbitai

coderabbitai Bot commented Jul 21, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

Antigravity Engram injection now reconciles global and plugin registrations, preserves --tools=agent, handles write failures and malformed configuration, and recognizes Linuxbrew’s stable Engram path. Tests cover convergence, recovery, idempotency, and plugin-scoped golden output.

Changes

Antigravity Engram injection

Layer / File(s) Summary
Antigravity configuration reconciliation
internal/components/engram/inject.go
Adds reconciliation for Antigravity global and plugin MCP configuration, legacy format normalization, atomic writes, convergence detection, rollback, and joined errors.
Injection routing and command arguments
internal/components/engram/inject.go
Routes Antigravity through the dedicated installer, uses fixed MCP arguments, removes the generic merge path, and recognizes the Linuxbrew Engram binary path.
Antigravity injection validation
internal/components/engram/inject_test.go, internal/components/golden_test.go
Validates plugin-scoped configuration, --tools=agent, convergence, idempotency, write-failure recovery, malformed input rejection, and golden output.

Estimated code review effort: 4 (Complex) | ~60 minutes

Possibly related PRs

Suggested labels: type:bug, size:exception

Suggested reviewers: alan-thegentleman

Sequence Diagram(s)

sequenceDiagram
  participant injectWithOptions
  participant installAntigravityEngramPlugin
  participant AntigravityGlobalConfig
  participant EngramPluginFiles
  injectWithOptions->>installAntigravityEngramPlugin: install Antigravity Engram integration
  installAntigravityEngramPlugin->>AntigravityGlobalConfig: read and reconcile global MCP registration
  installAntigravityEngramPlugin->>EngramPluginFiles: write MCP config, hooks, and plugin manifest
  EngramPluginFiles-->>installAntigravityEngramPlugin: return convergence and write results
  installAntigravityEngramPlugin-->>injectWithOptions: return staged paths and joined errors
Loading
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Out of Scope Changes check ⚠️ Warning The MCP overlay args rewrite for non-OpenCode/OpenClaw agents appears broader than #797's Antigravity-only scope. Limit the change to Antigravity registration and Linuxbrew-path handling, or document why the non-Antigravity args rewrite is required.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title matches the main change: recoverable Antigravity Engram registration and plugin ownership.
Linked Issues check ✅ Passed The changes address #797 by removing duplicate Antigravity registration, preserving --tools=agent, and recognizing the Linuxbrew Engram path.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@internal/components/engram/inject.go`:
- Around line 302-308: Update the global configuration parsing around root so
zero-byte or whitespace-only global.data is normalized to an empty object before
json.Unmarshal. Preserve the existing parse error for non-empty invalid JSON and
the expected-object validation for other decoded values, allowing recoverable
empty mcp_config.json files to continue with {}.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: 144c5cee-28de-4e1d-97aa-5794254181b4

📥 Commits

Reviewing files that changed from the base of the PR and between 51a5d9e and f64ff92.

⛔ Files ignored due to path filters (1)
  • testdata/golden/engram-antigravity-mcp.golden is excluded by !testdata/**
📒 Files selected for processing (3)
  • internal/components/engram/inject.go
  • internal/components/engram/inject_test.go
  • internal/components/golden_test.go

Comment thread internal/components/engram/inject.go

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

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (2)
internal/components/engram/inject.go (2)

701-727: 🗄️ Data Integrity & Integration | 🔵 Trivial | ⚡ Quick win

Make every Antigravity user-config write transactional.

The settings bootstrap and failure tests must prove that later activation failures cannot leave partial configuration behind.

  • internal/components/engram/inject.go#L701-L727: verify that a newly created settings file is removed, or an existing file is restored, when a later install step fails.
  • internal/components/engram/inject_test.go#L712-L774: add failure cases and state assertions for settings.json, plugin mcp_config.json, and hooks.json, not only the global config and plugin.json.

As per path instructions, “Install/sync operations must be idempotent (running twice equals running once). Any write to user config must have a backup/restore path.”

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@internal/components/engram/inject.go` around lines 701 - 727, Make
ensureAntigravitySettings participate in the install transaction by recording
whether settingsPath existed and preserving its original contents before
writing; expose or connect that backup to the later activation rollback so
failures remove newly created settings.json or restore an existing file. Extend
the failure cases in internal/components/engram/inject_test.go lines 712-774 to
assert rollback for settings.json, plugin mcp_config.json, and hooks.json
alongside the existing global config and plugin.json assertions.

Source: Path instructions


346-354: 🎯 Functional Correctness | 🟠 Major | 🏗️ Heavy lift

Preserve the resolved engram binary for Antigravity.
preferredStableEngramCommand() collapses non-Homebrew paths to "engram", so downloaded installs lose the concrete binary path here and the generated MCP config depends on PATH inheritance.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@internal/components/engram/inject.go` around lines 346 - 354, Update the
Antigravity command resolution around existingMergedEngramCommand and
preferredStableEngramCommand so a downloaded or otherwise non-Homebrew install
retains its resolved concrete binary path instead of being collapsed to
"engram". Keep the stable Homebrew command behavior, then pass the preserved
command through stableEngramCommandForExisting when generating the engram MCP
configuration.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Outside diff comments:
In `@internal/components/engram/inject.go`:
- Around line 701-727: Make ensureAntigravitySettings participate in the install
transaction by recording whether settingsPath existed and preserving its
original contents before writing; expose or connect that backup to the later
activation rollback so failures remove newly created settings.json or restore an
existing file. Extend the failure cases in
internal/components/engram/inject_test.go lines 712-774 to assert rollback for
settings.json, plugin mcp_config.json, and hooks.json alongside the existing
global config and plugin.json assertions.
- Around line 346-354: Update the Antigravity command resolution around
existingMergedEngramCommand and preferredStableEngramCommand so a downloaded or
otherwise non-Homebrew install retains its resolved concrete binary path instead
of being collapsed to "engram". Keep the stable Homebrew command behavior, then
pass the preserved command through stableEngramCommandForExisting when
generating the engram MCP configuration.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: caad2ab2-c50d-431c-9316-79ff3984370d

📥 Commits

Reviewing files that changed from the base of the PR and between f64ff92 and 90319cc.

📒 Files selected for processing (2)
  • internal/components/engram/inject.go
  • internal/components/engram/inject_test.go

@dnlrsls

dnlrsls commented Jul 21, 2026

Copy link
Copy Markdown
Contributor Author

Superseded by the reviewable stacked-to-main delivery chain: #1643 first, followed by the input-resilience slice tracked in #1635 after approval. No published history was rewritten; this PR remains the audit trail for the original implementation and CodeRabbit correction.

@dnlrsls dnlrsls closed this Jul 21, 2026
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.

fix(engram): prevent double MCP registration in Antigravity and support Linuxbrew path

1 participant