A person planning their leave on an older phone cannot get a plan reliably. A heavy configuration takes several times longer than on a recent phone, and some calculations end with Chrome's generic error page. On a Pixel 11, the benchmark's loaded year takes about 4.6 seconds. The wait and the chance of success depend on the device the person happens to own.
Solution
Every calculation runs on the VacOptimizer server instead of on the device, so the wait is the same on any phone. The person uses the app exactly as before:
Calculate, the indicative duration estimate, progress and Cancel behave as today, and Cancel still keeps the best valid plan found so far.
The stable plan explanation and counterfactual date analysis are unchanged.
When the server cannot be reached, refuses the calculation, or runs a different build, the device calculates locally without notice. When the connection drops mid-calculation, the person gets an incomplete calculation with the best valid plan already received, and can calculate again.
User Stories
As a person on an older phone, I want my calculation to run on the server, so that I get my plan without the browser crashing.
As a person on any device, I want the wait for a given configuration to be about the same as on a recent phone, so that the device I own does not decide whether planning is usable.
As a person running a server calculation, I want Cancel to keep the best valid plan found so far, so that cancelling behaves as it does today (ADR 0006).
As a person running a server calculation, I want the same planning outcome, stable plan explanation and final state as the local engine would produce for the same request and Europe/Paris calendar date, so that the place where it ran never changes my plan.
As a person, I want counterfactual date analysis of a displayed leave placement to work after a server calculation, so that no feature is lost.
As a person arriving while the server is busy, I want my calculation to wait in line and start as soon as capacity frees up, so that I am not refused and pushed back onto a slow device.
As a person waiting in line, I want Cancel to remove my calculation from the line, so that I am not stuck waiting.
As a person whose device cannot reach the server (offline, server down, WebSockets blocked), I want the calculation to run on my device, so that I still get a plan.
As a person who has exceeded the per-IP limit, I want the calculation to run on my device, so that I still get a plan.
As a person with a tab opened before a deployment, I want my calculation to run on my device's own engine, so that a protocol mismatch never breaks it.
As a person whose connection drops mid-calculation, I want an incomplete calculation with the best valid plan already received, without an automatic retry, so that I decide whether to calculate again.
As the operator, I want one client IP to hold at most five calculations, running or queued, so that one script cannot occupy the server.
As the operator, I want concurrency set by PLANNING_WORKERS and the container held to 8 GB, so that the server is used fully without exceeding its memory budget.
Implementation Decisions
Agreed (ADR 0011):
Transport. A same-origin WebSocket carries the existing WorkerRequest/WorkerResponse protocol, JSON-encoded, with one socket per worker job: a plan, an incomplete-checkpoint explanation, or a counterfactual analysis.
Client seam. The planning coordinator gets a second implementation of its worker-job interface (post, release), backed by the socket. Liveness, heartbeats, cancellation, checkpoint retention, explanation delivery, stale-calculation supersession and failure handling stay in the coordinator, unchanged. Remote is the default. Local fallback lives inside the remote job: if the socket cannot open or the server closes it before any message, the job starts a local worker and replays the messages posted so far.
The calculation date stays on the client. The client keeps fixing the calculation's Europe/Paris calendar date and sending it in the request, so the server clock never decides it.
Server. The existing Bun server, alongside the static handler, accepts planning sockets. For each socket it runs the unchanged planner worker in a Bun Worker and relays messages both ways. It terminates the worker and drops queued work when the socket closes. It stores nothing once the socket closes.
Capacity. At most PLANNING_WORKERS calculations run at once. Excess jobs wait in a FIFO queue, during which the server sends heartbeat messages every second so the client's 30-second liveness timer does not expire. No queue position is shown.
shortcut: if PLANNING_WORKERS is unset, it defaults to half of navigator.hardwareConcurrency, which assumes two threads per core; set it to the physical core count on machines without SMT. Throughput was measured to stop growing at physical cores.
Per-IP limit. Five open jobs per client IP, running or queued. The IP comes from CF-Connecting-IP, falling back to the socket's remote address. The server refuses a job beyond the limit with a dedicated close code before any message.
Build check. The client sends its build identifier when opening the socket. The server refuses a different build with a dedicated close code.
No server duration limit.deadlineMs stays opt-in and the server does not set it.
Runtime stays Bun (ADR 0009). The JavaScriptCore performance work is a separate change.
Deployment. The production Compose file drops the one-CPU and 512 MB limits, caps memory at 8 GB and exposes PLANNING_WORKERS.
Proposed (decide during implementation):
Connect timeout. About 5 seconds before falling back. Without one, a blackholed server would trip the 30-second liveness timer and give a worker error instead of a local plan.
Incoming message cap (maxPayloadLength) of about 1 MB. Requests are kilobytes; responses are not capped.
Slot release. A running slot is released on the job's terminal message (artifacts or error for a plan, explanation for a checkpoint explanation, the result or error for a counterfactual) or when the socket closes. An idle client that keeps its socket open therefore does not hold a core.
Build identifier. Generated at build time and shared by the client and server bundles. No such identifier exists today.
Unresolved, to verify first:
The server is bundled into a single file. The planner worker must ship as its own entry point in the build output and load from the bundled server.
Messages must survive JSON encoding unchanged: no Date, Map, Set, undefined-sensitive fields or non-finite numbers. The request survived it in a manual check; the responses have not been checked.
Testing Decisions
What makes a good test. Tests target observable behavior: planning outcomes, explanation delivery, cancellation results and server admission. They do not target relay internals.
Equivalence (highest risk). For the benchmark scenarios, a server calculation over a real socket produces the same planning outcome, stable plan explanation and final state as the local engine for the same request. This covers JSON transport and the build check end to end.
Coordinator. With a fake WebSocket modeled on the existing FakeWorker approach in the worker-lifetime and cancellation specs, check:
fallback on open failure, connect timeout, limit refusal and build refusal, with replay of plan and an early cancel;
an incomplete calculation with its retained checkpoint plan when the connection drops mid-calculation, and no retry;
cancellation and supersession over the socket.
Server. In the style of the existing server spec, against a real createServer instance, check:
queue order beyond PLANNING_WORKERS, with heartbeats while queued;
removal from the queue and worker termination on socket close;
the per-IP limit through CF-Connecting-IP;
build refusal and the incoming message cap;
static file serving left unchanged.
Benchmark. It keeps measuring the path the app uses, which is now the server. Its existing budget specs keep running against the local engine.
Out of Scope
Parallelism inside one calculation (rejected in ADR 0011).
Running the planner on Node.
Accounts, persistence and cross-device synchronization.
A server-side duration limit.
Showing queue position or where a calculation ran.
Automatic retry after a dropped connection.
A dev-server proxy for the backend: ng serve falls back to local.
JavaScriptCore hotspots (Object.freeze in plan observations, keeping its immutability contract; the iteration protocol), with frozen-engine determinism and before/after measurements. This is #321.
Further Notes
Measurements on the development machine (Ryzen 7 7800X3D), 2026-10-28. Loaded year: Bun 5.3 s, Node 24 3.8 s, Pixel 11 4.6 s. With 1, 2, 4, 8 and 16 concurrent calculations, each took 5.5, 6.8, 7.3, 12.2 and 24.4 s. Each calculation adds about 60 to 150 MB of memory. A five-year horizon takes 10.8 s.
Operator prerequisites. Enable WebSocket support on the Nginx Proxy Manager host. Restrict the origin to Cloudflare, or the per-IP limit can be bypassed with a forged header.
Risk. If a phone crashes while rendering the calendar rather than while planning, this change does not fix it.
Docs to update. README architecture, the benchmark README ("adds no solver or backend dependency"), and the Compose files.
Decision record: [ADR 0011 — Server-Side Planning for Every Device](https://gitea.nessar.fr/nessar/vac-optimizer/src/branch/develop/docs/adr/0011-server-side-planning-for-every-device.md), added by #327, which supersedes ADR 0002 and ADR 0006's in-browser requirement.
## Problem Statement
A person planning their leave on an older phone cannot get a plan reliably. A heavy configuration takes several times longer than on a recent phone, and some calculations end with Chrome's generic error page. On a Pixel 11, the benchmark's loaded year takes about 4.6 seconds. The wait and the chance of success depend on the device the person happens to own.
## Solution
Every calculation runs on the VacOptimizer server instead of on the device, so the wait is the same on any phone. The person uses the app exactly as before:
- Calculate, the indicative duration estimate, progress and Cancel behave as today, and Cancel still keeps the best valid plan found so far.
- The stable plan explanation and counterfactual date analysis are unchanged.
When the server cannot be reached, refuses the calculation, or runs a different build, the device calculates locally without notice. When the connection drops mid-calculation, the person gets an incomplete calculation with the best valid plan already received, and can calculate again.
## User Stories
1. As a person on an older phone, I want my calculation to run on the server, so that I get my plan without the browser crashing.
2. As a person on any device, I want the wait for a given configuration to be about the same as on a recent phone, so that the device I own does not decide whether planning is usable.
3. As a person running a server calculation, I want Cancel to keep the best valid plan found so far, so that cancelling behaves as it does today (ADR 0006).
4. As a person running a server calculation, I want the same planning outcome, stable plan explanation and final state as the local engine would produce for the same request and Europe/Paris calendar date, so that the place where it ran never changes my plan.
5. As a person, I want counterfactual date analysis of a displayed leave placement to work after a server calculation, so that no feature is lost.
6. As a person arriving while the server is busy, I want my calculation to wait in line and start as soon as capacity frees up, so that I am not refused and pushed back onto a slow device.
7. As a person waiting in line, I want Cancel to remove my calculation from the line, so that I am not stuck waiting.
8. As a person whose device cannot reach the server (offline, server down, WebSockets blocked), I want the calculation to run on my device, so that I still get a plan.
9. As a person who has exceeded the per-IP limit, I want the calculation to run on my device, so that I still get a plan.
10. As a person with a tab opened before a deployment, I want my calculation to run on my device's own engine, so that a protocol mismatch never breaks it.
11. As a person whose connection drops mid-calculation, I want an incomplete calculation with the best valid plan already received, without an automatic retry, so that I decide whether to calculate again.
12. As the operator, I want one client IP to hold at most five calculations, running or queued, so that one script cannot occupy the server.
13. As the operator, I want concurrency set by `PLANNING_WORKERS` and the container held to 8 GB, so that the server is used fully without exceeding its memory budget.
## Implementation Decisions
**Agreed (ADR 0011):**
- **Transport.** A same-origin WebSocket carries the existing `WorkerRequest`/`WorkerResponse` protocol, JSON-encoded, with one socket per worker job: a plan, an incomplete-checkpoint explanation, or a counterfactual analysis.
- **Client seam.** The planning coordinator gets a second implementation of its worker-job interface (`post`, `release`), backed by the socket. Liveness, heartbeats, cancellation, checkpoint retention, explanation delivery, stale-calculation supersession and failure handling stay in the coordinator, unchanged. Remote is the default. Local fallback lives inside the remote job: if the socket cannot open or the server closes it before any message, the job starts a local worker and replays the messages posted so far.
- **The calculation date stays on the client.** The client keeps fixing the calculation's Europe/Paris calendar date and sending it in the request, so the server clock never decides it.
- **Server.** The existing Bun server, alongside the static handler, accepts planning sockets. For each socket it runs the unchanged planner worker in a Bun `Worker` and relays messages both ways. It terminates the worker and drops queued work when the socket closes. It stores nothing once the socket closes.
- **Capacity.** At most `PLANNING_WORKERS` calculations run at once. Excess jobs wait in a FIFO queue, during which the server sends `heartbeat` messages every second so the client's 30-second liveness timer does not expire. No queue position is shown.
- shortcut: if `PLANNING_WORKERS` is unset, it defaults to half of `navigator.hardwareConcurrency`, which assumes two threads per core; set it to the physical core count on machines without SMT. Throughput was measured to stop growing at physical cores.
- **Per-IP limit.** Five open jobs per client IP, running or queued. The IP comes from `CF-Connecting-IP`, falling back to the socket's remote address. The server refuses a job beyond the limit with a dedicated close code before any message.
- **Build check.** The client sends its build identifier when opening the socket. The server refuses a different build with a dedicated close code.
- **No server duration limit.** `deadlineMs` stays opt-in and the server does not set it.
- **Runtime stays Bun** (ADR 0009). The JavaScriptCore performance work is a separate change.
- **Deployment.** The production Compose file drops the one-CPU and 512 MB limits, caps memory at 8 GB and exposes `PLANNING_WORKERS`.
**Proposed (decide during implementation):**
- **Connect timeout.** About 5 seconds before falling back. Without one, a blackholed server would trip the 30-second liveness timer and give a worker error instead of a local plan.
- **Incoming message cap** (`maxPayloadLength`) of about 1 MB. Requests are kilobytes; responses are not capped.
- **Slot release.** A running slot is released on the job's terminal message (artifacts or error for a plan, explanation for a checkpoint explanation, the result or error for a counterfactual) or when the socket closes. An idle client that keeps its socket open therefore does not hold a core.
- **Build identifier.** Generated at build time and shared by the client and server bundles. No such identifier exists today.
**Unresolved, to verify first:**
- The server is bundled into a single file. The planner worker must ship as its own entry point in the build output and load from the bundled server.
- Messages must survive JSON encoding unchanged: no `Date`, `Map`, `Set`, `undefined`-sensitive fields or non-finite numbers. The request survived it in a manual check; the responses have not been checked.
## Testing Decisions
- **What makes a good test.** Tests target observable behavior: planning outcomes, explanation delivery, cancellation results and server admission. They do not target relay internals.
- **Equivalence (highest risk).** For the benchmark scenarios, a server calculation over a real socket produces the same planning outcome, stable plan explanation and final state as the local engine for the same request. This covers JSON transport and the build check end to end.
- **Coordinator.** With a fake WebSocket modeled on the existing `FakeWorker` approach in the worker-lifetime and cancellation specs, check:
- fallback on open failure, connect timeout, limit refusal and build refusal, with replay of `plan` and an early `cancel`;
- an incomplete calculation with its retained checkpoint plan when the connection drops mid-calculation, and no retry;
- cancellation and supersession over the socket.
- **Server.** In the style of the existing server spec, against a real `createServer` instance, check:
- queue order beyond `PLANNING_WORKERS`, with heartbeats while queued;
- removal from the queue and worker termination on socket close;
- the per-IP limit through `CF-Connecting-IP`;
- build refusal and the incoming message cap;
- static file serving left unchanged.
- **Benchmark.** It keeps measuring the path the app uses, which is now the server. Its existing budget specs keep running against the local engine.
## Out of Scope
- Parallelism inside one calculation (rejected in ADR 0011).
- Running the planner on Node.
- Accounts, persistence and cross-device synchronization.
- A server-side duration limit.
- Showing queue position or where a calculation ran.
- Automatic retry after a dropped connection.
- A dev-server proxy for the backend: `ng serve` falls back to local.
- JavaScriptCore hotspots (`Object.freeze` in plan observations, keeping its immutability contract; the iteration protocol), with frozen-engine determinism and before/after measurements. This is #321.
## Further Notes
- **Measurements on the development machine (Ryzen 7 7800X3D), 2026-10-28.** Loaded year: Bun 5.3 s, Node 24 3.8 s, Pixel 11 4.6 s. With 1, 2, 4, 8 and 16 concurrent calculations, each took 5.5, 6.8, 7.3, 12.2 and 24.4 s. Each calculation adds about 60 to 150 MB of memory. A five-year horizon takes 10.8 s.
- **Operator prerequisites.** Enable WebSocket support on the Nginx Proxy Manager host. Restrict the origin to Cloudflare, or the per-IP limit can be bypassed with a forged header.
- **Risk.** If a phone crashes while rendering the calendar rather than while planning, this change does not fix it.
- **Docs to update.** README architecture, the benchmark README ("adds no solver or backend dependency"), and the Compose files.
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.
Decision record: ADR 0011 — Server-Side Planning for Every Device, added by #327, which supersedes ADR 0002 and ADR 0006's in-browser requirement.
Problem Statement
A person planning their leave on an older phone cannot get a plan reliably. A heavy configuration takes several times longer than on a recent phone, and some calculations end with Chrome's generic error page. On a Pixel 11, the benchmark's loaded year takes about 4.6 seconds. The wait and the chance of success depend on the device the person happens to own.
Solution
Every calculation runs on the VacOptimizer server instead of on the device, so the wait is the same on any phone. The person uses the app exactly as before:
When the server cannot be reached, refuses the calculation, or runs a different build, the device calculates locally without notice. When the connection drops mid-calculation, the person gets an incomplete calculation with the best valid plan already received, and can calculate again.
User Stories
PLANNING_WORKERSand the container held to 8 GB, so that the server is used fully without exceeding its memory budget.Implementation Decisions
Agreed (ADR 0011):
WorkerRequest/WorkerResponseprotocol, JSON-encoded, with one socket per worker job: a plan, an incomplete-checkpoint explanation, or a counterfactual analysis.post,release), backed by the socket. Liveness, heartbeats, cancellation, checkpoint retention, explanation delivery, stale-calculation supersession and failure handling stay in the coordinator, unchanged. Remote is the default. Local fallback lives inside the remote job: if the socket cannot open or the server closes it before any message, the job starts a local worker and replays the messages posted so far.Workerand relays messages both ways. It terminates the worker and drops queued work when the socket closes. It stores nothing once the socket closes.PLANNING_WORKERScalculations run at once. Excess jobs wait in a FIFO queue, during which the server sendsheartbeatmessages every second so the client's 30-second liveness timer does not expire. No queue position is shown.PLANNING_WORKERSis unset, it defaults to half ofnavigator.hardwareConcurrency, which assumes two threads per core; set it to the physical core count on machines without SMT. Throughput was measured to stop growing at physical cores.CF-Connecting-IP, falling back to the socket's remote address. The server refuses a job beyond the limit with a dedicated close code before any message.deadlineMsstays opt-in and the server does not set it.PLANNING_WORKERS.Proposed (decide during implementation):
maxPayloadLength) of about 1 MB. Requests are kilobytes; responses are not capped.Unresolved, to verify first:
Date,Map,Set,undefined-sensitive fields or non-finite numbers. The request survived it in a manual check; the responses have not been checked.Testing Decisions
FakeWorkerapproach in the worker-lifetime and cancellation specs, check:planand an earlycancel;createServerinstance, check:PLANNING_WORKERS, with heartbeats while queued;CF-Connecting-IP;Out of Scope
ng servefalls back to local.Object.freezein plan observations, keeping its immutability contract; the iteration protocol), with frozen-engine determinism and before/after measurements. This is #321.Further Notes