Skip to content

Epic: rows and transcripts that cross a storage or SDK boundary are parsed, not asserted #1344

Open
0 of 5 issues completed

Description

@schlessera

Outcome

Data read from SQLite or from an upstream SDK transcript is checked at the boundary by a schema or a typed mapper, so a schema skew or upstream shape change fails loudly at the read instead of silently producing wrong values deeper in.

Why now

Found by the 2026-10-09 code-quality review of main @ 0c69e0cb. Core has 124 and ui-server 191 .get()/.all() ... as T casts; every one asserts a row type the checker cannot verify. ui-server's activity code has 18 as any (for example packages/ui-server/src/activity/query.ts, packages/ui-server/src/activity/store.ts), core's briefing read as any[] (then in packages/core/src/cli/commands/briefing.ts), and the Claude backend reads SDK transcript JSON through 12 anys (packages/ui-backend-claude/src/history.ts). The backend contract test drives a scripted query cast as unknown as typeof query (packages/ui-backend-claude/tests/backend-contract.test.ts:33-53), so an upstream transcript change would not be caught.

Shared context

  • brain.db is disposable and schema-versioned (SCHEMA_VERSION, packages/core/src/lib/db.ts:21); skew is real when an old index meets new code.
  • Current source at main 3aadc8df5: refactor(core): move raw SQL out of CLI commands and keep one silent-edit query #3293 moved briefing's SQL out of the CLI command into packages/core/src/lib/briefing-reads.ts (focusLinkedDocuments, packages/core/src/lib/briefing-reads.ts:18; upcomingDeadlines, :39; overdueReviewRows, :57). Its as any[] reads are now unchecked as T row casts, which this epic still covers. Lines containing as any remain in packages/ui-server/src/activity/query.ts (4), packages/ui-server/src/activity/store.ts (8) and packages/ui-backend-claude/src/history.ts (7).
  • zod is already the runtime-validation library across the repo.
  • Hot paths (search, indexing) read many rows; validation cost must be measured there.

Constraints and non-goals

Breakdown

Native child #1367 owns the mechanism decision (zod per row versus typed mappers and any measured hot-path exemption); it is a scoped investigation deliverable, not a reason to mark this epic ready. Then #1368 owns core rows, #1369 server rows and #1370 Claude transcript parsing. Already-attached #2518 owns Pi server-to-worker messages and transcript resume probes. Preserve each child’s actual prerequisites; parent membership alone is not a blocker.

Definition of done

Each package has a documented row-reading convention, as any is gone from the listed files, and a test feeds a skewed row or transcript and asserts a typed failure.

2026-10-24 continued triage at main dc5d3c73282c29a3f0098306d398743ee18ec791: Refreshed the observed row-cast, scripted-query and SCHEMA_VERSION anchors and reconciled the breakdown with all five native children, including #2518. Historical review counts retain their review SHA. The mechanism decision belongs to #1367; no schema, query result or epic readiness changed.

2026-10-25 triage at main ab746a434c4ada11734ffea4e208d1d6211f1aca: Verified moved current-source anchors and refreshed navigation. Historical failed receipts, existing rulings and unresolved prerequisites are unchanged; this is not a new runtime qualification.

2026-11-10 triage at main 3aadc8df5: recorded that #3293 replaced briefing's as any[] reads with typed as T casts in briefing-reads.ts; the review paragraph keeps its review SHA. All five children remain open; the definition of done is unchanged.

Activity

  1. added
    type: refactor
    area: core
    area: ui-server
    area: backends
    priority: p3
    epic
    on Oct 9, 2026
  2. schlessera commented on Oct 24, 2026

    @schlessera
    OwnerAuthor

    2026-10-24 triage at main dc5d3c73282c29a3f0098306d398743ee18ec791: Refreshed the observed row-cast, scripted-query and SCHEMA_VERSION anchors and reconciled the breakdown with all five native children, including #2518. Historical review counts retain their review SHA. The mechanism decision belongs to #1367; no schema, query result or epic readiness changed.

  3. schlessera commented on Oct 25, 2026

    @schlessera
    OwnerAuthor

    2026-10-25 triage at main ab746a434c4ada11734ffea4e208d1d6211f1aca: Verified moved current-source anchors and refreshed navigation. Historical failed receipts, existing rulings and unresolved prerequisites are unchanged; this is not a new runtime qualification.

  4. schlessera commented on Nov 10, 2026

    @schlessera
    OwnerAuthor

    2026-11-10 triage at main 3aadc8df5: #3293 (merged 2026-11-03) moved briefing's SQL out of packages/core/src/cli/commands/briefing.ts into packages/core/src/lib/briefing-reads.ts. The old as any[] reads are now unchecked as T row casts (focusLinkedDocuments, packages/core/src/lib/briefing-reads.ts:18), so they are still in this epic's scope. I recorded this under Shared context. The review paragraph keeps its 2026-10-09 SHA, and the stale briefing line citation is gone. Lines containing as any remain in ui-server's activity/query.ts (4) and activity/store.ts (8), and in the Claude backend's history.ts (7). All five children remain open. The definition of done is unchanged.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area: backendsarea: corearea: ui-serverepicpriority: p3type: refactor

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions