Skip to content

Wave 1B: Post-v0.16.0 reader diagnostics, recall schema retention, & derivation privacy floors - #88

Merged
jsflax merged 13 commits into
mainfrom
agy/wave1-post-016-fixes
Nov 19, 2026
Merged

jsflax merged 13 commits into
mainfrom
agy/wave1-post-016-fixes

Conversation

@jsflax

@jsflax jsflax commented Nov 17, 2026

Copy link
Copy Markdown
Owner

Summary

Consolidates the 8 post-v0.16.0 runtime diagnostic, schema retention, write-budget, lock-hygiene, and derivation privacy PRs (#14, #71, #73, #83, #84, #85, #86, #87) cleanly onto main (26d8949 -> e2ca6987, 22 files changed, +2,335 / -92) while preserving EngramModels/Memory.swift wire compatibility at schema v3.

Consolidated Fixes (8 PRs)

  • #14 (PlannerStatistics.swift, Engram/main.swift): Runs bounded PRAGMA optimize=0x10002 before the MCP server opens Lattice connections so multi-million-row AuditLog cursor scans never degrade into full table scans, explicitly reporting SQLite < 3.46.
  • #71 + #73 (Sources/EngramLattice/MemoryTools+DerivationPrivacy.swift, Clustering, Core, Episodes, Organize): Enforces derivation privacy floors and privateGraphOnly write-target isolation across localLattice, syncedLattice, and all configured groupSpokes during consolidate, merge, organize, and end_episode so private or narrower-audience replica memories are never leaked through a public handle — while keeping Memory.swift wire-compatible at schema v3.
  • #83 (EngramMemoryCore/SubprocessSpawner.swift): Guards Foundation.Process launch helpers behind #if os(macOS) || os(Linux) for clean iOS 18 compilation.
  • #84 (AgentMemoryReader.swift): Emits structured, content-free table/column reader compatibility diagnostics without leaking memory text.
  • #85 (MemoryTools+AccessStats.swift): Opens independent recall access-statistic handles with for: localLattice.modelTypes rather than Memory.self alone so reader schemas remain intact across recall updates.
  • #86 (LatticeBeginRetry.swift): Caps defaultTotalCapSeconds at 4.5s to reserve response headroom within the 6s interactive busy-write budget.
  • #87 (SpawnAdmission.swift): Explicitly unlocks (flock(lease.fd, LOCK_UN)) completed preflight admission leases before close(lease.fd) prior to resource sampling.

Verification Gates

  • Focused Test Suites (swift test --scratch-path /Users/jason/localdev/.build-cache/engram --jobs 4): 60/60 tests passed across 9 suites (0 failed) — PlannerStatisticsTests, DerivationPrivacyTests, DerivationReplicaPrivacyTests, EpisodePrivacyTests (44/44), SpawnAdmissionPreflightLeaseTests (2/2), AgentMemoryReaderDiagnosticTests, RecallReaderSchemaTests, AgentMemoryStoreTests, and InteractiveBusyBudgetTests (14/14).
  • EngramModels/Memory.swift preserved at wire-compatible schema v3; zero .package(path:) overrides or .build artifacts.

Consolidates and supersedes #14, #71, #73, #83, #84, #85, #86, and #87.

jsflax and others added 12 commits November 17, 2026 12:01
Keep Process-based entry points out of the iOS memory-core module while retaining shared command, admission, and resource helpers on every platform. The launch implementations are unchanged on macOS and Linux.

Co-Authored-By: Codex <noreply@openai.com>
Identify the required schema or decoded field that fails compatibility without logging stored values. Preserve reader errors, admission order and public APIs, and cover refusal categories and reads with retained writers.

Co-Authored-By: Codex <noreply@openai.com>
Make the task-local closure infer its throwing behavior before Swift Testing expands the value assertions. Keep the same decode calls, expected values and empty-diagnostic check.

Co-Authored-By: Codex <noreply@openai.com>
Exercise vector and full-text recall through real memory stores, then verify
that independent readers retain the complete schema, saved rows and edges.
Keep dedicated access-stat connection ownership and timeout assertions.

Co-Authored-By: Codex <noreply@openai.com>
Open the dedicated access-stat connection with the owning store model list
so recall does not replace dynamic-reader metadata with a Memory-only schema.
Retain its short busy timeout and independent, transport-free connection.

Co-Authored-By: Codex <noreply@openai.com>
Exercise real checked-BEGIN contention with the interactive timeout and a
short-timeout control. Advance logical time from actual failure callbacks
so the admission assertions do not depend on scheduler timing, and verify
that a refused write leaves no row and the same handle recovers afterward.

Co-Authored-By: Codex <noreply@openai.com>
Reduce the default BEGIN retry-admission budget to 4.5 seconds so the
interactive two-second timeout cannot admit a third full wait. Preserve
short-timeout retries, custom budgets and the no-replay transaction fence.

Co-Authored-By: Codex <noreply@openai.com>
Retain a duplicate through successful preflight preparation to expose a
lock surviving into resource sampling and final admission. Keep a separate
control for the final worker lease until its retained duplicate closes.

Co-Authored-By: Codex <noreply@openai.com>
Explicitly release the successful preflight lock before closing its file
descriptor, so retained references cannot block final admission. Refuse
admission if unlocking fails. Preserve the worker lease lifetime.

Co-Authored-By: Codex <noreply@openai.com>
Each cross-process notification makes every Lattice instance run
`SELECT ... FROM AuditLog WHERE id > ? ORDER BY id`. On a hub whose
sqlite_stat1 was written while AuditLog was tiny, the planner believes the
table holds 1 row and picks a full scan instead of a rowid seek. With a
2.77M-row AuditLog each notification cost 4-22 s, and a dozen MCP servers
rescanning in turn held about 9 cores and 1 GB of RAM each.

LatticeCore no longer runs ANALYZE at open, its close-time PRAGMA optimize
does not repair these statistics, and an ANALYZE from another connection
does not reach a connection that is already open. So the server now runs
the bounded all-tables `PRAGMA optimize=0x10002` on a short-lived
connection before Lattice opens the hub and the synced store. It costs
about 30 ms on fresh statistics and a few seconds once on a stale hub. It
takes the writer lock with BEGIN IMMEDIATE, so a concurrent commit costs
at most the existing 2 s busy timeout, and a busy hub is skipped until the
next start.
Review follow-up to the planner statistics refresh.

- PRAGMA optimize's 0x10000 (all tables) bit arrived in SQLite 3.46.
  Older libraries ignore it and analyze nothing, which the refresh used to
  log as success. It now checks sqlite3_libversion_number() and reports
  unsupportedSQLite(version:) without touching the store.
- refresh returns an Outcome (refreshed, skippedMissingFile,
  unsupportedSQLite, failed(code:message:)) so the startup log carries the
  SQLite error message.
- Documented the real startup cost (busy wait plus a few seconds of
  analysis once on a stale hub, per store) and the one-time writer-lock hold.
- Softened the close-time optimize claim: in practice it does not repair
  AuditLog (servers usually exit through _exit, and the cursor query uses
  no index).
- Tests: remove temp databases, use #require for setup, rename the no-op
  test to refreshIsIdempotent and assert the statistics stay unchanged, add
  a test for the unsupported path, and skip plan assertions on old SQLite.

Correction to the previous commit message: the ~1 GB RSS per server was
the cache and mmap baseline, not a measured effect of the rescanning.
@jsflax
jsflax merged commit 229fcbe into main Nov 19, 2026
3 checks passed
@jsflax
jsflax deleted the agy/wave1-post-016-fixes branch November 19, 2026 00:57
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.

2 participants