Skip to content

Require a description on every play rule, condition and action, and reject stale ones - #3529

Merged
malibio merged 5 commits into
mainfrom
issue-3517-play-rule-descriptions
Oct 4, 2026
Merged

malibio merged 5 commits into
mainfrom
issue-3517-play-rule-descriptions

Conversation

@malibio

@malibio malibio commented Oct 4, 2026

Copy link
Copy Markdown
Collaborator

Closes #3517. Implements ADR-090 §1 and §7.

The type change

play is a structured core type; its kind and category are unchanged. The change is to the nested RuleDefinition value stored in play.rules:

Where Before After
RuleDefinition.description absent required string
RuleDefinition.conditions string[] (CEL) RuleCondition[]: { expr, description }, both required
each Action variant action_type, params, for_each plus a required description
Trigger no description unchanged

No field, relationship or structural rule of the play schema changes, so node-types.md already matches (node-types:check passes). Generated TypeScript is regenerated (rule-condition.ts is new). Pre-release: no migration of stored plays; reset the database.

Validation

  • Decode rejects a missing description and a bare-string condition, naming the rule and the field: rule[0] ('greet'): conditions[0]: invalid type: string …, expected an object { "expr": …, "description": … }. Stored rules and the typed update report the same text. This uses serde_path_to_error, a new direct dependency of nodespace-types (already in the lockfile).
  • Save time (playbook/descriptions.rs, called from validate_play_rules) rejects a blank description, and on a write that changes rules, a stale one: a changed condition expr, a changed action (action_type, params, for_each), or a changed rule trigger/class that keeps its stored description. Rules match by name, components by index; an unmatched component or a renamed rule is new. Messages read rule complete parent, condition 2: its expression changed and its description didn't. ….
  • A write that leaves rules alone runs neither check, so a play can still be switched off.
  • Resetting a seeded play to its shipped rules is exempt from the stale check. Without this, a reset fails when a user changed a condition and later put the shipped description text back. This is the one behavior the docs did not already state; ADR-090 §1 and playbook-system.md now say it (nodespace-docs 572303e).

The engine, CEL compiler, get_workflow_state and graph resolution work on compiled rules, so the only reader that changed is parse_rule, which now compiles condition.expr.

Seeds, CLI and skill docs

  • The core play and every Linear, Jira and spec-driven play carry descriptions, in the live rules and in _seed.default_rules. Tests check each through the description checks; the install tests take them through the rest of save-time validation.
  • The CLI needed no code change: it prints nodes as stored and writes rules through node update --property rules=…. A new integration test covers the round trip and both rejections over gRPC.
  • Two shared rule fragments (play-rule-descriptions, play-stale-description) in agent and skill forms, tied by anchors and a shared JSON example that is decoded as a real RuleDefinition. The skill form is rendered into a new generated region of references/cli.md. SKILL.md is unchanged (it is at its size cap). The agent forms are not included by any seeded skill yet; the play-authoring skill will include them.

Testing

bun run test:changed passed on every tier (frontend, scripts, skill, browser, types:check, node-types:check, Rust workspace) before the final commit. After it, quality:fix found one e2e fixture in the old shape and one clippy lint, both fixed; the e2e tier itself runs only in the merge gate.

Test fixtures were converted mechanically (placeholder descriptions such as "Test rule"); the production seeds were written by hand.

🤖 Generated with Claude Code

@malibio

malibio commented Oct 4, 2026

Copy link
Copy Markdown
Collaborator Author

Pragmatic Code Review — PR #3529

Review Type: Initial review (no prior reviews or comments on the PR). Read-only: diffs and code were read; no builds or tests were run (the author reports bun run test:changed green on all tiers).

Summary

The change does what ADR-090 §1 and §7 specify, in the right layers: the shape lives once in nodespace-types, the blank/stale checks are a pure function over typed rules (playbook/descriptions.rs), and the gate is the existing validate_play_rules call, which already runs only when rules changed. No compatibility code for the old conditions: string[] shape was left behind, and no bare-string condition survives outside the one test that asserts its rejection. One real edge case (duplicate rule names) and a few small inaccuracies are listed below; none blocks the merge.

