refactor(server): name the planning terminal messages and error handler
Rename TERMINAL to TERMINAL_MESSAGES and the shared error handler to internalError, which no longer shadows its parameter. Describe the browser cancellation check for server planning and its local fallback. Refs #319 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
aea16d29f2
commit
3044d507a2
2 files changed
+7
-7
No files matched your search
@@ -45,6 +45,6 @@ The public cancellation tests cover immediate cancellation, a stable partial out
|
||||
|
||||
The real-worker suite bundles the production worker source with Bun and runs it on a separate `node:worker_threads` thread of the Bun process. Its small host adapter maps browser worker messages to the thread's message port; the planner, CPU work, cancellation handling, and outcome and explanation delivery protocol are real. It checks interruption after preparation has started, before the first obligation solution, during active obligation CPU work after a solution exists, and after a completed checkpoint. It also compares an uncancelled outcome with the synchronous adapter's deterministic result. These checks complement the controlled worker boundary tests.
|
||||
|
||||
For a browser check, serve the production browser build and use native Chromium Web Workers with a saved annual horizon. Check cancellation during calendar preparation, a broad obligation search, and a quality pass. Confirm one planning request per Calculate, no new request on Cancel, the appropriate translated status, joint rule satisfaction and balance accounting for an incumbent, and stable explanation delivery after the outcome. Also check the Cancel control with the keyboard, at 375px width, and in light and dark themes.
|
||||
For a browser check, serve the production build with `bun run serve`, which plans over the server's planning socket, and repeat it after stopping the server with the page still open (or under `ng serve`, which has no build identifier) to exercise the local Web Worker; use a saved annual horizon. Check cancellation during calendar preparation, a broad obligation search, and a quality pass. Confirm one planning request per Calculate, no new request on Cancel, the appropriate translated status, joint rule satisfaction and balance accounting for an incumbent, and stable explanation delivery after the outcome. Also check the Cancel control with the keyboard, at 375px width, and in light and dark themes.
|
||||
|
||||
Earlier browser checks before #76: the production build was checked in native Chromium for all three interruption points, including keyboard cancellation during a 375px dark-theme obligation search and desktop light-theme checks. An editable input could still receive focus during CPU work, and focus moved to the result heading after keyboard cancellation. Each run sent one planning request and one cancellation request, displayed the appropriate French status, and completed acknowledged artifact delivery. The Cancel control was 44px high and the page had no horizontal overflow. In these sample runs, cancellation through artifact completion took under 200ms; this is measured evidence, not a latency guarantee.
|
||||
+6
-6
@@ -68,7 +68,7 @@ type PlanningSocketData = {
|
||||
};
|
||||
|
||||
// What a planning socket may start with, and the worker messages that end each kind of job.
|
||||
const TERMINAL: Record<string, readonly string[]> = {
|
||||
const TERMINAL_MESSAGES: Record<string, readonly string[]> = {
|
||||
plan: ['artifacts', 'error'],
|
||||
'explain-checkpoint': ['explanation', 'error'],
|
||||
counterfactual: ['counterfactual-result', 'error'],
|
||||
@@ -154,7 +154,7 @@ class PlanningJob {
|
||||
if (this.state !== 'running') return;
|
||||
this.socket.send(JSON.stringify(event.data));
|
||||
// The client closes the socket; the core is free for the next job meanwhile.
|
||||
if (TERMINAL[this.kind]?.includes(event.data?.type)) this.stop();
|
||||
if (TERMINAL_MESSAGES[this.kind]?.includes(event.data?.type)) this.stop();
|
||||
});
|
||||
worker.addEventListener('error', () => this.fail(1011, 'Planner worker failed'));
|
||||
// A worker that exits on its own sends nothing else; stop() sets 'done' before terminating.
|
||||
@@ -176,7 +176,7 @@ class PlanningJob {
|
||||
const type = parsed?.type;
|
||||
if (this.state === 'done') return;
|
||||
if (this.state === 'idle') {
|
||||
if (typeof type !== 'string' || !Object.hasOwn(TERMINAL, type))
|
||||
if (typeof type !== 'string' || !Object.hasOwn(TERMINAL_MESSAGES, type))
|
||||
return this.fail(1008, 'Unknown first message');
|
||||
this.kind = type;
|
||||
this.buffered.push(parsed);
|
||||
@@ -231,11 +231,11 @@ export function createServer({
|
||||
planning?: { worker: string | URL; build: string; workers: number };
|
||||
}) {
|
||||
const handler = createHandler(root);
|
||||
const error = (error: Error) => {
|
||||
const internalError = (error: Error) => {
|
||||
console.error(error);
|
||||
return new Response('Internal Server Error', { status: 500 });
|
||||
};
|
||||
if (!planning) return Bun.serve({ port, fetch: handler, error });
|
||||
if (!planning) return Bun.serve({ port, fetch: handler, error: internalError });
|
||||
|
||||
// Admitted sockets per client IP; entries are dropped at zero.
|
||||
const jobsByClient = new Map<string, number>();
|
||||
@@ -279,7 +279,7 @@ export function createServer({
|
||||
},
|
||||
maxPayloadLength: MAX_MESSAGE_BYTES,
|
||||
},
|
||||
error,
|
||||
error: internalError,
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user