execution.ts (1842B)
1 import type { Budget, CollectionPolicy } from './graph.js'; 2 // Execution has no application node/work/frame ceilings. Browser memory remains 3 // finite. Pure evaluation stops by terminating the Worker; IO Stop drains its structured 4 // session at scheduler boundaries. GC thresholds are not budgets. 5 export const BROWSER_BUDGET: Readonly<Budget> = Object.freeze({ nodes: Infinity, fuel: Infinity, stack: Infinity }); 6 export const PACKAGE_LOAD_MS = 60_000; 7 // Export is bounded transport/rendering, not program execution. 8 export const EXPORT_ACTIVE_MS = 120_000; 9 export const EXECUTION_COLLECTION = Object.freeze({ threshold: 250_000 }); 10 export const PACKAGE_COLLECTION = Object.freeze({ threshold: 100_000 }); 11 export function collectionPolicy(budget: Readonly<Budget>, threshold: number = EXECUTION_COLLECTION.threshold): CollectionPolicy | undefined { 12 return budget.nodes < 2 ? undefined : { threshold: Math.min(threshold, budget.nodes) }; 13 } 14 15 export type Operation = 'catalogue' | 'loading' | 'compiling' | 'running' | 'exporting' | 'downloading'; 16 const operationLabels: Readonly<Record<Operation, string>> = { 17 catalogue: 'Program catalogue loading', loading: 'Package loading', 18 compiling: 'Draft compilation', running: 'Program execution', 19 exporting: 'Definition export', downloading: 'Bundle download', 20 }; 21 export function operationFailure(operation: Operation | undefined, message: string): string { 22 return operation ? `${operationLabels[operation]} failed: ${message}` : message; 23 } 24 export function operationTimeout(operation: Operation): string { 25 return operation === 'loading' || operation === 'downloading' || operation === 'catalogue' 26 ? `${operationLabels[operation]} timed out. The deadline includes transfer and processing time; try again.` 27 : `${operationLabels[operation]} stopped: active time limit exceeded.`; 28 }