Repository navigation
feat(migrate): add agentcore migrate - #2584
Conversation
|
Claude Security Review: no high-confidence findings. (run) |
48920b5 to
3177257
Compare
|
Claude Security Review: no high-confidence findings. (run) |
3177257 to
e4dd37d
Compare
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## refactor #2584 +/- ##
============================================
+ Coverage 96.33% 96.55% +0.21%
============================================
Files 671 697 +26
Lines 51321 56670 +5349
============================================
+ Hits 49439 54716 +5277
- Misses 1882 1954 +72 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
|
Claude Security Review: no high-confidence findings. (run) |
|
Claude Security Review: no high-confidence findings. (run) |
b6c43b5 to
7f7d0b9
Compare
|
Claude Security Review: no high-confidence findings. (run) |
7f7d0b9 to
742f041
Compare
|
Claude Security Review: no high-confidence findings. (run) |
agentcore migrate upgrades a v0 project to the v1 format without replacing any deployed resource. - One flow: every run computes the full read-only preview from scratch, shows a short summary on stdout (the full plan goes to agentcore/.cli/migrate/plan-<UTC>.md, which the git check ignores), then asks "Apply these changes?" on a terminal. --yes skips only the prompt; non-interactive and --json runs without --yes stop after the preview. There is no --dry-run. - Names: the converted agentcore.json sets migratedFrom: "v1", so the CDK library keeps every v0 physical name. - Stacks: logical IDs move to v1's with CloudFormation stack refactoring, one deployment target at a time (--target when several are deployed; others are recorded as pending and finished later with --target). Every step is recorded first in an atomic journal (agentcore/.cli/migration-state.json), so an interrupted run is finished or undone by running migrate again. - Deploying a target the journal still lists is refused, in the project manager's deploy (CLI, TUI, harness dev) and the v0 deploy delegation. - Any file added or changed in agentcore/cdk blocks, since migrating replaces it; files are compared with what each v0 release vended. - Only a 4xx from ExecuteStackRefactor counts as not started; other failures are unknown, keep the journal with the refactor ID, never put files back, and print the commands to check it. - Credential providers of a migrated project keep v0's bare names and are never deleted. - Migration is blocked until the CLI vends an @aws/agentcore-cdk release that honors migratedFrom (AGENTCORE_MIGRATE_CDK_LIBRARY overrides it for testing only). - Progress uses the shared runWithProgress task list on stderr, including the stack's resource events while a refactor executes. With the testing override, the summary and the next steps show the npm install command for the library the plan was made with.
742f041 to
341c5a5
Compare
|
Claude Security Review: no high-confidence findings. (run) |
AlexanderRichey
left a comment
There was a problem hiding this comment.
I pulled this down and tried to run it but ran into a few errors.
If I create a new project with the latest v0 CLI, deploy, and try to migrate, I get these errors:
Not ready to migrate: 3 issues need fixing first.
✖ cdk library: This CLI's v1 CDK app uses @aws/agentcore-cdk 1.0.0-rc.3, which doesn't keep v0 resource names (migratedFrom needs 1.0.0-rc.4 or later), so the first deploy…
✖ v1 synth: The CDK library the v1 app synthesized with doesn't support migratedFrom yet, so it can't keep this project's v0 resource names.
✖ stack plan skipped: the converted project's v1 CDK app didn't synthesize (see the v1 synth check)
I'd expect this to work as a main case.
This CLI's v1 CDK app uses @aws/agentcore-cdk 1.0.0-rc.3, which doesn't keep v0 resource names (migratedFrom needs 1.0.0-rc.4 or later), so the first deploy after migrating would replace this project's resources. Update the AgentCore CLI to a release with that library, then run agentcore migrate again.
Can we include the command the user has to run in this message so that it's clear how to fix?
agentcore/cdk isn't the CDK app a release that creates v0 projects (v0.4.0 to v0.31.1, 1.0.0-preview.1 to 1.0.0-preview.33) created; compared with v0 0.20.0 to…
Unclear what this means.
in a checkout of #423
after migrating, before deploying:
I'll add this to the PR description.
I'll also have the summary show the edited files instead of hiding them |
jariy17
left a comment
There was a problem hiding this comment.
pretty good. My comments could be follow up prs.
| for (const blocker of stack.blockers) lines.push(`${stack.stackName}: ${brief(blocker)}`); | ||
| for (const change of [...stack.removed, ...stack.replaced, ...stack.updated]) { | ||
| if (change.severity === "blocker") { | ||
| lines.push(`${shortType(change.type)} ${change.logicalId}: ${brief(change.reason)}`); |
There was a problem hiding this comment.
Simplify the unsupported-resource errors
I tested migration with a project containing knowledge bases, datasets, capacity providers, and online insights.
Currently, the summary prints:
✖ supported resources: This project uses knowledge bases (ReviewKnowledge); datasets (ReviewDataset); capacity providers (ReviewCapacity), which v1 doesn't support yet.
✖ Dataset ApplicationDatasetReviewDataset9D0FBD40: the v1 template has no counterpart, so the v1 deploy would delete it
✖ CapacityProvider ApplicationCapacityProviderReviewCapacity1B8156D5: the v1 template has no counterpart, so the v1 deploy would delete it
✖ OnlineEvaluationConfig ApplicationOnlineEvalReviewInsights9296C75D: the v1 template has no counterpart, so the v1 deploy would delete it
Could we remove the individual deletion messages from the summary and point users to the full plan for remediation?
Proposed:
✖ Migration blocked: This project uses resources that v1 doesn't support yet: knowledge bases, datasets, capacity providers, and online insights.
Please see the full plan for instructions on how to fix this issue.
Full plan: <path to migration plan>
| `This project uses ${listed([ | ||
| ...keepable, | ||
| ["runtimes on capacity providers", runtimesOnCapacityProviders], | ||
| ])}, which v1 doesn't support yet. Take them out of the project before migrating:`, |
There was a problem hiding this comment.
Include online insights in the unsupported-resources summary
I also added online insights (ReviewInsights). The full plan correctly says:
This project runs online insights (ReviewInsights), which v1 doesn't support.
But the terminal summary omits online insights from the unsupported-resources list. It only appears as an OnlineEvaluationConfig that the v1 deploy would delete. Could we include it in the unsupported-resources summary, as shown above?
| ` 3. Remove them from ${SPEC_RELATIVE_PATH} and run \`agentcore deploy\` again. ` + | ||
| "They leave the stack but stay in AWS.", | ||
| " 4. Undo the change to cdk-stack.ts, commit, and run `agentcore migrate --dry-run`.", | ||
| ` If you don't need them: remove them from ${SPEC_RELATIVE_PATH} and run ` + |
There was a problem hiding this comment.
Remove the deletion instructions
Could we remove these deletion instructions from the plan?
If you don't need them: remove them from agentcore/agentcore.json and run `agentcore deploy`. This deletes them from AWS.
Remove the insights settings from those online eval configs in agentcore/agentcore.json and run `agentcore deploy`; insights hold no data to keep.
I don’t think we should encourage customers to delete resources to complete migration.
| if (resources !== "") { | ||
| lines.push( | ||
| " To keep them and their data in AWS:", | ||
| " 1. In agentcore/cdk/lib/cdk-stack.ts, set DeletionPolicy Retain on them (for example " + |
There was a problem hiding this comment.
Automatically prepare retention policies
Could migration automatically apply DeletionPolicy: Retain to unsupported resources and their required dependencies, instead of asking customers to edit the generated CDK app? Show the proposed changes for confirmation, then deploy and verify the retention policies before removing any resources from the stack. This would make the preservation steps easier to follow.
| * Regenerates src/core/project/migrate/v0CdkApps.ts: what every CLI release that | ||
| * creates v0 projects (v0.4.0 to v0.31.1, 1.0.0-preview.1 to 1.0.0-preview.33) | ||
| * vended in agentcore/cdk, read from its git tag's src/assets/cdk. Releases that | ||
| * vended identical apps share an entry. Run from a clone with the release tags: |
There was a problem hiding this comment.
Explain why the code is needed
Instead of explaining what the code does, explain why we need it. For example, scripts/generate-v0-cdk-apps.ts exists so migration can recognize CDK files generated by older CLI versions and avoid overwriting customer customizations. Could we include that rationale in the script's introductory comment?
| " 2. Run `agentcore deploy` (it deploys a v0 project with the v0 CLI).", | ||
| ` 3. Remove them from ${SPEC_RELATIVE_PATH} and run \`agentcore deploy\` again. ` + | ||
| "They leave the stack but stay in AWS.", | ||
| " 4. Undo the change to cdk-stack.ts, commit, and run `agentcore migrate --dry-run`.", |
There was a problem hiding this comment.
Fix the unsupported dry-run command in the instructions
The preservation instructions in src/core/project/migrate/preflight.ts:203 tell users to run agentcore migrate --dry-run, but the migrate command doesn't register a --dry-run flag.
Description
Adds
agentcore migrate, which upgrades a v0 project to the v1 format without replacing any deployed resource. Runtimes, memories (and their data), gateways, evaluators and the rest keep their ARNs.One flow, every run
Every
agentcore migraterun computes the full read-only preview from scratch: checks, file changes, and the selected target's refactor and first v1 deploy. Nothing from an earlier run is saved or reused.Apply these changes? (y/N).--yesskips only the prompt. The checks still apply, and a not-ready preview never applies.--jsonruns without--yesprint the summary (or, with--json, the full plan as JSON) and stop, exiting 0 when ready and 1 when not.--dry-run.Output
migrateprints a short summary on stdout. The full plan (every check, the names table, every file, each stack's moves, and the first v1 deploy's changes per resource) goes toagentcore/.cli/migrate/plan-<UTC>.mdon every run, and the result of applying goes toresult-<UTC>.md. Migrate never reads these back, and the git check ignores the directory even when a project's.gitignoredoesn't. Progress (each step, and the stack's resource events while a refactor executes) uses the sharedrunWithProgresstask list on stderr.A plan that isn't ready lists one line per blocker, then the report path:
After applying, it prints one line per stack and the next step. A partial or unknown outcome keeps the refactor ID and the commands to check it on stdout. With
AGENTCORE_MIGRATE_CDK_LIBRARY(testing only), both the summary and the next steps include thecd agentcore/cdk && npm install <library> --no-savecommand, to run beforeagentcore deploy.Target selection
--target <name>is required; only that target is planned and refactored.There is no
--all-targetsflag.agentcore migrate --target <other>then migrates each one with its own fresh preview, built from the current v1 files and its still-v0 stack. That's what "finish pending migration" means; it isn't a separate mode.How migration keeps resources
v1 renames almost every CloudFormation logical ID, and most AgentCore resource names can't change after creation, so deploying v1 over a v0 stack would replace them. Migration avoids that in two parts:
migratedFrom. The convertedagentcore.jsongets"version": 2, "migratedFrom": "v1", where"v1"is the schema version the v0 CLI wrote. The CDK library then builds every physical name the v0 way.PolicyNamestay untouched.The journal
agentcore/.cli/migration-state.jsonis written atomically, before migrate changes anything. If it can't be written, nothing changes. It's updated as each step completes:writing→written→installed, plus where the v0 backup is.pending, orrefactoringwith the refactor ID once a refactor is created.A run stopped at any point is either finished or undone by running migrate again:
Unknown execute outcomes
Only a synchronous 4xx client error from
ExecuteStackRefactorcounts as "not started". Timeouts, 5xx errors, network errors and lost responses are unknown, and repeatedAVAILABLEreads aren't treated as proof. An unknown outcome:aws cloudformation describe-stack-refactor --stack-refactor-id <id> --region <r>andaws cloudformation list-stack-resources --stack-name <s> --region <r>A rerun reconciles using that ID.
Deploy precheck
Deploying a target the journal still lists as pending (or refactoring) is refused. The error names the target's account and region and points to
agentcore migrate --target <name>. Other targets deploy as usual.deploy, which covers the deploy command, the TUI and harness dev's auto-deploy, and in the v0 deploy delegation.agentcore/cdk file check
Migrating replaces
agentcore/cdkwholesale, so any added or modified file there blocks, and the preview lists each one with guidance to move the custom code out or revert it.node_modules,cdk.outanddist, compared (formatting aside) with what each release from v0.4.0 to v0.31.1 and 1.0.0-preview.1 to .33 vended. That data is generated from the release tags byscripts/generate-v0-cdk-apps.tsintov0CdkApps.ts.package.jsonmay differ only in dependency versions, since v0 deploys re-pin them.Other checks and the plan
@aws/agentcore-cdkhonorsmigratedFromharness.yaml, the v1 CDK app) and synthesized. The first v1 deploy is predicted with@aws-cdk/cloudformation-diff.CreateStackRefactor, with aTemplateURLthrough the CDK bootstrap bucket for templates over 51,200 bytes.ExecuteStackRefactor.Dependencies
@aws/agentcore-cdkrelease that honorsmigratedFrom, vended insrc/assets/cdk/package.json. Until then, the plan fails itscdk librarycheck.AGENTCORE_MIGRATE_CDK_LIBRARY(dev/test only) plans against a local library build; it warns loudly and never writes the override into the project.MIN_MIGRATED_FROM_CDK_VERSIONis bumped together with the vended pin.Related Issue
No public issue yet. This follows the reviewed v0→v1 compatibility and migration proposal, like #2575.
Documentation PR
The migration guide is in progress separately.
MIGRATION_DOCS_URLandPRESERVE_RESOURCES_DOCS_URLhold the expected page URLs, to be confirmed when it's published.command.mdis generated, so it isn't edited here.Type of Change
Testing
bun test: 4436 pass, 0 fail. The tests cover:--yes,--json, non-interactive runs, and the removed--dry-runagentcore/cdkfile check: added and modified files,package.jsonand lockfile rules, generated directories, old releases and previewsbun run test:e2e, or explained why they are not applicable. There's no migrate e2e suite yet. Earlier revisions were migrated live end to end on real deployed v0 projects (CodeZip and container, v0 0.31.1). Every ARN,createdAtand IAM RoleId and the memory data stayed identical throughmigrate --yesand the first v1 deploy, andcdk diffwas clean afterwards. Theagentcore/cdkfile check was also run over every v0 project on hand, and every unmodified one passes.bun run typecheckbun run lint:checkbun run format:checkbun run buildsrc/assets/, I updated affected snapshots withbun test <test-file> --update-snapshotsand committed them (not modified)Checklist
command.mdis generated; the migration guide is separate)@aws/agentcore-cdkrelease withmigratedFromis pending)By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the
terms of your choice.