docs(adr): plan on the server for every device
CI / policy (pull_request) Successful in 18s
CI / validate (pull_request) Successful in 36s
CI / build (pull_request) Successful in 25s
CI / security (pull_request) Successful in 1m0s
CI / benchmark (pull_request) Successful in 1m47s
CI / test (pull_request) Successful in 1m55s
CI / images (pull_request) Successful in 1m22s
CI / required (pull_request) Successful in 3s
CI / policy (push) Successful in 13s
CI / validate (push) Successful in 32s
CI / benchmark (push) Successful in 1m19s
CI / build (push) Successful in 38s
CI / security (push) Successful in 1m2s
CI / test (push) Successful in 2m27s
CI / images (push) Successful in 1m18s
CI / required (push) Successful in 1s

Record ADR 0011 for issue #319: the Bun server runs the planner over a
WebSocket carrying the existing worker protocol, with the browser engine
as a fallback. Mark ADR 0002 and ADR 0006's in-browser requirement as
superseded.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit was merged in pull request #327.
This commit is contained in:
nessarandClaude Opus 5.5 committed 2026-10-28 19:09:05 +01:00
1 parent bc5ee50bd5
commit 8326511dc9
3 files changed
+23

No files matched your search

@@ -1,3 +1,5 @@
# Personal Client-Side Planner for Now
Superseded by [ADR 0011](0011-server-side-planning-for-every-device.md): the server plans for every device, and the privacy of leave data is no longer a constraint.
VacOptimizer remains a single-person planner without accounts, backend synchronization, or employer integration for now. This keeps leave data private and setup-free at the cost of cross-device persistence and collaboration; revisit if those needs become real.
@@ -2,6 +2,8 @@
Accepted for [issue #12](https://gitea.nessar.fr/nessar/vac-optimizer/issues/12). Fixed, saved planning horizons are implemented by [issue #57](https://gitea.nessar.fr/nessar/vac-optimizer/issues/57); user cancellation with a retained valid plan is implemented by [issue #58](https://gitea.nessar.fr/nessar/vac-optimizer/issues/58); removal of the automatic calculation deadline and heartbeat-based worker liveness are implemented by [issue #59](https://gitea.nessar.fr/nessar/vac-optimizer/issues/59). The indicative duration estimate is implemented by [issue #60](https://gitea.nessar.fr/nessar/vac-optimizer/issues/60); its initial model, session-local refinement and calendar-rendering measurement are documented in [planning-duration.md](../planning-duration.md).
[ADR 0011](0011-server-side-planning-for-every-device.md) supersedes the requirement that calculations remain in the browser: the server plans for every device and the browser engine is a fallback. Running to completion without an automatic cutoff, the Cancel action and the retained valid plan are unchanged.
`deadlineMs` remains an opt-in contract for technical callers: a finite non-negative planning-work budget with no ten-second cap. An omitted value is unlimited. It starts after calendar preparation and excludes observer callbacks and post-outcome explanation work. The calendar and benchmark omit it. A one-second worker heartbeat renews the coordinator's thirty-second inactivity timer during cooperative preparation and search; total elapsed time never triggers that timer while activity continues. Worker errors and unavailable execution retain their explicit outcomes, and monitoring ends when the outcome arrives so delayed explanation delivery cannot invalidate it.
VacOptimizer accepts explicitly selected, fixed planning horizons whose start may be past and whose duration may exceed twelve months, retaining today through the same date twelve months later as the default. Calculations remain in the browser and run to completion without an automatic elapsed-time cutoff, with an indicative duration estimate and an explicit Cancel action; this accepts variable waiting time and resource use to make longer horizons usable without silently changing the user's dates. This supersedes ADR 0003's ten-second automatic planning limit and its retention in both ADR 0004 documents, while preserving the separation between the planning outcome and stable explanation.
@@ -0,0 +1,19 @@
# Server-Side Planning for Every Device
Accepted on 2026-10-28 for [issue #319](https://gitea.nessar.fr/nessar/vac-optimizer/issues/319); implementation pending. This supersedes [ADR 0002](0002-personal-client-side-planner-for-now.md) and the requirement of [ADR 0006](0006-user-selected-horizons-and-cancellable-calculations.md) that calculations remain in the browser; ADR 0006's absence of an automatic cutoff, its Cancel action and its retained valid plan are unchanged.
Older phones are too slow for heavy configurations, and some crash near the end of a calculation. A Pixel 11 runs the benchmark's loaded year in about 4.6 seconds in its browser worker. The Bun server therefore runs the planner for every device, and the privacy of leave data is not a constraint. The browser engine remains a fallback. The server is not faster than a recent phone: on the development machine (Ryzen 7 7800X3D), the loaded year takes 5.3 seconds on Bun and 3.8 seconds on Node 24. It makes the wait independent of the device.
The server carries the existing `WorkerRequest`/`WorkerResponse` protocol over a same-origin WebSocket. On the client, it is a second implementation of `WorkerJob`, so heartbeats, liveness, cancellation, checkpoints, explanation delivery and counterfactual analysis keep their current behavior. Each connection runs the unchanged `leave-planner.worker.ts` in a Bun `Worker`, and the server keeps no state once the socket closes. Calculations run one per worker, up to `PLANNING_WORKERS`, which should equal the number of physical cores. Calculations beyond that limit wait in a FIFO queue that sends heartbeats. Each client IP, read from `CF-Connecting-IP`, may hold five calculations, running or queued, and there is no server-side duration limit. The container may use up to 8 GB.
The client falls back to its own engine without notice when the socket cannot open, when the server refuses the per-IP limit, or when the server's build differs from the client's. A connection lost during a calculation is an incomplete calculation with the best valid plan already received, without an automatic retry.
## Considered Options
- **Parallelism inside one calculation**: rejected. The planning objective order is sequential by design. Workers share no objects, so every improvement iteration would ship its state to every worker, and the planner core would need a rewrite under the frozen-engine determinism check. Throughput across calculations is enough: with 1, 4, 8 and 16 concurrent loaded-year calculations, each took 5.5, 7.3, 12.2 and 24.4 seconds. Throughput stops growing at the eight physical cores, and Bun's `navigator.hardwareConcurrency` reports 16. Each calculation adds roughly 60 to 150 MB, so CPU, not memory, limits concurrency.
- **Node for its faster V8 engine**: rejected. It needs a WebSocket dependency, a rewritten server and a departure from [ADR 0009](0009-bun-runtime-and-native-tooling.md). The gap comes from JavaScriptCore hotspots, such as `Object.freeze` in plan observations (about 10% of the loaded year on Bun, negligible on Node) and the iteration protocol. Reducing them is a separate performance change that also benefits Safari on iPhone.
- **HTTP with server-sent events, or one blocking request**: rejected. The first needs a second request to cancel. The second loses progress, checkpoints and the retained plan on cancellation.
## Consequences
The per-IP limit holds only if the origin accepts traffic from Cloudflare alone, and the reverse proxy must forward WebSocket upgrades. If a phone crashes while rendering the calendar rather than while planning, this decision does not fix it. A device that falls back while the server is unreachable can still crash.