Skip to content

feat(validate): let a rule acknowledge a trap notice by id - #723

Merged
aibex-agent[bot] merged 3 commits into
mainfrom
aibex/t_xPZFol3dyLpkxL9rgNDWz8U7
Nov 30, 2026
Merged

aibex-agent[bot] merged 3 commits into
mainfrom
aibex/t_xPZFol3dyLpkxL9rgNDWz8U7

Conversation

@aibex-agent

@aibex-agent aibex-agent Bot commented Nov 29, 2026

Copy link
Copy Markdown

validate reports the ast-grep authoring traps as notices, but they are structural: the awaited-generic callee notice fires on every TypeScript callee regex under field: function with no await_expression branch, whether or not the code base ever writes await fn<T>(). Nothing in a rule could record that the author had checked, so the notice repeated on every run. Two PMF survey runs reported it as noise.

Narrowing the heuristic is not sound (await api.get<Foo>() is a member callee too), so this lets the author say so instead.

What changes

  • Each trap notice has a stable id: ellipsis-before-comma, comma-before-ellipsis, sibling-without-stopby, descent-without-stopby, awaited-generic-callee. The two $$$ forms and the two stopBy forms get separate ids because they are separate decisions with separate remedies.
  • A rule acknowledges a trap in its own file:
    metadata:
      taskless:
        acknowledge: [awaited-generic-callee]
    metadata is ast-grep's free-form field, so the rule still passes the vendored schema and ast-grep's own parse. Confirmed end to end with validate, verify and check.
  • validate and verify skip an acknowledged notice and still print every other one. Acknowledgement is per rule and per id. It is not keyed to a relation's path, because that path shifts whenever a branch is added.
  • --json gains an always-present acknowledged: [{ id, notice }] per rule, so an agent can tell a silenced notice from one that never fired.
  • An unknown id, or a non-list value, draws a notice naming the known ids. It never fails the rule.
  • create-sg-rule (topic v19) documents the ids next to the Quirks table and prefers the in-rule spelling where one exists (stopBy: neighbor, strictness: ast). validate-rule (topic v13) documents acknowledged.

Why the rule file and not a sidecar or a comment: .taskless/rule-metadata/ has never been written by anything (see agent rule-meta). The YAML parser validate uses drops comments, so a comment would need a second parse and would not survive tools that rewrite the rule. The design is in openspec/changes/archive/2026-11-29-acknowledge-sg-trap-notices/design.md.

Checks

pnpm typecheck, pnpm lint, and pnpm test pass (3426 tests). New unit cases cover acknowledgement, isolation between traps, and unknown or malformed ids. A new end-to-end validate --json case runs the issue's reproduction rule with and without the acknowledgement. The OpenSpec change is archived and cli-rule-validation keeps every prior scenario (67 → 71).

Fixes #713

Each ast-grep trap notice gets a stable id, and a rule listing one under
metadata.taskless.acknowledge stops drawing it. validate/verify --json
report silenced notices under an always-present acknowledged array.
@aibex-agent

aibex-agent Bot commented Nov 29, 2026

Copy link
Copy Markdown
Author

@claude /review

@github-actions

github-actions Bot commented Nov 29, 2026 •

Copy link
Copy Markdown
Contributor

Claude finished @aibex-agent[bot]'s task in 2m 57s —— View job


Review complete

Review mode: incremental — read 0 prior review thread(s) before reviewing. .prior-review.json contained no reviews, review threads, or top-level comments beyond the trigger comment itself, so this is the first review of this PR.

  • Read .prior-review.json
  • Fetch PR diff and metadata
  • Review changed source files (sg-traps.ts, inspect.ts, verify.ts, rule-check.ts)
  • Review tests
  • Review docs/openspec changes
  • Post findings

Summary

The implementation is clean and the wiring is complete: findSgTraps now returns { notices, acknowledged }, and every caller that previously threaded a bare notices: string[] (verify.ts's several early-return branches, inspect.ts's validateSgRule/validateRuleComponents/verifyOneRule, the vale and runtime branches) now threads acknowledged alongside it — I checked each site and didn't find one that was missed. The human-output renderer (commands/verify.ts) only iterates result.notices, so acknowledged entries correctly stay silent outside --json, and results is passed straight into ruleCheckOutputSchema.parse, so acknowledged reaches JSON output unmolested. The five trap ids, the per-rule/per-id (not per-relation) design, and the "unknown id draws a notice, never fails the rule" behavior all match what's described in the proposal/design docs and are covered by the new tests in sg-traps.test.ts and the end-to-end case in verify.test.ts.

[New] One gap, posted inline on packages/cli/src/rules/sg-traps.ts:110: readAcknowledgements validates that metadata.taskless.acknowledge is a list of strings (and reports a notice if not), but doesn't validate the shape of metadata.taskless one level up. If an author nests the id one level too shallow — e.g. metadata: { taskless: ["awaited-generic-callee"] } instead of metadata: { taskless: { acknowledge: [...] } } — the field() helper returns undefined for a non-object taskless, and the function silently reports nothing: no acknowledgement takes effect, and no notice tells the author why. This is the exact kind of mistake the "unknown id" / "malformed list" notices exist to catch one level down, but it isn't caught here, and no test exercises a malformed (non-object) metadata.taskless.

No other correctness, security, or test-adequacy issues found. The docs (create-sg-rule.md, validate-rule.md) and openspec deltas accurately describe the shipped behavior.

Comment thread packages/cli/src/rules/sg-traps.ts Outdated
} {
const ids = new Set<string>();
const taskless = field(field(rule, "metadata"), "taskless");
if (taskless === undefined || !("acknowledge" in taskless)) {

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.

[New] readAcknowledgements only validates the shape of metadata.taskless.acknowledge itself (not-a-list-of-strings → a notice naming the known ids). It doesn't validate the shape of metadata.taskless one level up. If an author nests the id wrong — metadata: { taskless: ["awaited-generic-callee"] } or metadata: { taskless: "awaited-generic-callee" }, putting the id where acknowledge should sit — field(metadataObj, "taskless") returns undefined (line 141-144: non-object/array values return undefined), so this function takes the early return at line 110-112 and reports { ids: empty, notices: [] }. The trap keeps firing exactly as if nothing were declared, and — unlike an unknown id or a malformed acknowledge list — the author gets no notice telling them the acknowledgement did nothing.

That's the one authoring mistake this feature is most exposed to (three levels of nesting, taskless.acknowledge rather than taskless itself), and it's the one case D5 and the existing "unknown id" / "not a list" notices don't cover. Worth a third notice branch here: when metadata.taskless exists but isn't an object (or has no acknowledge key but isn't empty-object either), say so, the same way a bad acknowledge value does.

Not covered by any of the new tests either — sg-traps.test.ts's "ignores metadata that says nothing about Taskless" case uses metadata: { owner: "payments" } (no taskless key at all), not a malformed taskless value.

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.

Fixed in feb7a28. A metadata.taskless that is present but holds no acknowledge list (a list, a string, or an object missing the key) now draws a notice showing the right nesting and the known ids. Tests cover all three shapes, and the spec sentence now includes the case.

@aibex-agent
aibex-agent Bot merged commit 4487fb1 into main Nov 30, 2026
5 checks passed
@aibex-agent
aibex-agent Bot deleted the aibex/t_xPZFol3dyLpkxL9rgNDWz8U7 branch November 30, 2026 00:43
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.

validate: the awaited-generic callee notice can't be acknowledged, so it repeats on rules that never see a generic call

1 participant