DUNIN7 · LOOMWORKS · RECORD
record.dunin7.com
Status Current
Path substrate/cleanup/phase-62-implementation-notes-v0_1.html
Loomworks · Phase 62 · Implementation Notes

Phase 62 Implementation Notes — v0.1

Version. 0.1

Date. 2026-05-24

Author. Claude Code

Engine HEAD. ead29a8 (merge of phase-62-memory-events-cleanup)

Tag. phase-62-memory-events-cleanup

Companion documents.


1. What landed

Phase 62 closed in three commits on the engine, merged as ead29a8:

  1. 87bec47 — Migration 0072_memory_events_phase_25_wiring_cleanup + _ANCHOR_PRIORITY relocation to src/loomworks/foray/anchor_priority.py
  2. 6348c60 — Drop Phase 25 wiring from events.py; rename attestation column refs in stamp_commit_attestation SQL
  3. f2adf2f — Update tests for the rename + injection removal + registry move

The cleanup proceeds as planned by the scoping note v0.2: CR-A (audit) shipped first, smallest, validated the reserved-location pattern; CR-B (Phase 25 wiring) ships second; CR-C (credit substrate) ships last.

Substrate result

memory_events.attestation no longer exists. memory_events.commit_webauthn_attestation carries the 1 preserved row (event_id 0673cfd7-354b-4e2a-8a33-9d7355ebf180) with WebAuthn proof data intact. memory_events.content_hash and memory_events.foray_tx_ref no longer exist.

Schema today:

Column Type Status
event_id UUID PK unchanged
engagement_id UUID NOT NULL unchanged (FK to engagements)
engagement_version BigInt NOT NULL unchanged
object_id UUID NOT NULL unchanged
object_type VARCHAR(64) NOT NULL unchanged
object_version Integer NOT NULL unchanged
event_kind VARCHAR(64) NOT NULL unchanged
payload JSONB NOT NULL unchanged (no _foray injection)
provenance JSONB NOT NULL unchanged
timestamp TIMESTAMPTZ NOT NULL unchanged
actor_id UUID NOT NULL unchanged
actor_kind VARCHAR(16) NOT NULL unchanged
actor_instruction_version Integer NULL unchanged
commit_webauthn_attestation JSONB NULL renamed from attestation

Dropped: content_hash (494 write-only rows in dev DB lost; no consumer); foray_tx_ref (0 rows; never written).

Module result

src/loomworks/foray/ now holds two helpers:

foray/__init__.py re-exports both. Imports work via either the submodule (loomworks.foray.anchor_priority) or the package (loomworks.foray).

src/loomworks/memory/events.py simplified substantially:

src/loomworks/engagement/commit_orchestration.py:

Test result

Metric CR-A baseline (616bab9) Final (CR-B)
Collected 2708 2705 (-3 net)
Passed 2674 2670
Skipped 33 33
Failed 2 (pre-existing) 2 (same two)

Test changes:

Pre-existing failures unchanged (both confirmed against baseline): test_api_assertion_retract (JSON-encoding bug at app.py:461) and test_phase_44_evaluator::test_concern_scan_does_not_re_fire_within_dedup_window (dedup-window flake).


2. Attestation row survival evidence

The load-bearing change of CR-B. Pre/post comparison:

Before migration (alembic 0071):

