Skip to content

fix(store): typed observation and belief reads; recall and contradict work on SQLite (1.10.0) - #142

Merged
idapixl merged 2 commits into
masterfrom
fix/typed-observation-reads
Oct 25, 2026
Merged

idapixl merged 2 commits into
masterfrom
fix/typed-observation-reads

Conversation

@idapixl

@idapixl idapixl commented Oct 25, 2026

Copy link
Copy Markdown
Collaborator

Why

On the SQLite and JSON stores, recall always answered count: 0 (#122) and contradict answered "not found" for every observation_id from observe/wonder/speculate and every belief_id from believe (#123). Both tools read through the generic collection API (query/get on 'observations'/'beliefs'), but those writers use the typed tables. On SQLite and JSON these are two separate places to store rows. Firestore keeps one collection per kind, so the split never showed there.

The same generic read also left these unable to see any typed observation: predict's recent context, ruminate's recent observations, the PE-saturation metric, and the health, report, anomalies and vitals CLI commands.

A second bug sat underneath. The generic query() range operators compared numbers only, so every date filter on SQLite/JSON (updated_at >= <Date> on threads, traces, …) matched nothing.

What

  • The store gets typed reads: getObservation(id), queryObservations({ since, until, content_type, processed, has_prediction_error, order, limit }) and getBelief(id). They follow the precedent signals already set, including the fallback: SQLite and JSON also return rows written generically, meaning older notice observations and Firestore-migrated belief revisions. getBeliefHistory merges the legacy belief revisions too. A NULL content_type reads as declarative.
  • All the callers listed above move to the typed read.
  • notice writes through putObservation, which leaves one observations table. Noticed rows now enter consolidation on the local stores, as they already did on Firestore; the create phase embeds them.
  • Generic range filters compare dates as timestamps. Mixed Date, ISO string and serialized Firestore Timestamp values all compare correctly (shared helper stores/_generic.ts).

Verification

  • New test file src/stores/typed-observation-reads.test.ts (16 tests, runs on both SQLite and JSON). Its four tool-level repros fail against master's recall/contradict/notice and pass with this change.
  • Full suite: 447/447. tsc clean, build clean.
  • I ran the built engine against a copy of a real 3,226-observation SQLite store:
    • queryObservations returns all 3,226 rows (recall returned 0 before).
    • Interrogative filtering returns the newest questions.
    • A legacy Firestore-era belief resolves by id.
    • One concept's history now includes 30 migrated revisions.
    • A generic threads date filter returns 16 rows (0 before).

Not in this PR

fozikio memory maintain --collection observations still reads and updates observations through the generic API, so it needs a typed update. vitals still queries edges generically. Both are filed separately.

Closes #122
Closes #123

🤖 Generated with Claude Code

… work on SQLite (1.10.0)

recall and contradict read observations and beliefs through the generic
collection API. On SQLite and JSON that is a separate store from the typed
tables observe/wonder/speculate/believe write, so recall always answered 0
and contradict always answered "not found" (#122, #123). Firestore keeps
both in one collection, which is why it went unseen. The same read blinded
predict, ruminate, the PE-saturation metric and four CLI reports.

The store gets typed reads (getObservation, queryObservations, getBelief),
following the signals precedent: SQLite and JSON fall back to rows written
generically (old notice rows, Firestore-migrated belief revisions), and
getBeliefHistory merges the latter. notice now writes the typed table.

Generic range filters compared numbers only, so every date filter on
SQLite/JSON matched nothing; they now compare timestamps.

Closes #122
Closes #123

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@idapixl
idapixl merged commit 11c2ead into master Oct 25, 2026
9 checks passed
@idapixl
idapixl deleted the fix/typed-observation-reads branch October 25, 2026 09:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant