Skip to content

feat: run the setup plan - #921

Merged
cchu-ld merged 4 commits into
cchu/aws-devops-4b-setup-planfrom
cchu/aws-devops-4-setup-plan
Oct 21, 2026
Merged

cchu-ld merged 4 commits into
cchu/aws-devops-4b-setup-planfrom
cchu/aws-devops-4-setup-plan

Conversation

@cchu-ld

@cchu-ld cchu-ld commented Oct 20, 2026 •

Copy link
Copy Markdown
Contributor

Summary
This PR runs the plan from #928. RunPlan does a full setup, and ConnectPlan only connects the MCP server. Before each write, setup makes sure that AWS still matches the plan, so a change that another person made in the meantime stops the run. The setup command now uses the plan in place of the old Setup function.

Human note: large PR but it's mostly tests - most logic are in setup.go

Requirements

  • I have added test coverage for new or changed functionality
  • I have followed the repository's pull request submission guidelines
  • I have validated my changes against all supported platform versions

Related issues

None.

Describe the solution you've provided

  • Problem: AWS can change between the plan and the run, for example if another person creates a role at the same time.
    • Solution: RunPlan runs a full setup plan, and ConnectPlan runs a plan that only connects the MCP server. Before a step writes to AWS, a check makes sure that AWS still matches the plan. If AWS changed, the run stops with ErrPlanChanged. For the operator app, the check compares the sign-in method, not only on or off. The role and association steps can take minutes, so RunPlan checks the app again right before the app step.
  • Problem: Setup checked the LaunchDarkly token only when it replaced an MCP server registration. A bad token failed after setup had changed other AWS resources.
    • Solution: The run checks the token before any AWS write. Tests replace CheckToken, so they never call the real API.
  • Problem: A space that setup creates must carry the ownership tag.
    • Solution: RunPlan tags a new space with ldcli:managed=aws-devops-agent. AWS can also require aidevops:TagResource to tag a new space.
  • Problem: If AWS sent no operator app URL, the result had an empty URL.
    • Solution: RunPlan builds the URL from the space ID. SetupResult also reports operatorAppEnabled.
  • Problem: With --replace-mcp-token, a failed association on this space returned at once. The other spaces that lost the old server stayed disconnected, and the error did not name them. One failed reconnect also stopped the rest.
    • Solution: Setup reconnects every other space, even if this space or one of them fails. The error names each space that lost the server, and how to connect it again. If a disassociate, the deregister, or the new register fails part way, the error names the spaces that are already disconnected, and says to run setup with --agent-space-id <id> for each one. The new registration keeps the name of the replaced server, as the plan says.

The setup command now calls PlanSetup and RunPlan in place of Setup, and sets AuthFlowSet when you pass --auth-flow. connectMCPServer also passes the planned MCP step. A later PR replaces these five lines with the full command flow. Setup and ConnectExisting move to export_test.go, because only tests use them. FindAgentSpace is deleted.

Describe alternatives you've considered

None.

Additional context

Testing: go test ./... and golangci-lint pass on this branch.

🤖 Generated with Claude Code


Note

Overview
Replaces monolithic AWS DevOps Agent setup with a plan-then-apply flow: PlanSetup describes the run, RunPlan provisions IAM, agent space, associations, operator app, and MCP, and ConnectPlan only wires MCP on an existing space.

Before each write (and again after slow IAM steps), setup re-reads AWS and aborts with ErrPlanChanged if roles, spaces, associations, operator-app sign-in, or MCP state diverged from the plan. LaunchDarkly access tokens are validated before any AWS mutation; operator-app changes honor AuthFlowSet so sign-in is only changed when --auth-flow is passed.

New agent spaces get the ldcli:managed tag; results add operatorAppEnabled and synthesize an operator URL when AWS omits one. MCP token replace reconnects other agent spaces more safely and surfaces clearer errors. The setup CLI now calls PlanSetup + RunPlan; Setup/ConnectExisting move to test exports. Large runplan_test coverage exercises races and edge cases.

Reviewed by Cursor Bugbot for commit 2106a4c. Bugbot is set up for automated code reviews on this repo. Configure here.

@cchu-ld
cchu-ld added this pull request to stack #924 October 20, 2026 17:12
@cchu-ld
cchu-ld force-pushed the cchu/aws-devops-4-setup-plan branch from 21d3c2a to da7dbe7 Compare October 20, 2026 17:28
@cchu-ld
cchu-ld force-pushed the cchu/aws-devops-4-setup-plan branch from da7dbe7 to 55f2d19 Compare October 20, 2026 17:47
@cchu-ld
cchu-ld force-pushed the cchu/aws-devops-4-setup-plan branch from 55f2d19 to 6ced80d Compare October 20, 2026 17:59
@cchu-ld
cchu-ld force-pushed the cchu/aws-devops-4-setup-plan branch 2 times, most recently from d90108f to d0582f4 Compare October 20, 2026 18:32
@cchu-ld
cchu-ld force-pushed the cchu/aws-devops-4-setup-plan branch from d0582f4 to 8ae1c1d Compare October 20, 2026 18:36
@cchu-ld
cchu-ld removed this pull request from stack #924 October 20, 2026 18:38
@cchu-ld
cchu-ld added this pull request to stack #926 October 20, 2026 18:38
@cchu-ld
cchu-ld force-pushed the cchu/aws-devops-4-setup-plan branch 2 times, most recently from f6c619f to c27f1ef Compare October 20, 2026 19:11
@cchu-ld cchu-ld changed the title feat: plan the AWS setup steps before any write feat: run the setup plan Oct 20, 2026
@cchu-ld
cchu-ld force-pushed the cchu/aws-devops-4-setup-plan branch from c27f1ef to 089018c Compare October 20, 2026 19:13
@cchu-ld
cchu-ld removed this pull request from stack #926 October 20, 2026 19:13
@cchu-ld
cchu-ld changed the base branch from cchu/aws-devops-3-status to cchu/aws-devops-4b-setup-plan October 20, 2026 19:13

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

