Repository navigation
Split the worker-call progress count by cache hits - #1036
Merged
Merged
Conversation
Red for dirsql#1034. A worker may flag a response it served from its own cache; the summary must report those separately so a slow first run tells the user the second one will be cheap. skip-changelog: red tests only, no observable change yet
A raw round-trip count reads identically whether every call ran a model or
every call was a dictionary lookup, so it cannot answer the question a user
watching a slow first build is actually asking. Core cannot derive the split
-- a cache hit IS a round trip -- so the worker reports it, through an
optional `{"meta": {"cached": true}}` alongside `ok`.
The field is generic on purpose: any [[dirsql.function]] may set it and core
stays ignorant of what a given worker caches. It is advisory, so an absent or
unrecognized shape reads as "not cached" rather than failing a query over a
progress counter, and a worker that flags nothing gets exactly the line it
got before -- no `(0 cached)`.
Refs #1034
8 tasks done
The local testing-conventions CLI (0.0.85) prunes stale receipts as a side effect of `e2e attest` and commits the deletions with the one it adds. The e2e-verify gate is diff-based -- it only checks that a branch adds its own receipt -- so 28 unrelated deletions passed CI unnoticed. Prior attestation commits on main are add-only. Restored verbatim from origin/main; this branch's own two receipts stay.
Red for dirsql#1034. cachetta's wrapper returns a hit and a miss identically, so the worker cannot currently tell dirsql which answers cost nothing. skip-changelog: red tests only, no observable change yet
cachetta's wrapper returns a hit and a miss identically, so the only place
a miss is observable is the wrapped compute itself: it runs on a miss and
never on a hit. embed() clears a flag, calls through, and reads the flag
back, then the response carries `"meta": {"cached": <bool>}` for the
progress line to split.
Existing assertions that compared a whole response object now compare
`response["ok"]`; the meta key has its own tests.
Refs #1034
…-flag Report cache hits from the embeddings worker (plugin)
thekevinscott
enabled auto-merge
September 4, 2026 23:23
8 tasks done
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Both layers of #1034. This PR opened as layer 1 of a two-PR stack (core only), and the stack collapsed into it: layer 2 (#1038, the embeddings plugin) was merged into this branch, not into
main. So the diff below carries the core change and the plugin change, and this PR alone closes the issue.Fixes #1034
Layer 1 — core (this branch's own commits)
What
A worker may now flag a response it served from a cache of its own:
{"ok": [0.1, 0.2], "meta": {"cached": true}}and dirsql splits those out of the worker-call progress line:
Why the field is on the worker, and why it is generic
Core counts round trips, and a cache hit is a round trip — the worker is asked and answers from disk. Core cannot see the difference, so the worker has to say. The flag is deliberately not embedding-shaped: any
[[dirsql.function]]may set it, which keeps #1002's property that core knows nothing about what its workers do.metais advisory. It feeds a progress counter and nothing else, so an absent field, a non-objectmeta, or a non-booleancachedall read as "not cached" rather than failing a query. A worker that flags nothing gets exactly the line it got before — there is no(0 cached).Wire compatibility
parse_responsehas always readerr, elseok, and ignored every other key, so an existing worker is unaffected byte-for-byte. The break is in the documented contract, which enumerated the response shape exhaustively in two places that moved together here:docs/reference/config.md's "Worker protocol" and the## Protocolblock inpackages/rust/src/functions.rs.Precision note (documented)
docs/reference/cli.mdnow says in one sentence that both figures count worker round trips, not rows: adeterministic = truefunction lets SQLite reuse an answer for identical arguments within a query, so repeated content never reaches the worker and both numbers sit below the row count on a corpus with duplicates.Design note: where the count is taken
record()still fires before the call, so a slow worker's first round trip still puts a line on screen while it is in flight — that is the whole point of #1002's counter. Cachedness is only knowable once the response is in hand, so it is a second, separatemark_cached()after the call returns. The total count is therefore unchanged, including for calls that fail.Red/green
93e7870, Rust CI run 33920999219 — theIntegration testsjob,tests/worker_call_progress_e2e.rs:the_summary_splits_out_the_calls_the_worker_served_from_cacheandthe_summary_counts_only_the_flagged_calls_as_cachedboth FAILED, on the asserted strings (and names how many of them cost nothing: "…dirsql: ran 4 worker calls in 0.0s\n"). 7 passed, 2 failed — nothing else in the workspace broke, no compile error.97fdc1dcarries the implementation, the unit tests, the docs and the fragments.The red is at the e2e tier by necessity: the new behavior is a line on the CLI's stderr, which the Rust SDK integration tier cannot observe. The integration tier (
packages/rust/tests/functions.rs) carries the two guards it can assert — that ameta-carrying response binds only itsokvalue, and that an unrecognizedmetashape does not fail the query.Manual verification
A worker that caches by value, called twice per row over three files (the function is not
deterministic, so SQLite makes all six calls):Six round trips, three of them the worker's second sighting of a value, reported as
(3 cached). stdout is untouched JSON.Layer 2 — embeddings plugin (merged in from #1038)
#1038 was reviewed and merged on 2026-09-04 with
base: claude/tackle-1034-cachesplit, so its three commits (fc85500,f4ee741,6da2c8f) are ancestors of this branch's head and appear in this PR's diff againstmain. Its own description is preserved on #1038; the essentials:The problem
cachetta'swrap()returns a hit and a miss identically — same value, no signal — soWorker.embedhad no way to say which it got. Without it, layer 1's parenthetical never appears for the one worker in this repo that actually caches.The fix
The wrapped function is the signal.
_computeruns on a miss and never on a hit, so it sets a sentinel;embedclears the sentinel, calls through the cache, and reads it back:The response then carries the flag layer 1's protocol defines:
{"ok": [0.12, ...], "meta": {"cached": true}}.handlegained an_embed_responseextraction so it stays under the 24-lineone-function-per-fileratchet (21 lines now).{"ok": null}for a NULL value is unchanged — nothing is computed, so there is no cache state to report.Several existing tests compared a whole response object (
== {"ok": [1.0, 0.0]}) where the point was the vector. Those now compareresponse["ok"]; themetakey is asserted in its owndescribe_cache_reportingblocks rather than incidentally in every protocol test.Red/green
RED on the plugin layer: run 33922087464,
dirsql-plugin-embeddings integration tests (3.12)and(3.13)—assert response["meta"] == {"cached": False}→KeyError: 'meta',1 failed, 8 passed. GREEN inf4ee741.Manual verification
Worker directly, repeated value, real model2vec and real cachetta:
End to end through the real CLI over a four-file corpus, cold then warm against the same
XDG_CACHE_HOME:Identical rows, 3.3s versus 0.3s, and the line now says why.
E2E Verification
Covers both layers. Layer 1's suites were run on this branch; layer 2's on
claude/tackle-1034-plugin-flagbefore it merged in.cargo test --features cli --tests, whole workspace green;worker_call_progress_e2e9 passed)plugins/dirsql-plugin-embeddings) e2e: pass (17 passed; integration 49 passed)packages/python/e2e-attestations/<branch>.jsonreceipt written ifpackages/pythonchanged (just e2e-attest-python)packages/ts/e2e-attestations/<branch>.jsonreceipt written ifpackages/tschanged (just e2e-attest-ts)cargo test --manifest-path packages/rust/Cargo.toml --features cli --lib,… --tests,just e2e-attest-python,just e2e-attest-ts,just preflight; plugin:uv run --with-editable ../../packages/python python -m pytest tests/e2e/ -x -qviatesting-conventions e2e attestjust preflightreports 0 failing pairs, 3 skipped;unit mutationon rust tested 27 mutants with no survivors, on the plugin 5 with no survivors.Three receipts ride in the diff, one per package whose scoped source the combined change touches — a
packages/rust/srcchange puts both bindings in scope via[e2e].extra_scope, and the plugin change puts the plugin in scope:Changelog / Migrations
<root>/<pkg>/changelog.d/for each changed package —packages/rust/changelog.d/2026-09-04-worker-call-cache-split.mdandplugins/dirsql-plugin-embeddings/changelog.d/2026-09-04-report-cache-hits.md<root>/<pkg>/migrations.d/—packages/rust/migrations.d/2026-09-04-worker-call-cache-split.mdandplugins/dirsql-plugin-embeddings/migrations.d/2026-09-04-report-cache-hits.mdMigration-fragment decision: yes, written, for both packages. Nothing here is breaking, and both "Required changes" sections say so explicitly (
_None._). They are written anyway because two of AGENTS.md's triggers fire: the worker response shape is documented public contract, and the summary line's format changes at runtime with no API change. #1002 set the precedent by shipping one for a purely additive progress line. The core fragment's value is its "Behavior changes without code changes" section — a worker that already emitted a top-levelmetafor its own reasons now hasmeta.cachedread by dirsql. The plugin fragment covers the mirror case: anokline that read{"ok": [1.0, 0.0]}now reads{"ok": [1.0, 0.0], "meta": {"cached": false}}, which matters only to a third party doing exact-equality on the whole object.Parity
PARITY.mdupdated. No drift. The flag is part of the worker protocol, not any SDK's API surface — no SDK gained or lost a symbol, and both the parsing and the line live in the shared core, so all three SDKs change in this commit. The plugin exports no Python API (__init__.pyis empty) and adds nothing to any SDK surface.