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. Astaleanswer always gives its cause instale_reason, and no other answer has one. The API contract also listsblock_over_cap, a reserved value that Brussle never reports (a block past its cap readslimit_reached).on_readanswers. A get or query that reads anon_readanswer that is not current starts the judging, so the answer readspending, rather thanstaleorunavailable, until the new answer lands. There are two exceptions. While judging is paused, the read starts nothing, so the answer readsstale(judging_paused) if the document has an older answer andunavailableif it has none. The same holds while the judgment’s own budget is reached, or while its provider has no usable key, withbudget_reachedorcredential_unusableas the reason. While a referenced document that it names does not exist, it readsstale(referenced_missing), because judging it again would change nothing.staleandfailedkeep their numbers, the last good ones, with therevisionthey are for. Afailedanswer for a document that Brussle never judged successfully has none. Atext,jsonorembeddinganswer keeps its last goodvaluethe 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_changejudgment 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_forto the write. An answer that is not ready when the wait ends comes backpendingin the write’s response, whatever a get would show for it. - To wait for the
on_readanswers that a get starts, addwait_msto 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 thejudgment_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
jevcurrent, 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’sengine_version. - What clears it. The answer reads
freshagain 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 afresh_onlyquery 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 readsfailed. - Find them with a filter. Queries can filter on
answers.settles.judgment_versionand onanswers.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, itswatermark 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 customerpendinguntil 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
pendinguntil Brussle reads the block again. If nothing they read changed, they arefreshagain 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
matchreads makes each document that shares its keypending, 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
freshagain with no engine call. - A linked document can have work waiting for its matching judgment, and the evaluation’s
upstreamthen shows it aschild_pendingfor that judgment.
- A write to a document that the link’s
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 pastblock_capwaits as a whole, and so does a link whose block is past theblock_capof its matching judgment.
- its answers read
stale(limit_reached); - in a get’s
referenced_changes, the change hasdeferred: true; - the events feed records one
judgment.limit_reachedevent that names the limit; answers: "fresh_only"leaves its answers out.
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
Afresh 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:truewhen Brussle cut part of the context to fitmax_tokens.relations_capped:truewhen a relation stopped before it considered every matching document.
stats.truncation_rate afterwards. See what is cut first.
Is a judgment caught up?
After you load a batch, you can ask whether anon_change judgment has finished with it in two ways: compare revisions, or query for pending answers.
Compare revisions
Each write returns therevision 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_throughis at or above the highestrevisionof 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 outsideapplies_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_throughcan 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_throughstays below the writes that wait. Their answers readstale, withjudging_paused,limit_reachedorbudget_reachedas 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_throughbelow 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_throughbelow it until both of these are true:- The other judgment has finished with the write, and so has each judgment that it reads, if it reads answers too.
- Brussle has re-judged each document whose related answers changed.
- When it is
null.judged_throughisnullwhen the judgment has no active version or its policy is noton_change. It can also benullfor a short time after an upgrade of Brussle, until the judgment has finished with the writes from before the upgrade, so query forpendinganswers while it isnull. - The cost. A get of the judgment reads no documents, so it costs much less than a query for
pendinganswers. - Imports. The import helpers of both SDKs return the highest
revisionthey wrote, inrevision.
Query for pending answers
This query works for every judgment. Ask for one pending answer:
- No row means caught up. A query is
strongby 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 isfresh,failed,unavailableorstale, such asstalewithlimit_reachedorjudging_pausedwhile a change waits). The query counts a write that waits as done, however, wherejudged_throughdoes not. - A row means not yet. Query again a few seconds later, and expect a judgment with a
debounce_msto readpendingfor 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
pendingreads 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.
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 apending 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_mswaits until a document stops changing, so many quick writes cost one evaluation. See chatty documents.max_wait_msjudges a document that never stops changing once that long has passed since its oldest change that is not judged. It defaults to 12 ×debounce_msfor a judgment with related documents and adebounce_msabove 0. See the ceiling.wait_for_children, on a judgment that reads other judgments’ answers, waits while an answer it reads ispending, then judges once with the new answers. See loads of related documents.