Skip to content

RFC 972: Structured design context in synthesized templates - #981

Open
satyakigh wants to merge 10 commits into
aws:mainfrom
satyakigh:context-rfc
Open

satyakigh wants to merge 10 commits into
aws:mainfrom
satyakigh:context-rfc

Conversation

@satyakigh

@satyakigh satyakigh commented Aug 4, 2026

Copy link
Copy Markdown

This is a request for comments about Structured design context in synthesized templates. See #972 for
additional details.

APIs are signed off by @iliapolo


By submitting this pull request, I confirm that my contribution is made under
the terms of the Apache-2.0 license

Comment thread text/0972-metadata-context.md
Comment thread text/0972-metadata-context.md Outdated
Comment thread text/0972-metadata-context.md Outdated

@iliapolo iliapolo left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@satyakigh Are you also looking for feedback on the schema itself, or just the CDK part of things?

Comment thread text/0972-metadata-context.md Outdated
Comment thread text/0972-metadata-context.md
Comment thread text/0972-metadata-context.md Outdated
Comment thread text/0972-metadata-context.md Outdated
Comment thread text/0972-metadata-context.md Outdated
Comment thread text/0972-metadata-context.md Outdated
Comment thread text/0972-metadata-context.md Outdated
Comment thread text/0972-metadata-context.md Outdated
Comment thread text/0972-metadata-context.md Outdated
Comment thread text/0972-metadata-context.md Outdated
Comment thread text/0972-metadata-context.md Outdated
Comment thread text/0972-metadata-context.md
Comment thread text/0972-metadata-context.md
Comment thread text/0972-metadata-context.md Outdated
Comment thread text/0972-metadata-context.md Outdated
Comment thread text/0972-metadata-context.md
Comment thread text/0972-metadata-context.md Outdated
Comment thread text/0972-metadata-context.md Outdated
Comment thread text/0972-metadata-context.md
Comment thread text/0972-metadata-context.md Outdated
Comment thread text/0972-metadata-context.md
Comment thread text/0972-metadata-context.md Outdated

The four allowed sources are:

* `authored` - a person wrote or explicitly confirmed the information.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

What if a human authored it AND any of the other three below are also true? Just something to consider

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

I think it becomes more important to create a source for AI agents specifically, and less so for humans

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Added a precedence rule to Appendix A. authored applies whenever a person wrote or confirmed the text, even if it came from a comment, commit, or inference; the evidence goes in cite and note. Otherwise use the most direct evidence: comment, then commit. infer applies when the tool reasoned or combined evidence. A worked example is included.

