mirror of
https://github.com/morluto/rea.git
synced 2026-11-19 05:02:40 +00:00
refactor(domain): charge seven remaining hand-written allowances through Budget (#11419)
* refactor(domain): charge seven remaining hand-written allowances through Budget Projection work, Kuna run slots, HTTP dispatch slots, marshal object counts, kept deleted environment entities, MCP operation output and route-scan facts and work now charge Budget instead of adjusting a field and comparing it with a limit. The budget-arithmetic baseline drops from 11 to 4; the four left are a scan cursor, a token string and two output tallies that admit then trim, which are not allowances. * fix(process): omit the verifier transport's operation byte limit instead of passing Infinity
This commit is contained in:
1 parent
62d6cfac92
commit
80486e2d34
9 files changed
+78
-64
No files matched your search
@@ -1,4 +1,5 @@
|
||||
import * as t from "@babel/types";
|
||||
import { Budget } from "../budget.js";
|
||||
import { jsonValueByteLength } from "../jsonValueByteLength.js";
|
||||
import type { JsonValue } from "../jsonValue.js";
|
||||
import { JAVASCRIPT_STATIC_FACT_BYTES } from "./javascriptAnalysisResourceControls.js";
|
||||
@@ -275,7 +276,8 @@ export class JavaScriptRouteScan {
|
||||
>();
|
||||
readonly #routeChildren: t.ObjectExpression[] = [];
|
||||
#nextRuntime = false;
|
||||
#factBytes: number;
|
||||
/** Coverage metadata, facts and queued work share one allowance. */
|
||||
readonly #bytes: Budget;
|
||||
#workBytes = 0;
|
||||
|
||||
private constructor(
|
||||
@@ -283,7 +285,7 @@ export class JavaScriptRouteScan {
|
||||
readonly onLegacyRoute?: (fact: LegacyRoute) => void,
|
||||
readonly factByteBudget = JAVASCRIPT_STATIC_FACT_BYTES,
|
||||
) {
|
||||
this.#factBytes = jsonValueByteLength({
|
||||
const metadataBytes = jsonValueByteLength({
|
||||
candidates: [],
|
||||
unresolved: [],
|
||||
capacity: {
|
||||
@@ -293,13 +295,12 @@ export class JavaScriptRouteScan {
|
||||
accounted_work_bytes: factByteBudget,
|
||||
},
|
||||
});
|
||||
if (
|
||||
!Number.isSafeInteger(factByteBudget) ||
|
||||
factByteBudget < this.#factBytes
|
||||
)
|
||||
if (!Number.isSafeInteger(factByteBudget) || factByteBudget < metadataBytes)
|
||||
throw new RangeError(
|
||||
"Route accounting budget must fit its coverage metadata",
|
||||
);
|
||||
this.#bytes = new Budget(factByteBudget);
|
||||
this.#bytes.tryCharge(metadataBytes);
|
||||
}
|
||||
|
||||
/** Establish navigation data ownership before either adapter interprets syntax. */
|
||||
@@ -1673,25 +1674,24 @@ export class JavaScriptRouteScan {
|
||||
}
|
||||
}
|
||||
#remaining(): number {
|
||||
return this.factByteBudget - this.#factBytes - this.#workBytes;
|
||||
return this.#bytes.remaining;
|
||||
}
|
||||
#capacity(): void {
|
||||
this.#result.capacity ??= {
|
||||
kind: "route-work-or-facts",
|
||||
limit_bytes: this.factByteBudget,
|
||||
accounted_fact_bytes: this.#factBytes,
|
||||
accounted_fact_bytes: this.#bytes.used - this.#workBytes,
|
||||
accounted_work_bytes: this.#workBytes,
|
||||
};
|
||||
}
|
||||
#reserve(kind: "fact" | "work", value: JsonValue): boolean {
|
||||
if (this.#result.capacity !== null) return false;
|
||||
const bytes = jsonValueByteLength(value, this.#remaining()) + 1;
|
||||
if (bytes > this.#remaining()) {
|
||||
if (!this.#bytes.tryCharge(bytes)) {
|
||||
this.#capacity();
|
||||
return false;
|
||||
}
|
||||
if (kind === "fact") this.#factBytes += bytes;
|
||||
else this.#workBytes += bytes;
|
||||
if (kind === "work") this.#workBytes += bytes;
|
||||
return true;
|
||||
}
|
||||
#queue(node: t.Node, value: string | null = null): boolean {
|
||||
|
||||
Reference in new issue
Block a user