fix: truncate default harness name for long project names - #2233
Conversation
|
Claude Security Review: no high-confidence findings. (run) |
cf93448 to
5598a9f
Compare
There was a problem hiding this comment.
AgentCore Harness Review
Verdict: Looks good
Nice small fix. Math checks out for the reachable input space: ProjectNameSchema caps project names at 23 chars (^[A-Za-z][A-Za-z0-9]{0,22}$), and for any projectName in [1, 23]:
- Length ≤ 19: returned as-is, combined
project_project≤ 39 chars. - Length 20–23:
budget = 40 - len - 1∈ [16, 19],prefixLen = budget - 6∈ [10, 13], result is${prefix}_${5-hex-hash}=budgetchars, combined = exactlylen + 1 + budget = 40. ✓
Result always starts with a letter (inherited from projectName), so it passes HarnessNameSchema's ^[a-zA-Z]... regex.
A couple of minor observations that don't block:
- The
prefixLen <= 0fallback indefaultHarnessNameFor(src/handlers/project/create/index.ts:184) is currently unreachable givenProjectNameSchema.max(23), but if it ever were reached it would return a bare 5-char hex hash, which can begin with a digit and would failHarnessNameSchema's leading-letter regex. Consider prefixing the hash with a letter (e.g.h${hash}) or asserting/erroring, to make the helper self-consistent independent of upstream validation. - No unit tests were added for
defaultHarnessNameFor. Given it's a pure function with tight boundary conditions around the 40-char CFN cap, a quick test covering the 19/20-char boundary and the max-23 case would be worthwhile — this is exactly the kind of arithmetic that regresses silently if either limit changes.
|
Claude Security Review: no high-confidence findings. (run) |
The scaffolder defaulted the harness name to the project name, so the
derived CFN HarnessName `${projectName}_${harnessName}` was
`${projectName}_${projectName}` — twice the project length + 1. Any
project name > 19 chars pushed this past the 40-char CFN limit and
caused `agentcore project deploy` to fail at synth with no way to
recover other than hand-editing agentcore.json and app/<name>/harness.json.
When the doubled form would exceed the CFN cap, derive the harness name
as `<truncated-projectName>_<sha256[:5]>` so the concatenation stays
≤ 40 chars and distinct project names never collide. Short project
names keep the historical `harness.name == projectName` behavior.
5598a9f to
b83a66d
Compare
|
Claude Security Review: no high-confidence findings. (run) |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## refactor #2233 +/- ##
============================================
- Coverage 96.97% 96.97% -0.01%
============================================
Files 559 559
Lines 38581 38587 +6
============================================
+ Hits 37414 37418 +4
- Misses 1167 1169 +2 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Summary
agentcore project create --name <name>(no--template) defaulted the harness name to the project name. CFN builds the physicalHarnessNameas${projectName}_${harnessName}, capped at 40 chars, so any project name > 19 chars produced a name that failed synth with no recovery other than hand-editingagentcore.jsonandapp/<name>/harness.json.<truncated-projectName>_<sha256[:5]>so${projectName}_${harnessName}stays ≤ 40 chars and distinct project names never collide. Short project names keep the historicalharness.name == projectNamebehavior.Repro (before this change)
After
harness.jsonshortproj(9)shortproj(unchanged)shortproj_shortproj(19)HealthCareProfessional(22)HealthCareP_59ceb(17)HealthCareProfessional_HealthCareP_59ceb(40)Existing short-name projects: byte-identical output, no behavior change.
Test plan
bun run typecheckbun test src/handlers/project/create/(24/24 pass)HealthCareProfessionallocally; confirmharness.jsonreceivesHealthCareP_59ceband derived CFN name is exactly 40 charsshortprojlocally; confirm harness name is unchangedagentcore project deployagainst real AWS (skipped — no fixture account handy; reviewers may want to spot-check)Notes
project add harness(separate handler; users passing a name explicitly are still expected to pick something short) and projects with name > ~34 chars, where no harness name can fit and a create-time validation error would be the right guardrail. Happy to add in a follow-up if reviewers want.@aws/agentcore-l3-cdk-constructs— fixing it there (turn the synth-time throw into a deterministic truncation +Annotations.addWarning) would eliminate the trap at the root and cover every scaffolder, not justproject create. This CLI fix stops the bleed today.