Skip to content

fix: truncate default harness name for long project names - #2233

Merged
jariy17 merged 1 commit into
refactorfrom
fix/harness-name-truncation
Sep 4, 2026
Merged

fix: truncate default harness name for long project names#2233
jariy17 merged 1 commit into
refactorfrom
fix/harness-name-truncation

Conversation

@jariy17

@jariy17 jariy17 commented Sep 4, 2026

Copy link
Copy Markdown
Contributor

Summary

  • agentcore project create --name <name> (no --template) defaulted the harness name to the project name. CFN builds the physical HarnessName as ${projectName}_${harnessName}, capped at 40 chars, so any project name > 19 chars produced a name that failed synth with no recovery other than hand-editing agentcore.json and app/<name>/harness.json.
  • When the doubled form would exceed the 40-char CFN cap, derive the harness name as <truncated-projectName>_<sha256[:5]> so ${projectName}_${harnessName} stays ≤ 40 chars and distinct project names never collide. Short project names keep the historical harness.name == projectName behavior.

Repro (before this change)

agentcore project create --name HealthCareProfessional
cd HealthCareProfessional
agentcore project deploy
# ✕ Synthesizing CloudFormation templates
#   AgentCore CDK synthesis failed: Harness name
#   "HealthCareProfessional_HealthCareProfessional" is 45 characters;
#   the maximum is 40 (CloudFormation HarnessName limit).

After

projectName (len) harness.name written to harness.json CFN physical (len)
shortproj (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 typecheck
  • bun test src/handlers/project/create/ (24/24 pass)
  • Scaffold HealthCareProfessional locally; confirm harness.json receives HealthCareP_59ceb and derived CFN name is exactly 40 chars
  • Scaffold shortproj locally; confirm harness name is unchanged
  • Full agentcore project deploy against real AWS (skipped — no fixture account handy; reviewers may want to spot-check)

Notes

  • Not addressed here: 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.
  • The underlying constraint lives in @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 just project create. This CLI fix stops the bleed today.

@github-actions github-actions Bot added the size/xs PR size: XS label Sep 4, 2026
@agentcore-devx-automation agentcore-devx-automation Bot added agentcore-harness-reviewing AgentCore Harness review in progress claude-security-reviewing Claude Code /security-review in progress labels Sep 4, 2026
@github-actions github-actions Bot added size/xs PR size: XS and removed size/xs PR size: XS labels Sep 4, 2026
@agentcore-devx-automation

Copy link
Copy Markdown
Contributor

Claude Security Review: no high-confidence findings. (run)

@agentcore-devx-automation agentcore-devx-automation Bot removed the claude-security-reviewing Claude Code /security-review in progress label Sep 4, 2026
@jariy17
jariy17 force-pushed the fix/harness-name-truncation branch from cf93448 to 5598a9f Compare September 4, 2026 19:29

@agentcore-devx-automation agentcore-devx-automation Bot 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.

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} = budget chars, combined = exactly len + 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 <= 0 fallback in defaultHarnessNameFor (src/handlers/project/create/index.ts:184) is currently unreachable given ProjectNameSchema.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 fail HarnessNameSchema'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.

@agentcore-devx-automation agentcore-devx-automation Bot removed the agentcore-harness-reviewing AgentCore Harness review in progress label Sep 4, 2026
@github-actions github-actions Bot added size/xs PR size: XS and removed size/xs PR size: XS labels Sep 4, 2026
@agentcore-devx-automation agentcore-devx-automation Bot added the claude-security-reviewing Claude Code /security-review in progress label Sep 4, 2026
@agentcore-devx-automation

Copy link
Copy Markdown
Contributor

Claude Security Review: no high-confidence findings. (run)

@agentcore-devx-automation agentcore-devx-automation Bot removed the claude-security-reviewing Claude Code /security-review in progress label Sep 4, 2026
AlexanderRichey
AlexanderRichey previously approved these changes Sep 4, 2026
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.
@jariy17
jariy17 force-pushed the fix/harness-name-truncation branch from 5598a9f to b83a66d Compare September 4, 2026 19:34
@github-actions github-actions Bot added size/s PR size: S and removed size/xs PR size: XS labels Sep 4, 2026
@agentcore-devx-automation agentcore-devx-automation Bot added the claude-security-reviewing Claude Code /security-review in progress label Sep 4, 2026
@agentcore-devx-automation

Copy link
Copy Markdown
Contributor

Claude Security Review: no high-confidence findings. (run)

@agentcore-devx-automation agentcore-devx-automation Bot removed the claude-security-reviewing Claude Code /security-review in progress label Sep 4, 2026
@codecov-commenter

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 71.42857% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 96.97%. Comparing base (9be9780) to head (b83a66d).
⚠️ Report is 3 commits behind head on refactor.

Files with missing lines Patch % Lines
src/handlers/project/create/index.ts 71.42% 2 Missing ⚠️
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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@jariy17
jariy17 merged commit 81f5af2 into refactor Sep 4, 2026
18 checks passed
@jariy17
jariy17 deleted the fix/harness-name-truncation branch September 4, 2026 19:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size/s PR size: S

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants