{"slug": "introducing-tanstack-oracles", "title": "Introducing TanStack Oracles", "summary": "TanStack released an early preview of TanStack Oracles, a framework that lets developers define how software should behave and tests real implementations against those requirements, with coding agents used to find bugs. TanStack creator Kyle Mathews said he tested Oracles on more than 100 repositories, including many of the most-downloaded npm packages, and it found bugs in every one. The framework grew out of work to bring TanStack DB to 1.0 RC1, and Mathews argues verification is becoming the bottleneck as coding agents make implementation cheaper.", "body_md": "# Introducing TanStack Oracles\n\nI'm excited to share an early preview of **TanStack Oracles**, a framework that helps developers define how software should behave and tests real implementations against those requirements. It helps coding agents find bugs, compare implementations with independent models, and improve the checks as you learn more about your code.\n\nOracles grew out of how hard it was to get [TanStack DB to 1.0 RC1](https://tanstack.com/blog/tanstack-db-1.0-rc1-going-all-in-on-oracles). I needed better ways to find bugs and preserve the behavior I wanted as the implementation changed.\n\nThe challenge extends beyond DB. We want TanStack's libraries to be as correct, capable, and sophisticated as possible. Better verification lets us pursue designs and optimizations that previously cost too much to implement and validate.\n\n**I've now tested Oracles on more than 100 repositories—including [many of the most-downloaded](https://github.com/isaacs/node-lru-cache/issues/427) [packages on npm](https://github.com/immerjs/immer/issues/1367)—and it found bugs in every one.** It's especially fun to run it against [old projects I wrote by hand](https://github.com/KyleAMathews/react-headroom/pull/215) and see the [absurd number of bugs it digs up](https://github.com/KyleAMathews/react-spinkit/pull/103).\n\n## Try it in your repository[#](#try-it-in-your-repository)\n\nBefore reading further, open a coding agent in a project you know well and paste in the [prompt below](https://github.com/TanStack/oracles/blob/main/packages/oracles/README.md). See what bugs Oracles can find—and what it feels like to approach your code differently: start with a behavior the software should preserve, then see whether your agent can find a case where the implementation breaks it.\n\n```\nShow me what oracle testing with @tanstack/oracles can find in this repository.\n\nDownload https://raw.githubusercontent.com/TanStack/oracles/main/packages/oracles/skills/oracles-explore/SKILL.md\n\nRead it in full and follow it to explore this repository with Oracles.\n```\n\nYour agent will read your code, documentation, and tests, exercise the code, and help you choose one behavior to check. You'll work out what should happen, then compare that expectation with what the code does. If the intended behavior is unclear, the agent asks you to clarify.\n\nSometimes this exploration finds a problem before the oracle exists. The oracle then reproduces it and checks the broader behavior you want to preserve. You can turn a finding into a fix and a regression test in your existing suite, or keep the oracle and expand it as it proves useful.\n\nYou can leave the agent exploring while you read on.\n\n## The verification problem[#](#the-verification-problem)\n\nAs coding agents get better, we're running into a new problem: they can produce far more code than we can comfortably review. PRs pile up. How do we know these changes are correct? How do we know they actually do what we wanted? We can't keep scaling line-by-line human review to match what agents can generate.\n\nThe economics of programming are changing. Writing implementations used to consume a huge share of our engineering effort. We invested in tests and review, of course, but implementation itself was expensive. Agents are making it dramatically cheaper. **Verification is becoming the bottleneck.**\n\nSince publishing [my post about using Oracles to harden TanStack DB](https://tanstack.com/blog/tanstack-db-1.0-rc1-going-all-in-on-oracles), I've heard from lots of people exploring how to improve verification. [Anthropic has been using agents to formally verify properties of real software](https://www.anthropic.com/research/formal-verification), and [Microsoft Research is exploring formal verification of agent-written applications](https://www.microsoft.com/en-us/research/blog/formally-verifying-agent-written-full-stack-web-apps-with-pdd-kit/). There are different approaches, but we're increasingly running into the same question:\n\n**How do we turn human judgment about what software should do into something agents can act on and tools can enforce?**\n\nGetting this right could automate much of the behavioral correctness work in code review. Agents could work more independently, leaving us more time for deciding what software should do, exploring designs, and making tradeoffs.\n\nI think figuring all of this out will be a multi-year effort across the industry. But the starting point can be remarkably simple: one rule about how software should behave, and a way to test it.\n\n## A simple rule exposes a real bug[#](#a-simple-rule-exposes-a-real-bug)\n\nHere's a bug from Headroom, my scrolling-header library. With its default settings, the rule was simple: **the wrapper must track the header's height, even as its contents change.** In Oracles, I record a rule like this as a **law**: a statement of expected behavior independent of how the code works.\n\nTo test this rule, Oracles generated sequences of changes to the header, varying its content and size, and checked the layout after each change. One sequence exposed a bug in an earlier version of Headroom: when the header grew, its wrapper still reserved space for the old height. The header covered the content below it. The fix was to keep the reserved space in sync with the header's actual height.\n\nThat's the basic idea behind Oracles. It combines property-based testing, model-based testing, fuzzing, and mutation testing into a framework that agents can use to discover and enforce behavioral requirements. Rather than writing out every example and its expected answer, I can describe the behavior I want and let the framework explore sequences I wouldn't have thought to test individually.\n\nA layout rule like Headroom's can be checked directly: measure the header and compare it with the space its wrapper reserves. But what if determining the correct result requires calculating the effects of many interacting changes?\n\n## One history, two answers[#](#one-history-two-answers)\n\nConsider a task list backed by TanStack DB. Complete a task, and it disappears from the list of open tasks. Reopen it, and it comes back.\n\nEasy enough.\n\nNow imagine displaying only the ten highest-priority open tasks, updating the list as tasks are added, completed, deleted, and reprioritized. Tasks with equal priority appear in ID order. TanStack DB maintains live queries incrementally, so it has to keep that result correct without filtering and sorting every task from scratch after each change.\n\nSuppose I add tasks A, B, and C, then complete C. C should disappear. But imagine the incremental implementation accidentally keeps it in the result.\n\nI could write a test for that exact sequence. But what about a tie at the tenth slot? A task that drops out of the list and returns? A batch that deletes one task and changes another's priority? There are far more sequences than I can write tests for individually.\n\nInstead, I can write a small model that calculates expected answers for sequences I never thought to test individually.\n\nThe model keeps task records in a plain JavaScript Map. After applying each batch of changes, it filters out completed tasks, sorts the rest by priority and ID, and takes the first ten:\n\n```\nfunction expectedTopTasks(tasks: Iterable<Task>) {\n  return [...tasks]\n    .filter(task => !task.completed)\n    .sort((a, b) =>\n      b.priority - a.priority ||\n      (a.id < b.id ? -1 : a.id > b.id ? 1 : 0)\n    )\n    .slice(0, 10)\n    .map(task => task.id)\n}\n```\n\nLet's give those three tasks priorities: A gets 2, B gets 1, and C gets 3. The model calculates [C, A, B].\n\nComplete C, and it expects [A, B].\n\nNow reopen C and raise B's priority to 4 in the same batch. The model expects [B, C, A].\n\nI didn't have to write down the expected answer for each combination of edits. The model calculates it as the changes happen.\n\nOracles runs the same sequence against the real TanStack DB query and compares the results after each batch. If production still includes C after completing it, the disagreement shows up immediately—even if a later change makes the final result correct.\n\n**One history. Two answers.**\n\nAnd the two answers are calculated very differently. Production might maintain sophisticated indexes, caches, and incremental algorithms to make the query fast. The model just recomputes everything from its Map. That independence matters: if the model reused production's query-maintenance code, it might reproduce the same bug. It's a design requirement the agent and I have to review, not something the framework can guarantee automatically.\n\nBut which answer is right?\n\nNeither is automatically authoritative. The law records the behavior I've decided the software should have, and both the model and production need to honor it.\n\nWhen they disagree, that difference gives the agent a precise clue about what to investigate. It can replay the history, trace how each side arrived at its answer, and work out what needs to change to reconcile them with the law. If the law itself doesn't settle the question, the agent asks me to make the design decision.\n\nIn Oracles, a sequence of actions like this is called a *history*. A **driver** executes those actions against production and records what happens. A **check** compares the observations with the answers calculated by the model.\n\nThe framework brings these pieces together through oracleProperty:\n\n```\noracleProperty({\n  id: 'top-open-tasks',\n  law: topTasksLaw,\n  histories: taskHistories,\n  model: expectedTaskResults,\n  driver: driveTaskQuery,\n  check: checkTaskResults,\n})\n```\n\nThe **law** is a concrete record, not a special language. Here, topTasksLaw would contain a plain-English statement (return the ten highest-priority open tasks, breaking ties by ID), an authority (the decision or contract that established it), and limits (what this oracle doesn't claim to verify). The framework connects that law to histories, a model, a production driver, and a comparison that an agent can run, replay, and strengthen.\n\nWhen a generated history fails, Oracles can also **shrink** it to a much smaller reproduction while preserving the disagreement.\n\nFor our illustrative bug, a long sequence of changes might reduce to just two actions: add C, then complete C.\n\nExpected: []. Actual: [C].\n\nThe agent now has a short history to replay, the specific law it violated, and a precise disagreement to investigate.\n\nBut this only works if the oracle can recognize when production is wrong. One of my TanStack DB oracles taught me how easily that can fail.\n\n## What if the oracle itself is wrong?[#](#what-if-the-oracle-itself-is-wrong)\n\nDuring a review, another agent spotted a problem in one of my TanStack DB oracles. My test subscriber was accepting updates that should have been impossible.\n\nTanStack DB sends insert, update, and delete messages to subscribers, which use those messages to maintain their own copy of the data. An **insert** adds a row the subscriber doesn't have. An **update** changes a row it already has.\n\nBut my test subscriber used Map.set for both. That meant an update to a nonexistent row would silently create it. The final data could look correct even though the sequence of messages was invalid.\n\n**And production was sending invalid updates.**\n\nThe bug was buried in the interaction between optimistic mutations and synchronization. In certain sequences, a row disappeared from the subscriber's view, often following an optimistic delete. When a later sync made that key visible again, the state manager sometimes emitted an update because it remembered a completed optimistic request.\n\nBut the subscriber had already removed the row. There was nothing to update. Production should have sent an insert.\n\nThe state machine was complicated. The rule it violated was tiny: **every update must refer to a row the subscriber already has.**\n\nI [strengthened the checker](https://github.com/TanStack/db/commit/721a607e82e7d4c906e2ae1e23833842753be810) to enforce that rule, rejecting updates for missing rows and inserts for existing ones.\n\nAnd here's the surprising result: **without generating a single new history, 26 of the existing 378 cases started failing.**\n\nThose histories had already exercised the production bug. The original checker just couldn't recognize it. Once I fixed the checker, the existing histories immediately exposed the invalid messages. [Fixing production](https://github.com/TanStack/db/commit/182b992622cfdf65788af15a29c33442f224af5f) then made the cases pass again.\n\nThat changed the question I ask whenever a bug gets through. Why did production get this wrong? And why didn't the oracle catch it?\n\n**The second question is often much more interesting than the first.** Fixing production addresses one bug. Understanding why the oracle missed it can uncover a whole class of bugs that the existing checks were incapable of detecting.\n\n## Testing the oracle[#](#testing-the-oracle)\n\nThe subscriber bug left me with two questions for any passing oracle: Did it reach the situations where bugs might hide? And if it did, would the checker recognize something wrong?\n\n**First, did it reach the right situation?**\n\nOur task query combines a ten-item limit with a tie-breaking rule. That suggests an interesting boundary: what happens when two tasks compete for the tenth slot?\n\nAn agent can add a **constructed history** that starts with nine higher-priority tasks, then adds B and A with equal priority. A should take the final slot because its ID comes first. Complete A, and B should enter. Reopen A, and A should return.\n\nThe model still calculates the expected results. I don't have to write those answers by hand. A reach check can also use production observations to confirm that execution actually entered the intended situation, rather than merely trusting the input history.\n\nSometimes the law itself suggests where to look. Other times it's accumulated experience: bugs keep surfacing in one area, a subsystem is notoriously tricky, or a reviewing agent discovers a bug the oracle missed.\n\nConstructed histories capture that judgment. I want Oracles to guide agents through these decisions as part of the framework: which situations matter, why they matter, and how to reach them.\n\n**Second, would the checker notice a wrong answer?**\n\nFor that I can add a **calibration**. Take an existing passing history where two equal-priority tasks both fit in the result, so the model expects [A, B]. I tell Oracles to feed the checker [B, A] instead.\n\nThat deliberately wrong observation is called a *corruption*. I'm not changing production code. I'm checking whether the oracle would recognize this particular mistake.\n\nOracles handles the execution: it runs the original history, substitutes the wrong answer, and requires the ordering law to reject it. If the change doesn't take effect, the wrong law fires, or the test crashes for an unrelated reason, the calibration fails.\n\nThat's useful, but someone still had to think of reversing the order. I want Oracles to guide agents toward useful calibrations, helping them decide which mistakes to simulate and which law should catch them.\n\n**What if I want to challenge the whole oracle?**\n\nOracles already does this automatically through its oracle-gaps CLI. It makes small changes to copies of the production code an oracle owns, runs the oracle against each variant, and reports changes that no law rejects. This is **gap investigation**. For our task query, a generated change to the ID tie-breaker tests whether the oracle notices tasks returning in the wrong order.\n\nEach reported gap comes with instructions for the agent to investigate why it went undetected. Did the histories miss the relevant situation? Did the driver fail to observe the consequences? Was the model or checker too weak? Or does the change preserve behavior the law already allows?\n\n**I don't allow enforcement gaps to be waived.** A surviving mutant might be a valid alternative implementation, but the agent has to establish that rather than dismissing it as harmless. Otherwise agents are remarkably good at finding reasons to excuse a failing check instead of fixing it.\n\nAll of these techniques point toward something bigger.\n\n**The ideal oracle isn't a static collection of carefully designed tests. It's a system that actively searches for reasons not to trust itself.**\n\nThat skepticism applies at two levels. Formal methods can help challenge the model itself, exploring its possible behaviors, finding counterexamples, and proving properties it should satisfy. Generated histories, calibrations, and production mutations challenge whether the implementation follows the model—and whether the checks can recognize violations.\n\nI want agents continuously searching for weaknesses in both. Every discovery should improve the model or its enforcement, leaving the next agent with a stronger oracle than the previous one had.\n\n## What changes when Oracles is in your codebase?[#](#what-changes-when-oracles-is-in-your-codebase)\n\nSoftware accumulates thousands of design decisions. Why does this query break ties by ID? What happens when two optimistic updates overlap? When is a transaction allowed to become visible?\n\nSome answers are documented. Others live in PR discussions or are buried in the implementation. Now imagine a coding agent arriving a month later to optimize a query. How is it supposed to know which decisions matter?\n\nI can write long architectural documents and instructions, but an agent still has to know when to read them and which details apply to its task.\n\n**With Oracles, the decisions I've captured become executable.**\n\nSuppose an agent optimizes the task query and accidentally changes how equal-priority tasks are ordered. The oracle fails, identifies the exact history and the law it violated, and points back to the reason for the decision: break ties by ID so the same tasks always appear in the same order, regardless of which arrived first.\n\nThe agent doesn't have to search through an architectural document hoping to discover that ordering matters. The relevant decision surfaces because the agent's change violated it. **It's a form of memory that becomes relevant when the code runs afoul of it.**\n\nAnd this memory can improve with every change. When an agent finds a bug the oracle missed, I ask it to investigate why. Maybe the model omitted an important case; maybe the history generator missed an interaction; maybe the checker ignored something that mattered. The fix to the oracle becomes part of what the next agent inherits.\n\nI think of these as two connected loops. The **design loop** makes and revises decisions about what software should do, informed by bugs, feature requests, and experience using it. The **enforcement loop** checks whether production follows those decisions and whether the checking machinery is capable of detecting violations.\n\nEvery resolved bug, feature request, and design decision can make that memory more precise. The next agent inherits not just more instructions, but more of the project's accumulated judgment—and a way to check its work against that judgment.\n\nAnd as more of that judgment becomes explicit and enforceable, **the implementation itself starts to become replaceable.**\n\n## What could we build with this?[#](#what-could-we-build-with-this)\n\nThat's led me to think of an agent implementing against an oracle as a kind of compiler. The laws and model describe the behavior I want; the agent turns them into code and uses the oracle to check its work.\n\nIn pursuit of making that analogy more literal, I'd love to explore Oracles growing into an **agent-powered optimizing compiler**, progressively lowering high-level specifications into concrete plans and code while agents experiment with different implementations against the same laws.\n\nThere's a lot to explore here, from using formal methods like Lean and TLA+ to strengthen models, to stronger verification, to finding implementations that are faster, smaller, or use less memory.\n\nBut I don't think any one team is going to discover the best approaches to all of this.\n\n**I want Oracles to win by making the best tools work together.**\n\nLLVM is a useful model: shared compiler infrastructure that many programming languages build on and benefit from improving. I'd like Oracles to become similarly modular, with great defaults but room to plug in the best models, generators, verification techniques, and agent strategies wherever they come from.\n\nI'm also building shared evaluation infrastructure to compare approaches against real repositories. Which strategies find more bugs, faster and at lower cost? By pooling our efforts, improvements to one part of the framework can benefit everyone using it.\n\nIn 2027, I'll be working with the [Protocol Institute](https://protocol-institute.org/) on a broader **Future of Programming** research effort. We'll bring people together to explore these questions, run experiments, and turn promising discoveries into tools people can use.\n\nMy employer, Databricks, is sponsoring both my time on this work and the research group directly.\n\nIf you tried the prompt at the beginning, take a look at what your agent found. Did it find a bug? And perhaps more interestingly, what might its oracle still be missing?\n\nI've had enormous fun exploring these questions, and I think we're just scratching the surface.\n\nIf you'd like to join the exploration or simply follow along, [sign up for the Future of Programming research list](https://forms.gle/XGeS4rtwnn3QX5av9). I'll share what we're learning and opportunities to get involved. There's also space to tell me what you're working on—I'd love to find people to collaborate with as the research takes shape.", "url": "https://wpnews.pro/news/introducing-tanstack-oracles", "canonical_source": "https://tanstack.com/blog/introducing-tanstack-oracles", "published_at": "2026-12-03 12:00:00+00:00", "updated_at": "2026-12-03 19:45:57.433906+00:00", "lang": "en", "topics": ["ai-agents", "ai-tools", "developer-tools", "artificial-intelligence"], "entities": ["TanStack", "TanStack Oracles", "TanStack DB", "Kyle Mathews", "npm", "Anthropic", "Microsoft Research"], "also_reported_by": [], "takeaway": "TanStack Oracles lets a coding agent read a repository, pick one behavior to preserve, and check the implementation against it; Mathews reports it found bugs in all of more than 100 repositories tested.", "recommendation": null, "alternates": {"html": "https://wpnews.pro/news/introducing-tanstack-oracles", "markdown": "https://wpnews.pro/news/introducing-tanstack-oracles.md", "text": "https://wpnews.pro/news/introducing-tanstack-oracles.txt", "jsonld": "https://wpnews.pro/news/introducing-tanstack-oracles.jsonld"}}