Skip to content

fix(box): refuse build-owned target names on a Box gateway - #2864

Open
vvargu wants to merge 8 commits into
aws:box-integrationfrom
vvargu:box/fix-2839-reserved-target-names
Open

vvargu wants to merge 8 commits into
aws:box-integrationfrom
vvargu:box/fix-2839-reserved-target-names

Conversation

@vvargu

@vvargu vvargu commented Nov 19, 2026

Copy link
Copy Markdown

Description

This PR fixes a blocking item from the review of #2839 ("Box integration: review of merged PRs"):

A user target can take a name build owns (bedrock, agentcore, egress-*) and silently replace the agent's Bedrock or Memory route. add gateway-target should refuse those names on a Box gateway.

add gateway-target and add gateway-connector now refuse these names on a Box gateway:

  • The check is in ProjectManager.addResource, so the CLI and the TUI both get it.
  • It runs only for a gateway that isBoundGateway accepts. On other gateways, these names stay available.
  • reservedBoxTargetNameProblem (boxNetwork/network.ts) uses the existing constants BOX_GATEWAY_BEDROCK_TARGET_NAME, BOX_GATEWAY_AGENTCORE_TARGET_NAME and isManagedTarget. It does not copy the strings.

The error:

the gateway target name 'bedrock' is reserved on Box gateway '<gateway>': build writes the targets 'bedrock', 'agentcore', 'egress-*' for the agent's model, Memory, and egress calls. Choose another name.

The check is not in ProjectSpecSchema.superRefine. Build writes targets with these names into agentcore.json, so a name-only schema check would reject build's own targets.

This PR does not limit target types on a Box gateway. Box creates and routes only passthrough targets. A user can add any target type to the gateway, as #2839 allows.

Related Issue

None.

Documentation PR

Not applicable.

Type of Change

  • Bug fix
  • New feature
  • Breaking change
  • Documentation update
  • Other (please describe):

Testing

  • I ran bun test: 5335 pass, 6 skip, 1 fail. The failure is the box on PATH > resolves a profile into the rules the tests fake. It also fails on box-integration without this change, because the local box binary has no metadata_hosts rule.
  • I ran the relevant end-to-end tests with bun run test:e2e, or explained why they are not applicable
    (CI does not run them for you). Not run: the change is a local input check, and the unit tests cover it.
  • I ran bun run typecheck
  • I ran bun run lint:check
  • I ran bun run format:check
  • I ran bun run audit
  • I ran bun run secrets:check
  • I ran bun run build
  • If I modified src/assets/, I updated affected snapshots with bun test <test-file> --update-snapshots and committed them
  • If I re-recorded fixtures or golden files, every change beyond account identifiers is explained
    by this PR

New tests:

  • CLI: bedrock, agentcore and egress-api-example-com are refused on a Box gateway, and the gateway stays empty.
  • CLI: the same names are accepted on a gateway that is not a Box gateway.
  • CLI: a Box gateway with the targets that build writes passes ProjectSpecSchema, and a new target can still be added.
  • TUI: the wizard shows the error for bedrock on a Box gateway and writes no target.

add gateway-target (CLI and TUI) and add gateway-connector now refuse the
names 'bedrock', 'agentcore' and 'egress-*' on a Box gateway. Build writes
targets with these names. A user target with one of these names took the
agent's Bedrock or Memory route, or build changed or removed it.

The check is in ProjectManager.addResource, which both paths use. The same
names stay valid on a gateway that is not a Box gateway, and the targets
that build writes stay valid in agentcore.json.
@vvargu
vvargu requested a review from a team November 19, 2026 23:07
@codecov-commenter

codecov-commenter commented Nov 19, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 96.80%. Comparing base (e2ac9d7) to head (cb5bee7).
⚠️ Report is 12 commits behind head on box-integration.

Additional details and impacted files
@@               Coverage Diff                @@
##           box-integration    #2864   +/-   ##
================================================
  Coverage            96.79%   96.80%           
================================================
  Files                  766      766           
  Lines                66803    66856   +53     
================================================
+ Hits                 64665    64719   +54     
+ Misses                2138     2137    -1     

☔ 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.

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

Review of #2864: refuse build-owned target names on a Box gateway

Decision: APPROVE. All findings below are non-blocking.

