Skip to content

Inherit a parent's enum values live when a subtype extends the field (closes #3749) - #3764

Merged
malibio merged 3 commits into
mainfrom
issue-3749-inherited-enum-values
Oct 12, 2026
Merged

malibio merged 3 commits into
mainfrom
issue-3749-inherited-enum-values

Conversation

@malibio

@malibio malibio commented Oct 12, 2026

Copy link
Copy Markdown
Collaborator

Closes #3749

What changes

A type that extends an inherited enum field now stores only the values it adds. The field's values are built along the extends chain as the ancestors' current values plus each extending type's own, each added value placed after the value it maps to.

  • Resolution: flatten_chain_fields (schema/extends_chain.rs) is the one function that builds the effective field set; every reader (validation, get_schema_definition, maps_to, boards, tables, agent tools, entity-type blocks) already goes through it. The frontend reads backend-resolved fields via getSchema, so no TypeScript composer was needed.
  • Stored shape: extend_inherited_field stores the extension with its added values only; the seeded issue schema declares changes_requested and ready_to_merge, not task's five.
  • Order: an issue's statuses read open, in progress, changes requested, in review, ready to merge, done, cancelled. IssueStatus variant/CORE order follows it; generated issue-status.ts regenerated.
  • Collisions: adding a value a descendant already added is refused, naming the descendant.
  • Storage of a node's value is unchanged. No migration; existing databases reset.

Node type sequence

Kind: core subtype (issue extends task), category unchanged. No field, relationship or rule added; the status field's stored values and the effective order change. Docs: components/node-types.md issue sheet and ADR-078's enum-extension section, pushed to nodespace-docs main before merge.

Tests

  • The test that pinned the frozen list (a_status_added_to_task_is_not_an_issues) now asserts the opposite (a_status_added_to_task_is_an_issues).
  • New: stored shape, live inheritance on an extension with its own values, collision naming the descendant, three-level order, and unit tests of the merge.
  • bun run test:changed passes (frontend, scripts, browser, types:check, node-types:check, Rust).

🤖 Generated with Claude Code

@malibio

malibio commented Oct 12, 2026

Copy link
Copy Markdown
Collaborator Author

Code Review: PR #3764 (closes #3749)

Review Type

Initial review (no prior reviews or comments). Commit reviewed: 27c7c44.

Requirements Check (issue #3749 acceptance criteria)

  • A value added to task's status later is valid on an issue and on a user type that extended the status. Covered by a_status_added_to_task_is_an_issues and a_value_added_to_the_parent_later_is_valid_on_an_extension_with_its_own.
  • Seeded issue stores only changes_requested and ready_to_merge; effective order is open, in progress, changes requested, in review, ready to merge, done, cancelled (core_schemas.rs test plus IssueStatus::CORE).
  • add_field_values on an inherited field stores only the added values (extend_inherited_field, an_extension_stores_only_the_values_it_adds).
  • Adding a value a descendant already added is refused and names the descendant (reject_descendant_value_collisions, test asserts the type name).
  • task-scope mapping and "inherited value reads as itself": resolve_value_at_scope is untouched and reads the effective set.
  • "Entity-type prompt blocks read through [one function]": NOT MET, see blocker below.
  • [~] App status menu, board columns and table cells: these load the schema through the daemon's get_schema_definition, which goes through resolve_field_owners and so flatten_chain_fields. The effective list reaches the UI without a TS change. No frontend test pins it, and the issue's "one function in TypeScript" is not delivered. That is defensible (the frontend consumes the backend's effective field), but say so in the PR description.
  • The test that pinned the frozen list asserts the opposite.
  • node-types.md and ADR-078 text are correct in /Users/malibio/nodespace/nodespace-docs (uncommitted there; push before merge). bun run node-types:check passes against the working tree and bun run types:check is clean.

Code Review Findings

Critical / Blocker

  • packages/core/src/ops/entity_types_block.rs:297: EntityTypeDescriptor::from_chain still builds a type's fields with flatten_chain_by_name, not flatten_chain_fields. For issue the nearer status now holds only two values, so name-shadowing makes the entity-type block (agent prompt, search_skills, resolve, from_corpus) list status as changes_requested, ready_to_merge and nothing else. Before this PR it listed all seven. This is a model-facing regression, and it is exactly the "entity-type prompt blocks read through it" criterion. The function's doc even says it must see "the merged set". Fix: build the field set with flatten_chain_fields (clone the &SchemaFields into the chain input) so there is a single builder, and add a test that an issue's descriptor lists all seven statuses and a subtype's lists the parent's later values. A snapshot or golden test in packages/agent that renders an issue block would also catch this.

Suggested Improvements

  • packages/core/src/schema/mod.rs:3413: reject_descendant_value_collisions is called inside the per-addition loop, and each call reloads the whole extends parent map, re-resolves every schema's ancestor chain, and fetches each descendant. Hoist the descendant list out of the loop (one load per update_schema). The same file already has get_subtype_closure (used by validate_no_shadowed_extension_fields, ~line 1614): prefer it over scanning the whole parent map, so the two descendant walks use one mechanism.
  • Collision coverage gaps (mod.rs:3413, re-point path near mod.rs:3085): the check runs for both the inherited and own-field paths (good), but nothing covers re-pointing a type's extends. If a type that stores its own added values moves under a parent that already has one of those names, extend_enum_field silently drops the descendant's value (the present.insert skip), including its maps_to, with no error. Either refuse in the re-point block (it already computes fields_after) or document and test that the parent's value wins. The silent drop is the case ADR-078's "never copied, never listed twice" wants to be loud about. Also create_schema with extends plus values is not routed through the check; confirm it cannot introduce a collision, or add a test.
  • packages/core/src/schema/extends_chain.rs:253-290 (extend_enum_field): ordering relies on the iteration order of a merged extension (core then user). That works for a chain built nearest-first, but a middle-level value that maps to a leaf-level value cannot occur, so there is no bug today; add a test with a mixed core and user list across three levels (the existing three-level test uses user values only) to pin the "mixed core/user lists" behaviour that the doc comment promises.
  • Tests: the test for a parent gaining a value on a 3-level chain (each_level_of_a_chain_adds_after_the_value_it_maps_to) only asserts that parked is writable at the end, not its position (["open","backlog","triaged","done","parked"]). Assert effective_state_values(&svc, "crash") there. No test exercises the own-field path of reject_descendant_value_collisions (a parent adding to a field it declares itself, where a descendant added the same name): seed_maps_to_chain's ticket.state is that case, so it is covered by the existing test; say so in a comment or add a user-defined variant.
  • packages/core/src/schema/mod.rs:3419-3422: the comment above the inherited branch still says the values are "materialized onto this schema ... carrying the inherited definition plus the new values". It now stores only the added values.

Nitpicks

  • Nit: extends_chain.rs extend_enum_field's after_target closure takes the sibling offset even when the target lives in the other list; harmless, but a short comment on why siblings is keyed by target value (not list) would help.
  • Nit: packages/agent/src/local_agent/tools.rs:6470 doc ("currently-declared vocabulary read from the stored schema") remains true only because task extends nothing; a one-line note would stop a future copy of the pattern onto a subtype.

AGENTS.md rules

  • No compatibility code, no migration, no #[deprecated] / #[allow(dead_code)], no lint suppression, no issue numbers in comments or code: pass. No literal node_type == comparisons added; the lifecycle_status rules are untouched. Wire type change is one enum reorder in nodespace-types; generated TS is current.
  • Verified fail-without-fix: the stored-shape, later-parent-value, and collision tests all depend on the new behaviour (the collision test would have the parent add succeed without the check).

Recommendation

REQUEST CHANGES. The core design is right and well tested for validation and resolution, but one reader (entity_types_block.rs:297) still bypasses the single builder and regresses the issue's status vocabulary in the agent's prompt, which the issue names as an acceptance criterion. Fix that with a test, then take or consciously defer the re-point collision gap and the loop hoist. After that this is an approve. Docs must be pushed to nodespace-docs main just before 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.

Verdict: REQUEST CHANGES (self-authored PR, so posted as a comment). Blocker: packages/core/src/ops/entity_types_block.rs:297 still builds fields with flatten_chain_by_name, so an issue's entity-type block lists only its two added statuses. Route it through flatten_chain_fields and add a test. Full report in the previous comment.

@malibio

malibio commented Oct 12, 2026

Copy link
Copy Markdown
Collaborator Author

Review addressed

Fixed

  • 🔴 entity_types_block.rs: EntityTypeDescriptor::from_chain now builds fields through flatten_chain_fields, so an issue's descriptor (agent prompt, search_skills, resolve, from_corpus) lists all seven statuses. New test a_subtypes_enum_lists_the_ancestors_values_with_its_own; it fails when the call is reverted to flatten_chain_by_name.
  • 🟡 Collision check hoisted out of the per-addition loop (one closure read per call) and walks descendants with get_subtype_closure, like validate_no_shadowed_extension_fields.
  • 🟡 Stale "materialized onto this schema" comment updated.
  • 🟡 Tests: mixed core/user values across three levels (unit), and the root-addition position asserted in the three-level integration test.
  • 🟢 Comment on why the sibling offset is keyed by target value; note on valid_task_statuses that its stored read is correct only because task extends nothing.

Re-pointing extends (🟡): no code change, pinned by a test. Moving a type that holds its own extension of a field under a parent that also has that field is already refused as a redeclaration by validate_no_field_redeclaration, so nothing is silently dropped. re_pointing_a_type_with_an_extension_under_another_vocabulary_is_refused pins it. The present skip in extend_enum_field stays as the backstop for the retroactive case ADR-078 names.

Not done: the issue's "one function in TypeScript" — the frontend reads backend-resolved fields (getSchema → get_schema_definition), so there is no TS composer to unify; the status menu, boards and tables get the effective list with no TS change.

bun run test:changed passes (frontend, scripts, browser, types:check, node-types:check, Rust).

🤖 Generated with Claude Code

@malibio

malibio commented Oct 12, 2026

Copy link
Copy Markdown
Collaborator Author

Code Review: PR #3764 (closes #3749), re-review

Review Type

Re-review of ab20437 (the single fix commit on top of 27c7c44). Only git diff 27c7c4410..HEAD reviewed.

Previous Review Summary

REQUEST CHANGES: 1 blocker, 3 suggested improvements (+ test/comment items), 2 nits.

  • Blocker (entity_types_block.rs from_chain bypassing flatten_chain_fields): FIXED.
  • Hoist + get_subtype_closure: FIXED.
  • Re-point extends gap: resolved by reasoning plus a test (confirmed sound, one narrow residual below).
  • Test additions, stale comment, nits: FIXED.

Verification

  • entity_types_block.rs:299: fields now built by flatten_chain_fields(chain.iter().map(|s| s.fields.clone())); .iter() over the result into from_schema_field is correct. Grepped packages/ for flatten_chain_by_name: the only remaining callers build relationships (entity_types_block.rs:302, node_service/schema.rs:758); no field reader uses it. flatten_chain_fields is used by resolve_field_owners (schema/mod.rs:1715, node_service/schema.rs:686) and core_schemas tests. from_corpus/resolve route through from_chain. from_chain(&schema, []) in context_ops.rs:1262 is a test-only standalone helper.
  • New test a_subtypes_enum_lists_the_ancestors_values_with_its_own asserts all seven statuses in order against the real seeded issue/task; it would fail on the old call.
  • reject_descendant_value_collisions now takes &[FieldValueAddition], reads get_subtype_closure once per call, drops schema_id itself, sorts for deterministic errors. Error text unchanged; semantics preserved. Early return on empty additions is fine.
  • Re-point reasoning: sound. An extension is stored as the type's own field, so update_schema's re-target path (validate_no_field_redeclaration(node_service, new_parent, &fields), mod.rs:3557) sees it in fields and refuses when the new parent chain has that field name. create_schema with extends runs the same check (mod.rs:2275) on stored_fields, so an inherited enum can't be re-declared at creation; extending one is only possible through add_field_values, which goes through the collision check. The present skip in extend_enum_field is therefore only a backstop.
  • New tests: mixed core/user three-level unit test and the position assertion in the integration test are correct and pin the doc-comment promise.

Findings

Critical

None.

Suggested Improvements

  • 🟡 packages/core/src/schema/mod.rs:3557 (residual, narrow): the redeclaration check on re-point covers the re-pointed type's own fields only. If a descendant of the moved type holds an extension of state and the new parent chain also has state (with a clashing value), the descendant's duplicate value is still dropped silently by the present skip. This is the retroactive case ADR-078 already names and was equally possible via a later add_fields on an ancestor, so it is not new in kind and not a blocker; the test comment ("the parent's values are never silently preferred") slightly overstates it. Either soften the wording or run the descendant collision walk on re-point. Consider recording it, not blocking on it.

Nitpicks

  • Nit: extends_subtype_identity_test.rs re_pointing_a_type_with_an_extension_under_another_vocabulary_is_refused asserts only is_err(). Assert the message contains "already declared" so the test cannot pass because of an unrelated refusal.
  • Nit: the new from_chain doc is accurate; no other changes needed.

AGENTS.md rules

Pass: no compatibility code, no suppression, no issue numbers in comments, no literal node_type comparisons, no new lifecycle reads, no wire-type change in this commit. I did not re-run the Rust tests locally; the author reports bun run test:changed green.

Recommendation

APPROVE. The blocker is fixed through the single field builder with a test that fails without it, and the remaining items are optional. Reminder: push the nodespace-docs changes (node-types.md, ADR-078) just before bun run merge. Merging is the user's call.

@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.

Re-review verdict: APPROVE (self-authored PR, posted as a comment). The entity_types_block.rs blocker is fixed via flatten_chain_fields with a test; hoist, closure walk, and tests verified. Details in the previous comment. Reminder: push nodespace-docs before bun run merge.

malibio and others added 3 commits October 12, 2026 17:36
…loses #3749)

An extending schema now stores only the values it adds; the field's values
are the ancestors' current ones plus each extending type's own, placed after
the value each maps to. Adding a value a descendant already added is refused,
naming the descendant.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
…uilder

- Route EntityTypeDescriptor::from_chain through flatten_chain_fields so a
  subtype's enum lists the ancestors' values (an issue's status regressed to
  its two own values in the agent prompt)
- Read descendants once per add_field_values call, through the subtype closure
- Add tests: descriptor vocabulary, mixed core/user values over three levels,
  root-addition position, re-pointing a type that holds an extension
- Fix a stale comment and note the stored-schema read in valid_task_statuses

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
@malibio
malibio force-pushed the issue-3749-inherited-enum-values branch from cd8383f to 5d06c26 Compare October 12, 2026 15:36
@malibio
malibio merged commit c9098d4 into main Oct 12, 2026
@malibio
malibio deleted the issue-3749-inherited-enum-values branch October 12, 2026 15:36
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.

A subtype that extends an inherited enum must keep inheriting its parent's values

1 participant