event_id                            attestation (first 150 chars)
0673cfd7-354b-4e2a-8a33-9d7355ebf180  {'challenge': 'l_VtYtA6rzJj2K0fZOFqigL9Xpb3VoO3e5FsYwHywDs',
                                       'signature': 'MEUCIQC7Ubv-u4Q28XLbhXCMe9fQlNZNNRfs2lkhxeuIn
                                       Pt4bgIgR5YQvb4YrnZCHxmp4sFmi_Y...

After migration (alembic 0072):

event_id                            commit_webauthn_attestation (first 150 chars)
0673cfd7-354b-4e2a-8a33-9d7355ebf180  {'challenge': 'l_VtYtA6rzJj2K0fZOFqigL9Xpb3VoO3e5FsYwHywDs',
                                       'signature': 'MEUCIQC7Ubv-u4Q28XLbhXCMe9fQlNZNNRfs2lkhxeuIn
                                       Pt4bgIgR5YQvb4YrnZCHxmp4sFmi_Y...

Same event_id. Identical data. Round-trip verified: alembic upgrade headalembic downgrade -1alembic upgrade head preserves the row through the cycle.

The op.alter_column(... new_column_name=...) approach (true rename, PostgreSQL metadata-only) was correct for preserving operational WebAuthn data. A drop-and-add approach would have lost the proof; the design's insistence on a true rename was validated.


3. Reserved-slot consumption — both slots used

Slot 1 — Test scope expansion beyond design's "10 incidental files"

Design §6.3 said the 10 non-dedicated test files had only "incidental references — these tests do not test the Phase 25 wiring." During execution, this proved partially wrong. Four additional test functions DO test Phase 25 wiring directly:

The pattern across these tests: each phase that added a new event kind to _ANCHOR_PRIORITY also added a test_foray_namespace_injected (or equivalent) test verifying its new entry got the _foray block injected. The design didn't enumerate these. They were discovered when grep for compute_content_hash and _foray namespace usage surfaced them post-migration.

Additionally: 7 _ANCHOR_PRIORITY import sites across 4 test files needed updating to import from loomworks.foray instead of loomworks.memory.events. The design said "no external importers" (§9.3) — that turned out to be false; the test code uses the registry liberally for entry-presence assertions.

Slot 2 — Raw-SQL INSERT helper writing content_hash

Design §2.7 inherited the events.py docstring claim "append_event is the single code path for writing to the memory event log." That claim is true for ORM-level writes, but not for raw SQL. There are 19+ raw INSERT sites across the codebase. Of these:

The fix was mechanical (remove content_hash from one column list + one parameter map), but the root finding was the design's "single code path" claim was too strong — raw-SQL bypasses exist and are perfectly legitimate (each test helper has reasons to bypass append_event: avoiding circular imports, fixture-style setup, etc.).

Both slots consumed; no third surprise emerged

The design's risk assessment §9.6 anticipated both slot-1 and slot-2 categories (registry import drift; views/raw-SQL dependency on dropped columns). The slot budget held: no halt-and-surface beyond what the slots covered.


4. Decision retrospectives

D1 — _ANCHOR_PRIORITY symbol name kept (no rename to _FORAY_INTEGRATION_PRIORITY)

Held up cleanly during execution. The new module path (loomworks.foray.anchor_priority) provides the FORAY context. Imports read clearly: from loomworks.foray import _ANCHOR_PRIORITY. Test code didn't need refactoring beyond the import-path change. No reader was confused; no rename pressure surfaced. If a future ship wants to rename for clarity, that's a discrete one-line change with broader test churn — defer until a concrete clarity need emerges.

D3 — commit_webauthn_attestation column name (verbose two-piece)

Held up cleanly during execution. The verbose name read well in SQL and ORM contexts. No shorter alternative tempted. The two pieces of context proved load-bearing because the surrounding function names (stamp_commit_attestation, verify_commit_attestation) already overload "commit attestation" as a phrase — the column name needed the "webauthn" specificity to avoid echoing that ambiguity.

D4 — compute_content_hash removed entirely

Held up cleanly during execution. Three test files imported the function; all three imports were inside test functions that were also being deleted as part of removing the _foray namespace tests. Removing the function alongside its only callers was the right move. No production caller remained.

D5 — Reserved-emit at end of append_event (after post-append hooks fire)

Held up cleanly. The placement semantics ("emit only when the event fully landed and post-append hooks completed") proved correct during the new test development. The 2 new tests in test_foray_reserved_emit_for_memory.py exercise the emit, and the monkey-patch pattern works because the placement is deterministic.

Test-filename-to-current-substrate alignment — third instance, methodology candidate

CR-A established the principle (renamed one test file). CR-B now extended it twice:

  1. Rename test_phase_25_commit_attestation.pytest_commit_webauthn_attestation.py (logic preserved; framing matches surviving column)
  2. Delete test_phase_25_content_hash_and_foray.py (both framing and tested functionality gone)
  3. Delete three test functions in three other files where the function tested removed Phase 25 wiring

Three CR-A pattern + three CR-B applications = the principle has settled. Promote to methodology candidate for the next consolidation pass. The principle: when a test's filename or function-name framing references an origin that has been cleaned up, the artifact should be renamed (if its logic survives) or deleted (if its tested functionality is also gone). CR-C will validate scale-up to a fourth instance (8 affected test files in credit).

Per-call-site reserved-emit discipline — scale-down validated

CR-A: 3 sites → 3 emits. CR-B: 1 site → 1 emit. The principle "one emit per business event" holds across both scales. CR-C's 12 sites will be the third data point.


5. What CR-C inherits

From the substrate side

From the call-site pattern

From the testing pattern

From the design discipline

Deferred from CR-B


6. Future ledger items

Items surfaced during CR-B execution that don't fit CR-B:

  1. Pre-existing test_api_assertion_retract JSON-encoding bug — same item flagged in Phase 61 implementation notes §6.1. Still pre-existing; still worth a small future fix at src/loomworks/api/app.py:461 (probably str(exc) or repr(exc) in the JSONResponse body).

  2. Pre-existing test_phase_44_evaluator::test_concern_scan_does_not_re_fire_within_dedup_window — same item flagged in Phase 61 implementation notes §6.2. Still pre-existing; worth investigation alongside CR-C since both touch evaluator surfaces.

  3. Test DB engagement_display_identifier_seq overflow — known follow-on workaround applied during CR-B as in CR-A (ALTER SEQUENCE ... RESTART WITH 1). Conftest still doesn't reset the sequence; existing follow-on stays open.

  4. The _ANCHOR_PRIORITY registry has 19 entries today. Phase 25 added the first batch; Phases 31/53/54/55/58/59 each added entries. The growth-pressure argument that the scoping note v0.2 §1 surfaced is now somewhat reduced: with the registry safely in src/loomworks/foray/, future entries land in the new home and don't add cleanup pressure. The argument is preserved here for future scoping rounds: the registry will keep growing as Loomworks adds anchor-worthy events.

Items NOT for the ledger (resolved within CR-B):


7. Confidence

CR-B landed clean. Two reserved slots consumed by execution-time discoveries that didn't require design revision. The attestation rename preserved real WebAuthn data (verified pre/post). The Phase 25 wiring is fully cleaned up; the foray module foundation now holds two helpers and is ready for CR-C's value-flow addition.

The methodology candidate "test-filename-to-current-substrate alignment" has three CR-validated instances now. CR-C will be the fourth; if it holds across credit's 8 affected test files, the principle is settled.