mirror of
https://github.com/morluto/rea.git
synced 2026-11-16 11:43:20 +00:00
refactor(javascript): charge the worker's retained result bytes through an over-committing Budget (#11399)
* refactor(javascript): charge the worker's retained result bytes through an over-committing Budget Static checkpoints may retain past the result budget up to the static capacity, and the worker reports that exhaustion itself. Budget.chargeOverCommitting records the excess (overCommitted) and reports no remainder until refunds bring use back under the maximum. The budget-arithmetic baseline is now empty. * refactor(domain): charge hand-written allowances through Budget and count limit-checked fields (#11405) * refactor(domain): charge hand-written allowances through Budget and count limit-checked fields Pyc report and key-walk tallies, reverse-engineering capture admission, Playwright trace fact retention and semantic alias selections now charge a Budget. The budget-arithmetic guard also counts a field outside Budget classes that is adjusted by hand and compared with a limit-named value; the eleven remaining sites are a counted baseline. * fix(verify): scope limit-checked fields to their class and match limit names in any case
This commit is contained in:
1 parent
d1034867ff
commit
28332d43ca
10 files changed
+269
-96
No files matched your search
@@ -15,6 +15,7 @@ import {
|
||||
} from "../../providers/OwnedCommandCleanup.js";
|
||||
import { analysisErrorWithCancellation } from "../../domain/analysisErrorCancellation.js";
|
||||
import { safeParseUtf8Json } from "../../domain/safeJson.js";
|
||||
import { Budget } from "../../domain/budget.js";
|
||||
import { analysisSettingLimit } from "../../domain/analysisSettingDefinitions.js";
|
||||
import { WorkerFrameSignal } from "../../process/WorkerFrameSignal.js";
|
||||
import type {
|
||||
@@ -146,7 +147,6 @@ export class JavaScriptAnalysisWorker {
|
||||
#terminalResponseId: string | undefined;
|
||||
#phase = "startup";
|
||||
#lastFailure: AnalysisError | undefined;
|
||||
#estimatedRetainedBytes = 0;
|
||||
#staticProjectionReservations: {
|
||||
sourceIndex: number;
|
||||
path: string;
|
||||
@@ -158,7 +158,12 @@ export class JavaScriptAnalysisWorker {
|
||||
#parentCapacityExhaustion: Readonly<Record<string, number>> | undefined;
|
||||
#sourcesRemaining: number | undefined;
|
||||
#deadline: ProviderStartupDeadline | undefined;
|
||||
#resultBudgetBytes = 0;
|
||||
/**
|
||||
* Estimated retained result bytes against the result budget. Static
|
||||
* checkpoints may over-commit it up to the static capacity; the worker
|
||||
* reports that exhaustion itself rather than refusing the checkpoint.
|
||||
*/
|
||||
#retained = new Budget(0);
|
||||
#staticCapacityBytes = 0;
|
||||
/** Null when the runtime enforces the V8 heap flags instead. */
|
||||
readonly #processMemoryLimitBytes: number | null;
|
||||
@@ -278,7 +283,6 @@ export class JavaScriptAnalysisWorker {
|
||||
"JavaScript worker source count must be a nonnegative safe integer",
|
||||
);
|
||||
this.#sourcesRemaining = sourceCount;
|
||||
this.#estimatedRetainedBytes = 0;
|
||||
this.#staticProjectionReservations = [];
|
||||
this.#revokedStaticProjections = [];
|
||||
this.#nextSourceIndex = 0;
|
||||
@@ -308,7 +312,7 @@ export class JavaScriptAnalysisWorker {
|
||||
this.#remainingParentHeapBytes() -
|
||||
24 * JAVASCRIPT_ANALYSIS_TRANSFER_RECORD_BYTES,
|
||||
);
|
||||
this.#resultBudgetBytes = Math.floor(capacity / 2);
|
||||
this.#retained = new Budget(Math.floor(capacity / 2));
|
||||
this.#staticCapacityBytes = Math.floor(capacity * STATIC_CAPACITY_SHARE);
|
||||
}
|
||||
|
||||
@@ -515,7 +519,7 @@ export class JavaScriptAnalysisWorker {
|
||||
`Completed module facts for ${file.path} exceed the parent's remaining result budget; static facts were retained`,
|
||||
{
|
||||
...this.#limits(),
|
||||
parent_result_budget_bytes: this.#resultBudgetBytes,
|
||||
parent_result_budget_bytes: this.#retained.maximum,
|
||||
parent_available_result_budget_bytes: remaining,
|
||||
module_transfer_bytes: descriptor.module_bytes,
|
||||
module_retention_estimate_bytes: moduleEstimate,
|
||||
@@ -538,8 +542,9 @@ export class JavaScriptAnalysisWorker {
|
||||
);
|
||||
module = decoded.module;
|
||||
projection = decoded.projection;
|
||||
this.#estimatedRetainedBytes +=
|
||||
moduleEstimate + (retainGraph ? graphEstimate : 0);
|
||||
this.#retained.chargeOverCommitting(
|
||||
moduleEstimate + (retainGraph ? graphEstimate : 0),
|
||||
);
|
||||
result = retainGraph
|
||||
? ok({ javascript, module, projection: decoded.projection })
|
||||
: err({
|
||||
@@ -552,7 +557,7 @@ export class JavaScriptAnalysisWorker {
|
||||
`Semantic graph for ${file.path} exceeds the parent's remaining result budget; static and module facts were retained`,
|
||||
{
|
||||
...this.#limits(),
|
||||
parent_result_budget_bytes: this.#resultBudgetBytes,
|
||||
parent_result_budget_bytes: this.#retained.maximum,
|
||||
parent_available_result_budget_bytes: remaining,
|
||||
module_retention_estimate_bytes: moduleEstimate,
|
||||
graph_retention_estimate_bytes: graphEstimate,
|
||||
@@ -885,9 +890,8 @@ export class JavaScriptAnalysisWorker {
|
||||
const staticCeiling =
|
||||
retainedBytes + used_heap_size <= liveAvailable
|
||||
? this.#staticCapacityBytes
|
||||
: this.#resultBudgetBytes;
|
||||
const needed =
|
||||
retainedBytes - (staticCeiling - this.#estimatedRetainedBytes);
|
||||
: this.#retained.maximum;
|
||||
const needed = retainedBytes - (staticCeiling - this.#retained.used);
|
||||
if (needed > 0 && retainedBytes <= liveAvailable) {
|
||||
// Plan all revocations first so an insufficient set leaves the earlier
|
||||
// relationships intact rather than sacrificing them for a failed read.
|
||||
@@ -900,14 +904,14 @@ export class JavaScriptAnalysisWorker {
|
||||
if (reclaimable >= needed) {
|
||||
const revoked = this.#staticProjectionReservations.splice(start);
|
||||
for (const reservation of revoked) {
|
||||
this.#estimatedRetainedBytes -= reservation.bytes;
|
||||
this.#retained.refund(reservation.bytes);
|
||||
this.#revokedStaticProjections.push({
|
||||
sourceIndex: reservation.sourceIndex,
|
||||
error: new AnalysisResourceConstraintError(
|
||||
OPERATION,
|
||||
"memory",
|
||||
`Expanded application relationships for ${reservation.path} were omitted to retain static facts for later sources`,
|
||||
{ parent_result_budget_bytes: this.#resultBudgetBytes },
|
||||
{ parent_result_budget_bytes: this.#retained.maximum },
|
||||
{
|
||||
remediationAction: `Read the retained static facts or analyze fewer source files. ${JAVASCRIPT_PARENT_RESULT_BUDGET_REMEDIATION}`,
|
||||
},
|
||||
@@ -920,7 +924,7 @@ export class JavaScriptAnalysisWorker {
|
||||
// admission so a second read cannot reject after revocations commit.
|
||||
const remaining = Math.max(
|
||||
0,
|
||||
Math.min(staticCeiling - this.#estimatedRetainedBytes, liveAvailable),
|
||||
Math.min(staticCeiling - this.#retained.used, liveAvailable),
|
||||
);
|
||||
this.#parentCapacityExhaustion =
|
||||
retainedBytes > remaining
|
||||
@@ -931,7 +935,7 @@ export class JavaScriptAnalysisWorker {
|
||||
static_retention_estimate_bytes: retainedBytes,
|
||||
}
|
||||
: undefined;
|
||||
this.#estimatedRetainedBytes += retainedBytes;
|
||||
this.#retained.chargeOverCommitting(retainedBytes);
|
||||
const expandedBytes = estimateJavaScriptStaticApplicationProjection(
|
||||
facts,
|
||||
bytes,
|
||||
@@ -939,7 +943,7 @@ export class JavaScriptAnalysisWorker {
|
||||
);
|
||||
const availableResultBudget = this.#remainingResultBudget();
|
||||
if (expandedBytes <= availableResultBudget) {
|
||||
this.#estimatedRetainedBytes += expandedBytes;
|
||||
this.#retained.chargeOverCommitting(expandedBytes);
|
||||
this.#staticProjectionReservations.push({
|
||||
sourceIndex,
|
||||
path: sourcePath,
|
||||
@@ -951,7 +955,7 @@ export class JavaScriptAnalysisWorker {
|
||||
"memory",
|
||||
`Expanded application relationships for ${sourcePath} exceed the parent's result budget; complete static facts were retained on the file node`,
|
||||
{
|
||||
parent_result_budget_bytes: this.#resultBudgetBytes,
|
||||
parent_result_budget_bytes: this.#retained.maximum,
|
||||
parent_available_result_budget_bytes: availableResultBudget,
|
||||
application_projection_required_bytes: expandedBytes,
|
||||
},
|
||||
@@ -972,7 +976,7 @@ export class JavaScriptAnalysisWorker {
|
||||
`The parent's result capacity was exhausted after retaining static facts for ${path}; remaining sources were not analyzed`,
|
||||
{
|
||||
...this.#limits(),
|
||||
parent_result_budget_bytes: this.#resultBudgetBytes,
|
||||
parent_result_budget_bytes: this.#retained.maximum,
|
||||
...this.#parentCapacityExhaustion,
|
||||
parent_result_budget_exhausted: true,
|
||||
},
|
||||
@@ -1024,7 +1028,7 @@ export class JavaScriptAnalysisWorker {
|
||||
#remainingResultBudget(): number {
|
||||
// One sequential worker produces one next checkpoint at a time. Reserve
|
||||
// its maximum protocol size at the same retained expansion used on receipt;
|
||||
// earlier checkpoints are already charged to estimatedRetainedBytes.
|
||||
// earlier checkpoints are already charged to the retained budget.
|
||||
// Reserving every unexamined source's maximum would reject useful results
|
||||
// merely because many small files remain. Actual retained growth and live
|
||||
// heap capacity are checked again for every checkpoint and transfer.
|
||||
@@ -1040,7 +1044,7 @@ export class JavaScriptAnalysisWorker {
|
||||
return Math.max(
|
||||
0,
|
||||
Math.min(
|
||||
this.#resultBudgetBytes - this.#estimatedRetainedBytes,
|
||||
this.#retained.remaining,
|
||||
this.#remainingParentHeapBytes() -
|
||||
24 * JAVASCRIPT_ANALYSIS_TRANSFER_RECORD_BYTES,
|
||||
),
|
||||
|
||||
Reference in new issue
Block a user