Requirements Check (issue #3517)

# Criterion Status Notes
1 description on rule, condition {expr, description}, action; required; generated TS committed ✅ play.rs; rule-condition.ts new, action.ts / rule-definition.ts regenerated.
2 Decode rejects a missing description and a bare-string condition, naming rule and field ✅ decode_rule_list via serde_path_to_error; the same text on stored rules and on PlayNodeUpdate. Tested for all five cases.
3 Save time rejects a blank description, naming rule, component, index ✅ Unit tests plus create and typed-update tests in schema.rs.
4 Stale rejection per ADR-090 §1, with the listed test cases ✅ Changed expr, each of action_type / params / for_each, trigger, class, new component, renamed rule, and rules-untouched write are all tested. See finding 1 for duplicate names.
5 CEL compiler, engine, get_workflow_state, graph resolution read expr; no evaluation change ✅ parse_rule is the only reader of the definition's conditions; everything downstream works on compiled rules. No other .conditions reader exists in agent, CLI, daemon or frontend source.
6 Every core and bundled play carries descriptions; a test validates each through save-time validation ✅ (in two parts) New tests run check_descriptions only; the rest of save-time validation is covered by the install path, which creates each play with create_node (install.rs:392).
7 _seed.default_rules carries the descriptions ✅ Core play test checks both copies; bundled plays write one rules value to both (methodology/mod.rs:133), with an existing equality test.
8 CLI prints the new shape, accepts it, surfaces errors readably ✅ No CLI code change needed. The new test reads through node_to_json, which playbook list --json also uses.
9 SKILL.md / references/cli.md teach it as shared fragments; drift check passes ✅ (partly) Taught in references/cli.md only; SKILL.md is at its size cap and is unchanged. The agent-form fragments are not yet included by any seeded skill (the play-authoring skill is later ADR-090 work).
10 node-types.md still matches ✅ (as reported) No schema field, relationship or structural rule changed. Not re-run here.
11 quality:fix clean, test:changed passes ✅ (as reported) Not re-run here.

Questions the author asked to have checked

  • Does the stale check match ADR-090 §1? Yes. Rule by name, conditions and actions by index, condition content = expr, action content = (action_type, params, for_each), rule description tied to trigger and class only. Comparison is on the typed values, so a re-serialized but equal rule (class omitted vs "reactive", defaulted params) is not a change. Inserting or removing a condition shifts indexes but only misfires when two neighbours carry identical description text.
  • Ungated update paths — new gap? No. On origin/main, validate_play_rules was already called from exactly the same two places (create at crud.rs:620, the version-checked update at crud.rs:1809). update_node_unchecked, update_node_unchecked_in_tx, update_node_in_tx, bulk_update and bulk_create were ungated before and still are. Their non-test callers are internal (play actions, schema writes, the skill updater, seeding); bulk_update has no daemon or CLI caller.
  • Can the reset exemption be abused or misfire? It only drops the stale comparison; blank checks and the full rule validation still run. It needs stored _seed.default_rules to equal the incoming rules exactly, so a non-seeded play never qualifies. See finding 4.
  • Unmet criteria? None unmet; 6 and 9 are met with the caveats above.
  • Are the shipped descriptions accurate? Yes, with one imprecision (finding 3).

Code Review Findings

🔴 Critical

None.

🟡 Important

1. Duplicate rule names make the stale check compare against the wrong rule
📁 packages/core/src/playbook/descriptions.rs:94-95

stored.iter().find(|previous| previous.name == rule.name) takes the first stored rule with that name, and nothing in save-time validation requires rule names to be unique (validation.rs only rejects duplicate action lists). With two stored rules sharing a name — the "duplicate a rule, then change its trigger or condition" authoring pattern that validation.rs:148 describes — the second rule is always compared against the first:

  • Wrong rejection: the second rule kept the copied description and has a different trigger, so any later write that changes anything in rules reports it stale, although the writer did not touch it.
  • Slip-through: a real content change in the second rule is compared with the first rule's text and passes.

The error message is also ambiguous, since it identifies the rule by name alone.

Recommendation: reject duplicate rule names in validate_play_rules (ADR-090's matching and its error format both assume a name identifies one rule), with a message naming both positions. Matching the Nth occurrence to the Nth occurrence would also work but keeps the ambiguous messages. Add a test either way.
Principle: correctness under an input the validator accepts; an identity key must be unique.

🟢 Suggestions

2. A whitespace-only edit counts as a rewritten description
📁 packages/core/src/playbook/descriptions.rs:116, 125, 136

Descriptions are compared with ==, so appending a space satisfies the stale check. Compare trimmed text (the blank check already trims). The check can never stop a determined writer, but this is the cheapest accidental pass, especially for a model re-emitting JSON.
Principle: a validation rule should hold for trivially equivalent input.

3. One shipped description understates the rule it describes
📁 packages/core/src/methodology/jira.rs:418-433

The legal moves are unset → future, future or unset → active, active → closed (jira.rs:401-405). The rule description names only "future to active or active to closed", and the condition description says "a start from future". A sprint started with no status set is allowed and neither text says so. Suggested condition text: "The status change is not a first setting to future, a start from future or from no status, or a close from active". The other descriptions in core_plays.rs, linear.rs, jira.rs and spec_driven.rs were checked against their expr and params and are accurate.
Principle: ADR-090 notes validation cannot catch text that misdescribes its rule; the seeds are the model other authors copy.

4. The reset exemption trusts a client-writable marker
📁 packages/core/src/services/node_service/crud.rs:2672-2682

_seed.default_rules can be supplied by a client at create time (the generated playbook references do exactly that with --properties '{"_seed":{"default_rules":…). A writer could plant rules there and then write them to skip the stale comparison. The impact is small: only the stale check is skipped, and renaming the rule skips it too. No change required; a one-line comment stating that the exemption relaxes only the stale check would keep a later reader from treating _seed as trusted for anything stronger.
Principle: state the trust assumption where the code relies on it.

5. rules: null on a typed update is now an error
📁 packages/nodespace-types/src/play.rs:683-691

deserialize_update_rules decodes through Value, so an explicit "rules": null now fails with "rules: expected an array of rules", where it used to mean "leave unchanged". This matches the generated TypeScript (rules?: Array<RuleDefinition>, no null) and the doc comment ("has no clear path"), so the new behaviour is the better one. It is untested; add one assertion so it stays deliberate.
Principle: behaviour changes at a wire boundary should be pinned by a test.

Nit: packages/agent/src/skill_rules.rs:57 — SchemaRule and all_schema_rule_ids_are_unique now also cover play rules. The doc comment explains it; a neutral name (AnchoredRule) would read better when the play-authoring skill lands.

Nit: packages/core/src/services/node_service/crud.rs:2637-2647 — description errors return before the parse and schema checks, so a write with both kinds of problem takes two attempts to repair. Acceptable; noted only because the messages are meant for an agent's repair loop.

Nit: packages/nodespace-types/Cargo.toml:25 — serde_path_to_error = "0.1" is declared in the crate rather than in the workspace dependency table used by its neighbours.

What was verified and how

  • Verified by reading the code: findings 1 (the find call; the absence of a name-uniqueness check is from searching playbook/ and nodespace-types/ for one and finding none), 2, 3, 5 and the nits; the gate comparison against origin/main; the callers of the ungated paths; the exemption's logic; the CLI playbook list --json path; that no old-shape condition remains.
  • Inference, not executed: the runtime behaviour in finding 1 (no test was run to reproduce it); in finding 4, that _seed is accepted on create is taken from the generated playbook references, and whether a later update may change it was not traced; criteria 10 and 11 rest on the author's reported runs.

Recommendation: APPROVE

The change is a clear net improvement and matches the spec. Finding 1 is worth folding into this PR because it is small and belongs to the same check; the rest are optional.

@malibio malibio left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Automated pragmatic-code-review: APPROVE (posted as a comment — GitHub blocks self-approval). Full findings in the review comment above.

@malibio

malibio commented Oct 4, 2026

Copy link
Copy Markdown
Collaborator Author

Review addressed (commits 'Address review…' and 'Regenerate the Jira playbook reference')

Addressed

  • 1 (duplicate rule names): two rules of one play sharing a name are now rejected at save time (rule x: more than one rule in this play has this name…), on create and on any write that changes rules. Tested. ADR-090 §1 and playbook-system.md say so.
  • 2: descriptions are compared trimmed, so padding the stored text is not a rewrite. Tested.
  • 3: the Jira transition rule's two descriptions now name the start from no status; the playbook reference is regenerated.
  • 4: comment on restores_shipped_rules states that it relaxes only the stale comparison.
  • 5: rules: null on a typed update is pinned by an assertion.
  • Nit: serde_path_to_error moved to the workspace dependency table.

Skipped

  • Renaming SchemaRule: belongs with the play-authoring skill that will use the play rules.
  • Reporting description and schema errors in one pass: rated acceptable by the review; two attempts at worst.

bun run test:changed passes on all tiers after these commits.

@malibio

malibio commented Oct 4, 2026

Copy link
Copy Markdown
Collaborator Author

Pragmatic Code Review — PR #3529

Review Type: Re-Review. Scope: git diff 2e266761..HEAD (commits "Address review: reject duplicate rule names, compare descriptions trimmed" and "Regenerate the Jira playbook reference; format"). Read-only: no builds or tests were run (the author reports bun run test:changed green on all tiers after these commits).

Previous Review Summary

Count Items
Previous recommendations 8 1 Important, 4 Suggestions, 3 Nits
Addressed 6 Findings 1–5 and the serde_path_to_error nit
Not addressed (skipped with a reason) 2 SchemaRule naming; description errors returned before schema errors
New issues 0 blocking 3 optional nits below

Status of each previous finding

# Finding Status What was checked
1 Duplicate rule names make the stale check match the wrong stored rule ✅ Addressed check_descriptions now reports every rule whose name an earlier rule of the same write already has. Tested with and without stored rules.
2 Whitespace-only edit counts as a rewrite ✅ Addressed All three comparisons (rule, condition, action) go through same_text, which trims both sides. Tested on a condition.
3 Jira description understated its rule ✅ Addressed Rule and condition text now cover the start from no status, matching the legal expression; jira-playbook.md is regenerated with the same text in rules and _seed.default_rules.
4 Reset exemption trusts a client-writable _seed ✅ Addressed The comment on restores_shipped_rules states that only the stale comparison is relaxed.
5 rules: null on a typed update untested ✅ Addressed Assertion added in play.rs, pinning the error text.
Nit serde_path_to_error outside the workspace table ✅ Addressed Declared in root Cargo.toml; the crate uses { workspace = true }.
Nit SchemaRule naming Skipped Deferred to the play-authoring skill work. Reasonable.
Nit Description errors returned before schema errors Skipped The first review rated it acceptable.

Questions asked for this re-review

Is the duplicate-name rejection correct? Yes.
📁 packages/core/src/playbook/descriptions.rs:102-112

  • It compares each rule with the rules before it in the incoming list, so N rules with one name give N−1 errors, each naming the rule. It does not depend on stored, so it applies to a new play and to an update alike.
  • Names are compared exactly, the same way the stale check matches a rule to its stored rule (line 114), so the two agree on what "the same name" means.
  • The message renders as "rule x: more than one rule in this play has this name. Give each rule its own name", which the test pins.

Could it wrongly block anything? No case found.

  • Engine load path: check_descriptions has one non-test caller, validate_play_rules (crud.rs:2638), which is called from create (crud.rs:620) and from the version-checked update only when play_rules_changed (crud.rs:1808-1811). The engine, activate_play and the unchecked update paths do not call it.
  • Shipped and bundled plays: the two existing tests that run check_descriptions over every core play (core_plays.rs:174-190, both rules and _seed.default_rules) and every bundled play (methodology/mod.rs:301-312) now also assert that no shipped play repeats a rule name, with no test change needed.
  • A play stored with duplicate names before this check: switching it off, or changing its description or an extension field, does not change rules, so the gate does not run and the write succeeds. Only a write that changes its rules must fix the names, which is the intended behaviour.
  • Reset to shipped rules: the exemption drops only stored, so the duplicate check still runs on a reset. No shipped play has duplicates, so this blocks nothing real.

Is the trimmed comparison right? Yes. Both the stored and the incoming text are trimmed before comparing, so padding in either direction is not a rewrite, and the blank check already trimmed. A change of case or inner spacing still counts as a rewrite; the first review noted the check cannot stop a determined writer, and that remains true and acceptable.

Findings

🔴 Critical

None.

🟡 Important

None.

🟢 Suggestions (all optional)

Nit: a duplicate name can also produce an unrelated stale error in the same rejection
📁 packages/core/src/playbook/descriptions.rs:113-114

On an update, the second rule of a duplicated name is still matched against the first stored rule with that name, so the rejection may list a stale error for it next to the duplicate-name error. The write is rejected either way and fixing the name clears both, so this is only extra text in an agent's repair message. Skipping the stale comparison for a rule already reported as a duplicate would remove it.

Nit: DuplicateName is carried by description-named types
📁 packages/core/src/playbook/descriptions.rs:34-43

DescriptionProblem::DuplicateName inside a DescriptionError is a name problem, not a description problem. The module comment explains why it lives here (matching by name needs it), which is enough for now.

Nit: the play's own summary and its reject message still name only two moves
📁 packages/core/src/methodology/jira.rs (the play description and the reject message; visible in packages/skill/references/jira-playbook.md:69)

The play-level description ("any sprint_status change other than future → active or active → closed") and the message shown on a rejection ("A sprint moves only from future to active, and from active to closed") still leave out the first setting to future and the start from no status. Neither is a rule, condition or action description, so they are outside ADR-090 §1 and outside finding 3; mentioned only because the rule text next to them is now more precise than they are.

What was verified and how

  • Verified by reading the code: the full diff of the two commits; the Display output for the new problem; that check_descriptions has a single non-test caller and that the update gate runs only when rules changed; that the engine and load paths do not call it; that the shipped-play tests call check_descriptions and so now cover duplicate names; both workspace Cargo.toml entries; the regenerated Jira reference against jira.rs; that ADR-090 §1 and playbook-system.md in the local docs checkout state the unique-name rule and the trimmed comparison.
  • Inferred, not executed: that the new and existing tests pass (author's reported test:changed run); that no shipped play repeats a rule name (follows from those tests passing, not checked by hand play by play); that the docs changes are pushed to the docs remote (only the local working tree was read); the extra stale error in the first nit is from reading the loop, not from a run.

Recommendation: APPROVE

Every finding from the first review is addressed or skipped with a sound reason, the duplicate-name check is correct and runs only at the save-time gate, and the two commits introduce no new problem. The three nits are optional.

@malibio malibio left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Automated pragmatic-code-review (re-review): APPROVE (posted as a comment — GitHub blocks self-approval). Full findings in the review comment above.

@malibio

malibio commented Oct 4, 2026

Copy link
Copy Markdown
Collaborator Author

Re-review addressed

The re-review approved with three optional nits; all three are skipped, so there are no new commits.

  • Extra stale error beside a duplicate-name error: the write is rejected either way and fixing the name clears both; not worth new logic.
  • DuplicateName under description-named types: the module comment explains why it lives there.
  • Jira play summary and reject message name only two moves: existing text outside ADR-090 §1 (neither is a rule, condition or action description) and outside this PR.

Re-review decision: NO RE-REVIEW NEEDED — nothing changed since the reviewed head 347f2bc9.

malibio and others added 5 commits October 4, 2026 14:01
…eject stale ones (closes #3517)

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
…mmed

- Two rules of a play sharing a name are rejected: a rule is matched to the
  stored rule by name, so a name has to identify one rule
- Padding a stored description is not a rewrite of it
- The Jira transition rule's descriptions name the start from no status
- Say what the reset exemption relaxes, and pin `rules: null` with a test
- serde_path_to_error is declared in the workspace dependency table

Skipped: renaming SchemaRule (belongs with the play-authoring skill that
uses it), and reporting description and schema errors in one pass.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
@malibio
malibio force-pushed the issue-3517-play-rule-descriptions branch from 347f2bc to d4a5c06 Compare October 4, 2026 12:01
@malibio
malibio merged commit 5262f83 into main Oct 4, 2026
@malibio
malibio deleted the issue-3517-play-rule-descriptions branch October 4, 2026 12:02
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.

Require a description on every play rule, condition and action, and reject stale ones

1 participant