mirror of
https://github.com/morluto/rea.git
synced 2026-12-04 05:51:06 +00:00
* fix(browser): bound armed timeline rows by the retained-event allowance Armed timeline rows were appended with no byte budget. Pre-arm messages and document request identities already stop at the retained-event allowance. Count each armed row before keeping it. A row that does not fit fails the observation with payload_limit and does not return a shorter timeline. Event count has no separate ceiling. * chore(browser): format the timeline allowance check oxfmt --check rejects the wrapped comparison in TimelineCapture.#add. * fix(browser): give timeline retention a caller control Armed timeline rows use browser.timeline_retained_bytes. A call can pass timeline_retained_bytes. Request identities keep a separate counter. A row that does not fit returns payload_limit with details.limit, including a row admitted during terminal progress. * fix(browser): refresh advertised schemas for the timeline allowance The new setting and per-call field change the compact input hashes for observe_web_session, inspect_analysis_settings, and update_analysis_settings. * fix(browser): report measured timeline bytes without required_value Admission stops at the first row that does not fit, so later rows are unknown. measured_timeline_bytes records the rows already measured. The budget test waits until all four lifecycle events are delivered.
130 lines
5.7 KiB
TypeScript
130 lines
5.7 KiB
TypeScript
import type {
|
|
BrowserObservationFailureReason,
|
|
BrowserObservationOperation,
|
|
} from "./browserObservationErrors.js";
|
|
import {
|
|
AnalysisError,
|
|
type AnalysisCleanupObservation,
|
|
type AnalysisErrorOptions,
|
|
} from "./analysisErrorBase.js";
|
|
import { AnalysisCancelledError } from "./analysisErrorCore.js";
|
|
import { errorMessage } from "../kernel/errorMessage.js";
|
|
import type { JsonValue } from "./jsonValue.js";
|
|
import { ProviderCleanupError } from "./providerCleanupError.js";
|
|
|
|
/** Describe browser cleanup failure without discarding its resource evidence. */
|
|
export const browserCleanupObservation = (
|
|
cause: unknown,
|
|
): AnalysisCleanupObservation => {
|
|
if (cause instanceof AnalysisError && cause.cleanup !== undefined)
|
|
return cause.cleanup;
|
|
// The cleanup owner keeps its concrete failure separately from generic guidance.
|
|
const reason =
|
|
cause instanceof ProviderCleanupError &&
|
|
typeof cause.diagnostics?.reason === "string"
|
|
? cause.diagnostics.reason
|
|
: errorMessage(cause);
|
|
return {
|
|
reason,
|
|
resources:
|
|
cause instanceof AnalysisError && cause.cleanupResources.length > 0
|
|
? cause.cleanupResources
|
|
: ["browser_transport"],
|
|
};
|
|
};
|
|
|
|
/** A bounded passive browser observation failed at its CDP boundary. */
|
|
export class BrowserObservationError extends AnalysisError {
|
|
readonly _tag = "BrowserObservationError";
|
|
override readonly userCategory: "cancelled" | undefined;
|
|
override readonly userMessage: string | undefined;
|
|
/** Producer-supplied explanation; undefined selects the operation default. */
|
|
readonly detail: string | undefined;
|
|
readonly remediationAction: string | undefined;
|
|
/**
|
|
* Bytes or counts measured before admission stopped. A lower bound, not
|
|
* `limit.required_value`.
|
|
*/
|
|
readonly reportedLimits: Readonly<Record<string, JsonValue>> | undefined;
|
|
|
|
constructor(
|
|
readonly operation: BrowserObservationOperation,
|
|
readonly reason: BrowserObservationFailureReason,
|
|
options?: AnalysisErrorOptions & {
|
|
readonly detail?: string;
|
|
readonly remediationAction?: string;
|
|
readonly reportedLimits?: Readonly<Record<string, JsonValue>>;
|
|
},
|
|
) {
|
|
super(`Browser observation ${operation} failed: ${reason}`, options);
|
|
this.detail = options?.detail;
|
|
this.reportedLimits = options?.reportedLimits;
|
|
this.userMessage =
|
|
options?.detail ?? observationFailureMessage(operation, reason);
|
|
this.remediationAction = options?.remediationAction;
|
|
this.markCleanupIncomplete(
|
|
this.cleanup !== undefined || reason === "cleanup_failed",
|
|
);
|
|
this.setCleanupResources(
|
|
this.cleanup?.resources ??
|
|
(reason === "cleanup_failed" ? ["browser_transport"] : []),
|
|
);
|
|
this.userCategory =
|
|
reason === "cancelled" ||
|
|
options?.cause instanceof AnalysisCancelledError ||
|
|
(options?.cause instanceof AnalysisError &&
|
|
options.cause.userCategory === "cancelled")
|
|
? "cancelled"
|
|
: undefined;
|
|
}
|
|
|
|
/**
|
|
* Attribute this failure to the caller's operation without discarding
|
|
* producer facts; the original cause keeps the primary failure chain intact.
|
|
*/
|
|
forOperation(
|
|
operation: BrowserObservationOperation,
|
|
): BrowserObservationError {
|
|
if (operation === this.operation) return this;
|
|
return new BrowserObservationError(operation, this.reason, {
|
|
cause: this.cause,
|
|
...(this.detail === undefined ? {} : { detail: this.detail }),
|
|
...(this.remediationAction === undefined
|
|
? {}
|
|
: { remediationAction: this.remediationAction }),
|
|
...(this.limit === undefined ? {} : { limit: this.limit }),
|
|
...(this.reportedLimits === undefined
|
|
? {}
|
|
: { reportedLimits: this.reportedLimits }),
|
|
cleanupPrimary: this.cleanupPrimary,
|
|
diagnostics: this.diagnostics,
|
|
capturedOutput: this.capturedOutput,
|
|
cleanup: this.cleanup,
|
|
partialObservation: this.partialObservation,
|
|
});
|
|
}
|
|
}
|
|
|
|
const observationFailureMessage = (
|
|
operation: BrowserObservationOperation,
|
|
reason: BrowserObservationFailureReason,
|
|
): string | undefined => {
|
|
if (reason === "cancelled")
|
|
return `${operation} was cancelled. Collected observations and cleanup status are reported when available.`;
|
|
if (reason === "timeout")
|
|
return `${operation} exceeded its execution deadline. Review the target's responsiveness and retained observations before retrying.`;
|
|
if (reason === "endpoint_unreachable")
|
|
return `${operation} could not reach the selected loopback debugging endpoint. Verify that the target process is running with debugging enabled and that the endpoint's port matches it, then retry.`;
|
|
if (reason === "target_not_found")
|
|
return `${operation} could not find the selected target at the debugging endpoint. Refresh target discovery for that endpoint and retry with a returned target ID.`;
|
|
if (reason === "target_session_detached")
|
|
return `${operation} lost its debugging session while the target may still exist. Refresh target discovery and attach to the selected target again.`;
|
|
if (reason === "target_changed")
|
|
return `${operation} could not retain a stable document because the target changed during observation. Retry after navigation settles; refresh target discovery if the selected page was replaced.`;
|
|
if (reason === "service_worker_blocked")
|
|
return `${operation} refused the selected page because it is controlled by or has a registered service worker while the service-worker policy is block. Set environment.service_workers to allow to permit observation, or remove the service worker registration through the browser.`;
|
|
if (reason === "disconnected")
|
|
return `${operation} lost its debugging connection. Verify that the target process is still running, refresh target discovery, and retry the observation.`;
|
|
return undefined;
|
|
};
|