Cursor Bugbot has reviewed your changes using default effort and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, have a team admin enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 7683a40. Configure here.

Comment thread internal/awsdevops/setup.go Resolved
@cchu-ld
cchu-ld force-pushed the cchu/aws-devops-4-setup-plan branch from 7683a40 to b3fc47d Compare October 21, 2026 18:10
@cchu-ld
cchu-ld force-pushed the cchu/aws-devops-4-setup-plan branch from b3fc47d to f2be130 Compare October 21, 2026 18:18
@cchu-ld
cchu-ld force-pushed the cchu/aws-devops-4-setup-plan branch from f2be130 to 371b0a3 Compare October 21, 2026 18:36
@cchu-ld
cchu-ld force-pushed the cchu/aws-devops-4-setup-plan branch from 371b0a3 to 87faa19 Compare October 21, 2026 18:48
@cchu-ld
cchu-ld force-pushed the cchu/aws-devops-4-setup-plan branch from 87faa19 to 188bbd3 Compare October 21, 2026 19:11
@cchu-ld
cchu-ld force-pushed the cchu/aws-devops-4-setup-plan branch 3 times, most recently from 680bbba to be06594 Compare October 21, 2026 19:35
@cchu-ld

cchu-ld commented Oct 21, 2026

Copy link
Copy Markdown
Contributor Author

@Andrewjeska thanks! checkApp now has a comment on the sign-in check (2106a4c1). If someone else makes the planned change after the plan, for example IAM to IdC, the run still stops with "sign-in changed after the plan". EnableOperatorApp would work then, but a new plan is safe and finds that nothing is left to change.

@cchu-ld
cchu-ld force-pushed the cchu/aws-devops-4-setup-plan branch from b4164e6 to dd04576 Compare October 21, 2026 19:59
cchu-ld and others added 4 commits October 21, 2026 14:32
RunPlan runs a full setup plan. ConnectPlan runs a plan that only
connects the MCP server. Before a step writes to AWS, a check makes
sure that AWS still matches the plan. If AWS changed, the run stops
with ErrPlanChanged. For the operator app, the check compares the
sign-in method too. The role and association steps can take minutes,
so RunPlan checks the app again right before the app step. The LaunchDarkly token is checked before any AWS
write. Tests replace CheckToken, so they never call the real API.

RunPlan tags a new space with ldcli:managed=aws-devops-agent. If AWS
sends no operator app URL, RunPlan builds it from the space ID.
SetupResult reports operatorAppEnabled.

When --replace-mcp-token replaces the server, setup reconnects every
other space, even if this space or one of them fails. The error names
each space that lost the server. If a disassociate fails part way, the
error names the spaces that are already disconnected.

The setup command calls PlanSetup and RunPlan in place of Setup, and
sets AuthFlowSet if you pass --auth-flow. The next PR replaces the
call lines with the full command flow. Setup and ConnectExisting move
to export_test.go, and FindAgentSpace is deleted.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
RunPlan skips the MCP server step if the plan says MCPSkip, and it does
not check the MCP server before the run. The tests read the plan lines
from Text. A test that pointed setup at an MCP server on another
endpoint now passes that endpoint with --mcp-endpoint.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… writes

The role and association steps can take minutes. If the plan keeps the
AWS account association and someone removed it in that time, setup
created a new one. It now stops with ErrPlanChanged.

RunPlan checks the MCP server again right before the MCP step. A server
that appeared or went during the writes now stops the run with
ErrPlanChanged, instead of an AWS error that does not say why.

A comment in checkApp says that a sign-in change by someone else also
stops the run, and that a new plan then finds nothing to change.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A token replacement removes the MCP server from every space before it
registers the new one. If the deregister failed, or if the register
failed because another server has the name, the error did not name the
spaces that lost the server. Both errors now name them. The name clash
error no longer suggests --mcp-service-id, because that server serves
another endpoint.

The recovery advice now says to run setup with --agent-space-id for each
space, because a new run reconnects only one space.

The new registration keeps the name of the replaced server, as the plan
says. ConnectPlan reads the operator app again, so it reports the app as
it is at run time.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@cchu-ld
cchu-ld force-pushed the cchu/aws-devops-4-setup-plan branch from dd04576 to 358b317 Compare October 21, 2026 21:32
@cchu-ld
cchu-ld merged commit 4d0ea53 into main Oct 21, 2026
8 checks passed
@cchu-ld
cchu-ld deleted the cchu/aws-devops-4-setup-plan branch October 21, 2026 21:33
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.

4 participants