Plan mapping. This PR is not one of the plan PRs. It is a standalone follow-up on box-integration that fixes a blocking item from the #2839 review. box-integration-development has no equivalent commit (I checked git log --grep and git grep for reservedBoxTargetName and the refusal text). So there is no commit list to check against the plan, and nothing is ported twice. The plan doc (https://pippin.amazon.dev/docs/XFRmP1pP9L90nl/box-integration-squash-and-pr-plan-v2) returned 401, so I checked against the branches directly.

Base and conflicts. The base is box-integration and GitHub reports the PR as MERGEABLE. The branch forks at dd36f7b2 (#2853), so #2857 is not in it. The diff is additive: five files, +135/-3, and the only lines removed are import lines. None of the box-integration-only fixes from #2845, #2848/#2849, #2850, #2851, #2852, #2853 or #2857 are touched or reverted. A trial merge of this branch with each of #2859, #2860, #2862 and #2863 is clean, with no textual conflicts.

CI. All checks are green: verify on Linux, Windows and macOS, Analyze, CodeQL, and CodeBuild agentcore-e2e. The GitHub e2e job was skipped, as usual.

What I checked

  1. Test coverage. It is good. The CLI test refuses bedrock, agentcore and egress-* on a Box gateway and checks that the gateway stays empty. It also checks the same names are accepted on a non-Box gateway. Another test checks that build's own targets still pass ProjectSpecSchema and that a new target can still be added. The TUI test covers the wizard error and confirms no target is written. There are no Windows-unsafe patterns: no paths, no sh, no file modes.
    • Nit: the PR body says add gateway-connector is covered, and it is, because toAddGatewayConnectorInput goes through addResource. No test pins it, though. One add gateway-connector --name bedrock case on the Box gateway would.
  2. Silent failures. The new check throws InputValidationError and nothing is swallowed. Projects that already have a user bedrock or agentcore target on a Box gateway, from before this PR or from a hand edit, still go through silently. placeTarget treats such a target as the user's and leaves it, so the agent's route goes to it with no warning. The PR body explains why the schema can't refuse these names. A build-time warning for a non-build-shaped bedrock/agentcore target on a Box gateway would close that gap. Optional, for a follow-up.
  3. Comment accuracy. The comments are accurate. For bedrock/agentcore, placeTarget keeps a same-named user target, so that target takes the route. For egress-*, boxNetwork drops unmanaged-claimed targets, so build rewrites or removes them. Both doc comments match that behavior.
  4. New types. None. reservedBoxTargetNameProblem returns string | undefined, like the existing *Problem helpers (targetHostProblem, policyFileProblem). It reuses the existing constants and isManagedTarget instead of copying the strings.
  5. General. See the inline comments. The main point is about agentcore/bedrock on a non-Box gateway in a Box project. It is non-blocking because the later failure is loud, and the cross-gateway duplicate-name case is covered by #2860.

Open items from earlier reviews (this PR does not address them, and doesn't need to)

None of these are in scope for this PR, and all stay open for later PRs: the network?.region ?? DEFAULT_EGRESS_BEDROCK_REGION fallback, the empty .venv getting past dev's Python check, the unreported credential refresh failure and the misspelled AWS_PROFILE, dev not applying the box.version rule, the "before anything is written" comment, the wrong refusal message after remove, the seven duplicated template files, the missing start.py test, 29d283d6's skipped telemetry targets, the missing local-profile tests for A2A/AG-UI/MCP, and #2859's silently empty profile.

Known flaky CI on the base is non-blocking: the Windows transactionSearch EFAULT test, and the occasional 5 s macOS screen-test timeouts.

`and egress calls. Choose another name.`,
InputValidationError,
);
// The same name is the user's on a gateway that is not a Box gateway.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Non-blocking. This test asserts that agentcore is accepted on the non-Box gateway tools in a Box project. Build then refuses that same project if a boxed runtime has the default Memory: addBoxMemoryTarget calls refuseTargetNameOutsideBoxGateways(spec, "agentcore", ...), which says "gateway 'tools' has a target named 'agentcore' ... Rename that target." So add accepts a name that the next build rejects. The failure is loud, not silent, but the PR body's line "On other gateways, these names stay available" doesn't hold for agentcore in a Box project.

Two options:

  • In addResource, also refuse agentcore on a non-Box gateway when projectType === "box", so add matches build's rule.
  • Keep the current behavior and say in the PR body or comment that build enforces the name project-wide.

bedrock on a non-Box gateway is a related case. Build then writes a second bedrock target on the Box gateway, and today's L3 output keys don't include the gateway name. #2860 (identifierOf, with L3 #470) already handles that case, so it isn't an issue for this PR.

const parent = projectSpec.agentCoreGateways.find(
(candidate) => candidate.name === input.gatewayName,
);
const reserved =

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Non-blocking nit. This only covers add. If a project already has a user bedrock/agentcore target on a Box gateway, from before this PR or a hand edit, placeTarget keeps it as "the user's", and the agent's model or Memory route goes to it with no message. A one-line build warning when the existing target is not the build shape would make that visible. Fine as a follow-up.

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

Thanks, the refusal of build-owned names works for add gateway-target, --target-configuration, add gateway-connector and the TUI, and it fails the CLI and TUI tests when removed. Requesting changes because this is the follow-up for the #2839 review, and two of its three items aren't in here yet:

  1. MCP, connector and Lambda targets on a Box gateway still get no Runtime route, so the boxed agent can't call them. Routing still keeps only passthrough targets (boxProfile.ts:627-629, and runtimeProfile/rules/gateway.ts:118-119 on box-integration). Either add a route for the gateway host and prove it with one e2e call, or bring back a passthrough-only check until then.
  2. boundRuntimeNote still checks boundRuntime directly (handlers/project/add/shared.ts:114-115) instead of isBoundGateway, and the two line builders in remove/notice.ts (removedGatewayLines and boundGatewayWarningLines) are still separate.

If you'd rather keep this PR to the name check, that's fine, just point at the follow-up that takes these two. A couple of things on the check itself inline.

Comment thread src/core/project/manager.tsx Outdated
(candidate) => candidate.name === input.gatewayName,
);
const reserved =
parent && isBoundGateway(parent)

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.

