Skip to content

Fix four latent defects in methodology install and Play path validation #2792

Closed

Description

@malibio

Overview

Four latent defects found during the code review of #2777 (PR #2777), deliberately skipped there as unreachable today. Filed so they are recorded somewhere a future reader will look, rather than only in a merged PR thread.

None is a live bug. Each becomes one under a specific, foreseeable change.

1. is_already_exists matches on error-message text

packages/core/src/methodology/install.rs

Collision detection during a methodology install decides "this id is taken" by substring-matching "already exists" in the error's Display output. That is the only signal available today — the schema layer reports both an id collision and other failures through one error type.

Becomes a bug when: any other schema error grows that phrase. add_field_values already rejects a duplicate enum value; if its message is ever reworded to contain "already exists", a genuine value collision is misread as an id collision and the install silently proceeds under a suffixed id.

Fix: a structured variant (SchemaError::AlreadyExists { id }) the installer can match on.

2. create_node_resolving_collisions has a TOCTOU, and swallows read errors

packages/core/src/methodology/install.rs

The node path checks get_node(&id) for existence, then creates. Two installs racing can both see "free". It also treats a read error as "does not exist", so a transient failure produces a create attempt rather than a reported problem.

Notably inconsistent with the schema path directly above it, which deliberately lets the write path be the authority and reads the collision out of the rejection.

Fix: mirror the schema path — attempt the create, detect the collision from its rejection.

3. validate_schema_path tries reverse before forward, inverting the resolver's precedence

packages/core/src/playbook/validation.rs

rel_ops::resolve_relationship_name documents and implements forward-first: a forward name always wins over a same-spelled reverse name on another schema. Play path validation checks reverse first.

Becomes a bug when: one schema's forward relationship name equals another's reverse name. No core pair collides today, but #2777 adds cycle.tasks as a third declarer of tasks (alongside project and person), so the namespace is getting denser.

Fix: swap the order so validation and runtime agree.

4. Play path validation issues several uncached queries per segment

packages/core/src/playbook/validation.rs

resolve_reverse_segment and resolve_forward_segment each resolve the type chain and fetch schemas per path segment, with no shared cache — and resolve_reverse_segment is the more expensive of the two while being the only one that takes no schema_cache parameter.

Save-time only, so no user-visible latency today. Partly overtaken by measurement: get_extends_parent_map is a single indexed SELECT, not the full scan an earlier review pass assumed.

Fix: thread the existing schema_cache through both helpers.

Acceptance Criteria

  • is_already_exists replaced with a structured error match
  • Node-collision path detects collisions from the write rejection, consistent with the schema path
  • Forward resolution precedes reverse in validate_schema_path, matching resolve_relationship_name
  • Both validation helpers share the existing schema_cache
  • A test pins the forward-over-reverse precedence with a deliberately colliding name pair

Activity

  1. mstomar125 commented on Sep 22, 2026

    @mstomar125
    Contributor

    Frontend: 5240 passed (260 test files, 68.72s)

  2. self-assigned this
    on Sep 22, 2026
  3. mstomar125 commented on Sep 22, 2026

    @mstomar125
    Contributor

    PR #2796 merged into issue-2596-methodology-recipes (#2777). Fix reaches main once #2777 itself merges. Marking status Done here since the fix work is complete; the issue itself can be closed once #2777 lands.

  4. mstomar125 commented on Sep 22, 2026

    @mstomar125
    Contributor

    Merged in PR #2796 (commit 87afc00 on issue-2596-methodology-recipes). Important: this branch is #2777's — the fix only reaches main once PR #2777 itself merges, not before. All four acceptance criteria implemented and covered by tests: structured MarkdownError::AlreadyExists replaces the substring match; create_node_resolving_collisions now attempts the create first and reads the id's occupancy to interpret a rejection rather than checking-then-creating; validate_schema_path checks forward before reverse; resolve_reverse_segment now shares schema_cache; and test_forward_relationship_wins_over_colliding_reverse_name pins the precedence (verified it fails under the old reverse-first order). A pragmatic-code-review round (10 finder angles, posted inline to the PR) surfaced 13 further findings; 2 small ones were fixed pre-merge (an overclaiming doc comment, a duplicate error-match collapsed into the existing shared helper). The rest trace back to one root cause — NodeServiceError has no structured duplicate-id signal, so schema-collision detection still rests on a pre-write existence check rather than the write's own rejection, same as the node path did before this issue — already tracked as a deliberate non-goal in core#2798, updated with two more concrete instances (hierarchy.rs VERSION_CONFLICT, desktop-app's Tauri status mapping) found by this round. One more small fix (a missing debug log in resolve_reverse_segment matching its sibling ensure_schema_cached) was implemented, tested and pushed but landed just after the merge went out from under it — not resurrecting it as its own PR for one log line; whoever next touches that function or core#2798 can pick it up.

  5. malibio commented on Sep 22, 2026

    @malibio
    CollaboratorAuthor

    Landed on main via #2796, which merged into #2777's branch and reached main with that PR's squash (14d8ae99).

    Staying open was a mechanical artifact rather than a signal: the closing keyword lived in the individual commit message, which the squash collapsed. Verified all four acceptance criteria against main before closing:

    1. Structured AlreadyExists replaces substring matching — MarkdownError::AlreadyExists in methodology/install.rs and markdown/error.rs.
    2. create_node_resolving_collisions attempts the create rather than pre-checking existence; the get_node pre-check is gone, so the write path is the authority and a read failure is reported rather than read as "not found".
    3. Forward before reverse in validate_schema_path — forward lookup at validation.rs:914, resolve_reverse_segment fallback at :950, matching rel_ops::resolve_relationship_name's documented precedence.
    4. schema_cache threaded through both resolution helpers.

    Thanks @mstomar125 — item 3 also closed a gap I had skipped as latent in the round-1 review of #2777.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions