Repository navigation
fix(box): Address the review of the host map and the gateway targets - #2877
Conversation
…d on one path The host map decides each host on sample requests. A sample path comes from one path test at a time. A permit with two path tests, such as `path like "/v1/*"` and `path like "*/items"`, got no sample that passes both. The host was then unreachable, with no failure, and build gave it no gateway target, but Box allows GET /v1/items. When no sample request is allowed, the host map now searches for a path that the path tests of a permit allow together and that no forbid surely denies (pathSolver.ts). The search is exact for `like`, `==`, and `!=`. When the search is too large (more than 4096 states), the host stays reachable, the permit goes in `uncheckedBy` and `enforcedByBox`, and build gives a warning that names the rule. Tests: hostMap.test.ts "finds a host reachable when two path patterns of one permit hold on one path", "finds a path of a permit that a forbid of one path leaves open", "finds no path when the path patterns of a permit never hold together", "keeps a host reachable, and names the permit, when its path tests are too many to check"; network.test.ts "names a permit whose path tests build cannot check together, and keeps its host". The random-rule property test still passes. Mutations: no search, a search that ignores the forbids, and no state limit each make a test fail.
Box reads a rule as Cedar types it: it does not read the right operand
of `||` after an action test that holds, the right operand of `&&`
after one that does not, the other branch of `if`, or a later `when`
after an action test that is false. So box 0.1.11-preview.10 accepts
`permit (principal, action == Box::Action::"net:connect", resource)
when { context.input.host == "a" && (action == Box::Action::"net:connect"
|| context.input.method == "GET") }`. The host map read every operand,
refused the rule with UNKNOWN_ATTRIBUTE, and build stopped.
checkAttributes now skips each operand that an action test keeps from
the action (actionValue), and clausesFor stops at a condition that an
action test makes false. A field that no action test keeps from the
action is still refused.
The review's own example puts http:request and net:connect in one rule.
Box 0.1.11-preview.10 refuses that rule for another cause (it reads
context.input under two action families), so the tests use the forms
that box accepts.
Tests: hostMap.test.ts "an attribute that an action test keeps from the
action, as Box reads it" (6 tests: `||`, `&&` with `!=`, `if`, a request
rule that reads ip4, a later `when`, and the refusal of an unguarded
field). Mutations: no `&&`/`||` stop, both `if` branches read, and every
condition read each make a test fail.
…rules Box applies A host's enforcedByBox named the request permits that limit a host and the forbids, but no connection permit. A permit that allows connections to a host only at some addresses (`context.input.ip4 like "10.*"`) is a limit that Box applies and the gateway does not. Build gave no warning for it. The host map now names each connection permit of a reachable host whose every clause there limits the address or has a condition build cannot read. A connection permit with a clause that allows any address is not named. The review's example used `ip(context.input.ip4).isInRange(...)`. Box 0.1.11-preview.10 refuses that form (ip() takes only a literal, and ip4 is a string), so the test uses the form that Box writes itself. Tests: hostMap.test.ts "names a connection permit that limits the address, and not one that allows any". Mutations: no connection permits named, and every connection permit named, each make a test fail.
The host map took the port that a rule fixes (`context.input.port == 65536`, `== 0`, or `== -1`) with no check. Box accepts such a rule, which never holds, but build made a host of `host:65536` and wrote a gateway target for an endpoint that is not a URL. The host map now refuses each rule that fixes a port that is not an integer from 1 to 65535, with the new failure code INVALID_PORT, at the rule's line. A destination of an [egress] entry already had this check (parseDestination). Tests: network.test.ts "fails each rule that names port %d, which is not a port" (65536, 0, and -1, for a connection and a request rule). Mutations: an upper bound of 65536 and a lower bound of 0 each make a test fail.
…asts of the profile parser Box 0.1.11-preview.10 wraps its error at 80 columns. It wraps at a space or inside a word, and starts each next line with 12 spaces. The uv sync hint took the venv path from one line, up to the last space. For a project path with a space, or a path that Box wrapped, the hint named a wrong folder, such as "Run 'uv sync' in agent" or "in /agent". The hint now joins the lines of each Box error in each way (a space or no space at each wrap, up to 8 wraps). It names the folder only when one way gives a folder that is on disk. It quotes a folder that has a space. When no way, or more than one way, gives a folder, the error says "Fix what Box reports". The profile parser and the telemetry reader now use the shared Date-aware isTable of runtimeProfile/projectPaths.ts, TomlError for the place of a TOML syntax error, and type predicates in place of casts. The section banner comments of hostMap.ts and dogwood.ts are removed. Tests: boxProfileResolver.test.ts "the uv sync hint, when Box refuses a missing .venv under a write grant" (5 tests: one line, a wrap at a space in "my agent", a wrap before "/agent", a wrap inside a word, and a path of no folder). A run of box 0.1.11-preview.10 on a project in "/tmp/rf/venv test/proj with space" and on a long path gave the right folder. profileParser.test.ts "places a TOML syntax error at its line and column" pins the TomlError place. Mutations: no space at a wrap, no check on disk, and no quotes each make a test fail.
…has its route rule's @id Box adds the rules route_<name>_connect and route_<name>_request for each [egress.<name>] route, and refuses a profile in which another rule has one of those @ids. The AgentCore Runtime profile names some routes after their gateway target: each other host of an entry (`egress-models-two`), a host that only a rule names, and an entry whose name a target of another host has (`egress-api`). A rule of the user's policy with the @id `route_egress-api_request` is valid locally, but box 0.1.11-preview.10 refused the Runtime profile: "box writes a rule with the id ... so give your rule another id". The gateway rule now gives each such route the first free name of `<name>`, `<name>-2`, `<name>-3`, and so on: a name for which no rule of the local policy, other than the route rules that Box adds itself, has the @id route_<name>_connect or route_<name>_request, and that no other route has. The Box network model gives the derivation these @ids (RuntimeProfileContext.ruleIds). The route still sends its calls to the same gateway target. Tests: gateway.test.ts "names no route so that box adds a rule with the @id of a rule of the policy" (an entry whose route takes the name of its target, and another host of an entry past a name that another route has), and "give a route a free name when a rule of the policy has the @id of its route rule" through buildBoxNetwork. Box 0.1.11-preview.10 refused [egress.egress-api-b-example-com] beside the rule route_egress-api-b-example-com_request (exit 1), and accepts [egress.egress-api-b-example-com-2] beside it (exit 0). Mutations: no check of the rule ids, no check of the other routes' names, and no rule ids from the model each make a test fail.
…her variable `env://GITHUB_TOKEN` and `env://AGENTCORE_CREDENTIAL_GITHUB` both resolve to the API key credential `github`. The Box network model compared the two variable names, found them different, and failed the build and the deploy with API_KEY_CREDENTIAL_SHARED. The same comparison across two runtimes (sharedKeyFailures) failed in the same way. But the two names give one key: build copies the key of `GITHUB_TOKEN` to `AGENTCORE_CREDENTIAL_GITHUB`, the credential's own variable (`seed` in planBoxProfileCredentials), and deploy reads it from there. Both checks now skip an entry that reads the credential's own variable. Two entries that read two other variables for one credential still fail, because the credential can hold only one of the two keys. Not changed: on the first build, before the credential `github` is in agentcore.json, an entry that reads AGENTCORE_CREDENTIAL_GITHUB names the credential after its own entry. Its target is then not written until the next build. Tests: network.test.ts "takes one credential for its own variable and for one other variable, which build copies to it" (in both orders; it replaces the test that pinned the failure); boxNetworkSource.test.ts "takes the credential of another runtime for the credential's own variable". network.test.ts "fails a server that takes the API key credential of an [egress] entry for another variable" still pins the real conflict. Mutations: raw names in the model, raw names across runtimes, and no conflict at all each make a test fail.
…el-provider route its credential
A host whose target sends an API key that no credential of
agentcore.json holds got no gateway target. Build said so only as a
step ("not adding gateway target ..."), not as a warning, and the agent
could not reach the host on AgentCore Runtime. For a model-provider
route that `agentcore create` writes with no key ([egress.openai] with
env://OPENAI_API_KEY, and the same for Anthropic and Gemini), the
credential planner skipped the route with no message. Thus "set the
key and build again" did not work for these routes: build never added
their credential, so their target never came.
This change ports the rule of box-integration-development: a
model-provider route is a route like any other. On AgentCore Runtime its
gateway target sends the key of its credential, so the planner declares
the credential `openai` and stores the key of OPENAI_API_KEY under
AGENTCORE_CREDENTIAL_OPENAI, when that key is set. The planner also
records, for each route that gets no credential, why and what to do
(BoxCredentialPlan.unprovisioned). Build gives a warning for each host
with no target (unsentTargetWarnings): the host, the entry, that the
agent cannot reach it on AgentCore Runtime, and the planner's cause and
fix. The step stays only when build removes a target that agentcore.json
had.
Tests: manager.boxNetwork.test.ts "writes no target for an env:// route
whose key build cannot find, and says what to set", "stages no Runtime
[mcp] server for an HTTP MCP server whose key build cannot find", and
"writes the target of a model-provider route once its key is set, as
the warning says" (the fix of the warning works for OpenAI);
boxNetworkWriters.test.ts "unsentTargetWarnings" (3 tests);
boxProfileCredentials.test.ts "adds a credential for a model-provider
route create writes, from the provider's variable" and "adds a
credential for a route that uses a model-provider name or variable in
another way" (these replace the two tests that pinned the skip).
Mutations: the provider skip put back, no warnings, and no cause for an
unset key each make a test fail.
…nd remove casts and copies
Four smaller items of the review of the Box gateway targets:
- Two box runtimes that stage box in one folder (two CodeZip runtimes
with one code folder, or a container runtime whose build context is
the code folder of another) made staging stop with a programmer error:
"Box network writers 'runtime profile' and 'runtime profile' both
write {...}/.box-dist/profile.toml". ProjectSpecSchema now refuses
them, with the two runtimes and the folder, however the path is
written (`./app/agent` and `app/agent/`).
- network.ts imported boxGatewayAgentCoreHost from
src/handlers/project/shortcuts.ts. The function is now in
boxNetwork/egress.ts, beside the other AWS endpoint names, and
shortcuts.ts imports it from there.
- boxNetworkSource.ts read an IAM policy document through `as` casts.
It now parses the document and each Allow statement with zod, and
uses the shared isTable. The other casts there are gone.
- boxCodeZip.ts and boxContainer.ts each had a copy of the step that
writes the Runtime profile into the staged folder and into
.box/<name>/aws/. Both now use stagedRuntimeProfiles in
boxStaging.ts, in the same order as before.
Not done here: the box model is still on the generic ProjectBackend
input (backends/types.ts `boxNetworks`), and boxNetworkSource.ts still
imports DEFAULT_EGRESS_BEDROCK_REGION from src/handlers/. Both need the
Box gateway constants out of shortcuts.ts, which is an item of
[aws#2789](aws#2789).
Tests: project.test.ts "Box runtimes and the folder build stages box
in" (3 tests); boxNetworkSource.test.ts "counts the actions of an Allow
statement in each form IAM takes, and of no other". The staging,
network, and manager suites pass with no change. Mutations: no folder
rule, no path normalization, and any Effect counted each make a test
fail.
…a user's egress- target Build took each gateway target whose name starts with `egress-` as its own, by the name alone (isManagedTarget, writeGatewayTargets, and the gateway rule of the Runtime profile). So it changed or removed a target that a user added with that name, and stopped on one with another shape (MANAGED_TARGET_CHANGED). Build now records, in agentcore/box-gateway-targets.json, the targets that it writes for each Box gateway, by the gateway's name. It owns only the targets in that record: it adds, rewrites, and removes them, and it keeps each other target, whatever its name. MANAGED_TARGET_CHANGED now applies only to a recorded target, and it says to remove the name from the record to keep the target. The Box network model gives the writers and the Runtime profile one set of the targets build owns (BoxNetwork.managedTargets). A project that an older CLI built has no record of its gateway. For such a gateway, build takes as its own each `egress-` target that has exactly the shape build writes (a CUSTOM passthrough target to an https:// host, with one of the outbound auths build writes), once, and then writes the record. It keeps an `egress-` target of another shape as the user's. A target that build wrote and the user then changed is thus the user's. The record is a file beside agentcore.json and not a field in it: the L3 schema of agentcore.json is strict, so a new field stops synth until the L3 takes it. A malformed record stops build, names the file, and says to remove it. Tests: network.test.ts "the targets build owns" (4 tests); boxNetworkWriters.test.ts "keeps a user's egress- target that the record does not name, and records the targets it writes" and "records no file for a project with no box runtime"; boxNetworkSource.test.ts "the record of the targets build writes" (3 tests); manager.boxNetwork.test.ts "owns only the targets it records, after it takes its old egress- targets once", which also checks the route of the Runtime profile. manager.test.ts expects the new step "writing agentcore/box-gateway-targets.json". docs/box-local-testing.md says the new rule. Mutations: the record not read, every egress- target taken in an old project, and no owned set for the Runtime profile each make a test fail.
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## box-integration #2877 +/- ##
===================================================
+ Coverage 96.87% 96.89% +0.02%
===================================================
Files 774 776 +2
Lines 68750 69352 +602
===================================================
+ Hits 66599 67202 +603
+ Misses 2151 2150 -1 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
leo237
left a comment
There was a problem hiding this comment.
Thanks for this — careful work. Each fix is its own commit with a test that fails first, and the PR body says what you checked against Box 0.1.11-preview.10. I read all 11 commits against box-integration (the branch is up to date with base).
Blocking: none. The one CI failure on 8942a80 (CodeQL js/incomplete-url-substring-sanitization at manager.boxNetwork.test.ts:394) is fixed by c065a0a, which compares the host exactly. The bot's thread is now outdated but still unresolved, and the ruleset requires every thread to be resolved, so please resolve it once Analyze/CodeQL pass again on the new head.
What I checked, and found correct
pathSolver.ts: the BFS over the product of thelikeautomata is correct for Cedarlike.*matches any run of characters, including none, and matching is case-sensitive. One stand-in character for every character the patterns do not name is enough. The visited set makes the search finish. At the 4096 bound, the search stops undecided and lets the host through, not drops it.decidethen keeps the host reachable, and puts the permit inuncheckedByandenforcedByBox.buildBoxNetworkwarns with the rule's place. Tests exist for the 13-pattern case and for that warning (network.test.ts:1069). A path that a forbid has unreadable conditions for is still taken as reachable. That matches how sample requests worked before. Each path the solver finds is run throughconsider()again, so the solver cannot add a request that the policy does not allow.conditions.ts: the short-circuit incheckAttributes/actionValue(and||/&&/if, and stopping at a laterwhenthat an action test makes false) matches Cedar's evaluation order. The tests cover each form, and one negative case.INVALID_PORT, thelimitsConnectionIP case, the free-2route names (routeKeysskips both a policy@idand the key of another route), the reserved-variable alias (in the model and insharedKeyFailures), the warnings for a host with no target, and the move ofstagedRuntimeProfiles: each looks correct and has a test. TheboxCodeZip/boxContainersteps keep the same order.- Target record: a missing file uses the old
egress-+ build-shape rule once. A file that is not valid JSON, or does not match the schema, stops with aProjectStateErrorthat names the file and says to remove it, and a test covers this. Build rewrites the record from all box runtimes each time, so a gateway that has gone falls out of it. - All the must-survive fixes I checked are still in place (
ENV_LOCAL_RELATIVE_PATH,writesBedrockRoute/tomlKey,runtimeRunsInBox/assertBoxRuntimesHaveBoxVersion,boxStartFolder,.venv/bin/python,upsert,publishInstall,BOX_OTHER_MACHINE_HINT, the0.1.11-preview.10pin,--no-same-owner,--containment,enableApplicationLogs/enableTraces).verifypasses on Linux and Windows. The new tests use temp folders and no unsafe patterns.
Non-blocking
- Back-merge to
box-integration-development. None of these fixes are on dev yet (findPath,BOX_GATEWAY_TARGETS_FILE,INVALID_PORT,routeKeys,unsentTargetWarnings,boxFolderOf, the alias rule). Only d0f9523's planner rule was already there. Dev still takes ownership from theegress-prefix, so the record design has to land on dev too, or the next phased squash brings the old behavior back. - Item 9 design (you asked). The record file seems right to me, given that the L3 schema is strict. Two suggestions, inline: (a) on the one-time migration, a target named
egress-*whose shape differs is now kept as the user's with no message. Before, it was aMANAGED_TARGET_CHANGEDfailure. A one-time step such as "keeping 'egress-x' as your target: its shape is not one build writes" would make that visible. (b) The docs should say to commitagentcore/box-gateway-targets.json. A clone without it falls back to the heuristic. - pathSolver has no direct unit tests. It is tested only through
hostMap, which coverslikein a permit and==in a forbid. Small table tests forfindPath/pathTestwould pin!=, negatedlike,present,==in a permit, and thefreeCharfallback when§is a literal. - Schema refinement (
project.ts): it is correct, and the error message is clear. Note that it now stops every command for a project that already has two box runtimes in one folder. That project could not stage anyway, so it is fine. On a case-insensitive file system,Appandappstill pass. - Follow-ups / "2 items stay". The PR lists the follow-ups (first-build
AGENTCORE_CREDENTIAL_*naming; the box model onProjectBackendplus theDEFAULT_EGRESS_BEDROCK_REGIONimport, which depend on #2789; the release repository text in the docs), but there is no issue for them. Please file one or link it, so they are not lost. None of them blocks this PR. - CI: I posted while
verify(Linux/Windows/macOS) andAnalyzewere still running on c065a0a. The only change since 8942a80 is that one test line. On 8942a80, Linux, Windows, Analyze, and CodeBuild e2e passed, and macOS was still pending. Please merge only after they pass. Nit: c065a0a usesw.split(":", 1)[0]. That works for this host, but it would fail for ahost:portauthority.w.startsWith("api.openai.com:")would hold for both.
…t on pathSolver.ts
…eps as the user's, for the review comment on network.ts
…review comment on box-local-testing.md
tejaskash
left a comment
There was a problem hiding this comment.
Thanks for the thorough pass, the per-item commits with a failing test each made this easy to check. Twelve of the items are fixed and each test fails when its fix is reverted. Requesting changes for the regression in conditions.ts and the egress- first-build case (inline), plus a few smaller ones.
Also still open and not claimed here, fine as follow-ups: Dockerfile text matching (backends/boxStaging.ts:38, backends/boxContainer.ts:26, :30, :38), the box model on the generic ProjectBackend interface (backends/types.ts:14), boxNetworkSource.ts:17 importing DEFAULT_EGRESS_BEDROCK_REGION from handlers, and build and deploy rewriting files on every run, which now includes agentcore/box-gateway-targets.json.
…n, for the review comment on conditions.ts line 130
leo237
left a comment
There was a problem hiding this comment.
Re-review of the three commits since my approval at c065a0a (2d3ef4a, 40116bd, 0628b15). The new code looks right. I'm leaving a comment rather than approving again only because of the merge state.
Blocking (merge state, not code)
- The branch is one commit behind
box-integration(e2ac9d7, #2870), and that commit conflicts with this PR indocs/box-local-testing.md. While the PR conflicts, no checks run on 0628b15 (0 check runs, status pending), so none ofverify,Analyze, or CodeQL has run on the new head. Please rebase or mergebox-integration, fix the conflict in the doc, and merge once CI is green.
Addressed
- pathSolver tests (2d3ef4a).
pathTesthas a table forlike,!(like),==,!(==),!=,!(!=),has, and!(has).findPathhas tests for!=and a negatedlikein a permit, a forbid, no path, the 4096-state bound, and the free character. The free-character test is useful:never("/§*")andnever("//*")make the expected result/\uE000, so a solver that fell back to§would fail it. On the non-string!=: your reply (Box rejectspath != 5at load, and the condition reader makes no path test from a number) is enough for me. - Migration warning (40116bd). It fires only when the record does not name the gateway (
recorded === undefined), the target is namedegress-*, andunmanagedShapereturns a reason. That is exactly the set thatisManagedTargetleaves to the user. A target whose shape matches gets no warning and build adopts it. The writer records every Box gateway, with an empty list if it has no targets, so the next build has a record and the warning does not repeat. The message says what to do, and both the positive and the negative case are tested. - Docs (0628b15). The path matches
BOX_GATEWAY_TARGETS_FILE, and the doc says what a clone without the file does. This text is the hunk that now conflicts with #2870, so please keep it when you resolve the conflict. - The CodeQL bot thread is now resolved.
Still open (non-blocking, from my earlier review)
- Back-merge to
box-integration-development. Dev still has nopathSolver.tsand noBOX_GATEWAY_TARGETS_FILE, and it still takes ownership from theegress-prefix. - The listed follow-ups ("2 items stay") still have no issue. Please file one or link it.
- Nit:
w.split(":", 1)[0]vsw.startsWith("api.openai.com:")inmanager.boxNetwork.test.ts.
Other
- tejaskash's 7 review threads are still unresolved. The ruleset requires every thread to be resolved, and the
conditions.ts:130thread (a temporal or guardrailswhenbefore a hostwhen) is a correctness claim, so it should be answered before merge.
…ate and add runtime, for the review comment on network.ts line 304
…times read, for the review comment on boxNetworkSource.ts line 168
…is build adds, for the review comment on boxNetworkWriters.ts line 341
…nd the warnings from the written spec, for the review comment on boxNetworkWriters.ts line 214
…for the review comment on conditions.ts line 307
…he review comment on network.ts line 377
leo237
left a comment
There was a problem hiding this comment.
Re-review at eddef5f (since our approval at 9180136).
What changed. The only new commit is eddef5f, a merge of box-integration that brings in #2878 and #2886. No PR code changed beyond resolving the conflicts. The PR has no conflicts with its base now (merge base is 2f9422d, the tip of box-integration).
How the merge was resolved (checked with git show --remerge-diff eddef5f). There were four conflicted files, and each was resolved correctly:
backends/boxCodeZip.ts: takes #2886's singleawait box()for the pinned release in place of the per-versionbuildsmap, and keeps this PR'sstagedRuntimeProfiles/writeProfile(stage). Nothing from the removed per-version code is left behind.backends/boxContainer.ts: takesboxReleaseEnv(BOX_RELEASE)in place ofreleaseFor(runtime.box?.version), and keepswriteProfile(stage)and thestagedRuntimeProfilesimport. The unusedruntimes[index]lookup is gone.manager.boxNetwork.test.ts: keeps both import sets (BOX_RELEASEandFS_RECORD_FILES/EnvLocalFile).docs/box-local-testing.md: keeps this PR's record-file paragraph and the model-provider sentence. The base side was only a reflow of the same bullets, so no base content was dropped. Nit: that section keeps the old wrapping, and one line of the Failures bullet now runs past the column width. Re-run the formatter if the docs check flags it.
Earlier notes. None were addressed in this push, and I don't expect them to be, since it is a merge only. All of them stay non-blocking and I'm not repeating them inline:
- The stale
//comment above thecommitSpecJSDoc (nowmanager.tsx:1420-1421). - The
boxRouteKeyHeldElsewhereJSDoc still has the model-provider sentence, which belongs onplanBoxProfileCredentials. - The record is still written with a plain, non-atomic write (pre-existing).
- The record still does not cover #2887's
egress-gateway-<name>targets. #2887 is not merged and there is noegress-gatewaycode in this PR.
Review areas.
- Tests: no new logic, so no new tests are needed. The two record-restore tests are unchanged.
- Silent failures: none introduced.
- Comments: the new
stagedRuntimeProfilesJSDoc is accurate. - New types: none.
- General: the resolution is minimal and correct.
FYI (not blocking): #2887 (head fa87fb5) and #2889 (head 84e0efa) haven't changed and still conflict with this head (manager.tsx, boxNetworkWriters.ts, network.ts, manager.boxNetwork.test.ts, docs, and others). Whichever merges second will need a rebase.
CI: when posted, verify / macOS passed, e2e was skipped, and verify / Linux, verify / Windows and Analyze were still pending. Approval assumes CI passes.
Squash plan for context: https://pippin.amazon.dev/docs/XFRmP1pP9L90nl/box-integration-squash-and-pr-plan-v2
tejaskash
left a comment
There was a problem hiding this comment.
Comment, not a new approval. The write-failure follow-up from our approval at eb8673a8 is fixed. Before merge, the branch needs current box-integration (11 files conflict after #2887 and the v1.x merge #2902), and these should be handled:
- The #2887 gateway targets need to be in the record when you merge.
box-integrationnow writesegress-gateway-<name>targets (src/core/project/boxNetwork/projectGateways.ts:33-47) and owns them by theegress-prefix, which this PR replaces with the record (managedTargetsOf,recordOf). If the merge does not add them tomanagedTargets, the next build treats them as the user's and never updates or removes them. Add them, and one test that builds twice with a called gateway removed in between. - A user's
egress-*target can be deleted (src/core/project/boxNetworkWriters.ts:281-284). When one runtime of a multi-runtime project loses itsboxfield for a while,readBoxNetworks()leaves it out and the record is replaced without its gateway. Whenboxcomes back, the gateway is treated as legacy and adopts shape-compatible useregress-*targets, and a later build deletes those that are not in the profile (reproduced with an unownedegress-mine). Keep the records of gateways outside the current models, and remove entries only when their gateway is removed. - A rotated key can be deployed stale (
src/core/project/boxNetwork/network.ts:437-440).[egress.github]readingAGENTCORE_CREDENTIAL_GITHUBand[mcp.github]readingGITHUB_TOKENare now accepted for onegithubcredential, butenvRoutesOf()still dedupes by route name and drops the MCP alias. The planner then skips that route, so a rotatedGITHUB_TOKENis never copied and deploy uses the old stored key with no warning. Keep distinct (route, variable) pairs within each network. - Smaller:
manager.tsx:1780reads and patches agentcore.json after the record write and outside thetryat:1788, so a failed read leaves the stale record the fix meant to prevent. Move the read and the patch abovereplaceRecord.
…gets and the record, and let remove gateway remove only a target that build owns
…'s review item on the PR 2887 targets
leo237
left a comment
There was a problem hiding this comment.
Re-review at 4d165b2 (since my approval at eddef5f).
What changed. There are two new commits. cf76c2c merges box-integration (#2887 and the v1.x merge #2902). 4d165b2 puts the #2887 gateway targets in the record. I checked the merge with git show --remerge-diff cf76c2c. Thirteen files conflicted, and each one keeps both sides. BoxNetwork has both projectGateways and managedTargets. The kept count in hostTargets uses the record-aware isManaged, and TOO_MANY_TARGETS also counts the gateways of the project. The writeGatewayTargets JSDoc is #2887's version, which mentions gateways. Nothing from either side was dropped.
The egress-gateway-<name> targets and the record: resolved.
hostTargetsadds the target of each gateway of the project tomanaged(network.ts:624-626), sorecordOflists it.- A later build removes it: when the gateway gets CUSTOM_JWT (new test), when the gateway gets
boundRuntime, and when the gateway is gone from agentcore.json (existing tests). In those cases it is owned through the record. - A user target that has the gateway target's name now fails with
TARGET_NAME_COLLISIONinstead of being taken over (new test innetwork.test.ts). remove gatewaynow checks the record when the record names the Box gateway (manager.tsx:1387-1404).
Still open from the previous review (blocking). None of tejaskash's items 2-4 changed in this push, and I found no reply on them. box-integration-development has no record code, so no later phase fixes them.
- A user's
egress-*target can still be deleted.recordOf(boxNetworkWriters.ts:282-291) writes entries only for the networks of this build, andreplaceRecord(manager.tsx:1904) replaces the whole file. So the entry of a runtime that has lostboxfor a while is dropped. Whenboxcomes back, that gateway falls back to theegress-rule. Keep the entries of gateways outside the current models, and drop an entry only when its gateway is removed. - A rotated key can still be deployed stale.
envRoutesOf(network.ts:316-326) still dedupes by route name only, so[mcp.github]readingGITHUB_TOKENloses its pair when[egress.github]readsAGENTCORE_CREDENTIAL_GITHUB.uniqueRoutesin the writers already dedupes by (route, variable). Do the same within each network. manager.tsx:1904-1911:replaceRecordruns beforethis.json.read(specPath), and that read is outside thetryat:1917. A failed read leaves the new record with the old agentcore.json. Move the read and the patch abovereplaceRecord, or into thetry.
New finding.
- The record check in
remove gatewayhas no test. I replaced theownsrecord condition withtrue, and all 2405 tests insrc/core/project/still pass. Add a test where the Box gateway's record entry does not list a useregress-target that haspassthrough.gateway: "<removed>", and check that remove keeps it. - Follow-up (non-blocking):
isBuildOwnedTargetandBOX_EGRESS_TARGET_PREFIX(project.ts:39-59) still decide ownership by the prefix alone. Their JSDoc ("Build manages every target whose name has it, and no other") is out of date now that the record decides. The schema refine atproject.ts:234also skips anyegress-target on a Box gateway. So a user'segress-target that the record leaves out, and whosepassthrough.gatewaynames a gateway that was removed, passes the schema. The comment atmanager.tsx:1385-1386says such a target "stays, and fails", but here it stays and does not fail. Either check the record there too, or reword the comment.
Review areas. 1) Tests: the new gateway-target logic has tests, but the remove-path record branch has none (above). 2) Silent failures: items 1 and 2 above. 3) Comments: the prefix JSDoc above. The new comments in hostTargets and manager.tsx are accurate. 4) New types: none. 5) General: the merge resolution is correct.
Checks. Locally at 4d165b2, bun run typecheck passes and bun test passes (6495 pass, 9 skip, 0 fail). CI: Analyze, CodeQL, and verify on Linux, Windows, and macOS pass; e2e is skipped.
… in a build, for Tejas's review item on boxNetworkWriters.ts
…l planner, for Tejas's review item on network.ts
…d, for Tejas's review item on manager.tsx
|
This comment answers the four items of your comment of 2026-11-24.
|
leo237
left a comment
There was a problem hiding this comment.
Re-review at 4417bd3 (since my review at 4d165b2).
Fixed (checked by mutation; each mutation was reverted):
- Item 2 (a user's
egress-*target):recordOfnow keeps the entry of each gateway that has no model in this build, and drops an entry only when agentcore.json no longer has its gateway. If I drop the kept entries, or keep entries whose gateway is gone, the newboxNetworkWriterstest fails. Build has no runtime filter, andassertBoxRuntimesHaveBoxVersionstops a Box runtime that has nobox.version, so a partial build cannot drop an entry. Stale entries are not kept forever: an entry goes when its gateway goes, and its targets are still removed once the model comes back. - Item 3 (rotated key):
envRoutesOfnow dedupes by route and variable. If I revert to route-only, the new test fails (ghp_oldinstead ofghp_new). I also checked the planner directly: two routes for one new credential add the credential once, so there are no duplicates. - Item 4 (record written before the agentcore.json read): the read, patch, and schema check now run before
replaceRecord. If I write the record before the read, the new read-failure test fails.
Still blocking: the record branch of remove gateway has no test. da17faf tests that a build-owned target goes away, but a later build removes that target anyway. If I replace the record check in owns (manager.tsx:1393) with true, all tests in manager.boxNetwork, manager.box, manager, and remove.screen still pass (357 pass). The code itself is right. I checked with a throwaway test: build, then add a user target egress-mine with passthrough: { gateway: "tools" } that the record does not list, then remove gateway tools. egress-mine stays. Please add that as a test. It's about 10 lines next to "lets remove gateway remove the gateway after a build…", and it fails under the true mutation.
Follow-ups (non-blocking, unchanged from my last review):
- nit: the JSDoc of
BOX_EGRESS_TARGET_PREFIXandisBuildOwnedTarget(projectSchemas/project.ts:39-48) still says the prefix alone decides ownership. - The comment at
manager.tsx:1385-1386says the user's target "stays, and fails". The probe above shows thatremove gatewaysucceeds, and the schema refine atproject.ts:234skips everyegress-target on a Box gateway. Reword the comment, or check the record there too. - New, low: when two variables of one credential hold different keys (
[egress.github]readsenv://GH_Aand[mcp.github]readsenv://GITHUB_TOKEN, neither reserved), the planner stores the first route's key without a warning (seedreturns early onentries.some(...)). This did not get worse in this push, but a rotated key in the second variable is still ignored in that case. A warning would help. - The schema-failure path of item 4 has no test. If I write the record before the
!parsed.successthrow, everything still passes. The read-failure test covers the ordering.
Checks: locally at 4417bd3, bun run typecheck passes and bun test passes (6499 pass, 9 skip, 0 fail). CI: Analyze, CodeQL, and verify on Linux, Windows, and macOS pass. e2e is skipped.
…w-fixes-host-map # Conflicts: # src/core/project/boxNetwork/network.ts # src/core/project/boxNetworkSource.test.ts # src/core/project/boxNetworkWriters.test.ts # src/core/project/boxNetworkWriters.ts # src/core/project/manager.boxNetwork.test.ts # src/handlers/project/shortcuts.ts
|
Merge commit a4b249d3 merges |
leo237
left a comment
There was a problem hiding this comment.
Re-review at a4b249d. The only change since 4417bd3 is the merge of box-integration, which brings in #2889.
The merge resolution is sound. I checked it with git show --remerge-diff a4b249d, and both sides' behavior survived:
- From this PR: the record,
recordOf/managedTargets, the kept entries for gateways that have no model, the dedupe by route+variable, and the unsent-target warning. Themanager.boxNetworktest keeps this PR's warning, not #2889's step message. - From #2889: the direct route to the AgentCore host, and no gateway target for a host sent direct. The removal step for that host is kept.
agentCoreDataPlaneHostnow lives inegress.tsand is re-exported fromshortcuts.ts. Theagentcoretarget andBOX_GATEWAY_AGENTCORE_TARGET_NAMEare gone, and the expected target lists were updated to match. - Where the two sides meet: a direct host's managed target is removed from the spec before
recordOfreads it, so the record never lists it. Nothing of the user's is affected.
bun run typecheck is clean. bun test gives 6503 pass, 0 fail, 9 skip. CI is green.
One blocker remains: the record branch of owns in remove gateway (manager.tsx:1391-1394) still has no test. I replaced the record check with true again, and all 5055 tests in src/core/project, src/cli, and src/handlers still pass. A test needs a user egress- target with passthrough.gateway that is not in the record, and must check that it survives remove gateway.
The low items from the last review remain as follow-ups: the stale JSDoc in project.ts, the "stays, and fails" comment, the second variable for one credential being ignored silently, and the missing test for the schema-failure path.
…en its gateway goes (review)
…ides which targets build owns (review)
…way stays and stops the next deploy (review)
…ferent key (review)
…e schema (review)
…ewhere to planBoxProfileCredentials (review)
…ry file and a rename (review)
|
These commits correct each item in your inspection of a4b249d. The item that stops the merge
Items from the earlier inspections
Small items from 2026-11-23
Checks: |
leo237
left a comment
There was a problem hiding this comment.
Re-review at 0692c03 (since my comment at a4b249d). Approving.
Fixed (checked by mutation; each mutation was reverted):
- The blocker (the record branch of
ownsinremove gateway): when I replace the record check withtrue, the new test in 1f30525 ("lets remove gateway keep an egress- target of the user…") fails, becauseegress-minegets removed. With the real code it passes. - The schema-failure path: when I move the record write in
applyBoxNetworkabove the patch and schema check, the new test in bd61b5c fails, and so does the earlier read-failure test. - The JSDoc of
BOX_EGRESS_TARGET_PREFIXandisBuildOwnedTargetis now correct. - The comment in
remove gatewayis now correct. The schema's passthrough check skipsisBuildOwnedTargettargets, so the user's target is not refused. The deploy then stops in the CDK library atgateway-targets.ts:63("the project has no gateway …") onbox-integrationof agentcore-l3-cdk-constructs. - 0692c03 (the record write through a temporary file): the temporary file is in the record's own directory, so the rename is atomic. A failure removes the temporary file and throws again.
renameSynconto an existing file replaces it on Windows too, and nothing else depends on the platform. The tests cover both paths, and Windows CI passes.
Non-blocking follow-up (4857ff9, two variables of one credential): the warning works on a first build, but on the next build the stored key flips to the other variable's key, with no warning. seed returns early on value === stored without setting entries/seededFrom. So once .env.local holds GH_A's key, the GITHUB_TOKEN route finds no earlier entry. It then takes the "updating" path and stores ghp_rotated. The build after that switches back to GH_A's key and gives the warning again. I reproduced this with planBoxProfileCredentials and two routes, GH_A: ghp_a and GITHUB_TOKEN: ghp_rotated:
- with
envLocal: {AGENTCORE_CREDENTIAL_GITHUB: "ghp_a"}, the result is an entryghp_rotated, the message "updating …", and no warning; - with
envLocalholdingghp_rotated, the result is an entryghp_aand the warning.
So the warning's claim that "deploy provisions the key in GH_A for both" holds only on alternate builds. One fix: record the first route that resolves each credential's key, including on the value === stored return, and check against that. Then add a test that runs the planner a second time with .env.local already seeded. This alternation was already there before 4857ff9, so it does not stop the merge.
Nits on 0692c03:
- If
rmSync(partial)throws in the catch, its error replaces the original one. - A process killed between the write and the rename leaves
box-gateway-targets.json.<pid>.tmpinagentcore/, where it could be committed.
Checks: bun run typecheck passes. bun test gives 6509 pass, 9 skip, 0 fail. CI is green: verify on Linux, Windows, and macOS, plus CodeQL. e2e is skipped.
Description
The report "Box integration: review of merged PRs" (2026-11-19) found defects in
aws/agentcore-cli#2847, which reads a box profile
and finds its hosts, and in aws/agentcore-cli#2849,
which writes the Box gateway targets from those hosts. The reviewer examined
box-integrationat1f3ae974. This PR examines each item again at f98cfd68, after
aws/agentcore-cli#2866 and the PRs that came
after it.
The defects have three effects on the user:
build: a rule that Box accepts, two names of one key, and a user rulewhose
@idBox also writes.buildremoves a user target whose name starts withegress-.Each correction is in a different commit, with a test that gives an error before the correction, and a
mutation proof. The table gives each item.
hostMap.test.ts"finds a host reachable when two path patterns of one permit hold on one path" (and 3 more)hostMap.test.ts"an attribute that an action test keeps from the action, as Box reads it" (6 tests)enforcedByBoxhostMap.test.ts"names a connection permit that limits the address, and not one that allows any"buildaccepts port 65536network.test.ts"fails each rule that names port %d, which is not a port" (65536, 0, -1)mquang-amazon/box-releasesBOX_RELEASE.repofromboxRelease.jsonisTable, theuv synchint, and bannersboxProfileResolver.test.ts"the uv sync hint, when Box refuses a missing .venv under a write grant" (5 tests)@idof a user rulegateway.test.ts"names no route so that box adds a rule with the @id of a rule of the policy" (2 tests), and one test throughbuildBoxNetworknetwork.test.ts"takes one credential for its own variable and for one other variable, which build copies to it";boxNetworkSource.test.ts"takes the credential of another runtime for the credential's own variable"buildremoves a useregress-*targetmanager.boxNetwork.test.ts"owns only the targets it records, after it takes its old egress- targets once" (and 9 more)box-integration-development)manager.boxNetwork.test.ts"writes the target of a model-provider route once its key is set, as the warning says" (and 6 more)project.test.ts"Box runtimes and the folder build stages box in" (3 tests)Decisions that the diff does not show
through, the host map finds a path that the path tests of a permit let through together, and
that no forbid denies when
buildcan read all of its conditions. The result is accurate forlike,==, and!=. After 4096 searchsteps, the search stops, and the host stays reachable. Then
buildgives a warning that namesthe rule.
causes. Box rejects a rule that reads
context.inputin two action families, andip()acceptsonly a literal. The tests use the shapes that Box accepts: an action test in one family, and
context.input.ip4 like "10.*".[egress.egress-api-b-example-com]adjacent to theuser rule
route_egress-api-b-example-com_request, with exit 1. Box accepts the new nameegress-api-b-example-com-2adjacent to that rule, with exit 0.buildrecords its targets inagentcore/box-gateway-targets.json, and not in afield of
agentcore.json. The L3 schema ofagentcore.jsonis strict. Thus a new field stopssynth until the L3 accepts the field.
buildchanges and removes only the targets in the record.buildrecords eachegress-target with the same shape thatbuildwrites. It does thisone time.
buildkeeps anegress-target of a different shape as a target of the user. Thus a targetthat
buildwrote and the user then changed is a target of the user.aws/agentcore-cli#2845 did not add a
credential for a model-provider route that
agentcore createwrites with no key, such as[egress.openai]withenv://OPENAI_API_KEY. On AgentCore Runtime, the gateway target of thatroute sends the key of its credential. Thus the OpenAI, Anthropic, and Gemini routes did not
get a target. Now the planner adds the credential
openaiwhenOPENAI_API_KEYhas a value.This is the rule of
box-integration-development. This change replaces two tests of aws/agentcore-cli#2845. Varun, examine this item, because it changes your planner.Checks that continuous integration cannot do
SHA256SUMS.txt) accepted or rejectedeach policy shape that the tests of items 2, 3, 4, and 7 use.
uv synchint gave the correct folder for two errors from Box: a project path with spaces,and a long path that Box breaks in a word.
Follow-ups that this PR does not do
build, an entry that readsAGENTCORE_CREDENTIAL_GITHUBcan get a differentcredential name, before the credential
githubis inagentcore.json. The nextbuildwritesits target. For this correction, the model must use the planner. Thus it is a different change.
ProjectBackendinput of all backends, andboxNetworkSource.tsimportsDEFAULT_EGRESS_BEDROCK_REGIONfromsrc/handlers/. For the two changes, the Box gateway namesmust move out of
shortcuts.ts, which is an item ofaws/agentcore-cli#2789.
README.mdanddocs/box-local-testing.mdgive the release repository as text. The move of thereleases changes them.
Related Issue
The report on the merged Box PRs. There is no issue for it.
None.
Documentation PR
This PR changes one paragraph of
docs/box-local-testing.md: which gateway targetsbuildchanges.Type of Change
Testing
How have you tested the change?
bun test: 5869 pass, 7 skip, 0 fail, in 5876 tests. Before this change: 5829 pass, 7 skip, 0 fail, in 5836 tests.bun run test:e2e, or explained why they are not applicable(CI does not run them for you). I did not do the end-to-end tests. No change is in deploy,
and each changed path has unit tests and command-flow tests.
bun run typecheckbun run lint:checkbun run format:checkbun run auditbun run secrets:checkbun run build, andbun run test:packagesrc/assets/, I updated affected snapshots withbun test <test-file> --update-snapshotsand committed themby this PR
command.md(the release workflow regenerates it)Checklist
By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the
terms of your choice.