Repository navigation
Conversation
Build decrypted every .env.local entry before it planned the box egress credentials, so one undecryptable entry stopped a valid build, even when no route used it or the shell set its variable. Build now reads .env.local with the same select and overrides options that the credential provisioner uses. It reads only each route's env:// variable and the reserved variable of the route's credential, and skips each variable that the shell sets to a non-blank value. A blank shell value does not win, so build still reads that variable from the file. An undecryptable entry that a route uses still stops the build with the decrypt error.
…env.local With AGENTCORE_CREDENTIAL_GITHUB= in .env.local and GITHUB_TOKEN set, build added the github credential but insertIfNew skipped the blank entry, so the next deploy could not provision it. insertIfNew takes an optional keep rule. Build passes boxKeyIsSet, the same rule the credential plan uses to decide which keys need a seed, so the two cannot disagree again. A blank key gets the seed at its line. A key the user set stays. The writer decrypts only the existing keys it must check, so an unused secret that cannot be decrypted does not block the seed write.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## box-integration #2863 +/- ##
================================================
Coverage 96.80% 96.80%
================================================
Files 766 766
Lines 66928 66979 +51
================================================
+ Hits 64790 64841 +51
Misses 2138 2138 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
leo237
left a comment
There was a problem hiding this comment.
Review of #2863: fixes for the two blocking items from the #2845 review
Decision: APPROVE. I found no correctness bugs, no unhandled silent failures, and no missing tests for the important logic. All findings below are non-blocking.
Plan placement and commit list
- This is not one of the squashed plan PRs (VV/MQ/SA/TK/DOCS). It is a follow-up fix on
box-integrationfor the two blocking code items from the review of the merged #2845 (VV-2 credentials). - I could not check it against the plan doc (squash plan v2), because the doc returned 401. I checked the branches directly instead.
- The PR has two commits,
e9ec0dbdand1a96f719, and both are new. Neither is a port frombox-integration-development: dev has noboxKeyReads,boxKeyVariables,boxKeyIsSetorkeepoption. Nothing is missing, and there are no extra commits. - Nothing is applied twice. The PR has no overlap with the merged PRs, #2859, #2860 or #2862.
Base, conflicts, protected fixes
- The branch is based on
dd36f7b2, so it predates the merge of #2857 (f5503f02).git merge-treemerges it cleanly with the currentbox-integration, and also with #2859, #2860 and #2862. - File overlap:
- No fix that exists only on
box-integrationis lost. InboxProfileCredentials.ts, the model-provider skip, the key-presence check, the Secrets Manager skip andENV_LOCAL_RELATIVE_PATHare all unchanged. The PR touches none of the other protected files (boxProfile.ts, the templates,boxMemory, the telemetry code,region, the Dockerfile).
What I checked
boxKeyVariablesmatches the planner.seedis only ever called withcredential = route, socredentialEnvVarName(route)is exactly the reserved variable the planner looks up.uniqueRoutesdedupes the same way in both places.- The shell value wins only when it is not blank.
boxKeyReadspasses only non-blank env values asoverrides, so an undecryptable file entry whose variable the shell sets is never decrypted.- A blank shell value falls through to the file, as the planner expects.
readEnvFilemerges the overrides into the result, sosources.envLocalnow also holds the shell values. The planner checksenvfirst, so its behavior does not change.
insertIfNewwithkeep:- It decrypts only the existing keys that are being inserted, and does the in-place replacement with the same
ENV_ENTRYspan regex asencryptContent. replacements.hasguards against duplicate entries.- The snapshot and rollback still apply, because the content changes.
- I checked that
parseEnvyields""for the blank formsexport K=,K =,K=""andK= # c, so each of them gets the seed.
- It decrypts only the existing keys that are being inserted, and does the in-place replacement with the same
- The two parts agree.
buildpassesboxKeyIsSetaskeep, which is the same predicate the planner uses to decide that a seed is needed.
1. Test coverage
The new tests cover the important cases:
- an unused undecryptable entry;
- an undecryptable entry that the shell overrides;
- an undecryptable entry that a route uses, with no shell value and with a blank shell value (the build stops and
agentcore.jsonis unchanged); - a blank reserved variable getting the seed, and a set value being kept;
- a blank reserved variable plus an unused undecryptable entry;
insertIfNewwith and withoutkeep. Thekeeptest also checks that the value is replaced in place and stays encrypted.
The tests are Windows-safe: they use join, and have no POSIX modes, no sh and no : splitting.
Optional additions:
- a direct unit test for
boxKeyReads(no routes returnsundefined; only non-blank overrides are passed); - a manager test where the blank reserved line uses the
exportor""form.
2. Silent failures
- One low-risk path: see the inline comment on
envLocal.ts:88. A key thatKEY_LINEsees butparseEnvdoes not is skipped with no message, while build still adds the credential.
3. Comment accuracy
- The comments are accurate, apart from the
EnvLocalFileclass doc, which still says "never overwriting an existing key" (inline comment). - Cross-PR note: the
BoxKeySourcesdoc says.env.localis "whereagentcore devstores each box variable under its own name". After #2862 (dev handsbox runthe keys and no longer writes.env.local), that sentence will be out of date. Whichever of the two PRs merges second should reword it. The doc is not changed here, so this is non-blocking.
4. New types
- No new named types.
boxKeyIsSetis an alias ofhasValue. The alias is useful because it names the shared rule.insertIfNewgets an inline{ keep?: (value: string) => boolean }options type, which is fine.
5. General
- The design is clean. Build's read and write now go through the same select and keep rules that the planner uses, which removes the class of disagreement that caused both bugs.
- This fix exists only on
box-integration, so it must survive later dev squashes (inline comment onmanager.tsx).
Open items from earlier reviews
This PR addresses none of them, which is expected because they are out of scope:
- the
DEFAULT_EGRESS_BEDROCK_REGIONfallback; - the empty
.venv(MQ-6); - the unreported credential refresh failure and the silent
AWS_PROFILEtypo; devnot applying thebox.versionrule;- the "before anything is written" comment on the assert;
- the refusal message after
remove; - the duplicated template files;
- no
start.pytest; - the skipped telemetry targets (
29d283d6); - no local-profile tests for the A2A, AG-UI and MCP templates;
- the missing
.box/<name>/local/profile.toml(#2859).
CI
- Passing: Linux, Windows, Analyze, CodeQL and CodeBuild e2e.
e2eis skipped.verify / macOS: still pending after 10 min (job queued; it has not started) when this review was posted.
The macOS runner queue has been slow, and the 5 s timeouts in the macOS screen tests are a known flake on the base. Neither of these blocks.
| const value = values[entry.key]; | ||
| if ( | ||
| keep === undefined || | ||
| value === undefined || |
There was a problem hiding this comment.
Non-blocking nit (silent failure, low risk): when keep is set and a key is in existingKeys (per KEY_LINE) but parseEnv did not produce it, value is undefined and the key is reported as skipped. build reads only written, so it would add the credential while the reserved variable stays blank. That is the bug this PR fixes, but now it happens without any message. I could only reach this case with odd input, such as a KEY= line inside another entry's multi-line quoted value, so it does not block. You could treat undefined like a rejected value when keep is given, or have build warn about a seeded key that ends up in skipped.
| written.push(entry.key); | ||
| } | ||
| if (replacements.size > 0) { | ||
| content = content.replace(ENV_ENTRY, (span, prefix: string, key: string) => { |
There was a problem hiding this comment.
Non-blocking nit (comment accuracy): insertIfNew can now overwrite an existing key in place, but the class doc above (line 21) still says it "appends entries (never overwriting an existing key)". Please add "unless keep rejects its value" there, so the class doc matches the method doc.
| if (edits.envLocal.length > 0) { | ||
| const { written } = await envLocal.insertIfNew([...edits.envLocal]); | ||
| // A blank entry is one the plan seeds, so it gets the seed rather than being skipped. | ||
| const { written } = await envLocal.insertIfNew([...edits.envLocal], { keep: boxKeyIsSet }); |
There was a problem hiding this comment.
Non-blocking, for the squash plan: box-integration-development has neither boxKeyReads nor the keep option (dev's manager.tsx still calls insertIfNew([...edits.envLocal]) with no options, and reads .env.local in full). So this fix exists only on box-integration. Please add it to the list of fixes that a later dev squash of manager.tsx, envLocal.ts or boxNetworkWriters.ts must not overwrite.
box-integration now has 1b5b151, which replaces a box route's stored key when the route's variable holds a different value. That also fixes the blank reserved variable item, so this branch drops its own fix for it and keeps only the decrypt fix, plus a test that a blank reserved variable still gets its key when .env.local holds an unused undecryptable entry.
leo237
left a comment
There was a problem hiding this comment.
Re-review of #2863 at abb4ddf8 (previously approved at 1a96f719)
Decision: APPROVE. The merge resolution is correct, and the PR still fixes what it says it fixes on the new base. The remaining findings are non-blocking.
Scope
- The only new commit is
abb4ddf8 Merge box-integration into box/fix-2845-review. Its second parent is the currentbox-integrationtip,e2ac9d78, so the branch is up to date and has no conflicts. - The 72 base commits it brings in (the v1.x sync, #2854, #2857, #2859, #2860, #2862, #2865, #2866, #2867, #2870, #2871 and others) are not re-reviewed here.
- The PR's net diff against
box-integrationis now 4 files and +119/-5:boxNetworkWriters.ts,boxProfileCredentials.ts,manager.tsxandmanager.boxCredentials.test.ts.
Merge resolution (I compared the diff at 1a96f719 with the diff at abb4ddf8)
- Kept unchanged:
boxKeyVariablesboxKeyReads, with itsselectand non-blankoverrides- the
manager.tsxreadkeyReads ? await envLocal.read(keyReads) : {} - the five undecryptable-entry tests, with the
appendEnvLocalandstoredKeyhelpers
- Dropped, correctly: the blank-seeding half of the PR, which was the
insertIfNew(..., { keep })option,boxKeyIsSet, the twoenvLocal.test.tstests and the two manager tests for a blank or kept reserved variable.- Base
1b5b151e("Refresh a box route's stored key when its variable changes") replaced that design. Build now callsenvLocal.upsert(...), and the planner'sseedwrites an entry whenever the route's value differs from the stored one. A blankAGENTCORE_CREDENTIAL_<ROUTE>=therefore gets replaced in place, so the casekeepcovered is still handled. - The old test "keeps a reserved variable that
.env.localalready sets" would now contradict the base's rotation behavior, so removing it is right. - Blank seeding is still tested at the manager level by "seeds a blank reserved variable when
.env.localalso holds an unused undecryptable entry". That test now goes throughupsert's in-place branch.
- Base
- Nothing from the base is reverted. The net diff only adds lines, apart from one import and the
envLocal.read()call. The base'supsertand rotation path, the model-provider skip, the Secrets Manager skip,ENV_LOCAL_RELATIVE_PATH, #2862's devenv://handling, #2866's per-runtime profiles and the #2860 telemetry code are all untouched.
Does the logic still fit the new base?
- Key selection still matches the planner.
seedstill callscredentialEnvVarName(credential)only withcredential = route. It still readssources.envLocalonly atvariableand that reserved key. Routes whose variable an existing credential reserves still return before any lookup. SoboxKeyVariables(routes)is exactly the set the planner reads, and a superset where routes are skipped. - Per-runtime networks (#2866):
boxKeyReadsandcredentialsWriterboth useuniqueRoutes(networks)across all runtimes, so they dedupe the same way.credentialsWriteris still the only writer that readsenvLocal. upsertdoes not undo the fix. It never decrypts the file. It re-encrypts only plaintext sensitive values, andLocalSecrets.encryptskips values that start withenc:v1:. So an unused undecryptable entry passes through a seed write untouched.- The tests still fail without the fix. Without the select,
envLocal.read()decrypts every entry, so the three "builds when ..." and "seeds ..." tests would throw. The two "stops on ..." cases guard against over-filtering. The tests usejoinandappendFile, with no hard-coded/, no:splitting, no POSIX modes and no shell spawns.
Earlier comments
- The
envLocal.ts:88comment (a key thatKEY_LINEsees butparseEnvdoes not is silently skipped bykeep) and theenvLocal.ts:106comment (class doc says "never overwriting") no longer apply. Thekeepoption is gone from this PR, andenvLocal.tsis no longer in the diff. - The
manager.tsxcomment (this fix exists only onbox-integration) still applies.box-integration-development(435b6ba1) has noboxKeyReadsorboxKeyVariables. It still callsinsertIfNewand does not read.env.localin build at all, so it does not have the bug, but it also does not have the fix. A later dev back-merge or squash that touchesmanager.tsxorboxNetworkWriters.tsmust keepboxKeyReads. This is non-blocking.
New findings (non-blocking)
- An undecryptable reserved entry still stops a build, even when the shell supplies the route's key. Since
1b5b151e, a shellGITHUB_TOKEN=ghp_newreplaces the storedAGENTCORE_CREDENTIAL_GITHUBanyway. But build still decrypts the stored value only to compare it, so a user who lost their encryption key cannot fix things by setting the variable and building again. The error tells them to "re-add the credential". Stopping is safe, so this is optional. If you want it, treat an undecryptable stored key as one that differs (and write the seed) when the route's variable has a value. - The message is gone for a blank reserved variable. When
upsertseeds a blank reserved variable in place, the key lands inupdated, and build printswriting ...only forwritten. The planner printsupdating ...only when the stored value is set. So a blank reserved variable is now seeded with no message. This is base behavior from1b5b151e, not this PR's, and is cosmetic.
Plan
#2863 is not one of the plan PRs. It is the review follow-up for VV-2 (#2845, squash plan v2).
CI
All checks pass at abb4ddf8: verify on Linux, Windows and macOS, Analyze, CodeQL and CodeBuild e2e. e2e is skipped.
tejaskash
left a comment
There was a problem hiding this comment.
Thanks, items 1 and 2 from the #2845 review are fixed: build now decrypts only the .env.local keys the box routes use, non-blank shell values override them, and a blank reserved variable gets seeded. Each part of the fix fails a test when reverted, and the #2845 fixes are still in place on box-integration. Requesting changes because the rest of that review isn't here yet, and there's one test gap (inline):
- The skip, not-adding and key-gone messages are still steps, not warnings (
manager.tsx:1735maps everyedits.messagesentry totype: "step"). - The five skip tests in
boxProfileCredentials.test.ts(:207,:220,:232,:249,:260) could be onetest.each. - Fixtures still cast with
as unknown asinstead of going through the schema (boxProfileCredentials.test.ts:9,:157,:267). - "a OAuthCredentialProvider" at
boxProfileCredentials.ts:157. - From the #2862 review, both still untouched: a reserved variable exported in the shell makes dev and deploy disagree with no message (
boxProfileCredentials.ts:111), and a blank stored key is filled in with no message (:117-124).
If these go in a separate PR, that's fine, just link it here.
| * route's `env://` variable, and the reserved variable of the credential named for the route. | ||
| * Build reads only these from `.env.local`, so an entry no route uses cannot stop it. | ||
| */ | ||
| export function boxKeyVariables(routes: readonly BoxEnvRoute[]): Set<string> { |
There was a problem hiding this comment.
This also selects variables the planner never reads: it returns early for a model-provider route (:142) and for a route whose variable an existing credential reserves (:139). So with [egress.openai] on env://OPENAI_API_KEY and an undecryptable OPENAI_API_KEY in .env.local, build still stops with "Could not decrypt a stored secret" for a route the planner would have skipped. Could this drop those routes with the same two conditions, or the doc comment above stop saying these are the variables the planner looks up? Separately, no test fails if the reserved variable is removed from the set. A manager test for a second build where the key is stored only under AGENTCORE_CREDENTIAL_GITHUB would cover it.
There was a problem hiding this comment.
Fixed in 8766abb. boxKeyVariables and the planner now use one predicate, boxRouteKeyHeldElsewhere. Build reads no key for a model-provider route or a reserved route. New manager tests cover an undecryptable OPENAI_API_KEY and a second build with the key only under AGENTCORE_CREDENTIAL_GITHUB. Each test fails when the fix is reverted.
| expect(await storedKey(created.rootPath)).toBe("ghp_shell"); | ||
| }); | ||
|
|
||
| for (const [label, env] of [ |
There was a problem hiding this comment.
Small one: a for ... of loop with as const generates the two "stops on" tests. test.each([...]) matches the rest of the repo and drops the as const.
There was a problem hiding this comment.
Fixed in 57bfb0d. The two "stops on" tests now use test.each([...]), with no as const.
| env: NodeJS.ProcessEnv, | ||
| ): ReadEnvFileOptions | undefined { | ||
| const routes = uniqueRoutes(networks); | ||
| if (routes.length === 0) return undefined; |
There was a problem hiding this comment.
Small one: with no routes, select already rejects every name, so nothing is decrypted and the read returns {}. This guard and the | undefined return type can go, and manager.tsx:1692 becomes envLocal: await envLocal.read(boxKeyReads(networks, this.processEnv)).
There was a problem hiding this comment.
Fixed in da4f1df. The guard and | undefined are removed. manager.tsx now calls envLocal.read(boxKeyReads(...)). A new test shows that a project with no box routes builds with an undecryptable entry in .env.local.
…nner skips boxKeyVariables now drops a model-provider route and a route whose variable an existing credential reserves, through the same predicate planBoxProfileCredentials uses.
With no routes, select rejects every name, so the read decrypts nothing and returns no entry.
…s warnings planBoxProfileCredentials returns them in a separate warnings list, and build emits them as warning events. Progress messages stay steps.
…ress skip warning
…n schema-parsed specs The Secrets Manager fixture now uses a valid secretRef, which the old cast hid. A payment credential row covers the article of the warning.
…s from the box route's key Deploy provisions the reserved variable, but agentcore dev hands box the route's variable. Build now warns when the two hold different keys.
|
Thanks. All five items are fixed in this PR:
This branch also merges the current |
leo237
left a comment
There was a problem hiding this comment.
Re-review at 100b38a (was approved at abb4ddf). I looked at the PR's own commits 8766abb..76bbfd0 and the two merges of box-integration.
Merges. Both merges, 6857721 and 100b38a, match what git merge-tree produces automatically, so no conflicts were resolved by hand. box-integration (now including #2883, #2884 and #2885) is an ancestor of the head. git diff box-integration pr touches only the PR's 5 files, so no base change is reverted and no PR change is lost. ENV_LOCAL_RELATIVE_PATH, EnvLocalFile.upsert and the boxProfileCredentials checks are all still there. This branch merges into the base with no conflicts.
Addressed
- Our earlier item (2), a blank stored key filled in with no message: 76bbfd0 adds the step "filling in the blank ... with the key in ...". It is tested in both the planner test and the manager test.
- tejaskash's 5 items and 3 inline comments are all addressed. 3d64c00 adds a separate
warningschannel, andmanager.tsxemits those astype: "warning"events next to the network and IAM warnings, so they are still printed and nothing is swallowed. The build still stops where it should: thetest.each"stops on an undecryptable entry that a route uses" cases still pass. - 8766abb:
boxKeyVariablesand the planner now share one check,boxRouteKeyHeldElsewhere. Tests cover an undecryptableOPENAI_API_KEYand a second build whose key is only under the reserved variable. - da4f1df: with no routes,
selectrejects every name, sofromFileis empty.LocalSecrets.decryptthen returns early before any key is loaded, so nothing is decrypted. The new test covers this. - The fixtures now go through the schema, and the skip tests are one
test.each. The tests are CI-safe: no host paths, no splitting on:, no POSIX modes, no subprocesses, no network. The only account ID in the diff is the AWS documentation example ID.
The 3 affected test files pass locally (61 pass). CI is green: Linux, Windows and macOS verify, CodeQL, and e2e CodeBuild.
Still open (non-blocking)
- Our earlier item (1) is not addressed and has had no reply. If the stored
AGENTCORE_CREDENTIAL_<NAME>cannot be decrypted, build still stops even when the shell sets the route's variable.boxKeyReadsselects the reserved variable, and only the route's variable is inoverrides, so the reserved entry is still decrypted. The fix we suggested earlier still works: if the route's variable is set in the shell, leave the reserved variable out of the read (or treat an undecryptable value as "different"), and seed it. - Back-merge to
box-integration-developmentis still needed.
New, non-blocking
boxKeyVariablesstill reads the variables of routes the planner skips with a warning: anOAuthCredentialProviderorPaymentCredentialProvidercredential with the route's name, an API key credential that keeps its key in Secrets Manager (secretRef), a route that uses only a model-provider name or only a model-provider variable, an invalid name, a credential-field suffix, or a derived-variable clash. In each of these cases an undecryptable value for the route's variable in.env.localstill stops the build, even though the planner never uses it. The doc comment does say "for each route it does not skip first", but the title of 8766abb says more than that ("a route the credential planner skips"). Two ways to fix it: have the planner itself report which variables it read, or move the remaining skip checks into the shared check. See the inline comment.- da4f1df now reads and parses
.env.localon every build, even when there are no box routes. A.env.localthat does not parse now stops such a build, where before this step skipped the file. It is probably fine because dev and deploy already parse that file, but this is a change in behavior.
Overlap with #2886 (0a84859)
#2886 adds the same two messages as 3e19603 and 76bbfd0, and the two branches conflict in boxProfileCredentials.ts (trial git merge-tree; manager.tsx, backends/cdk.ts and docs/box-local-testing.md conflict too). They behave the same way:
- #2886 has an extra
variable !== keyguard. Here it makes no difference: if the route's variable is the reserved variable,valueequals the exported key, so no warning is raised. - #2886 checks for a pending entry before the shell check. That only changes anything for two routes mapped to one credential, which
uniqueRoutesalready rules out in practice.
This PR's version is the better one: it reports the mismatch as a warning, which #2886 cannot do because it has no warnings channel and pushes the mismatch into messages (steps). This PR also has manager-level tests for both messages. I recommend that #2886 drop 0a84859 and take this version when it rebases.
Approving. None of the items above blocks this PR.
| const reserved = new Set(credentials.flatMap(credentialEnvironmentVariableNames)); | ||
| return new Set( | ||
| routes | ||
| .filter((route) => !boxRouteKeyHeldElsewhere(route, reserved)) |
There was a problem hiding this comment.
Non-blocking: this drops only the routes the planner skips silently. A route the planner skips with a warning (an OAuth or Payment credential with the route's name, a Secrets Manager secretRef API key, a model-provider name or variable used alone, an invalid name or suffix, a clash) still has variable and credentialEnvVarName(route) read and decrypted, so an undecryptable entry for it still stops the build. You could move those checks into the shared check, or have the planner return the variables it actually looked up.
Description
This PR fixes a blocking code item from the review of #2845 ("Box integration: review of merged PRs").
1. One undecryptable secret blocks a valid build. Build decrypted every
.env.localentry, also the entries that no box egress route uses or that the shell overrides. Now build reads.env.localthrough the sameselectandoverridesoptions that the credential provisioner uses:boxKeyVariables(routes)lists the keys thatplanBoxProfileCredentialsreads.boxKeyReads(networks, env)builds the read options. Only non-blank shell values override, the same as the planner.2. A blank reserved variable. This PR no longer changes it.
box-integrationfixes it in 1b5b151: build now replaces a stored key when the route's variable holds a different value, and a blank stored key counts as not set. A new test checks that a blank reserved variable still gets its key when.env.localalso holds an unused undecryptable entry.Related Issue
None.
Documentation PR
Not applicable.
Type of Change
Testing
bun test: 5834 pass, 6 skip, 1 fail. The failure isthe box on PATH > resolves a profile into the rules the tests fake. It also fails onbox-integrationwithout this change, because the localboxbinary has nometadata_hostsrule.bun run test:e2e, or explained why they are not applicable(CI does not run them for you). Not run: the change is in build's local
.env.localhandling, and the unit tests cover the cases.bun run typecheckbun run lint:checkbun run format:checkbun run auditbun run secrets:checkbun run buildsrc/assets/, I updated affected snapshots withbun test <test-file> --update-snapshotsand committed themby this PR
New tests in
manager.boxCredentials.test.ts:.env.localalso has an unused undecryptable entry.