Skip to main content
Every answer tells you whether it is current, so you can act only on answers that agree with your records. Its freshness field says whether the answer agrees with everything it read and with the judgment’s active version. A plain column cannot tell you that, since it holds whatever was last written. Brussle judges documents after your writes rather than during them, so while the engine is healthy your answers run a few seconds behind the writes (and each answer shows that delay). Take the settles judgment, which matches payment pay_881 to an open invoice in its block (see entity matching). When you write a new open invoice in the same block, the payment’s answer reads pending, since something it reads changed. It reads fresh once Brussle has judged the payment again.

Freshness states

Brussle works out freshness when you read the answer, from the document, the judgment’s active version and its policy. It checks the states in this order, and the first one that applies wins:
  • stale_reason. A stale answer always gives its cause in stale_reason, and no other answer has one. The API contract also lists block_over_cap, a reserved value that Brussle never reports (a block past its cap reads limit_reached).
  • on_read answers. A get or query that reads an on_read answer that is not current starts the judging, so the answer reads pending, rather than stale or unavailable, until the new answer lands. There are two exceptions. While judging is paused, the read starts nothing, so the answer reads stale (judging_paused) if the document has an older answer and unavailable if it has none. The same holds while the judgment’s own budget is reached, or while its provider has no usable key, with budget_reached or credential_unusable as the reason. While a referenced document that it names does not exist, it reads stale (referenced_missing), because judging it again would change nothing.
  • stale and failed keep their numbers, the last good ones, with the revision they are for. A failed answer for a document that Brussle never judged successfully has none. A text, json or embedding answer keeps its last good value the same way.

pending or unavailable

A document you wrote a moment ago under an on_change judgment reads pending. An unavailable answer means that no first answer is on its way now, for one of these reasons:
  • The policy is on_read, and no get or query has asked for the answer yet.
  • The policy is manual, so only a backfill judges the document.
  • The policy is periodic, so the next run judges the document.
  • Judging is paused, and an on_change judgment judges the document when the pause ends.
  • The document existed before the judgment was created, so it waits for a backfill.

When a failed answer is retried

The next write to a document starts a new attempt, so its answer moves from failed to pending or stale. Brussle does not retry two kinds of document, which keep their failed answer: a document that failed for a cause of its own, and a document that still fails 24 hours after it last changed. Their answer stays failed until you write the document again or a backfill judges it again. See evaluations.

Read only fresh answers, or wait

  • To read only fresh answers, add answers: "fresh_only" to a query.
  • To wait for an answer after a write, add wait_for to the write. An answer that is not ready when the wait ends comes back pending in the write’s response, whatever a get would show for it.
  • To wait for the on_read answers that a get starts, add wait_ms to the get, at most 10,000.

Answers from an older version

When you activate a new version of a judgment, Brussle leaves the existing answers as they are, each with the judgment_version that made it. An answer from a version that judges differently reads stale with stale_reason older_version, so answers: "fresh_only" leaves it out, and old and new answers never mix without a sign.
  • Thresholds alone do not count. A version that differs from the active version only in its thresholds judges in the same way, so its answers stay fresh.
  • A new engine behaviour does not count. On an engine version that is not pinned, such as jev current, the engine’s behaviour can change with no new version of the judgment. That change never makes an answer stale, and it shows only in the answer’s engine_version.
  • What clears it. The answer reads fresh again once Brussle judges the document with the active version, which any of these events does:
    • a backfill of the judgment (confirming a shadow report starts one, at the cost that the report shows, and a backfill that you start yourself shows its cost before it starts);
    • for on_change, a change to the document, or to something that it reads;
    • for on_read, a get or query that reads the answer, including a fresh_only query that leaves the row out;
    • for periodic, the next run that judges the document.
  • The states before it in the order come first. If a new answer is on its way, the answer reads pending, and if the newest attempt failed, it reads failed.
  • Find them with a filter. Queries can filter on answers.settles.judgment_version and on answers.settles.engine_version. See find the answers of one version.

What counts as a change with relations

Each answer of a judgment with relations has a position, its watermark and answers_generation. “The document changed after the answer” means that one of these touched it from outside that position:
  • A write to the document, or to a document that points to it, after the answer’s watermark, whether the pointing document points to it before or after the write. A new payment that points to its customer, for example, makes the customer pending until an answer lands with a watermark at or above the payment’s write.
  • Another judgment’s answer that one of its relations shows, when that answer moved in a way the relation shows, such as across a band. See roll-ups.
  • A write to a candidate in its block, for a blocking relation. A block is the group of documents that share a key value, and its documents are pending until Brussle reads the block again. If nothing they read changed, they are fresh again with no engine call.
  • A change to the document that it points to, inside the re-judge scope. See fan-out.
  • A write to a linked document, for a link.
    • A write to a document that the link’s match reads makes each document that shares its key pending, from the moment Brussle acknowledges the write.
    • Brussle judges the linked document again if the write changed what the link shows, or whether it links, and the other documents are fresh again with no engine call.
    • A linked document can have work waiting for its matching judgment, and the evaluation’s upstream then shows it as child_pending for that judgment.

Deferral and catch-up

Brussle defers a change that would pass one of two limits, and never drops it:
  • The rolling limit. A change whose fan-out would pass the judgment’s rolling limit runs on as many documents as the limit has room for, and the rest waits. A re-judge that another judgment’s answer asked for, or that a posted outcome asked for, also waits when the limit has no room.
  • block_cap. A change to a block that is past block_cap waits as a whole, and so does a link whose block is past the block_cap of its matching judgment.
While a change waits:
  • its answers read stale (limit_reached);
  • in a get’s referenced_changes, the change has deferred: true;
  • the events feed records one judgment.limit_reached event that names the limit;
  • answers: "fresh_only" leaves its answers out.
Work held by the rolling limit runs by itself as older re-judges leave the 30-day window, or within about a minute of a PATCH that raises rolling_limit. Work held by block_cap is different. The 30-day window does not free it, so it waits until a PATCH raises block_cap or you use a finer key.

A fresh answer can have incomplete inputs

A fresh answer agrees with each document it read, at their current revisions, and with the judgment’s active version. That does not mean the engine read everything you intended. Say a moderation judgment reads a post and its policy, and together they pass the judgment’s max_tokens. Brussle cuts the policy, so the engine judges the post without it, and the answer is still fresh (its evaluation records context_truncated: true). Three fields of an evaluation tell you what the engine read:
  • related_documents: each related document that the engine read, with its revision.
  • context_truncated: true when Brussle cut part of the context to fit max_tokens.
  • relations_capped: true when a relation stopped before it considered every matching document.
Inspect one evaluation before you connect a judgment to your workflow, and watch its stats.truncation_rate afterwards. See what is cut first.

Is a judgment caught up?

After you load a batch, you can ask whether an on_change judgment has finished with it in two ways: compare revisions, or query for pending answers.

Compare revisions

Each write returns the revision of each document it wrote. A get of the judgment (GET /namespaces/{ns}/judgments/{name}, ns.judgments.get(name) in both SDKs) returns judged_through, which is also a revision, so you can compare the two:
  • Caught up. When judged_through is at or above the highest revision of your batch, the judgment has finished with the batch and with every write before it. Each document whose answer those writes affect then has its answer, has a failed last attempt, or is one the judgment does not judge (a document outside applies_to, outside the fan-out’s scope of a change to a document it reads, or there before the judgment was created and waiting for a backfill).
  • Not yet. Get the judgment again a few seconds later, since judged_through can trail the answers by a moment, though it never leads them.
  • Paused or limited. A write that waits does not count as judged, so while judging is paused, a change waits for the rolling limit, or the judgment’s own budget is reached, judged_through stays below the writes that wait. Their answers read stale, with judging_paused, limit_reached or budget_reached as the reason.
  • Relations. A write to a document that the judgment reads, such as a referenced document or a candidate in a block, keeps judged_through below it until Brussle has re-judged the documents that read it.
  • Answers of other judgments. When a judgment reads another judgment’s answers, as a roll-up does, a write to a document that the other judgment judges keeps judged_through below it until both of these are true:
    1. The other judgment has finished with the write, and so has each judgment that it reads, if it reads answers too.
    2. Brussle has re-judged each document whose related answers changed.
  • When it is null. judged_through is null when the judgment has no active version or its policy is not on_change. It can also be null for a short time after an upgrade of Brussle, until the judgment has finished with the writes from before the upgrade, so query for pending answers while it is null.
  • The cost. A get of the judgment reads no documents, so it costs much less than a query for pending answers.
  • Imports. The import helpers of both SDKs return the highest revision they wrote, in revision.

Query for pending answers

This query works for every judgment. Ask for one pending answer:
  • No row means caught up. A query is strong by default, so it sees each write that Brussle acknowledged before it. When it returns no row, each of those writes has its answer for the judgment, or no answer is on its way soon (the answer is fresh, failed, unavailable or stale, such as stale with limit_reached or judging_paused while a change waits). The query counts a write that waits as done, however, where judged_through does not.
  • A row means not yet. Query again a few seconds later, and expect a judgment with a debounce_ms to read pending for at least that long after a write.
  • Answers that never came. To also find the documents that have no answer and are not waiting for one, use ["answers.settles.freshness", "In", ["pending", "unavailable"]] (a document that existed before the judgment and waits for a backfill is one example).
  • The cost. A filter on pending reads each document in the namespace, because a document without an answer can match (see tradeoffs). Poll every few seconds rather than in a tight loop.
To wait for the answers of the documents in one write only, use wait_for on the write (read only fresh answers, or wait).

Freshness and subscriptions

A subscription checks a document only when the answers that its filter reads are settled. It waits for the new answer behind a pending answer, or a stale answer with judging_paused, while a failed answer keeps the document’s membership. Every other state, older_version and budget_reached included, is checked as a query reads it, with its stored numbers. A subscription’s filter cannot read freshness for this reason. The answers in an event are usually fresh. If you act only on fresh answers, check freshness in the event. Only settled answers count gives the full rule.

Freshness policies

A judgment’s freshness policy says when Brussle judges its documents. The policy is a setting, so changing it creates no new version. Any policy can also set how long Brussle waits before it judges. Quick writes to one document always combine, so a document that changes twelve times in a second is judged once, on the latest revision.
  • debounce_ms waits until a document stops changing, so many quick writes cost one evaluation. See chatty documents.
  • max_wait_ms judges a document that never stops changing once that long has passed since its oldest change that is not judged. It defaults to 12 × debounce_ms for a judgment with related documents and a debounce_ms above 0. See the ceiling.
  • wait_for_children, on a judgment that reads other judgments’ answers, waits while an answer it reads is pending, then judges once with the new answers. See loads of related documents.
Choosing a freshness policy gives the cost of each policy and every setting’s defaults and bounds.