Agreed on the second point. Three of the four values exist for automated producers, and the RFC now says so; a person writing Context directly in CDK code can omit trust. The enum is fixed by the published v1 schema (https://docs.aws.amazon.com/AWSCloudFormation/latest/TemplateReference/aws-attribute-metadata.html#aws-attribute-metadata-context-schema), so a dedicated agent value would be a schema change. infer already plays that role, and the authoring skill (https://github.com/aws/agent-toolkit-for-aws/blob/main/skills/core-skills/aws-cloudformation/SKILL.md) is where agent guidance is tuned.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

I see it. I think this information should be an instruction to authors and AI agents both, and should be part of the README (if not also the skill)

Comment thread text/0972-metadata-context.md Outdated
Comment thread text/0972-metadata-context.md Outdated
Comment thread text/0972-metadata-context.md Outdated

@iliapolo iliapolo left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Also please provide the full public API of all classes we are introducing (in TypeScript form). Right now its kind of scattered between examples and hard to get a full picture.

We can then approve that API and merge it as stable from the get go.

Comment thread text/0972-metadata-context.md Outdated
Comment thread text/0972-metadata-context.md Outdated
Comment thread text/0972-metadata-context.md Outdated
Comment thread text/0972-metadata-context.md Outdated
Comment thread text/0972-metadata-context.md Outdated
Comment thread text/0972-metadata-context.md Outdated

Two classes write the same documented template fields: `ResourceMetadataContext` writes
information on individual resources, and `TemplateMetadataContext` writes information once
for the whole template. `MetadataContextMixin` is a CDK Mixin, which is an API applied

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

For consistency with the aspect classes - it also makes sense because it can only be applied to resources.

Suggested change
for the whole template. `MetadataContextMixin` is a CDK Mixin, which is an API applied
for the whole template. `ResourceMetadataContextMixin` is a CDK Mixin, which is an API applied

@satyakigh satyakigh Sep 22, 2026

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

The Mixin is removed entirely (see the thread on the Mixin form section below)

Comment thread text/0972-metadata-context.md Outdated
People and automated tools that inspect a deployed template can
therefore use the author's intent instead of guessing it.

Two classes write the same documented template fields: `ResourceMetadataContext` writes

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
Two classes write the same documented template fields: `ResourceMetadataContext` writes
Two aspects write the same documented template fields: `ResourceMetadataContext` writes

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Changed to "Two APIs". I avoided "aspects" because TemplateMetadataContext isn't aspect-backed: it writes the stack's template Metadata directly when add() is called. Only ResourceMetadataContext registers an aspect.

Comment thread text/0972-metadata-context.md Outdated
Comment on lines +89 to +95
No `trust` block appears because the caller did not provide one. The `trust` field is
optional, and CDK never adds it automatically (see *Source and confidence* below).
`mutable` is `change-with-constraints`, and the governing rule is recorded in
`must`: `VisibilityTimeout` must remain at least six times the Lambda timeout.
`change-with-constraints` means a value may change only while its stated rules remain true;
using that value without a corresponding `must` rule gives the reader no useful guidance.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

No need for this entire paragraph - it should all be mentioned in the schema definition we link to already. Unless you want to emphasize a specific property - but then also give a short explanation about it. I think we can just remove it.

@satyakigh satyakigh Sep 22, 2026

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Removed

`why` or `must` when another applicable declaration supplies them, and no template-level
field is required either.

##### Propagation is explicit

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This should come sooner - just after you show the example of add, that way the reader still has this API in their mind.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Moved. Propagation is explicit now follows the first add() example directly, and the quality guidance moved to the end of the README as Writing good context.

Comment thread text/0972-metadata-context.md Outdated
`change-with-constraints` means a value may change only while its stated rules remain true;
using that value without a corresponding `must` rule gives the reader no useful guidance.

##### Resource context quality

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Should go last after all other field specific explanations. Also rename to Writing good context

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Done. It is now the last section, titled Writing good context, and it also absorbed the conciseness and size paragraphs that used to trail Template-level context.

Comment thread text/0972-metadata-context.md Outdated
Comment on lines +209 to +217
Template level here means `TemplateMetadataContext`, not the template's built-in
`Description`. The two serve different readers: `Description` is one short, unstructured
string (at most 1,024 bytes) that CloudFormation shows in the console stack list and
returns from `DescribeStacks`, so it works best as a one-line statement of what the stack is.
`TemplateMetadataContext` holds the structured fields `arch`, `must`, `ref`, and `owner`,
which are returned only inside the template body (`GetTemplate`) and answer how the system
is shaped, which rules apply everywhere, and where supporting material lives. Avoid repeating
the `Description` text in `arch`, and keep rules out of `Description`. See *Template-level
context* below for a side-by-side comparison.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Too much information about a side concept. Remove it (instead just link to the relevant section in the paragraph above).

@satyakigh satyakigh Sep 22, 2026

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Removed. The paragraph above now links to Template-level context

Comment thread text/0972-metadata-context.md Outdated
contributing evidence in `cite` and `note`.

For example, a tool that lifts `why` from a comment writes `src: COMMENT` and
`cite: 'lib/queue.ts:42'`; when the author reviews and accepts it, `src` becomes `AUTHORED`

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

You mean "src should become AUTHORED"? As in, the PR author should make a change after getting approval?

@satyakigh satyakigh Sep 22, 2026

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Yes. It now reads: "the author (or the tool, on the author's confirmation) should change src to AUTHORED and keep cite"

Comment thread text/0972-metadata-context.md Outdated
and `cite` stays. Three of the four values exist for automated producers, where `src` matters
most: a reader must be able to tell tool-derived Context from Context a person stands behind.
A person writing Context directly in CDK code can omit `trust`, because the reviewed source
already shows who wrote it. The Agent Toolkit's CloudFormation and CDK skills will be

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

already shows who wrote it

What do you mean? how? I thought a person writing context should explicitly use AUTHORED...

@satyakigh satyakigh Sep 22, 2026

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

That sentence conflated source history with what a template reader can see. It now reads: a person writing Context directly uses src: AUTHORED; a tool uses COMMENT, COMMIT, or INFER according to its evidence and switches to AUTHORED only after a person confirms the text. trust stays optional per the schema, so a block without it leaves the source unstated, and the text recommends setting it wherever tool-derived and human-written Context may share a template.

Comment thread text/0972-metadata-context.md Outdated
[Appendix A](#appendix-a---cloudformation-context-template-field-reference) for the
`trust` object.

##### Mixin form

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Why do we actually need the mixin here? what does it give that the aspect doesn't?

Im also seeing the mixin API doesn't have all the capabilities, for example inheritAncestorContext, is that intentional? If we don't really need the mixin, lets not have it. If we are keeping it - we should also mention how conflicts between the aspect and the mixin are handled.

@satyakigh satyakigh Sep 22, 2026

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Agreed, and removed. It was a strict subset of the aspect: .with() on an L1 is ResourceMetadataContext.of(cfnResource).add(), and Mixins.of(scope).apply() is add(..., { propagate: true }), except that it applied eagerly, so resources created after the call were missed. It also needed an awslint mixin-namespace exemption. The Public API is now three classes

Comment thread text/0972-metadata-context.md Outdated
Comment on lines +376 to +377
directly with `CfnResource.addMetadata()`. If manually added information and a metadata-
context API target the same resource and key, template generation fails instead of silently

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
directly with `CfnResource.addMetadata()`. If manually added information and a metadata-
context API target the same resource and key, template generation fails instead of silently
directly with `CfnResource.addMetadata()`. If manually added information and a metadata-context API target the same resource and key, template generation fails instead of silently

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Applied, rewrapped so metadata-context stays on one line.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants