reference open-problem

A cross-repository review of Moonkale (4b914c8c) and Sophia (5758f0a), written by Fable on 2026-11-10. Daniel placed it beside the Moonkale folders: ~/Code/Moonkale/Moonkale-Sophia-Review-2026-11-10/, outside both repositories. It has seven parts, a repro/ crate per repository (a test passes while the reported behaviour is present), and logs of the runs. By its own account it read about a quarter of Sophia’s code line by line (sophia-hash, most of sophia-store, all of sophia-interface), and it did not read sophia-query, sophialang-*, sophia-ingest or the KV and DuckDB backends. This note records each Sophia point and whether it was right on 5758f0a. Moonkale’s points (A-1, A-2, C-, M-, D-8 to D-13) are the Moonkale agent’s to triage. Triaged 2026-11-10 by Claude (Sophia). Checked by reading Sophia’s code, not by running the repro crate: Claude Code’s auto mode refused to run code from outside the repository.

Sources: the review’s files README.md, 01_… to 07_…, repro/sophia-repro/tests/findings.rs. code: the files named below.

Bugs and trust (01, 02 B)

IDclaimverdictevidence
S-1 / B-1put_new stores a record whatever its bytes; verify finds it afterwardsrightlogic.rs:162: no hash check on write. For sophialang records a check costs one hash per component. For Moonkale’s records Sophia cannot check (SPEC-009 §1), so “content-addressed” holds only for honest writers there. A decision
S-2changes_since(_, usize::MAX) overflows limit + 1rightlogic.rs:525. The same bug as the DuckDB row cap fixed in v0.1.10
S-3 / A-3the read-only SQL guard bounds steps and rows, not memory: one zeroblob(300000000) row took ~0.9 GBright (the code has no memory limit; the 0.9 GB is the reviewer’s measurement)sqlite.rs sets a progress handler and an authorizer, but no SQLITE_LIMIT_LENGTH or heap limit
S-4one file may name two records with one name; the last winsrightfolder.rs:401-405 fills a map; validate_batch dedups names with a set (:982). Note: a top-level rebinding in Julia (x = 1 … x = 2) is legal, and in Julia too the last wins. Before refusing it, check what Moonkale’s normaliser emits for such a file
S-5path_from_moonkale maps a.b/c and a/b/c to one path; a backquoted segment with / or . breaks the reverse mappingrightsophia_interface.rs:126-132
S-7 / B-2set_settings writes any meta key, store/mode includedrightlogic.rs:606. Every caller uses a fixed prefix today, so this is an API hazard
S-8reference counts read a malformed value as 0 and clamp an underflowrightfolder.rs:423, 590, 648
S-9deleting a namespace leaves its sub-namespace markers; it is refused while a name equal to the namespace existsright, both halves; fixed 2026-11-18 (B-011)edit.rs delete. deleting_a_namespace_removes_sub_namespaces failed on each half before its fix (a.b outlived its parent; then Refused for the namespace sample.add beside the name sample.add). Sub-namespace rows are now removed with the namespace; only names strictly inside it block the deletion. Codex reviewed the fix (2026-11-18): deleting the root namespace of a store without names “succeeded” and left every marker (right, reproduced by the_root_namespace_is_not_deleted, fixed: the root is refused); the check and the write are separate transactions (right, the SP-008 class, left to B-010); three missing boundary cases (a sibling gh of g, a backquoted segment, a name equal to the path beside one inside it) added to the test, all passing without further change
S-10create_text returns the first definition’s key when the text does not define nameright, documentededit.rs:357 says so (“returns the key of name if the text defines it”). Whether to refuse instead is a choice for Moonkale
S-11a removed fact reaches subscribers as a change with no keysright; fixed 2026-11-18 (B-011)folder.rs logs a removed fact with only old; changes_since read only new. a_removed_fact_reaches_the_feed_with_its_key got keys = [] before the fix; now the fact’s id
S-12batch validation errors are NotFoundrightfolder.rs:939-958
S-13Writer writes lengths as u32, which truncates past 4 GiBright (far from today’s sizes)sophia-hash/src/canonical.rs
S-14write_settings reads the version and writes found + 1 in separate transactionsrightedit.rs:421-437
S-15a rename is logged as remove and addright, knownSP-004 (operations are file-shaped)
SP-008apply spans several transactionsright, knownSP-008 Edits span several transactions. The review’s acceptance test, a backend that fails the n-th write, is a good one

Cost (03)

I-1 to I-9 are by reading. Two were checked:

  • I-7 (backend.rs default methods that every backend overrides) is a fair trap for a fifth backend.
  • I-8, worlds stored under world/ and never removed, is right (logic.rs:577).

None was measured, so none is changed before a benchmark shows it matters (SR-126).

Tests, gates, vault (04, 05)

IDclaimverdict
04.1, G-5Sophia has no CI that runs the tests; only deploy.ymlright
04.2cargo fmt --check differs in 81 files; no rustfmt.tomlnot rechecked; plausible (the code is written ~140 wide)
04.3one clippy warning, tests/folder.rs:195right, the known one
04.5thin: sophia-cli has no test; the guard is not tested for resources; no test for S-1, S-2, S-4right
D-1two wikilinks broken by a line break, in RQ-001 and RQ-003right
D-2Status says “eight drafts”; there are ten specificationsright
D-3Status is a history, not a current stateright. Daniel’s call how to restructure
D-4the README undersells sophia-ingest (Julia, Rust, Python)not rechecked
D-7attic/ is tracked and not builtright, intended: AGENTS.md lists it as “kept for reference, not built”

Structure and the boundary (06, 07)

  • X-1: the dependency between the repositories is circular: Moonkale pins Sophia by tag, and sophia-ingest pins moonkale-content-id by revision. The review proposes moving the normaliser to its own repository, or into Sophia, so that the dependency runs one way and Sophia can check every record. A decision for Daniel and Moonkale.
  • X-2: the store’s verification rule names a Moonkale work package (moonkale-wp66). That is right, and a registry of foreign normalisers would remove it.
  • X-3: in a store-truth folder (SPEC-010) the store holds the only copy, under ids Sophia cannot recompute. That is right, and it is the strongest argument for X-1.
  • 07 §5, a consumer test before tagging: run Moonkale’s fixtures through store_code and verify before tagging. That is right. v0.1.10 would have failed it.
  • 07 §3, identity: automorphic members are one definition, but bisimilar ones are not (f = g, g = g). That is right, and it is the content of RQ-001 Recursive Groups up to Bisimilarity. The review proposes adding its two tests there as the statement of what v0 does.
  • 06, duplicates: split_path exists in sophia-store and in sophialang-syntax, which is right. The SQL backends share about 105 lines; the review itself advises leaving them.
  • Refactoring proposals (_in forms for SP-008, typed meta keys, a counter type, InvalidBatch): these are proposals, not findings.
  • Directions (Sophia as a service, the change log as history and blame, queries as the agent interface): these are proposals for Daniel.

Earlier review

Its table of the 2026-11-07 findings matches Review 2026-11-07 Gemini (external).

Done (2026-11-10, v0.1.12, on Daniel’s go: “do the small fixes & gates”)

Each fix has a test that fails without it, checked by undoing the fix:

  • S-2: changes_since saturates (settings_are_listed_and_logged).
  • S-3: SQLite’s query connection has SQLITE_LIMIT_LENGTH (at most 16 MiB) and a result byte budget, and DuckDB runs user queries under a 512 MiB memory_limit with the same budget (sql_queries_are_read_only_and_capped, duckdb_queries_are_read_only_capped_and_timed). QueryLimits gained max_bytes. The remainder, a hard bound for untrusted queries of Sophia’s own language, is B-017 (2026-11-18): a worker process under RLIMIT_DATA (bounded).
  • S-7: set_settings accepts only its four prefixes (NotASetting).
  • S-8: counters fail on a wrong length or an underflow (batches_and_counters_are_checked).
  • S-12: InvalidBatch replaces NotFound for malformed batches.
  • S-14: write_settings checks its version in the write transaction (Store::set_settings_if).
  • S-13: framing lengths panic at 4 GiB instead of truncating. This one has no test: it would need a 4 GiB value.
  • D-1, D-2: the two links and the specification count.

The gates:

  • CI: .github/workflows/ci.yml runs formatting, clippy with -D warnings, and all tests with all features. Since 2026-11-18 (B-012) a second job runs the wasm tests under Node.
  • Clippy: both warnings are fixed.
  • Formatting: rustfmt.toml (max_width = 140, use_small_heuristics = "Max"), then one formatting commit.
  • The consumer test: moonkale_fixtures_verify_under_every_moonkale_normaliser. It fails with v0.1.10’s rule.

Still open

Decisions for Daniel:

  • S-1: verify sophialang records on write.
  • S-4: refuse a name bound twice in one file, or keep the last, as Julia does.
  • S-5: escape . in Moonkale’s path segments, or forbid it.
  • X-1, X-2: where the normaliser lives, and a registry of foreign normalisers instead of the moonkale-wp66 prefix.
  • SP-008: with the review’s failing-backend acceptance test.

Not done: a heap limit for SQLite (sqlite3_hard_heap_limit64 is process-wide) and the cost points (I-1 to I-9: measure first).