Skip to content

Add core task link and creator relationships (closes #2637) - #2686

Merged
malibio merged 2 commits into
mainfrom
issue-2637-task-relationships
Sep 17, 2026
Merged

malibio merged 2 commits into
mainfrom
issue-2637-task-relationships

Conversation

@malibio

@malibio malibio commented Sep 17, 2026

Copy link
Copy Markdown
Collaborator

Closes #2637.

What

task had no way to declare that it blocks or is blocked by another task, no general relates-to/duplicates link, and no record of who filed it as distinct from who it is assigned to. Every mainstream work tracker (Jira's blocks/is-blocked-by/relates-to, Linear's issue relations and Reporter) treats these as first-class, so they belong on the core schemas rather than behind any one methodology recipe's install.

Four SchemaRelationship declarations, all optional, all seeded through the existing set_schema_declarations path — no new relationship machinery:

task — self-referential, Many/Many, since a task can block several others while being blocked by several itself:

  • blocks / blocked_by
  • relates_to / related_from
  • duplicates / duplicated_by

person — mirrors the existing tasks/assignee declaration under a distinct name, because a task's creator is usually not its assignee:

  • reported_tasks / creator

Notes from implementation

  • BUILTIN_RELATIONSHIP_NAMES needs no entry — the issue asked this to be verified. Confirmed: project.tasks/tasks.project has no entry either, and that list is only the built-in structural names (member_of, has_child, mentions, has_role) that declaration queries key off excluding.
  • The self-referential shape puts both the forward and the reverse name on task. Name resolution already handles this — adr.supersedes/superseded_by exercises the identical case in relationship_reverse_name_traversal_test.rs. The relationship viewer intentionally renders each such pair as two groups (one per side), which is documented behavior in rel_ops, not double-counting.
  • Cycles are representable and nothing validates against them, as the issue anticipated. Only ADR-078's extends requires cycle detection; general relationships permit cycles, and a blocking cycle is real data a user can enter and needs to be able to see.
  • No reverse-name collisions with the existing core set (assignee, project).
  • Existing databases will not pick these up. Core-schema seeding gates on schema-node existence, so task and person — which already exist — are skipped, and the new declarations reach fresh databases only. Per CLAUDE.md this is the intended outcome, not a gap to backfill: change the shape, reset the database. No migration was written.

Two existing assertions that task.relationships is empty were expressing "task's project/assignee link is a derived inverse, not its own declaration". They now assert the absence of that specific name rather than emptiness, which is what they actually meant.

Testing

  • New packages/core/tests/core_task_link_relationships_test.rs exercises a seeded database end to end: declarations land as relationship rows on the right schema; each pair traverses from both ends and the reverse name agrees with the forward name read direction: "in"; creator resolves independently of assignee in both directions; a blocks cycle round-trips.
  • Unit coverage in core_schemas.rs pins each declaration's shape (target type, direction, both cardinalities, required: None).
  • Full cargo test -p nodespace-core: 0 failures.
  • Pre-push gate (test:all + cargo build --bin nodespaced + test:e2e): all passed.
  • bun run quality:fix: clean — clippy -D warnings, svelte-check 0 errors, no new design-token violations.

Acceptance criteria

  • task declares blocks/blocked_by, relates_to/related_from, duplicates/duplicated_by via set_schema_declarations
  • person declares reported_tasks/creator alongside its existing tasks/assignee
  • All new relationships queryable via NodeService::get_related_nodes
  • required: None on every new declaration, both ends
  • A cycle (A blocks B blocks A) is representable; no new cycle detection needed
  • Tests pass
  • Code passes bun run quality:fix

🤖 Generated with Claude Code

`task` had no way to declare that it blocks or is blocked by another task,
no general relates-to/duplicates link, and no record of who filed it as
distinct from who it is assigned to. Every mainstream work tracker treats
these as first-class, so they belong on the core schemas themselves rather
than behind any one methodology recipe's install.

Four `SchemaRelationship` declarations, all optional, all seeded through the
existing `set_schema_declarations` path — no new relationship machinery:

- task: `blocks`/`blocked_by`, `relates_to`/`related_from`,
  `duplicates`/`duplicated_by` — self-referential and Many/Many, since a
  task can block several others while being blocked by several itself
- person: `reported_tasks`/`creator`, mirroring the existing
  `tasks`/`assignee` declaration under a distinct name

The self-referential shape puts both the forward and the reverse name on
`task`, which resolution already handles (`adr.supersedes/superseded_by`
covers the same case); the relationship viewer intentionally renders each
such pair as two groups, one per side. Cycles are representable and nothing
validates against them — only ADR-078's `extends` needs cycle detection.

`BUILTIN_RELATIONSHIP_NAMES` needs no entry, matching `project.tasks`.

Two existing assertions that `task.relationships` is empty were expressing
"task's project/assignee link is a derived inverse, not its own declaration";
they now assert the absence of that specific name instead of emptiness.

Tests: unit coverage pins each declaration's shape, and a new integration
test exercises a seeded database end to end — declarations land as
relationship rows, each pair traverses from both ends and agrees with the
forward name read inbound, `creator` stays independent of `assignee`, and a
blocking cycle round-trips.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
@malibio

malibio commented Sep 17, 2026

Copy link
Copy Markdown
Collaborator Author

Pragmatic Code Review — PR #2686

Review Type: Initial Review
Commit: 807b554b — Add core task link and creator relationships (closes #2637)
Scope: 2 files (packages/core/src/models/core_schemas.rs, packages/core/tests/core_task_link_relationships_test.rs)


Requirements Check (issue #2637)

# Acceptance Criterion Status
1 task declares blocks/blocked_by, relates_to/related_from, duplicates/duplicated_by, seeded via existing set_schema_declarations path ✅
2 person declares reported_tasks/creator alongside existing tasks/assignee ✅
3 All new relationships queryable via existing traversal APIs ✅
4 required: None on every new declaration, both ends ✅
5 A cycle (A blocks B blocks A) is representable at the data level ✅
6 Tests pass ✅
7 Code passes quality:fix ✅

Struct-literal fidelity: I diffed all four SchemaRelationship literals field-by-field against the issue body. Every field matches exactly — name, target_type, direction, cardinality, required, reverse_name, reverse_cardinality, edge_fields, and all four description strings are byte-identical to the spec. This is a faithful implementation, not an approximation.

The BUILTIN_RELATIONSHIP_NAMES question (Technical Specifications): the issue asked to verify whether any new name needs adding to that list. It does not — the list is ["member_of", "has_child", "mentions", "has_role"], reserved structural names, and packages/core/src/ops/rel_ops.rs:246-276 treats schema-declared names via the resolver path instead. The precedent the issue cites (project.tasks) was correct. The verification was done implicitly (no change made, and the tests prove traversal works), but see 🟢-3 below.


Verification Performed

cargo test -p nodespace-core --lib core_schemas          → 22 passed, 0 failed
cargo test -p nodespace-core --test core_task_link_...   →  4 passed, 0 failed
cargo clippy -p nodespace-core --tests                   → clean, zero warnings

I also wrote and ran two throwaway probe tests (since deleted; worktree verified clean) to falsify two specific hypotheses — see 🟢-1 and 🟢-2.


Code Review Findings

🔴 Critical / Blocker

None.

🟡 Improvements

🟡-1 📁 packages/core/tests/core_task_link_relationships_test.rs:107-141 — task_link_pairs_traverse_from_both_ends never exercises direction asymmetry, which is the one thing that could actually break.

The test wires all three relationship types between the same ordered pair (t_source → t_target) and asserts count == 1 from each end. Because source and target roles never vary, the test would still pass if blocks and blocked_by resolved to the same set of edges — the single failure mode that matters for a self-referential pair, where forward and reverse names both live on task and the source_type narrowing at rel_ops.rs:371-377 degenerates to a no-op (node_type == "task" filters nothing).

I verified the production code is in fact correct, with a three-node probe (upstream blocks mid, mid blocks downstream):

mid blocked_by -> count=1 ids=["upstream"]
mid blocks     -> count=1 ids=["downstream"]

So this is a test-coverage gap, not a bug — the behavior is right, but nothing in the suite pins it. Adding one asymmetric case (a node that is simultaneously blocker and blocked) would convert the most valuable invariant here from "happens to work" into "regression-protected". Given that blocks is the relationship a future dependency-enforcement Play will build on, that invariant is worth a test. Principle: tests should be able to fail — an assertion that cannot distinguish correct from incorrect behavior provides coverage in name only.

🟡-2 📁 packages/core/src/models/core_schemas.rs:1678-1710 — the two modified unit tests were weakened more than the change required.

test_project_declares_tasks_relationship and test_person_declares_tasks_assignee_relationship previously asserted task.relationships.is_empty(). That assertion carried a real invariant: the inverse is derived, never co-declared. Both were relaxed to !task.relationships.iter().any(|r| r.name == "project" /* or "assignee" */).

Narrowing from "empty" to "does not contain this specific name" was necessary and correct — task legitimately has three relationships now, so is_empty() had to go, and the replacement preserves the actual intent (this particular inverse isn't co-declared). I'd call that a faithful translation.

The one genuine loss is assert_eq!(person.relationships.len(), 1) in the person test. That assertion was doing double duty: it also caught accidental additions to person. It's now gone entirely, so a stray fourth declaration on person would be caught by nothing. Consider assert_eq!(person.relationships.len(), 2) — it keeps the drift-detection property at zero cost and self-documents the expected set. Principle: prefer narrowing an over-broad assertion to deleting it.

🟢 Nits / Observations

🟢-1 📁 core_task_link_relationships_test.rs:107-141 — the loop-carried-state hypothesis is unfounded; no action needed.

Worth recording explicitly since it looks alarming on inspection: the loop creates three edges between the same node pair without resetting state, so edges from iteration n are still present at iteration n+1. I probed this directly and all three iterations return exactly count=1. The reason is structural — packages/core/src/db/sqlite_store/relationships.rs:1503-1504 keys every query on r.relationship_type = ?2, so a relates_to row is invisible to a blocks query. The shared fixture is safe here. (It would not be safe if the loop reused one relationship name, which is worth keeping in mind if this test is ever extended.)

🟢-2 📁 core_task_link_relationships_test.rs:180-212 — blocking_cycle_is_representable does prove a cycle, modestly.

It asserts both create_relationship calls succeed (the real criterion — nothing rejects the cycle) and that both nodes read back one blocks and one blocked_by, with assert_ne! confirming the edge points at the other task rather than self. That is genuinely a 2-cycle and not a tautology. The assert_ne! in particular is the assertion that earns its keep. Two tasks is the minimum interesting cycle; a 3-cycle would add little.

🟢-3 📁 issue #2637 Technical Specifications — the BUILTIN_RELATIONSHIP_NAMES verification is undocumented.

The issue explicitly asked to confirm whether these names need registering there. The answer (no) is correct but invisible — a reader six months from now re-derives it. One clause in the existing core_schemas.rs:207-217 comment block ("declared names resolve through the schema neighbourhood, so none of these belong in BUILTIN_RELATIONSHIP_NAMES, which is reserved for structural names") would close that loop. Nit, not a blocker.

🟢-4 📁 core_task_link_relationships_test.rs:36-62 — helper triplication across test files.

create_test_service, make_node, and get are now byte-identical across this file, relationship_reverse_name_traversal_test.rs, and schema_relationship_declarations_test.rs. Rust integration tests are separate crates, so this is the idiomatic cost of that model — extracting to tests/common/mod.rs is the standard remedy but is a codebase-wide refactor well outside this PR's scope. Flagging as an observation only; matching the existing pattern was the right call here. DRY yields to convention when the convention is the language's.

🟢-5 📁 core_schemas.rs:207-217, 1380-1384 — comment quality is notably good.

The comments explain why (Many/Many because a task blocks several and is blocked by several; cycles permitted because only ADR-078's extends requires detection; reported_tasks distinct from tasks because reporter ≠ assignee) rather than restating the struct fields. This is the standard the guide asks for.


Standards Compliance (CLAUDE.md)

  • ✅ No lint suppression, no #[allow(dead_code)], no #[deprecated]
  • ✅ No backward-compatibility or migration code
  • ✅ No GitHub issue numbers in code comments or doc content — the only reference is ADR-078, cited correctly by ADR number in both core_schemas.rs and the test module doc. Issue references appear solely in the commit message (process mechanics, permitted).
  • ✅ No new docs/ or .md files; no new dependencies
  • ✅ Clippy clean

Architecture Assessment

The change is atomic and additive. It introduces zero new machinery — four SchemaRelationship literals riding the set_schema_declarations path that project.tasks and person.tasks already exercise. YAGNI is respected: no cycle-detection, no Play logic, no UI, all correctly deferred per the issue's Non-Goals. The self-referential declarations compose with ADR-078's future extends for free.

On the seeding note (evaluated, as requested): core-schema seeding at packages/core/src/services/node_service/mod.rs:1703-1730 gates on schema-node existence. Since task and person nodes already exist in any established database, these new declarations reach fresh databases only. I confirmed this against seed_core_schemas_reconciles_missing_schema_on_next_service_new (mod.rs:2917), whose own comments state that existing core schemas are left untouched and only missing schemas are created.

The author's decision not to write a backfill is correct and I endorse it. CLAUDE.md is unusually explicit that this exact question — "how do existing databases get the new shape?" — is the signal, not the task, and that a lazy on-read or startup backfill is precisely the prohibited thing even for a purely internal data-shape change. The answer is reset the database. Writing the backfill would have been the review finding; not writing it is right.

I'd also note the practical stakes are near zero: these are brand-new relationship names with no existing edges, so a stale database is missing a capability, not carrying corrupt data — it degrades to "cannot create a blocks link until reset", which is the expected pre-release posture.

Nothing further is needed in the PR. The one thing I'd mildly favor is a line in the PR description (not the code — a code comment explaining DB-reset mechanics would itself drift toward migration-flavored documentation) noting that a nodespace database created before this commit needs a reset to pick up the declarations. That saves the next person a confusing "why does blocks not resolve?" session. Optional.


Summary

A tight, well-scoped, spec-faithful change. The implementation matches issue #2637's struct literals exactly, adds no machinery, respects every project standard, and is accompanied by genuinely useful integration tests that verify the declarations survive seeding and traverse — which is the part unit tests cannot reach. Comment quality is above average.

Two hypotheses I was asked to scrutinize (loop-carried state; whether the cycle test proves a cycle) I investigated directly and disproved — the code is correct on both counts. The one real gap is 🟡-1: the traversal test cannot distinguish blocks from blocked_by because it never varies the source/target roles. Production behavior is correct (verified by probe), so this is missing regression protection rather than a defect.

Neither 🟡 finding blocks merge. Both are cheap to address and would leave the suite meaningfully stronger.

Recommendation: APPROVE

Net-positive to code health with no critical or security findings. Addressing 🟡-1 (asymmetric traversal case) and 🟡-2 (restore a length assertion on person) is recommended follow-up — ideally in this PR since both are a few lines, but not a merge blocker.

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

Both 🟡 findings from the PR #2686 review.

🟡-1 The traversal test wired all three relationship types between one
ordered pair, so it could not distinguish "blocked_by resolves to the
reverse edge set" from "blocked_by collapsed onto the forward edge set" —
both spellings return "the other task" either way. That is the failure mode
that actually matters for a self-referential pair, since both names live on
`task` and the usual source_type narrowing is a no-op when the declaring and
target type are the same.

Rebuilt as a three-node chain (upstream -> mid -> downstream). From `mid`,
the forward name must reach downstream and the reverse name upstream, so
resolving the wrong direction surfaces the wrong node. Verified the new
assertion has teeth by temporarily inverting it: it fails with
`left: "t_upstream", right: "t_downstream"`, exactly the collapse it is
meant to catch. Also asserts the chain ends see one side each.

Renamed to task_link_pairs_resolve_direction_asymmetrically, which is what
it now tests.

🟡-2 Restored the count assertion that the earlier edit dropped from
person's test: narrowing `is_empty()` to a named-absence check was right,
but `relationships.len()` also caught accidental ADDITIONS, and that drift
detection was lost. Now asserted on both person (2) and task (3).

🟢-3 Documented the BUILTIN_RELATIONSHIP_NAMES verification the issue asked
for, so the next reader does not have to re-derive why these names need no
entry there.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
@malibio

malibio commented Sep 17, 2026

Copy link
Copy Markdown
Collaborator Author

Review addressed — commit 5d842983

Thanks for the review. Both 🟡 findings addressed, plus one 🟢. Two 🟢 items intentionally skipped.

✅ Addressed

🟡-1 — traversal test never exercised direction asymmetry

Correct, and the more valuable of the two findings. With all three types wired between a single ordered pair, the test could not distinguish "blocked_by resolves to the reverse edge set" from "blocked_by collapsed onto the forward edge set" — both spellings return "the other task" either way. That is precisely the failure mode that matters for a self-referential pair, since both names live on task and the source_type narrowing degenerates to a no-op.

Rebuilt as a three-node chain (upstream → mid → downstream). From mid, the forward name must reach downstream and the reverse name upstream, so resolving the wrong direction surfaces the wrong node. The chain ends are asserted to see one side each.

I confirmed the new assertion actually has teeth rather than trusting a green run — temporarily inverting it produces:

assertion `left == right` failed: blocked_by from mid must reach upstream —
if it returns downstream, the reverse name collapsed onto the forward edge set
  left: String("t_upstream")
 right: "t_downstream"

Then restored and re-verified. Renamed to task_link_pairs_resolve_direction_asymmetrically.

🟡-2 — drift detection lost

Right that narrowing is_empty() → named-absence was necessary but dropped the accidental addition check. Restored on both schemas: person (2) and task (3).

🟢-3 — BUILTIN_RELATIONSHIP_NAMES verification undocumented

Added a comment clause explaining why these names need no entry there (that list is the built-in structural edges; schema-declared names resolve through the ordinary resolver), so it needn't be re-derived.

⏭️ Skipped, with reasoning

🟢-1 loop-carried state — no action needed, as you concluded. We independently falsified the same hypothesis; the structural reason is that every query keys on relationship_type.

🟢-4 helper triplication — the idiomatic cost of Rust's separate-crate integration tests. Extracting a shared fixture crate for three ~15-line helpers would be scope creep for negligible benefit.

On the seeding / DB-reset note

The PR description already covers this; adding the practical detail you were after: a pre-existing local database will not gain these relationships and needs a reset to pick them up. Since these are brand-new names with no existing edges, a stale DB lacks a capability rather than holding corrupt data — nothing breaks, the relationships simply aren't there until reset. Agreed this belongs in the PR description rather than a code comment, where it would drift toward migration-flavored docs.

Verification

cargo test -p nodespace-core            → 0 failures across all targets
bun run quality:fix                     → clean (clippy -D warnings, svelte-check 0 errors)
pre-push gate (test:all + cargo build + test:e2e) → ✓ All tests passed

🤖 Generated with Claude Code

@malibio
malibio merged commit 69e5e67 into main Sep 17, 2026
@malibio
malibio deleted the issue-2637-task-relationships branch September 17, 2026 08:08
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.

Add core blocks/blocked_by, relates_to/duplicates, and creator relationships on task

1 participant