Status: working design doc for the attribute-granular misplacement rule (issues #60, #62), tracking PR #61. Living document — to be cleaned into reference prose once the implementation lands. Captures the redesign of the “configurable argument documented under Attribute Reference” check.
PR #61 implemented #60 as a two-pass, whole-subsection reclassification bolted
onto checkLabels. It has taken ~8 rounds of review, each patching one more
heading permutation. That is a design smell, not bad luck. The rounds cluster
around three assumptions that real docs violate:
### outer.notification and ### notification).The three still-open review comments are each a direct consequence:
checkComputedMisplacement
(schema_docs.go:489/516). The primary finding contradicts another rule. This
is a correctness defect in the advice itself, not a suppression gap.uniqueSchemaPathForLeaf
suppression matches on leaf alone and silently drops a warning for an
unrelated dotted heading.Root cause: the check operates at subsection granularity with an ownership-based heading→path resolver and a homogeneity assumption. The defect it is trying to describe is per attribute (“this configurable argument is under the wrong section”). Every mismatch between those two granularities becomes a special case.
Re-reading the issues from scratch:
argument "X" is documented under
Attribute Reference but is a configurable argument; move it to Argument
Reference, noting “That’s a distinct code path, not a relaxation of the
blockName == "" guard.”So the true requirement is one rule, stated per attribute:
A labeled attribute documented under Attribute Reference that is a purely configurable argument in the schema (
Required/Optionaland notComputed) is misplaced. Tell the author to move that argument to Argument Reference, instead of telling them to strip its (correct) label.
Nested blocks (#60) and root scalars (#62) are the same rule at different paths. The whole-subsection message is a presentation optimization for the common case where an entire block is misplaced — not the detection unit.
#60 scope after this redesign (crisp statement). #60 is resolved for configurable blocks documented under schema-name, dotted, or unique-leaf-headed subsections — the overwhelming majority. It is not 100% closed: prose-headed configurable blocks (§12: 9 measured labeled shared-shape cases across 3 resources) intentionally retain the legacy strip-label behavior, since resolving them requires the anchor bridge §12 declined to build. That residual is an accepted, measured limitation tracked as a follow-up — not an oversight.
Superseded in part by field-homes.md (#111).
configurableArgAtPathnow countsOptional+Computedas an argument, so the “not pure-config” rows below no longer cover it, and a field that Argument Reference also lists is a repeat (reported by the repeated-field finding), not a move.
Detect per attribute. Aggregate for the message only.
The per-attribute primitive already exists:
configurableArgAtPath(rs, path, attrName) bool returns true iff, at schema
path, attrName is a configurable argument (a Required/Optional non-
Computed scalar, or a child block whose subtree contains a pure-config field).
Given that primitive, misplacement no longer needs ownership resolution, “moved path” sets, alternate-heading suppression, or reference-bullet suppression. Each labeled attribute is judged on its own.
A under Attribute Reference, in a block resolved to schema path P| Condition | Finding |
|---|---|
configurableArgAtPath(P, A) is true |
misplacement — move A to Argument Reference |
A exists in schema at P but is not pure-config (computed-only, or Optional+Computed) |
strip-label warning (unchanged, pre-#60 behavior) |
A not resolvable in schema (P unknown, or A absent) |
fall back to strip-label (safe; coverage/phantom rules own “doesn’t exist”) |
Optional+Computed and ConfigUnknown remain non-misplacement by construction
(configurableArgAtPath already returns false), honoring #62’s guard.
Misplacement does not use the coverage “ownership” resolver
(schemaPathsResolvedByDocKey / most-specific single owner). Ownership exists to
avoid double-counting coverage; it is the wrong tool for “does this documented
argument correspond to a configurable schema field.” We resolve a subsection
heading K to a schema path P with a simpler, stricter rule:
K contains ., e.g. outer.notification): P = K
iff rs.Blocks[K] exists; otherwise unresolved. A dotted heading
claims an exact path — never remap it by leaf. (This is what fixes 2/3
cleanly: a phantom outer.notification never borrows other.notification.)K has no ., e.g. notification): P = K if
rs.Blocks[K] exists (root-level unique name); else
P = uniqueSchemaPathForLeaf(K) if exactly one schema path has that leaf; else
unresolved. (This is what fixes 1/3: ### notification resolves to the
sole outer.notification regardless of which heading “owns” it for coverage.)Inference watch-point. The bare-heading
unique-leafbranch is the only step that infers a path rather than reading it exactly. It is double-gated (unique leaf andconfigurableArgAtPathmust confirm pure-config at that path), so it cannot promote a non-configurable field. But it is new behavior vs PR #61 — PR #61’s ownership resolver returned “not owned” for split headings and emitted nothing there. Therefore PR #61’s “identical before/after” corpus evidence does not cover unique-leaf-inferred findings. These must be enumerated and cleared explicitly in the corpus delta before shipping at ERROR (see §9). The real FP axis is exact-resolved vs unique-leaf-inferred, which runs through both root and nested; the path-class severity split (§9) is a proxy for it and must not hide the inferred-nested slice from validation.
- Root (
K == ""):P = ""(top-level scalars — #62).- Heading-less synthetic block (dot-path reference bullets like
outer[*].notification): resolve the parent by exactrs.Blocks[parent]; the bullet’s attribute is the referenced leaf. (Same as today’s heading-less fallback, retained.)
Multiple headings resolving to the same P is now fine — each heading’s
labeled attributes are judged independently. No “steal ownership,” no
“suppress the alternate.”
Detection is per attribute; we choose the message per subsection:
For a resolved subsection at path P with a real heading, after classifying its
labeled attributes:
block "P" ... move this subsection to Argument Reference — iff:
Precision (required): condition 2 is the intersection of the subsection’s
own documented bullets with schema-computed status — not “the schema
subtree at P contains a computed leaf.” An undocumented computed leaf must
not block a legitimate collapse. Concretely: iterate the subsection’s
documented attributes; if any resolves to a computed-only schema field at P,
do not collapse. This is the #60 budget case: a purely configurable block
sitting in the wrong section → one clean, followable finding.
Otherwise emit per-attribute moves —
argument "A" in block "P" ... move it to Argument Reference — for each
misplaced attribute, and leave computed-only fields where they are. A
computed-only field that is correctly unlabeled draws no finding; one that
carries an erroneous (Required)/(Optional) label still draws the legacy
strip-label warning (it is not configurable, so it is never a move).
This is the mixed block (3/3): the author moves only the configurable bullets;
the computed outputs correctly remain under Attribute Reference. Following the
findings now yields a clean document — checkComputedMisplacement is never
provoked.
P == "") never collapses: always per-attribute (#62).The collapse condition keys on the schema (is any documented field computed-only), so it is deterministic and independent of heading style.
Emit at most one finding per resolved target:
(P, A);P;Two templates — the presence/absence of the block clause is the natural fallout
of “root never collapses / attribute-level phrasing.” Both keep “in the schema”
so per-attribute and collapse findings read as one family. Render every path via
displayPath() for consistent formatting.
block "P" is documented under Attribute Reference but
is a configurable argument block in the schema; move this subsection to
Argument Reference (unchanged from current).argument "A" in block "P" is documented under
Attribute Reference but is a configurable argument in the schema; move it to
Argument Reference.P==""): argument "A" is documented under Attribute
Reference but is a configurable argument in the schema; move it to Argument
Reference (no block clause — in block "(root)" reads badly).The new model removes the machinery that generated the rounds:
movedBlocks, movedSchemaPaths, movedPath,
misplacedLine);referencesMovedBlock (reference-bullet suppression);uniqueSchemaPathForLeaf-based alternate suppression as a suppression
(the helper stays, repurposed as bare-heading resolution);headedDocBlocks and the synthetic-ownership-stealing guard (ownership is no
longer used for misplacement);BlockAnchors suppression already removed earlier.Net: one pass over AttributeBlocks, a per-attribute classifier, and a
per-subsection message chooser.
| Item | Old behavior | New behavior |
|---|---|---|
| 3/3 mixed block | whole-subsection move → contradicts computed rule | per-attribute move; computed fields stay → clean doc |
| 1/3 split headings | config in alternate heading never flagged; strip-label leaks | bare heading resolves to sole path; attr flagged correctly |
| 2/3 leaf over-match | dotted phantom borrows another path’s move, drops warning | dotted heading resolves by exact path only → no borrow |
| prior: synthetic steals ownership | needed headedDocBlocks guard |
ownership unused; synthetic resolved by exact parent |
| prior: alternate heading strip-label | needed suppression pass | independent per-attr judgment |
| #62 root scalars | out of scope / misleading strip-label | same rule at P=="", per-attribute |
checkComputedMisplacement collision.Optional+Computed → no move (strip-label/none). Guards the sole inference step in §4.Optional+Computed and ConfigUnknown fields → never misplacement (strip-label/none), per #62 guard.skip_blocks path → exempt (carry over current filter, applied to P).Severity is split by false-positive risk per resolution class, not by a time-based “second pass”:
| Finding class | Severity | Rationale |
|---|---|---|
| Nested subsection collapse move | ERROR now | Whole block configurable; highest confidence; parity with merged behavior |
| Nested per-attribute move, exact-resolved | ERROR now | Same schema-grounded signal as collapse; only presentation differs — severity must not depend on sibling count |
| Nested per-attribute move, unique-leaf-inferred | ERROR now — gate measured clear | See below: 0 contested cases on the corpus, so no new-vs-#61 slice |
Root scalar move (P=="") |
WARN, promote to ERROR after a clean corpus run | Root legitimately holds many computed outputs; Optional+Computed common — exactly what #62 asked to gate |
configurableArgAtPath already structurally excludes the main root FP vectors
(Optional+Computed, ConfigUnknown), so WARN-at-root is cheap insurance, not a
permanent posture.
The split is explicitly transitional, not a permanent two-tier UX. A user must never see the same “move it” message as ERROR in one doc and WARN in another purely because of internal resolution method — that is confusing. The only lasting severity distinction is confidence, and once the root bucket clears its own corpus run it collapses to uniform ERROR with the rest. The WARN tier is a rollout artifact with a scheduled end, not a design feature.
Severity is derived from the resolved path, not a stored class. In the final
model every nested move and collapse is ERROR and only a genuine root scalar is
WARN, so severity is a function of the resolved (path, target): WARN iff both
are the root (""), else ERROR. The resolution class (dotted-exact /
bare-exact / unique-leaf / root) is still produced by
resolveSubsectionPath and pinned by the classifier test (it validates §4 and
documents provenance), but it is not threaded onto Result — the unique-leaf
gate below cleared the only class distinction that would have affected severity,
so no per-class field is needed. (Severity is data-driven from the resolved path,
never parsed back out of the message.)
The unique-leaf bucket is distinct from §12’s prose-bridge bucket: shared
shapes are ambiguous leaves (multiple schema paths) → uniqueSchemaPathForLeaf
returns false → they land in unresolved/prose, not here. Unique-leaf inference
fires only for a bare heading whose leaf maps to exactly one non-root schema
path. Measured on terraform-provider-aws (2,662 docs, same harness as §12):
| would-be move finding, by resolution class | subsections |
|---|---|
| dotted-exact | 0 |
| bare-exact | 3 |
| unique-leaf-inferred | 7 (18 cfg attrs, 3 resources) |
| …contested (path also documented by a competing heading — the only slice that differs from PR #61) | 0 |
The mainstream nested case (### endpoint → cluster.endpoint) resolves by
unique-leaf, but PR #61’s ownership resolver already resolved it the same way
via leaf matching — so it is not new behavior. The only genuinely-new slice
is contested unique-leaf (split/alternate headings), and there are 0 on the
corpus. That clears the gate: nested unique-leaf-inferred ships at ERROR now.
The examples are all real nested configurable blocks (recurrence.daily_settings,
rule.statement.rate_based_statement.custom_key, …).
This redesign changes corpus output on purpose — the PR #61 “identical before/after, zero new FPs” guarantee is void by design. Validation is:
The PR description must be rewritten to present this categorized delta and drop the “identical before/after” claim.
Both binaries run over terraform-provider-aws with .ci/swissshepherd-full.hcl
(schema_docs enabled broadly), JSON output, findings keyed on
(resource, path, severity, message). Stable across a schema refresh.
Nondeterminism floor. Running either binary twice differs by ~487
findings — all block "…" is not documented coverage findings on
many-identical-sibling resources (aws_quicksight_*, aws_wafv2_*), where the
representative sibling path is chosen nondeterministically. This is a
pre-existing coverage issue present in both binaries, unrelated to
misplacement (misplacement findings are fully deterministic: new-vs-new
misplacement delta = 0/0). Tracked separately as #65.
Deterministic misplacement delta: 4 removed, 9 added — all correct.
Removed (two-pass only):
aws_sagemaker_human_task_ui — attribute "ui_template" … should not have
(Required) label (WARN). A misleading strip on a required min_items=1
block — the #60 defect (two-pass skipped the root).aws_wafv2_rule_group — block "custom_key" … move this subsection
(ERROR). A wrong wholesale collapse: custom_key also documents
read-only child blocks (forwarded_ip, http_method, ip, asn), which a
wholesale move would drag into Argument Reference.
3–4. aws_ssmcontacts_rotation — attribute "daly_settings" in block
"recurrence" … should not have (Optional) label and attribute
"day_of_week" in block "shift_coverages" … should not have (Required)
label (WARN). Both recurrence and shift_coverages collapse (in both
binaries), so telling the author to strip these labels contradicts the
wholesale move to Argument Reference, where the labels are required. The
redesign suppresses strips inside a collapsing subsection; the unrelated
hand_off_time strips (that subsection does not collapse) are unaffected.Added (redesign only):
aws_sagemaker_human_task_ui — argument "ui_template" … move it (ERROR).
The redundant labeled config-block reference under Attribute Reference is
now surfaced as a move (child-ref dedup + target-based severity), replacing
the misleading strip.
2–9. aws_wafv2_rule_group — argument "<child>" in block "custom_key" … move
it (ERROR) for the eight pure-config children (cookie, header,
ja3_fingerprint, ja4_fingerprint, label_namespace, query_argument,
query_string, uri_path). The read-only children are correctly left under
Attribute Reference (the mixed-block / collapse-guard fix).Schema inspection confirmed custom_key is genuinely mixed (8 pure-config
children, 4 read-only), so per-attribute moves are correct and the two-pass
collapse was wrong.
Hard invariant satisfied: every added finding targets a genuinely misplaced configurable field; zero new false ERROR on a correctly-placed field. The net effect is strictly better guidance (a misleading strip, an over-broad collapse, and two collapse-vs-strip contradictions replaced by precise, non-contradictory findings).
classifyAttrPlacement(ctx, P, attr) -> {misplaced|stripLabel|ok}
wrapping configurableArgAtPath + label state.resolveSubsectionPath(rs, docBlocks, K) -> (P, class, ok)
implementing the §4 rules (dotted=exact, bare=exact|unique-leaf, root,
heading-less=exact parent). class is the resolution provenance
(dotted-exact / bare-exact / unique-leaf / root). Keep ownership
resolution untouched for coverage.
2b. Derive severity from the resolved path. Severity is a function of the
resolved (path, target) — WARN only for a genuine root scalar (both root),
ERROR otherwise (all nested moves and collapses). The resolution class from
resolveSubsectionPath is validated by the pinned classifier test but is not
stored on Result; no per-class field is needed, because the unique-leaf gate
(§9) cleared the only class-dependent severity distinction.checkLabels’ Attribute-Reference half as a single pass:
resolve P; classify each labeled attr; choose message granularity per §5;
dedup per §5.P==""; close #62 with this PR or note it.go test ./..., gofmt, go vet, make modern-check,
copyplop check).blockName=="" special case §6 deletes; root-in is a ~3-line consequence
(P=="" never collapses, always per-attribute). Close #62 with this PR.displayPath() throughout.Gap. §4 resolution is schema-grounded (dotted=exact, bare=exact|unique-leaf),
so a prose-headed subsection (### Budget Notification rather than
### notification Block) resolves to nothing and falls back to strip-label —
i.e. a prose-headed configurable block under Attribute Reference still slips
through, which is the #60 failure otherwise fixed. Terraform docs use
descriptive headings frequently, so this is a real gap.
Proposed mechanism (anchor-based resolution, distinct from the deleted
anchor-based suppression). The root argument bullet names a schema key and
links to the subsection:
`notification` - (Optional) ... [Budget Notification](#budget-notification).
That yields a chain schema-key bullet → link anchor → subsection heading. The
schema path comes from the key (reliable), not the slug; the anchor only
identifies which prose heading belongs to that key.
Why it is defensible where suppression was not. Suppression used anchors to silence a warning → fragility caused silent misses of real problems. Gated resolution uses anchors to find a candidate the schema then confirms → fragility causes a miss, never a false alarm.
Hard constraints if ever built:
configurableArgAtPath gate at the resolved
path, so a wrong/missing/mis-slugged anchor can only cause a false negative
(missed detection), never a false positive (fabricated move). This
containment is the price of re-coupling to the slug subsystem (the one PR #63
hardened).Measured with a build-tagged pipeline test (internal/check/measure_prose_test.go,
-tags measure; removed in #89, last version at 9b2f892; reusing the real runner + redesign §4 resolution + a generalized
anchor bridge that follows nested parents, not just root):
| metric | count |
|---|---|
| docs parsed | 2,662 |
| prose (unresolved) subsections under Attribute Reference | 70 |
| …with ≥1 labeled attribute | 9 |
| …bridgeable via a configurable-parent anchor | 9 (all) |
| …across resources | 3 (inspector2_filter, ssmcontacts_rotation, wafv2_rule_group) |
| …labeled configurable attrs the bridge would move | 23 |
| …prose+labels with NO bridge (residual) | 0 |
Findings:
#anchor, e.g. ### Date Filter linked from ~8 date fields), i.e.
the shared/renamed-subsection class, not plain prose headings.### Filter Criteria → filter_criteria), so the redesign already emits the
actionable primary finding (“move filter_criteria”). The bridge would add 23
per-attribute moves on the shared leaf shapes on top of that — more noise,
not more clarity.Decision: do not build the anchor bridge. The redesign leaves these 9 subsections at their current strip-label behavior (no regression). Track shared-subsection handling as a low-priority follow-up (fold into / alongside #62) with this evidence attached; revisit only if the population grows materially.
Both the §12 (prose/bridge) and §9 (resolution-class) numbers come from
measure_prose_test.go (removed in #89; restore it from 9b2f892 to re-run),
which was -tags measure and therefore never ran in CI. They are a point-in-time snapshot of an already-cleaned corpus — the
budgets_budget misplacements that motivated #60 have since been fixed and
ignore_targets masks known offenders, so the counts (9 prose / 3 resources; 7
unique-leaf / 0 contested) will drift as those change and understate the natural
frequency. To keep the claims honest:
ignore_targets shrinks
materially or before promoting the root bucket to ERROR; record the fresh
numbers in the follow-up issue.contested drift is visible
each validation. A tiny committed unit test over a synthetic fixture (not the
live provider) should assert the classifier behavior
(dotted/bare/unique-leaf/unresolved) so a parser/slug change cannot silently
reclassify — the corpus numbers may drift, but the classification logic stays
pinned.