Skip to content

feat(palace): Tiramemsu port phase 2 — graphs, query languages, paths, rules, saved answers, vectors, bundles, crypto-shredding - #487

Merged
dimetron merged 20 commits into
mainfrom
feat/palace-tiramemsu-phase2
Nov 22, 2026
Merged

dimetron merged 20 commits into
mainfrom
feat/palace-tiramemsu-phase2

Conversation

@dimetron

Copy link
Copy Markdown
Owner

Phase 2 of the Tiramemsu port (phase 1 merged in #483). Spec: specs/memory/tiramemsu/phase2/; Codex reviewed the plan before implementation (25 findings, resolutions at the end of design.md).

Every capability phase 1 deferred is now in internal/palace, in pure Go on
the same modernc.org/sqlite database: no cgo, no new module dependency.
Plan: design.md, plan.md. Codex reviewed the plan (codex-plan-review.md,
25 findings, all accepted; resolutions at the end of design.md).

Capability Files Surface
Migration 7: volatile, seal keys, vectors, saved answers (with never-forget guards on keys and vectors) kg_schema2.go, db.go —
Predicate schema: value type, subject type, is-edge, sensitive; unique upsert kg_predschema.go pi memory kg schema
Derived upsert (D51), widening (D52) kg_predschema.go, kg_verbs.go —
Named graphs kg_graph.go, kg_view.go palace-kg-graph, graph on add/query/select/path/recall/rules, pi memory kg graphs
Volatile state kg_volatile.go pi memory kg volatile
Crypto-shredding kg_seal.go pi memory kg erase --yes (CLI only, on purpose)
Query IR, SPARQL subset, Cypher read subset, budgets kg_query.go, kg_sparql.go, kg_cypher.go, kg_budget.go palace-kg-select, pi memory kg select
Paths, time-respecting paths kg_path.go palace-kg-path, pi memory kg path
Datalog (stratified negation, constraints, materialize), N3 Horn subset kg_rules.go, kg_rules_store.go, kg_n3.go palace-kg-rules, pi memory kg rules
ELPI Horn subset (SLD with fuel, tm.triple) kg_elpi.go palace-kg-rules syntax=elpi
Saved answers with conservative invalidation kg_answers.go palace-kg-select save_as/check, pi memory kg answers
Statement vectors, hybrid recall (RRF) kg_vector.go palace-kg-recall
Fact bundles kg_bundle.go palace-kg-bundle, pi memory kg bundle

Fixes to phase 1 found on the way: AsOf reads showed retractions made after
their bound (Codex #21); annotateEvidence replaced a predicate's whole schema
when it set confidence to cardinality one.

Subsets, stated

  • SPARQL: no CONSTRUCT/ASK/DESCRIBE, property paths, BIND, VALUES, subqueries,
    aggregates other than COUNT, dataset clauses other than GRAPH <g>.
  • Cypher: read only; no variable-length relationships, WITH, UNWIND, CALL.
  • N3 and ELPI: Horn clauses only; ELPI has no λ-terms, higher-order
    unification, constraints or modules. ELPI programs are not stored or
    materialized (Datalog and N3 are).
  • Rules: Materialize rejects programs with negation (upstream
    N3NotMaterializable) and reads only the now view.
  • Bundles: JSON only (no N-Triples).

Verification

  • Tests per capability (kg_*_test.go, tool_kg_*_test.go,
    internal/cli/memory_kg2_test.go); every new tool runs through tool.Run in
    tool_invoke_test.go. make build test lint vet clean.
  • Guards seen failing once: sealing off → plaintext found in kg_term/FTS;
    negative-query invalidation off → TestAnswers_NegativeQueryStaleOnRetraction;
    MinHops dropped from the path visited key → five path tests; own-conclusions
    filter off in Materialize → TestRules_OwnConclusionsAreNotInput;
    sealed filter off in embedding → TestVector_NeverEmbedsSealedValues;
    IncludeSensitive check off → TestBundle_Sensitive; plus the query
    agent's dedup mutation.

Not verified

  • Performance at scale: rules load stored predicates fully into memory; path
    search issues one lookup per node and predicate; vector search is exact.
    Nothing was measured.
  • Agent behaviour with the six new tools (make eval-tools not run).
  • WAL checkpoint after erase is tested only for success, not with a busy reader.

…atile state, crypto-shredding

Migration 7 adds side tables for volatile state, seal keys, statement
vectors and saved answers, with never-forget guards on seal keys and vectors.
Predicate schema gains value type, subject type, is-edge and sensitive, checked
in upstream order before anything is interned. Sensitive literals are sealed
per data subject with a deterministic SIV-style AES-GCM construction from the
standard library; Erase destroys the key and checkpoints the WAL. Named graphs
are bitemporal membership layers. As-of reads no longer show retractions from
after their bound.

Signed-off-by: pi <dimetron@me.com>
…rase CLI

Signed-off-by: pi <dimetron@me.com>
…all shortest, trails, time-respecting)

Signed-off-by: pi <dimetron@me.com>
Signed-off-by: pi <dimetron@me.com>
Stratified semi-naive evaluator with pointwise valid time (fragments per
support set), Solve/Check over one snapshot, stored programs, and
Materialize through Derive with program support, widening and reconcile.

Signed-off-by: pi <dimetron@me.com>
…) and elpi syntax in palace-kg-rules

