Decide where the planning socket's message allowlist lives #331

Closed
opened 2026-10-29 09:08:35 +01:00 by nessar · 1 comment
Owner

Follow-up from #319 / PR #328 (hardening commit e3db15d).

Current behaviour

Verification showed that one client could exhaust server memory. After its first message, a socket could send any number of messages: each extra plan started another calculation in the same worker, and a waiting socket buffered without limit. The measurement was 1.5 GB in 15 s from one socket.

The server now enforces exactly what the coordinator sends:

  • one job message (plan, explain-checkpoint or counterfactual);
  • for a plan, at most one cancel;
  • any other text message before the job ends closes the socket with 1008;
  • binary messages close it with 1003, and invalid JSON with 1007;
  • messages after the job's terminal message are ignored.

The allowlist and the terminal messages of each job kind live in src/server.ts (TERMINAL_MESSAGES, PlanningJob.receive). Nothing in leave-planner.worker-messages.ts points there.

Consequence

A new WorkerRequest type, or a coordinator change that sends a second message on a job, breaks against the server unless someone also updates src/server.ts. A second message on a job would close the socket with 1008. A new first-message type would close it with 1008 too, and the client would then fall back to local.

Options

  1. Keep the allowlist in src/server.ts. Add a comment in leave-planner.worker-messages.ts pointing to it.
  2. Share one table. Declare each job kind's first message, allowed follow-up messages and terminal responses in leave-planner.worker-messages.ts. Both the coordinator's tests and the server import it, so a protocol change is one edit and a test catches drift.
  3. Loosen to quotas. For example, accept any messages up to a small count per socket. This keeps the protocol open but only partly closes the abuse: extra plans would still run inside one slot.

Recommendation

Option 2. It is a small change and keeps the memory guard.

To decide

Which option to apply.

Follow-up from #319 / PR #328 (hardening commit e3db15d). ## Current behaviour Verification showed that one client could exhaust server memory. After its first message, a socket could send any number of messages: each extra `plan` started another calculation in the same worker, and a waiting socket buffered without limit. The measurement was 1.5 GB in 15 s from one socket. The server now enforces exactly what the coordinator sends: - one job message (`plan`, `explain-checkpoint` or `counterfactual`); - for a plan, at most one `cancel`; - any other text message before the job ends closes the socket with 1008; - binary messages close it with 1003, and invalid JSON with 1007; - messages after the job's terminal message are ignored. The allowlist and the terminal messages of each job kind live in `src/server.ts` (`TERMINAL_MESSAGES`, `PlanningJob.receive`). Nothing in `leave-planner.worker-messages.ts` points there. ## Consequence A new `WorkerRequest` type, or a coordinator change that sends a second message on a job, breaks against the server unless someone also updates `src/server.ts`. A second message on a job would close the socket with 1008. A new first-message type would close it with 1008 too, and the client would then fall back to local. ## Options 1. **Keep the allowlist in `src/server.ts`.** Add a comment in `leave-planner.worker-messages.ts` pointing to it. 2. **Share one table.** Declare each job kind's first message, allowed follow-up messages and terminal responses in `leave-planner.worker-messages.ts`. Both the coordinator's tests and the server import it, so a protocol change is one edit and a test catches drift. 3. **Loosen to quotas.** For example, accept any messages up to a small count per socket. This keeps the protocol open but only partly closes the abuse: extra plans would still run inside one slot. ## Recommendation Option 2. It is a small change and keeps the memory guard. ## To decide Which option to apply.
nessar added the needs-triage label 2026-10-29 09:08:35 +01:00
Author
Owner

Decision: option 2, landing in PR #328.

A PLANNING_JOBS constant in leave-planner.worker-messages.ts lists, per job kind, the follow-up messages the server relays (each at most once) and the responses that end the job. It is checked with satisfies against WorkerRequest and WorkerResponse, so a new job request type without an entry, or a misspelled message type, fails the typecheck. src/server.ts imports it in place of TERMINAL_MESSAGES and the hard-coded cancel/plan check. The client and server always share one build (PLANNING_BUILD_MISMATCH), so drift can only come from a code change, and the type checker and server-planning.spec.ts (the real coordinator against the real server) catch it.

Decision: option 2, landing in PR #328. A PLANNING_JOBS constant in leave-planner.worker-messages.ts lists, per job kind, the follow-up messages the server relays (each at most once) and the responses that end the job. It is checked with satisfies against WorkerRequest and WorkerResponse, so a new job request type without an entry, or a misspelled message type, fails the typecheck. src/server.ts imports it in place of TERMINAL_MESSAGES and the hard-coded cancel/plan check. The client and server always share one build (PLANNING_BUILD_MISMATCH), so drift can only come from a code change, and the type checker and server-planning.spec.ts (the real coordinator against the real server) catch it.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: nessar/vac-optimizer#331