Skip to content

Tier-1 class-read primitives (atomic add_relationship PR 1/2)#44

Merged
david-w-t merged 6 commits into
davidwt-com:mainfrom
david-w-t:develop
Jun 21, 2026
Merged

Tier-1 class-read primitives (atomic add_relationship PR 1/2)#44
david-w-t merged 6 commits into
davidwt-com:mainfrom
david-w-t:develop

Conversation

@david-w-t

Copy link
Copy Markdown
Contributor

Summary

PR 1 of 2 of the atomic add_relationship seam follow-up. Adds three
tier-1, in-transaction, bare-mnesia read primitives to graphdb_class
so that add_relationship (PR 2) and a future mutate/1 can compose all
their class reads into a single enclosing Mnesia transaction:

Primitive Contract
get_template_in_txn/1 {ok, #node{}} | {error, not_a_template | not_found}
class_in_ancestry_in_txn/2 boolean()
default_template_in_txn/1 {ok, Nref} | not_found

Each returns results identical to its existing gen_server twin
(do_get_template/1, do_class_in_ancestry/2, default_template/1) but uses
bare mnesia:read and assumes it already runs inside an Mnesia activity.

The honest framing

add_relationship is read-read-read-read-write today — only the last
phase writes — so there is no partial-write bug. Collapsing it (PR 2)
buys TOCTOU isolation and unblocks mutate/1; the real deliverable shared by
both follow-ups is this primitive library.

Key design decision — add, don't rewrap

The gen_server reads stay untouched. get_template/class_in_ancestry
keep their dirty_reads, which are load-bearing for
graphdb_rules:default_conflict_resolver/0 deadlock-safety (it runs outside
any transaction during plan_composition_firing). The new primitives are
separate functions; the resulting near-verbatim duplication of the ancestry
walk is the intended, explicitly-chosen design.

This PR is purely additive: no existing function body, handle_call
clause, or existing test changed.

Tests

+10 CT cases in graphdb_class_SUITE (3 + 4 + 3), each invoked inside a
graphdb_mgr:transaction/1, mirroring the existing gen_server-twin assertions.
Full suite: 444 CT + 105 EUnit = 549, all green, zero warnings.

Docs

  • Design: docs/designs/atomic-add-relationship-primitives-design.md
  • Plan: docs/superpowers/plans/2026-06-20-tier1-class-read-primitives.md
  • apps/graphdb/CLAUDE.md graphdb_class API + TASKS.md follow-up updated.

🤖 Generated with Claude Code

david-w-t and others added 6 commits June 20, 2026 19:55
…p PR 1/2)

Primitives-only slice: add default_template_in_txn/get_template_in_txn/
class_in_ancestry_in_txn to graphdb_class as exported, in-transaction,
bare-mnesia reads. Uniform add-don't-rewrap (gen_server reads stay dirty
for B5 conflict-resolver deadlock-safety); purely additive. The
add_relationship collapse is deferred to PR 2.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01EWukKCbrN8GybaScJGU2kF
4-task TDD plan: get_template_in_txn/1, class_in_ancestry_in_txn/2,
default_template_in_txn/1 added to graphdb_class as in-transaction
bare-mnesia twins, +10 CT cases; docs + full-suite verify. Purely
additive (gen_server reads untouched). Implements
docs/designs/atomic-add-relationship-primitives-design.md.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01EWukKCbrN8GybaScJGU2kF

@david-w-t david-w-t left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

ok.

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.

1 participant