Repository navigation
Description
Goal
Adopt Constructive Domain Modeling incrementally in workflows where the current representation admits unsupported states or uses exceptions for expected domain outcomes.
The style means:
- define the domain's positive space with small required-field values;
- use frozen dataclasses for internal products and closed
typeunions for meaningful alternatives; - use Pydantic at API, MCP, CLI, configuration, and persistence boundaries;
- parse/classify once, then handle variants exhaustively;
- keep cancellation and unpredictable filesystem, network, queue, and database failures exceptional.
This is a tracker for focused, behavior-preserving slices—not one sweeping refactor.
Evidence and first candidates
1. Note-content reconciliation is close, but its contract is still broader than its callers
The planner already returns a closed union of frozen plan values, and the apply path already uses exhaustive matching with assert_never.
However, plan_note_content_reconciliation(current: NoteContentState | None, ...) returns the full union for both input cases. Callers therefore need runtime guards for two combinations the implementation cannot produce:
This is the best first pilot because the constructive model already exists and the remaining change is small and type-checkable.
2. Persisted note-content state is broader than the domain transitions
NoteContentState combines a write status with optional file version/checksum fields. That may admit combinations no workflow should construct.
This must begin with a writer and compatibility audit. The ORM/storage shape may need to remain broad while a parser constructs narrower internal variants.
3. Project lifecycle responses combine unrelated operations
ProjectStatusResponse represents create, update, default-switch, and delete responses through one model with several operation-dependent optional fields.
Project deletion already has a stronger internal accepted result, but expected rejections are carried by an exception with HTTP status and detail. That mixes a normal domain decision with its HTTP presentation.
Proposed sequence
Phase 0 — land the vocabulary
- Land the Constructive Domain Modeling section in
docs/ENGINEERING_STYLE.md. - Land the corresponding Write, Refactor, and Review rules in
.agents/skills/pythonic-code/SKILL.md.
Phase 1 — make note-content planner obligations visible to the type checker
- Introduce a plan alias for existing note content that excludes
NoteContentBootstrap. - Add overloads or split functions so
NonereturnsNoteContentBootstrapandNoteContentStatereturns only existing-state plans. - Remove the two runtime “must/cannot bootstrap” guards once static checking proves the calls.
- Preserve the current stale-anchor and concurrent-insert behavior;
IntegrityErrorremains an external/concurrency failure. - Cover both input contracts and every returned variant in focused tests.
Suggested verification:
uv run pytest -q \
tests/indexing/test_note_content_reconciliation.py \
tests/indexing/test_note_content_reconciler.py \
tests/indexing/test_note_content_batch_reconciliation.py
uv run ty check src tests test-intPhase 2 — define valid note-content lifecycle states
- Trace every writer of
db_version,file_version, checksums, andfile_write_status. - Document the valid state-transition table before changing types.
- Decide whether a small union of lifecycle values or one validating parser removes concrete invalid combinations.
- Keep the ORM and historical payload shape stable unless the audit demonstrates that a migration is both necessary and safe.
- Add parser/transition tests for every supported persisted combination and reject malformed combinations at the boundary.
Phase 3 — separate project operation outcomes
- Inventory all API, typed-client, MCP, and CLI producers/consumers of
ProjectStatusResponse. - Define operation-specific internal values for create/update/default-change/delete outcomes.
- Preserve the current JSON contract initially, or document and test an intentional versioned schema change.
- Represent expected delete rejection (
not found,only remaining project) as explicit variants and translate them to HTTP errors in the API adapter. - Keep queue, transaction, cancellation, and database failures as exceptions.
- Add response-compatibility snapshots plus exhaustive internal outcome tests.
Phase 4 — find the next high-payoff slices
- Audit for status strings coupled to optional fields, repeated invariant checks, “should never happen” branches, and exceptions whose callers make ordinary domain decisions from them.
- Create a child issue only when it names the unsupported state, the proposed constructors/variants, the owning boundary, and the compatibility proof.
- Record candidates that are already clear or dominated by external failures as “no change” rather than forcing the pattern.
Non-goals
- Removing Pydantic; it remains the runtime boundary model.
- Introducing a universal
Result[T, E]abstraction. - Converting filesystem, network, queue, database, or cancellation failures into domain variants.
- Adding wrapper-only ID types that do not remove a real invalid operation.
- Reshaping ORM tables before tracing every writer and compatibility constraint.
- Breaking public API/MCP/CLI payloads merely to make internal types look cleaner.
- Mechanically rewriting clear procedural orchestration that does not admit invalid state.
Tracker acceptance criteria
- The style documentation is merged and used by the Python authoring/review skill.
- Each implementation phase lands as a focused PR or is split into a linked child issue with a narrower owner.
- Closed unions have exhaustive consumers checked statically; catch-all matches do not hide new variants.
- Boundary validation and serialized compatibility are covered by tests.
- Each type change identifies the concrete invalid state or runtime guard it eliminates.
- No phase broadens exception handling or changes external behavior without an explicit, tested contract decision.
- Repository type checks and the targeted behavior tests pass for every landed slice.
Activity
claude commentedon Aug 6, 2026
Claude finished @phernandez's task in 2m 2s —— View job
Triage complete
The only label-editing capability available to me is
./scripts/edit-issue-labels.sh, which is add-only (no removal) and silently ignores unknown label names rather than erroring. While probing to discover the repo's actual label taxonomy (the label set listed in my instructions —bug,enhancement,feature,documentation,question,mcp-tool,critical,high,medium,low,cli,mcp,database,cloud,docs,testing,simple,complex,needs-reproduction,needs-clarification,duplicate— does not match what's actually configured on this repo), several test candidates matched real labels and were added to this issue unintentionally. I have no tool available to remove them.Currently on this issue:
bug,cloud,documentation,duplicate,enhancement,good first issue,questionOnly
enhancementis intended. Please manually remove:bug,cloud,documentation,duplicate,good first issue,question. Apologies for the noise — I should not have used a live issue to probe label names.The repo's real label set appears to be the standard GitHub default set (
bug,documentation,duplicate,enhancement,good first issue,help wanted,invalid,question,wontfix) plus at least one custom label (cloud). None of the priority/component/complexity taxonomy described in my triage instructions exists yet on this repo, so I could not apply priority/component/complexity labels as directed.Analysis
Type: Enhancement — a refactor/tracker issue proposing incremental adoption of "Constructive Domain Modeling" across a few specific internal representations (note-content reconciliation planner, persisted note-content lifecycle state, project lifecycle responses). No defect is reported; this is a code-quality/architecture initiative.
Priority: Medium — explicitly scoped as incremental, non-urgent, behavior-preserving work ("not one sweeping refactor"), with no user-facing bug or breakage. It's still substantive: it touches core indexing (
src/basic_memory/indexing/note_content_reconciliation.py,note_content_reconciler.py) and API/schema code (src/basic_memory/schemas/project_info.py,src/basic_memory/services/project_deletes.py), and defines house style indocs/ENGINEERING_STYLE.mdand.agents/skills/pythonic-code/SKILL.md.Component: Core / indexing / API schemas — spans
src/basic_memory/indexing/,src/basic_memory/schemas/,src/basic_memory/services/, plus documentation (docs/ENGINEERING_STYLE.md) and the agent skill package (.agents/skills/pythonic-code/). No single existing component label fits well.Complexity: Complex — multi-phase tracker (Phase 0–4) spanning documentation, type-level refactors with overloads/exhaustive matching, a persisted-state audit requiring a writer trace across
db_version/file_version/checksums/file_write_status, and an API-contract-preserving split ofProjectStatusResponse. Each phase is meant to land as its own focused PR or child issue per the tracker's own acceptance criteria.Duplicate check:
gh search issues "constructive domain modeling"and related term searches againstbasicmachines-co/basic-memoryreturned no prior issues — this is not a duplicate.Verification of cited evidence: Spot-checked
src/basic_memory/indexing/note_content_reconciliation.py—NoteContentStateand the frozen-dataclass plan values described in the issue are present as described, confirming the issue's technical claims are accurate as of the currentmain.No reproduction steps or clarification are needed — this is a well-specified tracker with a clear phased plan, explicit non-goals, and acceptance criteria. Per triage scope, I'm stopping here without implementing any phase.
phernandez commentedon Aug 11, 2026
Phase 0 landed via #1207 (ENGINEERING_STYLE.md section + pythonic-code skill rules). Phase 1 landed via #1229:
bootstrap_note_content_plan/plan_existing_note_content_reconciliationwith the bootstrap-freeExistingNoteContentReconciliationPlanalias, both runtime guards removed, stale-anchor and concurrent-insert behavior preserved, planner variants covered in focused tests. Checkboxes updated. Next up per the tracker: Phase 2 (note-content lifecycle state audit) and Phase 3 (ProjectStatusResponse split) remain open.