Skip to content

Let rules and queries read a checkbox's checked state; let update and set-status name the version they change - #3573

Merged
malibio merged 4 commits into
mainfrom
issue-3556-derived-attrs-write-version
Oct 5, 2026
Merged

malibio merged 4 commits into
mainfrom
issue-3556-derived-attrs-write-version

Conversation

@malibio

@malibio malibio commented Oct 5, 2026

Copy link
Copy Markdown
Collaborator

Closes #3556. Implements ADR-094 §5 (derived attributes are readable) and §6 (a write names the version it read).

Derived attributes

Kind and category: no new type. checkbox (concrete, primitive) gains one declared derived attribute, checked (boolean). No schema field, relationship or structural rule changes; nothing is stored.

  • Registry (nodespace-types/src/core_type.rs): CoreTypeInfo.derived lists a type's DerivedAttributes; subtypes inherit through extends. Each attribute has a name, a value type, one Rust function (derive) and the same computation as SQL (sql). checkbox_is_checked is the one definition of checked state.
  • Play conditions: the CEL value builder adds each declared attribute to a node's map, so node.checked, c.checked and .where(checked == false) read it. The graph resolver reads it for action bindings too.
  • Mixed collections: a task's children are checkboxes and notes. Inside a comprehension, a derived attribute the comprehension reads is null on an item whose type does not declare it, so node.has_child.exists(c, c.checked == false) answers for the checkboxes instead of failing on the first note.
  • Save-time validation: accepted on a declaring type (or subtype) and through a built-in relationship, whose far end may be any type; refused on any other type, including the two-segment node.checked form and items of a relationship with a declared target type. A user type's own field of the same name is still a field.
  • Query filters: a property filter that names a declared attribute compiles to a per-row CASE (computed from content for rows whose type declares it, the stored property otherwise), so it works at the top level, under a wildcard and inside a related filter. Filters on every other name keep their exact expression.
  • Writes: a property named after a derived attribute of the node's type is refused, with a message pointing at the content.
  • A test holds the SQL form and the Rust function to the same answers.

Version on writes

  • nodespace node update and nodespace node set-status take --version <n>. A stale version exits non-zero with the node, the version given and the current version; --json also prints {"error": "version_conflict", ...}. Without it they behave as before.
  • The agent's update_node and update_task_status take an optional version, with a refusal that tells the model to read the node again.
  • The daemon's x-version-conflict header now escapes non-ASCII text. Before, a conflict on a node with any non-ASCII content produced a header clients could not read as a string, so they saw no conflict data at all.
  • A multi-threaded test runs two writes naming the same version concurrently: one lands, one is refused.

Docs

  • packages/skill/references/cli.md and SKILL.md: the version flag, what a conflict means, re-read before deciding.
  • nodespace-docs (commit 096a65a, pushed with the merge): components/node-types.md §3, components/type-registry.md, architecture/playbook-system.md.

Notes for review

  • Only checked is declared. The other derived values in the node-types sheet (header level, code-block language) stay undeclared until a rule or query needs them.
  • The stage-2 tool-surface golden changes: the two update tools gain the version parameter.

Testing

bun run test:changed passes (rust, skill, scripts tiers).

🤖 Generated with Claude Code

@malibio

malibio commented Oct 5, 2026

Copy link
Copy Markdown
Collaborator Author

Pragmatic Code Review: PR #3573 (issue #3556)

Review Type: Initial review (no prior reviews or comments on the PR).

Summary: The change is a clear net improvement and is well tested. Derived attributes are declared once in the registry, and the CEL builder, graph resolver, save-time validation, query compiler and write path all read that declaration, with no checkbox special case. The SQL added in query_service interpolates only registry constants and the already-validated stored expression, so there is no new injection surface. One correctness gap in the new --version flag should be fixed before merge; the other findings are non-blocking.

How this was checked: I read the full diff, the surrounding code and docs commit 096a65a. I ran no tests (test:changed had already passed), so the failure scenarios below come from reading the code.


Requirements Check

Derived attributes

  • ✅ Registry declares derived attributes; checkbox declares checked (boolean), computed by one function. CoreTypeInfo.derived, DerivedAttribute::Checked, checkbox_is_checked. Only checked is declared, although the issue says "each primitive type's derived attributes"; header level, code-block language and the others stay undeclared. The PR and the docs sheet say so explicitly, and it is defensible under YAGNI. See finding 5.
  • ✅ node.has_child.exists(c, c.checked == false) is true with an unchecked checkbox child, false otherwise. a_condition_reads_checked_on_checkbox_children covers mixed children, all checked, notes only and no children.
  • ✅ Save-time validation accepts it on a declaring type and refuses it elsewhere. Covers the two-segment form, declared relationship items, a path past a declared relationship, .where, traversal past the attribute, and a user field of the same name.
  • ✅ A query filter can name a derived attribute. Works at the top level, under a wildcard and inside a related filter over has_child.
  • ✅ The derived value follows the content, nothing stored. Tested for both the condition and the filter.
  • ✅ A derived attribute cannot be written. reject_derived_attribute_keys runs on create and update, across every bucket of the chain.
  • ✅ No content-prefix matching in the engine; one function decides. The remaining Rust prefix matches are markdown import/export (line classification and task-to-markdown rendering), not checked-state reads. The frontend checkbox-node.svelte keeps its own startsWith for display, which is outside "the engine".

Version on writes

  • ❌ node update / set-status accept a version; with one, the write succeeds only if the node is still at that version. True for content and property writes. Not true for a collection-only node update: the version is silently ignored. See finding 1.
  • ✅ A stale version exits non-zero naming node, version given and current version; --json carries the same. Holds for ordinary nodes; see finding 2 for large nodes.
  • ✅ Without a version the commands behave as today.
  • ✅ Two concurrent writes naming one version: one lands, one is refused. Multi-threaded, barrier-synchronised, 20 rounds.
  • ✅ The built-in agent's update tool accepts a version the same way. update_node and update_task_status; version is kept out of flat-key promotion.

General

  • ✅ references/cli.md and SKILL.md document the flag and the re-read rule. SKILL.md is 15,851 bytes, under the cap.
  • ✅ Docs updated (node-types.md §3, type-registry.md, playbook-system.md in 096a65a). It is unpushed; push it just before bun run merge so the gate's node-types:check reads it.
  • ✅ quality:fix / test:changed: reported as passing by the author; not re-run.

Code Review Findings

1. 🟡 Important: --version is silently ignored on a collection-only update

📁 packages/core/src/ops/node_ops.rs:307-332 (reached from packages/cli/src/commands/node.rs:286-324)

Failure scenario: nodespace node update <id> --collection work:claimed --version 3 when the node is at version 5. The CLI accepts collection-only updates. In ops::update_node, update.is_empty() is true, so the branch fetches the current node and never looks at input.version. The collection writes then run, and the command exits 0. The caller named a stale version and the write landed.

Recommendation: In the update.is_empty() branch, when input.version is Some(v) and differs from the fetched node's version, return the same OpsError::VersionConflict. Add one case to the CLI integration test. Refusing --version without --content/--property at the CLI would also close it, but the ops-level check covers the agent and gRPC callers too.

Principle: A safety flag that is accepted must be enforced or refused, never ignored (least surprise; the acceptance criterion says "succeeds only if the node is still at that version").

2. 🟡 Important: the conflict is carried in a header that also holds the whole node, and the client caps headers at 16 KB

📁 packages/daemon/src/services/node_service.rs:3014-3065, packages/cli/src/commands/node.rs:367-381

Rationale: x-version-conflict carries current_node (the full flattened node) alongside the three values the CLI needs. The pinned hyper 1.9.0 sets the HTTP/2 client's max_header_list_size to 16 KB (hyper-1.9.0/src/proto/h2/client.rs:52), and nothing in the repo raises it. A conflict on a node whose payload exceeds that should be rejected by the client's HTTP/2 layer as a stream error, so VersionConflict::from_status finds nothing and the CLI prints the generic UpdateNode RPC failed.

This is not new for ASCII nodes, but two things in this PR make it matter more:

  • The CLI now depends on this header as its only source of conflict data.
  • ascii_json inflates non-ASCII text: 6 bytes per BMP character, 12 per emoji. A note of roughly 2,700 CJK characters crosses the limit. Before this PR such a node lost only the header and still returned ABORTED with the message; now the whole response is at risk.

I did not run this; it follows from the pinned default and the code path. The existing non-ASCII test calls the service directly, so it does not cross the transport.

Recommendation: Add a CLI integration test (it goes over the socket) with a conflict on a node of about 20 KB of content. If it fails as expected, the smallest fix is to omit current_node from the header when the escaped payload exceeds a safe size, keeping node_id / expected / actual.

Principle: Do not put unbounded data in a bounded channel; test the seam the feature actually crosses.

3. 🟡 Important: null-filling a derived attribute makes all, != and has() answer wrongly on mixed children

📁 packages/core/src/playbook/graph_resolver.rs:838-905 (compare packages/core/src/playbook/cel.rs:547-558)

Failure scenarios, for a task whose children are two checked checkboxes and one text note:

  • node.has_child.all(c, c.checked == true) is false, because the note reads null == true. "Every checkbox is checked" cannot be written with all.
  • node.has_child.exists(c, c.checked != true) is true, because the note reads null != true. The task is treated as having an unchecked item.
  • has(c.checked) is true for the note, since the key is now present with null. node_to_cel_value_at_scope deliberately drops nulls so that has() stays honest; this fill reverses that for one key.

The shipped rule (exists(c, c.checked == false)) is correct and tested. The risk is the next rule author: these forms save without error and evaluate quietly wrong. The docs commit warns only about a bare c.checked.

Recommendation (non-blocking): At minimum, extend the "A collection can hold nodes that do not have it" bullet in playbook-system.md to say that all and != count non-checkbox items, give the supported spelling (!node.has_child.exists(c, c.checked == false)), and pin these cases in a test so the behaviour is a decision. If you want it tighter, save-time validation could refuse all(...) / != over a derived attribute on an untyped collection.

Principle: Least surprise; one meaning for "absent" across the CEL surface.

4. 🟢 Suggestion: a subtype of checkbox can declare a field named checked that can never be written or read

📁 packages/core/src/services/node_service/crud.rs:3107-3142

Scenario: A user schema criterion extends checkbox and declares a field checked. Schema creation succeeds. Every write that sets the field is then refused, and every read returns the derived value. The existing shadow warning in create_schema covers core property names; it could cover inherited derived attribute names, or refuse them.

Principle: Fail at definition time, not at each use.

5. 🟢 Suggestion: reconcile the first acceptance criterion with what ships

📁 packages/nodespace-types/src/core_type.rs:376-379

The issue says the registry declares "each primitive type's derived attributes"; only checked is declared. I agree with the choice, and the test only_a_primitive_declares_derived_attributes_and_every_declared_one_is_listed keeps the list honest. Reword the criterion in the issue when checking it off so the record matches.

6. 🟢 Nit: a string operand on a derived boolean filter matches nothing, silently

📁 packages/core/src/services/query_service/mod.rs:856-872

{"property":"checked","operator":"equals","value":"false"} compiles to CASE … END = 'false', which is never true, so the query returns an empty result and no error. Since value_type() is known for a derived attribute, the compiler could reject a non-boolean operand with a clear message. Optional.


What is good

  • One declaration, five readers, no type literal anywhere; is_a_sql handles user subtypes in SQL and nearest handles them in Rust.
  • The SQL/Rust parity test iterates DerivedAttribute::ALL, so a future attribute is held to it automatically.
  • only_a_derived_attribute_name_changes_the_filter_expression protects the indexed expression for ordinary fields.
  • The concurrency test uses multi_thread with a barrier, which actually exercises the race.
  • The agent's refusal text and the skill docs both tell the caller to re-read rather than retry with the new number.
  • No compatibility code, no issue numbers in comments, no Pro markers.

Recommendation: REQUEST CHANGES

Finding 1 is a small, concrete gap in the contract of the new flag and should be fixed in this PR. Findings 2 and 3 are worth addressing here too (a test for 2, a docs line and test for 3) but would not block on their own. Everything else is 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: REQUEST CHANGES (posted as a comment — GitHub blocks self-approval). Full findings in the review comment above.

@malibio

malibio commented Oct 5, 2026

Copy link
Copy Markdown
Collaborator Author

Review addressed

Addressed

  1. --version ignored on a collection-only update. ops::update_node now checks a named version before applying collection changes and returns the same version conflict. The CLI integration test covers it, and that a refused update creates and joins nothing.
  2. Conflict header size. Confirmed over the socket: with a ~56 KB node the client failed the stream (h2 protocol error … too_many_continuations) and the CLI printed a generic RPC failure. The header now leaves current_node out above 8 KB, so the versions always arrive. The CLI integration test covers a large non-ASCII node; it fails with the cap removed.
  3. all / != on mixed children. The behaviour is pinned by a_comprehension_reads_null_on_items_that_derive_nothing, and playbook-system.md now says which spellings answer for the checkboxes alone and gives the supported form for "every checkbox is ticked".

Skipped

  1. A checkbox subtype declaring a field named checked. Not refused at schema creation. A write to it is already refused with a message that says why, and no shipped or planned type does this. Worth adding to the schema shadow check if a user ever hits it.
  2. Wording of the first acceptance criterion. Only checked is declared; noted on the issue rather than in code.
  3. String operand on a derived boolean filter. Left as is: the same filter name can be an ordinary field on a user-defined type, where a string operand is legitimate, so the compiler cannot reject it by name alone.

