Repository navigation
perf: read only the lifecycle payload fields the check uses - #216
Conversation
The lifecycle snapshot parsed every bound thread's whole stored payload to reach settledAt and settledOverride. SQLite now returns those two fields, and json_valid keeps one malformed row from failing the whole query. Reconcile over 200 calls on a copy: 8.27 -> 7.35 ms wall, 8.74 -> 7.45 ms CPU. A copy server with 20 clients renewing a 3 s wait: 0.1293 -> 0.0952 cores. Refs #169
Walkthrough
Priority: Merge Risk:
|
|
@coderabbitai full review |
✅ Action performed
|
The lifecycle check runs on every wait renewal by a lifecycle-bound session. Its snapshot read parsed the whole stored payload of every bound thread to reach two fields. It now asks SQLite for just those fields, and
json_validkeeps one malformed row from failing the whole query.This is issue #169's option 1b. It does not change how fresh the check is: it still reads the source and checks the watermark on every call. A thread's state comes from the same fields, and an unreadable row still holds only its own identity.
Evidence
test/lifecycle.test.tscompares each payload shape with the formerJSON.parseresult: missing and null fields, every other JSON type, invalid text, arrays, scalars, BLOBs, escaped keys and surrounding whitespace. 69 tests pass in the file. The invalid-JSON cases also fail if the guard is removed: a barejson_extractwould make one unverified row returnunavailablefor the whole profile.{or[], both revisions returnedreadyand skipped only that unverified thread; after the threads were verified, both returnedunavailableand kept the previous states.Limits
bun) on a private copy, not the release binary and not the live server. The live server was not restarted or attached to.JSON.parse. Every T3-written payload and every row in the real database behaves identically; the real-database check above found no row where the two revisions differ.json_validreturns 0, the guardedSELECTreturns the row with a NULL type instead of raising, and the per-row handling holds only that row when it is unverified. A verified row still fails the profile closed, as any invalid verified row does.JSON.parsefor the four shapes measured 17.7 ms per query against 4.6 ms for this one and 5.4 ms for the old parse, so it is not part of this change.No live install is part of this change.