This gates on isBoundGateway, but build only writes bedrock, agentcore and egress-* targets for runtimes that runtimeRunsInBox accepts (boxMemory.ts:60-62, boxNetworkSource.ts:51). So a Box project runtime with no box.version, or a bound gateway outside a Box project, gets refused with "build writes the targets", which isn't true there. Could this gate on runtimeRunsInBox(projectSpec, boundRuntime)? The new tests run against a runtime from agent-typescript-vercel with no box.version, so they'd need one too.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 929cbe2. The check now refuses these names only on the Box gateway of a runtime that runtimeRunsInBox accepts. The tests give the runtime a box.version. A new test adds each name on a bound gateway whose runtime has no box.version, and it accepts them.

Comment thread src/core/project/boxNetwork/network.ts Outdated
* rewrite or remove it.
*/
export function reservedBoxTargetNameProblem(name: string, gateway: string): string | undefined {
if (!BOX_DEFAULT_TARGET_NAMES.includes(name) && !isManagedTarget({ name })) return undefined;

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.

Heads up, this conflicts with #2877, which changes isManagedTarget to take a full target and require build's shape, so isManagedTarget({ name }) won't compile after it. #2877 also stops build removing a user's egress- target, so half of the reason in the comment above goes away. Whichever merges second needs a plain check like name.startsWith(BOX_EGRESS_TARGET_PREFIX). Also small: boxMemory.ts already owns two of these three names and imports isBoundGateway, so this helper would sit better there than in the network model.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in e6376c9. The helper is now in boxMemory.ts and uses name.startsWith(BOX_EGRESS_TARGET_PREFIX), so #2877 can change isManagedTarget. The import from boxNetwork/egress makes no runtime import cycle. The comment now gives only the route reason and the name reason.

).toEqual(["bedrock", "agentcore", "egress-api-example-com"]);
});