Signed-off-by: pi <dimetron@me.com>
…lters, query budgets

Signed-off-by: pi <dimetron@me.com>
…nd docs

Saved answers keep query, view, rows, dependencies and an event checkpoint;
checks invalidate conservatively (retracted support, new rows on read
predicates, retractions under negation, graph membership) and erasure drops
stored rows. The query and rules engines are merged; colliding private helper
names in the rules engine are renamed. The feature map no longer defers any
capability.

Signed-off-by: pi <dimetron@me.com>

@dimetron dimetron left a comment

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

Review of the Tiramemsu port (phases 1 and 2): 14 findings, inline. Each was checked against the code before posting.

— Codex review

Comment thread internal/palace/kg_rules_store.go Resolved
Comment thread internal/palace/kg_answers.go Resolved
Comment thread internal/palace/kg_predschema.go Resolved
Comment thread internal/palace/kg_elpi.go Resolved
Comment thread internal/palace/kg_query.go Resolved
Comment thread internal/palace/kg_bundle.go Resolved
Comment thread internal/palace/kg_predschema.go Resolved
Comment thread internal/palace/kg_elpi.go Resolved
Comment thread internal/palace/kg_path.go Resolved
Comment thread internal/palace/kg_predschema.go Resolved
- materialize refuses to copy a sealed value into a non-sensitive predicate
- erase deletes saved answers whose query quotes the erased values
- a predicate with volatile plaintext cannot become sensitive
- ELPI: occurs check; each _ in a goal is its own variable
- Cypher bare-node products are charged to the budget
- saved answers: GRAPH clauses depend on membership, OFFSET is non-monotonic
- palace-kg-select save_as runs under the same budget and row cap
- object-only literal patterns also find sealed objects
- graph-scoped bundles leave out statements outside the graph
- derived upsert on a sensitive predicate is refused
- To-only time-respecting path search is refused
- changing value type checks the kinds of sealed values

Signed-off-by: pi <dimetron@me.com>
@dimetron

Copy link
Copy Markdown
Owner Author

make vulncheck at d64d644: pass — no finding with an available fix.

9 advisories without a fix are reported, all in github.com/ollama/ollama (GO-2025-3557, -3558, -3559, -3582, -3689, -3695, -3824, -4251, GO-2026-5750). This PR adds no dependency; they are pre-existing on main.

@codecov

codecov Bot commented Nov 21, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 97.03367% with 163 lines in your changes missing coverage. Please review.
✅ Project coverage is 92.22%. Comparing base (04ebf5a) to head (1d53136).

Files with missing lines Patch % Lines
internal/palace/kg_bundle.go 93.96% 16 Missing ⚠️
internal/palace/kg_path.go 94.38% 16 Missing ⚠️
internal/palace/kg_sparql.go 97.27% 15 Missing ⚠️
internal/palace/kg_rules.go 98.06% 14 Missing ⚠️
internal/palace/kg_rules_store.go 93.29% 13 Missing ⚠️
internal/palace/kg_vector.go 95.92% 13 Missing ⚠️
internal/palace/kg_answers.go 94.82% 12 Missing ⚠️
internal/palace/kg_predschema.go 96.46% 11 Missing ⚠️
internal/palace/kg_seal.go 93.08% 11 Missing ⚠️
internal/palace/kg_elpi.go 97.19% 10 Missing ⚠️
... and 12 more
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #487      +/-   ##
==========================================
+ Coverage   91.31%   92.22%   +0.91%     
==========================================
  Files         403      426      +23     
  Lines       52380    57744    +5364     
==========================================
+ Hits        47831    53255    +5424     
+ Misses       4543     4483      -60     
  Partials        6        6              

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

…d select tool

Signed-off-by: pi <dimetron@me.com>
…d CLI

Inject a failure at every driver call of each write and read path so every
storage-error branch is checked to reach the caller, and add behavioural tests
for schema flags, seal errors, erase, volatile, graphs, bundle import,
vectors, the graph/recall/revise tools and the kg CLI commands.

Signed-off-by: pi <dimetron@me.com>
…them

visibleIn and isEngineOID swallowed database errors, so Bundle returned
ErrNotLive or silently dropped statements. Both now return the error, and the
fault-injection sweep checks the bundle paths strictly.

Signed-off-by: pi <dimetron@me.com>
@dimetron
dimetron merged commit 8a48b41 into main Nov 22, 2026
15 checks passed
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