Skip to content

daemon: the evidence store is one JSON string, so a store over ~512 MB fails every check with 'Invalid string length' (DB subset-dedupe, 6 checks on #133) #179

Open

Description

@KyleAMathews

Summary

The daemon's evidence store (diskStore, evidence.mjs) writes the whole store as one JSON.stringify string and reads it back as one string. V8 caps a string at about 512 MB, so a store past that size makes every later check end in an internal error:

RangeError: Invalid string length
    at JSON.stringify (<anonymous>)
    at Object.flush (oracle-gaps/evidence.mjs:98:37)
    at checkIn (oracle-gaps/check.mjs:2836:24)
    at async Object.check (oracle-gaps/check.mjs:1693:14)
    at async oracle-gaps/daemon.mjs:525:20

The CLI reports oracle-gaps: error Invalid string length: a bug in oracle-gaps, not in your oracle and exits 3.

Trace

TanStack DB 21c52a07, packages/db --source src/query/subset-dedupe.ts (559 units), Arca pool tag r133-dbb4-all. Each variant ran a daemon sequence from an empty state: a first check, 3 unchanged rechecks and 3 one-line-edit rechecks.

CLI Result Store size
main 97a4e7a all 7 checks complete 425 MB at the end
#133 head 9bb7c74, Vitest cache off the 3rd edit recheck (the 7th check) fails 457 MB at the last good flush
#133 head, Vitest cache on (every check recomputes all units) the 2nd unchanged recheck (the 3rd check) and every later check fail 358 MB at the last good flush

Composition

A store after 2 checks with the cache on (#133 head): 1,114 rows, 1 variant each. Each variant has about 481 inputs (52 KB of JSON) and a unit payload of about 83 KB.

Of the inputs, 261,508 are fs: keys (41 MB), 118,996 are env: keys (10 MB) and 22,662 are stat: keys. #133's every-read inputs add about 60% to a variant. Main already sits at 425 MB after 7 checks, so main reaches the ceiling a few edits later on the same suite.

Proposed fix (choose one)

  • Write and read the store one row per line (JSONL), streamed, so no single string holds the whole store.
  • Or store each distinct input list once, by its hash, and have variants name it, since most units share their env: and node_modules inputs.
  • Or both.

A bound on the store's size is a separate design question. The retention law (bounded retention) covers memory, not this file.

Under P9 the fix needs an oracle-first witness: a test-only knob that lowers the store's size ceiling, so that a constructed e2e history reaches the state with a small store and requires that the next daemon check complete.

Authority

R13 (the daemon is the default) and P10 (an internal error is a CLI defect). Found while measuring #133 for M "Vitest cache off, measured".

This issue was written by Isaac.

Activity

  1. KyleAMathews commented on Nov 20, 2026

    @KyleAMathews
    ContributorAuthor

    Fixed on #133 (6b2a085, oracle first in a3737b8): the store is now evidence.jsonl, written and read one row per line, so no string holds the whole store.

    • Witness: the constructed e2e history "a daemon store longer than the string limit, reloaded after a restart" uses a test-only limit (ORACLE_GAPS_TEST_STRING_LIMIT=32768) against a store of about 78,000 characters.
    • RED on the parent: after start, the daemon's check exited 3 (RangeError: Invalid string length).
    • Mutants: a flush that joins the rows into one string fails after start; an open that reads the file as one string fails after restart.
    • On DB: 7-check daemon sequences complete with a 490 MB store.

    This comment was written by Isaac.

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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions