Skip to content

fix(optimize): strengthen the result-cache fingerprint against collisions - #910

Merged
iamtoruk merged 1 commit into
getagentseal:mainfrom
ozymandiashh:fix/swarm-cache-correctness
Aug 4, 2026
Merged

fix(optimize): strengthen the result-cache fingerprint against collisions#910
iamtoruk merged 1 commit into
getagentseal:mainfrom
ozymandiashh:fix/swarm-cache-correctness

Conversation

@ozymandiashh

Copy link
Copy Markdown
Collaborator

Cache-correctness fix from the systematic audit (find -> verify -> adversarial -> manual confirmation + mutation check).

optimize.ts cacheKey fingerprinted only project count + api-call sum, so two datasets agreeing on those two numbers collided onto one cached OptimizeResult (the second scan received the first's findings), and a cost/token change that left call count unchanged - e.g. a re-price - served stale findings within the 60s TTL. Reachable in the long-lived menubar process. Fold total cost, savings and proxied cost (scaled to micro-dollars so float jitter cannot thrash the key) into the fingerprint.

Mutation-checked: cacheKey is exported and the old key is shown to collide two same-shape datasets and a re-price, while the new key separates both and still keys an identical dataset identically. tsc --noEmit clean, 121 optimize tests green.

…ions

cacheKey fingerprinted only project count + api-call sum, so two datasets
agreeing on those two numbers collided onto one cached OptimizeResult, and
a cost/token change that left call count unchanged (e.g. a re-price) served
stale findings within the 60s TTL - reachable in the long-lived menubar.
Fold total cost, savings and proxied cost (scaled to micro-dollars) into
the key. Exported cacheKey and mutation-checked: the old key collides two
same-shape datasets and a re-price; the new one separates both, while an
identical dataset still keys identically.

@iamtoruk iamtoruk left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed on the merged tree. Correct cache-correctness fix: the old cacheKey fingerprinted only project count + api-call sum, so two materially different datasets sharing those two numbers collided onto one cached OptimizeResult, and a re-price that left call count unchanged served stale findings within the 60s TTL (reachable in the long-lived menubar). The new key folds total cost, savings and proxied cost, each rounded to whole micro-dollars so float jitter cannot thrash the key while a real cost change gets a distinct key. It only ever invalidates more (never serves stale), and an identical dataset still keys identically. Mutation-checked: reverting to the old key fails both the collision and the re-price test, while the identical-dataset test passes either way. tsc clean, optimize suite green. Good to merge.

@iamtoruk
iamtoruk merged commit 22e122f into getagentseal:main Aug 4, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants