Skip to content

fix(facets): remove tags when their targets are deleted - #500

Merged
possiblyneal merged 4 commits into
mainfrom
fix/475-facet-cleanup
Nov 21, 2026
Merged

possiblyneal merged 4 commits into
mainfrom
fix/475-facet-cleanup

Conversation

@possiblyneal

@possiblyneal possiblyneal commented Nov 21, 2026 •

Copy link
Copy Markdown
Owner

Intent

Closes #475

Ordinary hard deletes remove Facets attached to the deleted Observations, Memories, and Lessons.

Read first

  • src/functions/facets.ts:18 — paged target-to-key lookup and invalidation.
  • src/functions/facets.ts:84 — deletion and best-effort Facet cleanup under the Facet lock.
  • src/functions/export-import.ts and src/functions/snapshot.ts — Facet writes use the same lock without changing replacement semantics.
  • src/functions/lessons.ts:352 — update Recall before Facet cleanup can yield; retain cleanup IDs across purge chunks.
  • src/engine/inproc/state.ts:307 — include imported empty keys on the first page without losing indexed paging.

Decisions

  • Use a per-store, generation-keyed lookup so eviction does not rescan every Facet for every target it deletes. Memory use scales with Facet count.
  • Serialize Facet mutations with cleanup; take the Memory write lock first where both apply. Cleanup failures do not stop remaining deletion bookkeeping.

Out of scope

Verified

  • Full local gate passed on e22c0730: clean install, build, generated hooks, skills, typecheck, npm test (3,311 passed, one skipped), npm run eval:gate, and npm run eval:gate:rules.
  • Regression tests cover stale delete candidates, Lesson re-saves and duplicate deletes, partial purge failures, and empty SQLite keys.

Not verified

  • No production store was used.

Merge danger

Door: One-way for Facets removed with their targets; a revert does not recreate deleted tags.

Blast radius: Ordinary Observation, Memory, and Lesson deletion paths; Facet mutation ordering during import and snapshot restore.

Generated-By: gpt-6.1-terra
Keep both documented contracts and verify Facet mutation ordering
against the landed Relation export and restore paths.

Refs: #475
Generated-By: gpt-6.2-sol
Keep tags on missing targets when a delete candidate is stale. Update
Lesson Recall before cleanup can yield and retain deleted IDs across
purge chunks. Include empty stored keys on the first SQLite page.

Refs: #475
Generated-By: gpt-6.2-sol
@possiblyneal

Copy link
Copy Markdown
Owner Author

Code review: standard scan, clean.

Axes: Standards+Spec, Correctness/Logic

Reviewed-Head: e22c073

@possiblyneal
possiblyneal merged commit 9b87bf4 into main Nov 21, 2026
3 checks passed
@possiblyneal
possiblyneal deleted the fix/475-facet-cleanup branch November 21, 2026 21:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Facets outlive the Observations, Memories and Lessons they tag

1 participant