bun run test:changed passes.

Re-Review Decision

Decision: RE-REVIEW NEEDED

Rationale: Findings 1 and 2 changed write-path and transport behaviour, not just tests or docs.

@malibio

malibio commented Oct 5, 2026

Copy link
Copy Markdown
Collaborator Author

Pragmatic Code Review: PR #3573 (issue #3556)

Review Type: Re-Review

Scope: commit 63bb2cbc only (the first review covered through 40771660), plus docs commit 7d555f2 in nodespace-docs.

Summary: The one blocking finding is fixed, and the fix is at the ops layer, so the CLI, gRPC and agent callers are all covered. The header cap is sound and does not break the desktop client. I found no bug in the new commit. The findings below are all optional.

How this was checked: I read the commit, the surrounding code in ops::update_node and ops_error_to_status, and every reader of x-version-conflict (CLI, desktop app-lib, the frontend store). I ran no tests; test:changed was reported as passing on this commit.


Previous Review Summary

Count
Previous recommendations 6
Addressed 3 (findings 1, 2, 3)
Not addressed, with a sound reason 3 (findings 4, 5, 6)
Not addressed, without a sound reason 0
New issues in this commit 0 blocking, 4 optional

1. --version ignored on a collection-only update: addressed.
📁 packages/core/src/ops/node_ops.rs:310-331
The update.is_empty() branch now compares a named version with the fetched node and returns OpsError::VersionConflict before any collection write. With no version it behaves as before. The CLI test asserts the refusal text and that no claimed collection was created (limit: 0 is "no limit" in query_nodes_simple, so the check is not vacuous).

2. Conflict header size: addressed.
📁 packages/daemon/src/services/node_service.rs:3014-3078
The author reproduced the failure over the socket (too_many_continuations at about 56 KB). Above 8 KB of escaped payload the header is rebuilt with current_node: null. The size is measured after ascii_json, which is the form that is sent. The remaining trailers (grpc-status, a short grpc-message) leave ample room under hyper's 16 KB. The new test sends about 170 KB of escaped CJK text across the socket and asserts the versions arrive.

Consumers of x-version-conflict with a null current_node: none break.

  • 📁 packages/cli/src/commands/node.rs:367-381 reads only node_id, expected, actual; its unit test already uses "current_node":null.
  • 📁 packages/desktop-app/app-lib/src/commands/nodes.rs:275-280 passes the JSON through unchanged.
  • 📁 packages/desktop-app/src/lib/types/errors.ts:114-125: isVersionConflict requires only node_id, and the type already declares current_node: Node | null.
  • 📁 packages/desktop-app/src/lib/services/shared-node-store.svelte.ts:2441-2542 and 3562-3603: both handlers fall back to resyncNodeFromServer when current_node is null.
  • 📁 packages/agent/src/local_agent/tools.rs:627-639 ignores current_node.

This is also an improvement for the desktop app: a conflict on a node over 16 KB previously failed the stream and surfaced as GRPC_ERROR. It now arrives as VERSION_CONFLICT and resyncs. Nodes between 8 KB and 16 KB cost one extra get_node.

3. all / != on mixed children: addressed.
📁 packages/core/tests/it/derived_attributes_test.rs:161-202, nodespace-docs/architecture/playbook-system.md:235
The test pins all six spellings, and the docs line states which ones answer for the checkboxes alone and gives the supported form. The two agree.

4. A checkbox subtype declaring checked: skipped, reason accepted. The write is already refused with a message that says why, and no shipped type does this (YAGNI).

5. Wording of the first acceptance criterion: skipped, reason accepted. It is a record-keeping point on the issue, not code.

6. String operand on a derived boolean filter: skipped, reason accepted. A user-defined type can declare an ordinary field of the same name, where a string operand is valid. A check would have to resolve the type first, which is more than a nit warrants.


Findings on the new commit

A. 🟢 Suggestion: a collection-only --version is a check, not a claim, and the CLI reference does not say so

📁 packages/core/src/ops/node_ops.rs:318-330, packages/skill/references/cli.md:125

Scenario: two sessions read a task at version 3 and both run nodespace node update <id> --collection claimed --version 3. Both pass the check, because joining a collection does not advance the node's version, and both exit 0. With set-status --version 3 exactly one would win.

