Repository navigation
fix: guardrail version quota, credentials race, late reconciler writes; CI cleanup - #1084
Conversation
writeSecretFile truncated the file and then wrote it. A refreshed token is saved this way, and a second bgagent process that read credentials.json in between got an empty or partial file and reported a valid login as corrupt. `bgagent login`, which the message advises, did not help, and the next parallel run could fail the same way. The content now goes to a temporary file beside the target, created exclusively with mode 0600 under a name of its own, and a rename puts it in place: a reader gets the old file or the new one. The function is shared, so invite files, pending Linear consents and `replay --output` are written the same way. A device, a FIFO and a symbolic link are still written in place, because a rename would replace the node or the link. A regular file that can be written but not replaced now fails where it used to be written in place: a file in a directory the user cannot write to, and a file name too long to take the temporary suffix. Closes #1080
Both workflows started after every build and did no work. deploy.yml could deploy only for a `deploy` label or a dispatch input, and the repository has no such label. integ.yml waited for an approval of the `deploy` environment; its test step last ran on 2026-11-17 and failed. The emulator-backed tests are the integration check that CI runs, and no workflow uses an AWS account any more. build.yml loses what fed the two: the `deploy` dispatch input, the steps that wrote cdk/cdk.context.json (stack name, github:* tags, the AZ override of AGENTCORE_AVAILABILITY_ZONES) and the upload of cdk.out and of the deploy intent. Its one-value matrix stays, because it names the required check `build (agentcore)`. The manual path goes with them: the integ task of cdk/mise.toml, the smoke app under cdk/test/integ, its two test suites, the ignore patterns for it in the jest configuration and in their copy in contracts/coverage-thresholds.json, and the two dependencies that served it, integ-runner and integ-tests-alpha. Nothing ran the task any more, and no run of it in CI had completed since the workflow's call of it was repaired (PR 1048). No automated test of a deployed stack exists now. The secret scan loses the path exemption for integ-runner snapshot directories, which matched nothing any more. Tests, comments and documents that described the pipeline say what is true now. ADR-013 records the change and drops the accepted risk of fork code running with the deploy role, which ended with the integ workflow.
The reconciler runs for every write on the record of a finished task, not only for the write that ended it. For a child that did not succeed, each of those writes moved the child's issue back out of its started state and replaced its reaction with the failed one, also after a person had taken the work over: the preview of a later push put a Linear issue from In Review back to Todo. The stream delivers the new image only, so the write that ended the task cannot be told from a later one by its content. The time between the task's end and the write separates them. The step now runs for a record written within five minutes of the task's finish time and not for a later one. The finish time is completed_at, else updated_at; the write time is the one the stream stamps on the record, so a delivery that comes late, or again, decides as the first one would have. Inside the window the step still runs for every record on purpose: nothing retries a failed call to the tracker, and the orchestrator's ttl stamp, one poll after the terminal write, is that retry. A late write still records the verdict, skips the dependents and refreshes the panel, which is how a preview reaches it. Two comments of the step said more than the code does and are corrected: the revert demotes any issue in a running state, and a reaction is matched by its emoji alone. Closes #1073
createVersion() of the alpha library names the version resource after an unresolved token (issue 38674 of aws/aws-cdk). aws-cdk-lib starts its token counter at a random number, so the name differed from one synthesis to the next and about nine deploys in ten replaced the version of the input guardrail. Since PR 904 the replaced version is retained, because a retained version of the orchestrator function can still name it. A long-lived stack therefore reached Bedrock's quota of 20 versions per guardrail, which cannot be raised, and deploys failed and rolled back until versions were deleted by hand. A real change of the guardrail, on the other hand, was published only by the same chance. The stack now creates the version itself, under a construct id that ends in a hash of the guardrail's CloudFormation properties (without tags) and of the description. A deploy publishes a version when the guardrail changed and only then, and the version stays retained. The name is computed where the version is created, so synthesis fails when the guardrail is changed after that. The network tests no longer map the guardrail version id between the two topologies. The first deploy with this change publishes one more version, because the logical id changes one last time. A guardrail at its quota has to be cleaned up first: see "Deploys stop once the input guardrail reaches its version quota" in the deployment guide. Old versions are not deleted by this change. Closes #1079
The pin moves from 1.0.523 to 1.0.610, the newest release. The suites were not run on it before this commit: the Docker engine of the machine it was made on did not answer, so the emulator workflow of the pull request is their first run. One assertion is changed ahead of that run. From 1.0.606 the iss claim of a Cognito ID token names a host in the loopback zone, cognito-idp.<region>.localhost:<port>, where it named the endpoint. The cli suite expects the new form, as upstream's fix commit and one of its own records give it. With the old value the cli step would fail and the agent suite, the step after it, would not run. The README says what was not done. Nothing in it was probed again, and it names the four statements that upstream's release notes and fix commits say no longer hold as written: the iss claim, the malformed expression forms, an MCP record that matches no schema version, and the operations answered with 501. The package and image sizes are those of the new version; the image size is computed from the package, not measured.
The emulator workflow of the pull request was the first run of the suites on the new pin, and all three passed. The cli suite asserts the iss claim of a Cognito ID token in the form it has since 1.0.606, cognito-idp.<region>.localhost:<port>, so that form is observed now. The README's row on the claim has the new form, the note on the pin no longer lists it among the statements nobody observed, and the release history names 1.0.606 beside the two earlier changes of the claim.
ayushtr-aws
left a comment
There was a problem hiding this comment.
Approve with nits. All three fixes address their root cause, CI is green, and nothing below blocks merge. Item 1 is worth fixing or rewording in this PR.
Non-blocking
cdk/src/stacks/agent.ts:119-147— a filter added afterpublishGuardrailVersionis silently dropped. Reproduced: a guardrail with one denied topic, thenpublishGuardrailVersion, thenaddDeniedTopicFiltersynthesizes cleanly with only the first topic in the template; without the publish call both appear.configuration()resolves the alpha library's cachedLazyprops at construct time, so the later filter never renders and the validation re-reads the same cached value and passes. Same for a second PII, regex or word filter; a second content filter andaddPropertyOverridedo fail synthesis. No live impact today (AgentStackconfigures the guardrail only in its constructor), but the doc comment ("or synthesis fails") and the comment at 590-593 promise a guard that does not hold, and the failure mode is a weaker guardrail. Suggested: compute the hash at synthesis as Lambda's version hashing does (Lazy.uncachedString+overrideLogicalId), or state the freeze in the doc and add a test with a second filter of an existing kind (cdk/test/stacks/agent.test.ts:1331covers only the empty-to-one case). Reproduced onaws-cdk-lib2.261; theLazycaching code is the same in 2.276.cli/src/config.ts:134-140— a symlinkedcredentials.jsonis still truncated in place, so the dotfiles setup thatcli/test/config.test.ts:200supports can still hit #1080. The doc comment at 114-119 promises "never a truncated one" unconditionally. Suggested: temp-and-rename beside therealpathSynctarget, or qualify the comment.cli/src/commands/replay.ts:53—replay --outputfollows a symlink at a user-chosen path (predates this PR). In a directory others can write to, a planted link redirects the bundle. The new comment "a link planted there is not followed" holds only for the temp name. Suggested: refuse a symlink for--output, or open withO_NOFOLLOW.cli/src/config.ts:122-131— the rename needs write permission on the parent directory. The read-only directory case is disclosed in the description; a single-file bind mount ofcredentials.jsonwould likely fail withEBUSY(not tested). Suggested: fall back to the in-place write onEACCES/EPERM/EBUSY.cli/src/commands/setup.ts:751still says "local and CI deploys"; no workflow deploys now.scripts/aws-emulator/README.md:59,73,81— three rows that upstream release notes contradict stay as written (the README says so at line 85). Probe them or mark the rows inline.
Nits
cli/src/config.ts:129-131: thefinallyremoves a file it did not create onEEXIST, and a cleanup error replaces the original one.cdk/src/handlers/orchestration-reconciler.ts:559: nothing is logged when a first terminal record is skipped as late (for example an agent clock more than five minutes slow).cdk/test/handlers/orchestration-reconciler.test.ts:613: no case at exactly five minutes..github/workflows/build.yml:35,59:actions: writeand theself_mutation_happenedoutput look unused (predates this PR).docs/research/aws-emulator-local-tests.md:44,60describes the removed workflows as current.
Checked and found correct
- Reconciler: every terminal writer sets
completed_at, and no post-terminal write (ttl stamp, screenshot fields, PR outcome) movesupdated_at, so the fallback is not defeated.ApproximateCreationDateTimeis epoch seconds; the NaN paths keep the old behavior. - Guardrail: every consumer pins the published version, none reads the draft. The hash is stable across processes, env-agnostic vs concrete environments, and with stack tags applied. A→B→A is safe for CloudFormation.
ApplyGuardrailIAM is unaffected, and a wrong version fails closed. - CLI: regular and missing targets are replaced atomically at 0600; the lstat-to-rename window cannot write through a link.
- CI and docs: no dangling references to the removed workflows, the required check name is unchanged, no coverage floor moved, the
.gitleaks.tomlchange narrows the exemption, all seven doc sources match their mirrors, ADR-013 is consistent. Bootstrap synth-coverage is not applicable (no new resource type).
Governance
#1073, #1079 and #1080 are approved and the branch name is valid. The three issues carry no priority label or assignee, and the workflow removal and emulator bump have no issue of their own.
Not run locally: the PR's test suites (relied on CI) and anything that deploys.
There was a problem hiding this comment.
Reviewed the diff at 00a310d3 and live-tested the guardrail change on a long-lived dev stack (this PR merged onto the build that stack was running). The three items marked important inline are the ones I'd like fixed before merge; the rest are suggestions and nits.
Live test: guardrail version (#1079)
| Step | Result | Published versions |
|---|---|---|
| Before | stack on the previous build | 11 |
| Deploy 1 | UPDATE_COMPLETE |
12 |
| Deploy 2, same tree, fresh synth | UPDATE_COMPLETE |
12 |
- Deploy 1 created
InputGuardrail/Version233b14ea39532000, retained the old version resource (DELETE_SKIPPED), and all 10 functions that carryGUARDRAIL_VERSIONpicked up the new number. - Deploy 2 was a real stack update (the
RepoConfigCRtimestamp churn). The fresh synth produced the same logical ID and CloudFormation raised noAWS::Bedrock::GuardrailVersionevent. cdk diffbefore deploy 1 showed no IAM role changes and no stateful replacements. An error scan of the stack's functions after both deploys was clean.
So the fix does what the description says: one extra version on the first deploy, none on a repeat deploy.
Not covered live: the reconciler change (#1073) and the credentials change (#1080). The comments on those are from reading the code.
Two notes without an inline anchor
.gitignore: removing the rules for/cdk/test/integ/*.snapshot/and/cdk/test/integ/cdk-integ.out.*/makes leftover integ-runner output in existing checkouts untracked and committable (bundled Lambda assets, roughly 100 MB), and the gitleaks path exemption is gone as well. Keeping the two ignore lines for a while, or telling contributors to deletecdk/test/integ/, avoids an accidentalgit add ..docs/research/aws-emulator-local-tests.md(around lines 266, 289, 401) still describesdeploy.yml,integ.ymlandmise //cdk:integas live. A dated note that they were removed would do.
isadeks
left a comment
There was a problem hiding this comment.
Requesting changes for the three items marked important in my review above (#1084 (review)):
cli/src/config.ts: no fallback when the secret file cannot be replaced (bind-mountedcredentials.json).orchestration-reconciler.ts: the late-write guard never fires for a record withoutcompleted_at, so #1073 remains for those.orchestration-reconciler.ts: a settle that fails inside the window is never retried once the window has passed.
The guardrail fix itself is confirmed on a deployed stack and looks good. The other comments are suggestions and nits, fine as follow-ups.
Since the write through a temporary file and a rename, a file that can be written but not replaced failed: a credentials.json mounted into a container on its own (the rename onto a mount point answers EBUSY), a file in a directory that takes no new file, `--output /dev/fd/N` on macOS when N is a regular file, a name or a path too long to take the temporary suffix. For credentials.json every token refresh failed there, where the code before #1080 worked. When the temporary file cannot be created or the rename fails with EACCES, EPERM, EROFS, EBUSY, EXDEV, ENOENT or ENAMETOOLONG, the file is now written in place. In a shared directory such as /tmp another user can make the rename fail on purpose, so the write in place is stricter than the old one: an existing file is made owner-only before the content goes in, and only if it is the user's own (root: any file); a file that was missing is created exclusively. For a file written in place the race of #1080 remains, and the comment says so. A symbolic link that leads to a regular file is resolved, and that file is replaced beside its real path: the link stays, and a credentials.json that is a link no longer has the race. Because links are followed on purpose, a link, a FIFO, a socket or a directory found at the path is refused when it belongs to another user (not root, not the owner of its directory) or has a second hard link: `replay --output` takes a path that can be in a directory others write to. A device is written whoever it belongs to: only a privileged user can make one. The entry is examined once and used by its name afterwards. In a directory with the sticky bit only the user, root and the owner of the directory can exchange it in between, and for root also the owner of a file that root writes in place. In a directory without it anyone who may write there can, and the write then follows a planted link. The comment of writeSecretFile says so. The temporary file is opened exclusively and removed only by the call that created it, and an error of the cleanup no longer replaces the first error. A process killed between the write and the rename leaves the temporary file, owner-only: the comments of writeSecretFile and of takePendingConsent say so. knip.json names mkfifo, which a test uses to make a FIFO. Not run: a rename onto a real mount point (no container engine), and anything as root or on Linux before CI.
Two gaps of the settle window that this branch added. The finish time of a record without completed_at was its updated_at. A late write that moved updated_at would have passed for the write that ended the task. updated_at is not read any more. A record is judged by its two times only when it carries both; one that lacks completed_at or the stream's stamp is late once the child's row already holds the failed verdict. A settle that failed inside the window was never retried after it, where every later write used to be the retry. A try inside the window that did not land (a call threw, or the reaction call answered false, which is how the Linear adapter reports a tracker that fails) now leaves the task's id on the child's row, in the new optional attribute unsettled_task_id. The first record after the window that finds the mark runs the step once more, however late it was written, and the mark is removed after that try whatever it did: a mark that stayed would repeat the step on every later write, which is #1073. Not covered, and said in the comment of the step: only a later write on the task record triggers that try; it is the last one, so the settle is lost when the tracker is still down then (a warning is logged); a state call that failed alone is not owed, because the adapter answers false both for a failed request and for nothing to move; the try after the window can move back an issue that a person has taken over by then. The mark is read with the rows by a query that is not strongly consistent, and its removal can fail: either can bring one more try after the window, also when nothing is owed. A record that the step leaves out as late is logged, as a warning when it is the record that brought the verdict to the row. Tests pin the boundary: 300 s after the end settles, 301 s does not. A comment in linear-feedback.ts now names this step as the one caller that reads the answer of the reaction swap.
publishGuardrailVersion() renders the guardrail at the call, and the alpha construct keeps what it rendered. A filter added afterwards was missing from the template without an error (a second denied topic, PII, regex or word filter), and the validation, which compared the same kept rendering, passed. The comment promised that synthesis fails. The validation now also compares the JSON text of what the construct renders from, the seven filter lists, the two tiers and the cross-Region configuration, with what it was at the call. The hash is computed from the same input as before, so the version keeps its name and a stack deployed from the previous commits publishes nothing new. Synthesis fails when the guardrail's rendered properties, or the filters, tiers and cross-Region configuration they are rendered from (compared as JSON text), are no longer what they were when its version was published. What the construct's add methods append between the call and the synthesis always fails it. The comparison is not complete: the doc comment says what it compares, and that a cached Lazy value in a property keeps what it produced at the call. Other ways past it are not closed: they take a cast, a filter class of the caller's own, a rebuilt CfnGuardrail, or a change made while synthesis validates. A test fails when a later version of the alpha library renders from one more member that is a list or is read by a generateCfn method. The deployment guide's entry on the version quota now says to count the versions before the first deploy with the fix.
setup.ts: the hint after `--no-deploy` and two comments named a CI deploy. No workflow deploys since deploy.yml was removed, so the hint says "every deploy of this stack", and a test pins it. scripts/aws-emulator/README.md: the three statements that upstream's fix commits contradict are marked "Not probed again on 1.0.610" where they stand, with what upstream says changed and from which release. None of the three was observed on 1.0.610: no container engine was available. docs/research/aws-emulator-local-tests.md: a dated note in the status line says that what the document tells about deploy.yml, integ.yml, `mise //cdk:integ` and the integ smoke describes the earlier state, and six passages carry a marker that points to it. The other mentions stay as the record of 2026-11-15 that they are. .gitignore: the two lines for the integ runner's output are back. A checkout that ran the integ test may still have those directories, about 100 MB by the comment these lines had, and without the lines `git add .` would stage them.
The job asked for `actions: write`, "upload-artifact when self-mutation is detected". The pinned upload-artifact takes no token: it uploads, and deletes for `overwrite`, through the results service with the run's own runtime token. upgrade-main.yml runs the same step under `contents: read`.
|
Thanks for both reviews. The changes are in the commits after Review of ayushtr-aws
Nits:
Governance: the removal of the workflows and the emulator move have no issue of their own because I asked for both directly, as the description says. I will set the priority labels and the assignees on the three issues. Notes of isadeks without a thread
|
isadeks
left a comment
There was a problem hiding this comment.
Approving at a03d7784. The three items I requested changes for are fixed, and I checked each one rather than only reading the replies:
- Secret file that cannot be replaced (
3ddbe375): withcredentials.jsonbind-mounted as a single file into a container,00a310d3fails withEBUSYand the head writes the file, owner-only. - Record without
completed_at(f9c4c73c): the new test for that case fails with the00a310d3handler and passes on the head. - Settle that did not land (
f9c4c73c): same check with the owed-settle test, fails before and passes now.
The CLI config tests and the reconciler and agent stack tests pass locally on the head. A fresh synth of the head gives the same guardrail version logical ID as the build I deployed, so 4be987c9 does not publish another version.
Fine with #1088 as the follow-up for the quota preflight, and with the documented limits (the temporary file left by a killed process, the single late retry, the emulator table rows marked as not probed again). Thanks for the thorough replies.
Three fixes, the removal of the unused deploy and integ pipeline, and a move of the AWS Emulator pin. They are on one branch because the repository owner asked for them together. Each has a commit of its own.
Area
cdk— infrastructure, handlers, constructsagent— Python runtime / Docker imagecli—bgagentclientdocs— guides or design sources (docs/guides/,docs/design/)tooling— rootmise.toml, scripts, CI workflowsRelated
Closes #1080
Closes #1079
Closes #1073
The removal of the workflows and the emulator update have no issue: the repository owner asked for both directly. The cause of #1079 is reported upstream as
aws/aws-cdk#38674.Changes
#1080: a valid login reported as corrupt (
cli/src/config.ts)writeSecretFiletruncated the file and then wrote it, so a secondbgagentprocess could read an empty or partialcredentials.json. It now writes a temporary file beside the target (created exclusively, mode 0600) and renames it over the target.replay --outputare written the same way. A device, a FIFO and a symbolic link are still written in place.#1079: deploys stop at the guardrail's version quota (
cdk/src/stacks/agent.ts)createVersion()of the alpha library names the version after an unresolved token, andaws-cdk-libstarts its token counter at a random number. About nine deploys in ten therefore replaced the version, and since feat(compute): add Lambda MicroVM P3 approval lifecycle #904 the replaced one is retained. A real change of the guardrail was published only by the same chance.#1073: a late write puts a failed sub-task's issue back to not started (
cdk/src/handlers/orchestration-reconciler.ts)ttlstamp, one poll after the terminal write, is that retry.updated_at.Deploy and integ workflows removed
.github/workflows/deploy.ymlandinteg.ymlare deleted.build.ymlloses what fed them: thedeploydispatch input, the steps that wrotecdk/cdk.context.json, and the uploads ofcdk.outand of the deploy intent. The required check keeps its name,build (agentcore).integtask ofcdk/mise.toml,cdk/test/integ, its two test suites and the dependencies@aws-cdk/integ-runnerand@aws-cdk/integ-tests-alpha. No automated test of a deployed stack exists now..gitleaks.tomlloses the path exemption of the account-id rule for integ-runner snapshot directories, which matched nothing any more.AWS Emulator 1.0.523 to 1.0.610
emulatorworkflow here was their first run, and it passed: cdk 29 tests, cli 7, agent 44.issclaim of a Cognito ID token namescognito-idp.<region>.localhost:<port>, and the cli suite now expects that form. The value came from upstream's fix commit; the run confirmed it, and a follow-up commit brings the README's row on the claim in line.What an operator or maintainer will notice
--output /dev/fd/Non macOS whenNis a regular file. The error then names the temporary file.integ-smokestatus.buildsynthesizes the default stack and uploads neithercdk.outnor a deploy intent. Required checks are unchanged.main's copies of both workflows still start after each build of this branch. Expect a faileddeployrun and a pendinginteg-smoke. Neither is required.deploy,diffandinteg; the secretAWS_ROLE_TO_ASSUME; the variablesAWS_REGIONandAGENTCORE_AVAILABILITY_ZONES; integ runs still waiting for approval; the IAM role behind that secret and any stack the workflows left.Not in this pull request
github:*stack tags, which nothing fills any more.Emulator integration testsa required check.saveConfig, which still truncatesconfig.json, andloadCredentials, which reports every read failure as corrupt.Verification
mise run buildpassed on the tree with all five changes. The last edits after it were the pin (1.0.609 to 1.0.610), wording in two documents, the secret-scan exemption and one assertion of an emulator suite.mise //cdk:test,mise //cli:test,mise //web:testand the agent tests, and the security scans of the push hook (secrets, dependencies, SAST, the masking rules, Grype, Retire.js, zizmor, shellcheck, Bandit).contracts/coverage-thresholds.json, a data file the agent does not read) and anything that deploys. The emulator-backed suites ran in CI only (see above).Acknowledgment
By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of the project license.