test("keeps the targets build writes on a Box gateway valid", async () => {

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.

This one passes with the new check removed, so it doesn't test this PR. It guards a schema rule the PR didn't take. If it's wanted, it belongs in project.test.ts.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 5461f2f. No schema test covered these targets, so I moved the test to project.test.ts as a schema test. I removed it from index.test.ts.

await writeProjectSpec(projectRoot, { ...spec, projectType: "box", agentCoreGateways: [box] });
await addGateway();

for (const name of ["bedrock", "agentcore", "egress-api-example-com"]) {

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.

Small one: three names in one loop share the tools gateway's state across iterations. A test.each over the names would match the rest of the file and say which name failed.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 1a231a0. The tests now use test.each over the three names, with a new project for each name.

# Conflicts:
#	src/core/project/boxNetwork/network.ts
The check now tests the egress- prefix with a plain startsWith, so it does
not depend on the signature of isManagedTarget. boxMemory already owns the
bedrock and agentcore names and imports isBoundGateway. The import of
BOX_EGRESS_TARGET_PREFIX from boxNetwork/egress makes no runtime import cycle.

The comment now gives only the reason that stays true: a user target of such
a name takes the agent's Bedrock or Memory route, or the name of an egress
target that build writes.
…s in a box

Build writes the bedrock, agentcore and egress- targets only on the Box
gateway of a runtime that runtimeRunsInBox accepts. The check gated on
isBoundGateway, so it also refused these names on a bound gateway whose
runtime does not run in a box, with a reason that is not true there.

The tests give the runtime a box.version, and a new test adds the three
names on a bound gateway whose runtime has no box.version.
The refusal and acceptance tests now use test.each over the three names, with
a new project for each name, so a failure names the target name and no state
carries over from another name.
The test that build's bedrock, agentcore and egress- targets stay valid on a
Box gateway tests ProjectSpecSchema, not add gateway-target: it passed with
the name check removed. It is now a schema test in project.test.ts, where no
test covered these targets before.
The wizard note now asks isBoundGateway whether a gateway is bound, as the
rest of the code does, and does not check boundRuntime itself.
… function

removedGatewayLines and boundGatewayWarningLines were near copies. One
function, boundGatewayLines, now makes both: the lines before the removal
name each bound gateway and its targets, and the lines after it name each
removed gateway and its target count. The text does not change. A new unit
test pins each form for zero, one and more targets.
@vvargu

vvargu commented Nov 21, 2026

Copy link
Copy Markdown
Author

Item 2 is fixed in 7cb96da and cb5bee7. boundRuntimeNote now uses isBoundGateway. One function, boundGatewayLines, now replaces the two line builders in remove/notice.ts. The text does not change, and a new unit test checks each form.

Item 1 is by design. By default, box creates and routes only passthrough targets. A user can add any target type to the Box gateway, which is why #2839 removed the limits. Since #2866, build derives the Runtime box profile from the local box profile of each runtime. Thus the user sets the routes of the boxed agent there.

This branch also merges the current box-integration.

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

Re-review of #2864 at cb5bee7

Decision: APPROVE. Everything below is non-blocking.

Scope. I approved this PR at 1661e23. This review covers the new commits 65b494f..cb5bee7. I left out the base content that the merge 65b494f brings in. To do that, I compared the net diff box-integration...pr (10 files, +229/-40) with the diff at 1661e23.

Base and CI. The branch now includes #2883. It is 6 commits behind box-integration, at #2885, and has no conflicts, so that is not blocking. All checks pass: verify on Linux, Windows and macOS, Analyze, CodeQL, and CodeBuild agentcore-e2e. The GitHub e2e job was skipped, as usual.

Review comments that are now addressed

  • Gate on runtimeRunsInBox (929cbe2). reservedBoxTargetNameProblem now refuses a name only when the gateway is bound and its boundRuntime is one of boxedRuntimes(spec). That is the same set of runtimes that build writes bedrock, agentcore and egress-* targets for. A gateway binds to only one runtime. So in a project that has both boxed and non-boxed runtimes, each gateway goes by its own runtime, and there is nothing to break a tie between. An unbound gateway is never refused. A new test.each checks that the names are accepted on a bound gateway whose runtime has no box.version.
  • Dependency on isManagedTarget (e6376c9). The check now lives in boxMemory.ts and uses name.startsWith(BOX_EGRESS_TARGET_PREFIX), so #2877's change to the isManagedTarget signature no longer breaks it. boxNetwork/egress.ts imports only zod and types, so the new import creates no cycle.
  • A test that passed without the check (5461f2f). That test is now a schema test in project.test.ts. It checks that the bedrock, agentcore and an egress- passthrough target that build writes all pass ProjectSpecSchema on a Box gateway, so build's own output is not refused. The refusal itself is in add (FsProjectManager), not in the schema, so a hand-edited agentcore.json still validates.
  • State shared across names (1a231a0). The tests now use test.each over the three names, with a new project for each one.
  • TUI refactors (7cb96da, cb5bee7). Both keep the old behavior. isBoundGateway is boundRuntime !== undefined, which is the same as the old inline check. boundGatewayLines tells the two inputs apart with "targetCount" in gateway. It keeps the old removedGatewayLines behavior: no filter, and the target count. It also keeps the old boundGatewayWarningLines behavior: a filter on boundRuntime, and the target names. The text is the same, and the new notice.test.ts checks both forms with zero, one and several targets.

Merge 65b494f and fixes that must survive

The PR's net diff against the base only adds lines in boxMemory.ts (an import plus the new helper) and in manager.tsx (the import plus the check in addResource). #2883's partition-aware Memory and Bedrock ARNs and its DNS suffixes are unchanged. The PR does not touch boxNetworkWriters, boxProfileCredentials, ENV_LOCAL_RELATIVE_PATH, writesBedrockRoute/tomlKey, the X-Ray grants, runtimeRunsInBox, the per-runtime profiles, --containment, enableApplicationLogs or the #2885 OTEL changes. No fix is lost.

Consistency with #2877 (still open, so this is about merge order and does not block)

  • The reserved names are bedrock, agentcore and every name that starts with egress-. #2887's egress-gateway-<name> targets fall under that prefix.
  • #2877 records build's targets in agentcore/box-gateway-targets.json, and build then keeps a user's egress-* target as the user's. That does not contradict this PR. #2877 makes build safe for an egress-* target that already exists or was edited by hand. This PR stops add from creating a new one, so a user target cannot take the name of a target that build writes. Once #2877 merges, the reason in the doc comment ("the name of an egress target that build writes") is still true.
  • With #2877 merged, the refusal is a policy choice: it is stricter than build needs. A one-line note in the PR body or the doc comment would help readers. It would say that hand-written egress-* targets still work under #2877, and that add refuses the prefix only to avoid name collisions.

Trial merges (FYI)

  • With #2877 and with #2886: clean.
  • With #2887: one textual conflict, in the manager.tsx import block. This PR adds import { reservedBoxTargetNameProblem } from "./boxMemory" and #2887 adds isManagedTarget to the ./boxNetwork import. Keep both lines.

Still open, non-blocking (from my earlier review)

  • No test pins add gateway-connector --name bedrock on the Box gateway.
  • If a project already has a user bedrock or agentcore target on a Box gateway, from before this PR or from a hand edit, build still uses it silently. A build warning would fix this, in a follow-up.
  • In a Box project with a boxed runtime that has the default Memory, add accepts agentcore on a non-Box gateway, but build later refuses it, with a clear error. See the inline comment.
  • Small point: the check refuses bedrock even for a runtime that does not call Bedrock (MCP), and agentcore for a runtime with no default Memory. Build would write neither target there. Being conservative keeps the rule simple, so this is fine.
  • The open items from earlier box reviews that I listed at 1661e23 are still out of scope.

Other checks. The new tests have no Windows-unsafe patterns: no host paths, no splitting on :, no file modes, no sh or python3, and no network. The diff and the PR's own commit messages contain no internal references or account IDs. The Co-authored-by lines in the range come from base commits brought in by the merge. box-integration-development does not have this change yet. A back-merge is needed there, but that does not block this PR. The squash-plan doc returned 401, so I checked against the branches directly.

Known flaky CI on the base does not block: the Windows transactionSearch EFAULT test, and the occasional macOS screen-test timeouts.

): string | undefined {
const boxed = boxedRuntimes(spec).some((runtime) => runtime.name === gateway.boundRuntime);
if (!isBoundGateway(gateway) || !boxed) return undefined;
if (!BOX_DEFAULT_TARGET_NAMES.includes(name) && !name.startsWith(BOX_EGRESS_TARGET_PREFIX)) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Non-blocking, about merge order with #2877. After #2877, build keeps a user's egress-* target as the user's, by its record in agentcore/box-gateway-targets.json. So this prefix check stays only as a guard against name collisions with the targets build writes, and #2887's egress-gateway-<name> targets are covered. The two PRs are consistent. A short note here, or in the PR body, would help readers: it would say that hand-written egress-* targets still work after #2877, and that add refuses the prefix only for new targets.

`and egress calls. Choose another name.`,
InputValidationError,
);
// The same name is the user's on a gateway that is not a Box gateway.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Non-blocking, carried over from my last review. Here add accepts agentcore on tools in a Box project whose runtime is boxed. If that runtime has the default Memory, build later refuses the project through refuseTargetNameOutsideBoxGateways. The error is clear, so this is fine. Making add and build agree on this would be good in a follow-up.

This branch has not been deployed

No deployments
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