The code comment says this plainly ("a check ahead of them, not a lock"), so the behaviour is a decision. The reference still reads "The update is written only if the node is still at that version" with no qualifier, and an agent could use collection membership as a claim.

Recommendation: one sentence in references/cli.md under "Writing at the version you read": a membership change does not change the version, so --version on a collection-only update guards against earlier edits but not against a second identical join; claim work with set-status. Not blocking.

Principle: document the limit of a guarantee where the caller reads it.

B. 🟢 Note: an update with nothing to change now conflicts on a stale version

📁 packages/core/src/ops/node_ops.rs:310-331

The new check applies to every empty NodeUpdate, including one with no collection changes. Such a call with a stale version used to return the current node and now returns ABORTED. The desktop command always sends a version (app-lib/src/commands/nodes.rs:719).

I looked for a frontend path that sends an empty update and found none: a persisted write carries content, nodeType or properties, and nodeType rides along on content writes. If one existed, the result would be a conflict toast and a resync on a node whose local version is already stale, which is correct. No change needed.

C. 🟢 Nit: the two conflict branches render current_node differently

📁 packages/core/src/ops/node_ops.rs:322-330 and 365-383

The new branch uses node_to_typed_value(...).await.ok(), which drops a render failure silently. The existing branch logs a warning for the same failure. A small shared helper that takes a Node and returns Option<Value> with the warning would keep them the same (DRY). Optional.

D. 🟢 Nit: two assertions in the new tests have no positive control

  • 📁 packages/cli/tests/it/cli_integration.rs:2805-2829: after join(Some(4)) succeeds, nothing asserts that claimed now exists. Adding that check proves the earlier "no claimed collection" assertion looks in the right place.
  • 📁 packages/core/tests/it/derived_attributes_test.rs:193-199: a false expectation passes for ConditionResult::Unresolved as well as Fail. The paired true cases make a silent evaluation error unlikely, but matching Fail { .. } for the false rows would state it exactly.

What is good

  • The fix for finding 1 is in ops::update_node, not in the CLI, so every caller gets it.
  • The author reproduced finding 2 before fixing it, and the test crosses the real transport and fails without the cap.
  • The cap is a named constant with a comment that explains the 16 KB limit it stays under.
  • The docs line and the pinning test describe the same six cases.
  • No compatibility code, no issue numbers in comments, no Pro markers, no node-type literals outside tests.

Recommendation: APPROVE

All three findings that needed work are addressed, and the three skipped ones have sound reasons. Finding A is worth one sentence in references/cli.md but does not block. The docs commit 7d555f2 is local: push it to nodespace-docs main just before bun run merge.

@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 5, 2026

Copy link
Copy Markdown
Collaborator Author

Re-review addressed

Addressed

  • A. references/cli.md now says that a collection change does not advance a node's version, so --version on a collection-only update is a check and not a claim; claim work with set-status.
  • D. The collection test asserts claimed exists after the update at the current version. The comprehension test matches Fail { .. } on the rows that must not hold, so an unresolved condition cannot pass for one.

Skipped

  • B. No change needed, as the review says.
  • C. The two conflict branches differ only in whether a failed render is logged. A shared helper for two call sites is not worth it; revisit if a third appears.

The two touched tests and skill:check pass.

Re-Review Decision

Decision: NO RE-REVIEW NEEDED

Rationale: One documentation sentence and two tightened test assertions. No product code changed.

malibio and others added 4 commits October 5, 2026 08:50
… set-status name the version they change (closes #3556)

Derived attributes are declared in the type registry (checkbox declares
checked), read by name in Play conditions, .where predicates and query
property filters, refused on write, and computed by one Rust function with
a SQL form held to the same answers.

node update, node set-status and the agent's update tools accept the
version the caller read; a stale one is refused with the node, the version
given and the current version.

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

- A version named on an update that changes only collections is checked
  before they are applied, instead of being ignored.
- The x-version-conflict header leaves the node out above 8 KB, so a large
  node's conflict still reaches the client with its versions.
- Pin how a comprehension reads a derived attribute on items that derive
  nothing.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
…tive controls to two tests

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
@malibio
malibio force-pushed the issue-3556-derived-attrs-write-version branch from 0ac85bf to a7ce330 Compare October 5, 2026 06:50
@malibio
malibio merged commit d7d2f69 into main Oct 5, 2026
@malibio
malibio deleted the issue-3556-derived-attrs-write-version branch October 5, 2026 06:50
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.

Let rules and queries read a checkbox's checked state, and let the CLI's update and status commands name the version they change

1 participant