Переглянути джерело

fix: do not ship an optional key in a conffile, and make the install carry a conffile policy

The 0.18.1 prod install ABORTED mid-transaction. /etc/smartbotic-vectorapi/
config.json is a dpkg conffile (create-debs.sh:88) and every real deployment
customises it - prod carries functions.runners, the scheduler and the events
block, none of which are in the shipped template. So adding database.timeout_ms
to the template gave dpkg a genuine three-way conflict; with no controlling tty
it asked, got EOF, and exited 1 after unpacking and before configuring.

THE HALF-CONFIGURED STATE IS THE PART WORTH RECOGNISING, because every obvious
signal looked fine: all three units active, /healthz 200, NRestarts 0 - while
dpkg-query said `install ok unpacked` and the running process was still
executing the OLD image from a replaced inode. Prod served correctly on the
previous version for about two minutes. No liveness check can tell that from a
successful deploy; `dpkg-query -W -f='${Status}'` can.

Repaired with `dpkg --configure -a --force-confold`, which logged "Using
current old file as you requested". Prod's config was proven untouched by md5
either side rather than asserted.

Two changes, and the second is the one that matters:

1. The template reverts. database.timeout_ms is documented in src/config.hpp
   and api/llms.txt and defaults to the value that was previously hardcoded, so
   shipping it in a conffile bought exactly one prompt per customised box. An
   OPTIONAL key with a correct default does not belong in a conffile - a
   conffile holds what a deployment must set, not a catalogue of what it may.

2. The install carries `-o Dpkg::Options::=--force-confold -o
   Dpkg::Options::=--force-confdef` under DEBIAN_FRONTEND=noninteractive, and
   then ASSERTS `install ok installed` per package rather than trusting the apt
   exit code. Reverting the template alone would not have fixed this: the prompt
   is a consequence of the file being a customised conffile, not of my
   particular edit, so the next template change of any kind would abort the same
   way. A warning is not a control.

CLAUDE.md records it with the signals that misled me, so the next reader checks
dpkg status rather than systemctl.
fszontagh 3 тижнів тому
батько
коміт
d133425534
2 змінених файлів з 7 додано та 1 видалено
  1. 6 0
      CLAUDE.md
  2. 1 1
      config/config.json

+ 6 - 0
CLAUDE.md

@@ -684,6 +684,12 @@ docker run -d --name svapi-dev -p 8080:8080 -e SMARTBOTIC_VECTORAPI_KEY=dev svap
   Two things they measured that are worth keeping because I could not have answered them from our side either. Their old 5xx arm was `/\b5\d\d\b/` over the message text, which equally matches a port in `127.0.0.1:502`, a byte count or a year - **a three-digit-number check wearing a status check's name** - and it is gone now that `e.status` is known to exist. And a test they had written an hour earlier asserting the slug was read out of the MESSAGE passed against `'vectorapi 504 {"error":"embedding_timeout"}'`, a string that also contains the word "timeout", so the prose arm answered and the assertion could not tell which arm had produced it: green, and blind to the only thing its name mentioned.
   **WHAT THE HOST ACTUALLY GIVES A FUNCTION, since this keeps being asked and is answerable only from source** (`throwApiError`, `runner/src/host_context.cpp:138`): a JS `Error` carrying `message`, **`code`** (the slug), **`status`** (the HTTP status the same error would have had) and `details` as a real object when non-empty. So `e.code` is a FIELD and digging a slug out of the stringified message is a branch that can never fire for a host-raised error. `host_prelude.js`'s own `fail()` sets `code` the same way, so both halves of the surface agree. And `rate_limited` and `memory_pressure` BOTH reach a function - the first through `requireCapabilityCore` charging the policy's limit on `ctx.collections` data access (a separate bucket from the `/fn` request charge, so a function can be admitted at the request and refused on its data access), the second through the same `translate()` both surfaces use.
 
+- **ADDING A KEY TO `config/config.json` ABORTED A PROD INSTALL MID-TRANSACTION, BECAUSE THAT FILE IS A dpkg CONFFILE AND EVERY REAL DEPLOYMENT HAS CUSTOMISED IT (0.18.1, 2026-11-03).** `create-debs.sh:88` writes `/etc/smartbotic-vectorapi/config.json` into `DEBIAN/conffiles`. Prod's copy carries `functions.runners`, the scheduler and the events block, none of which are in the shipped template - so the moment the template changed AT ALL, dpkg had a genuine three-way conflict, asked which version to keep, found no controlling tty, and exited 1 **after unpacking and before configuring**.
+  **The half-configured state is the part worth recognising, because every obvious signal looked fine.** `systemctl is-active` said active for all three units, `/healthz` answered 200, `NRestarts` was 0 - and `dpkg-query` said `install ok unpacked` rather than `installed`, with the running process still executing the OLD image from a replaced inode. So prod was serving correctly on the PREVIOUS version while the new binary sat on disk, which is a state no liveness check can distinguish from a successful deploy. **Read `${Status}` from `dpkg-query`, not `systemctl is-active`, when deciding whether an install finished.**
+  Repaired with `DEBIAN_FRONTEND=noninteractive dpkg --configure -a --force-confold`, which logs **"Using current old file as you requested"** - and prod's config was proven untouched by md5 either side (`312ec347...` before and after) rather than asserted.
+  **THE CONTROL, not the warning: the install must carry a conffile policy, because the prompt is not a consequence of editing the template - it is a consequence of the file being a conffile that every box customises.** Reverting my template change does not fix it; the next template change of any kind would do the same thing. So a prod install of these packages runs `-o Dpkg::Options::=--force-confold` with `DEBIAN_FRONTEND=noninteractive`, and `--force-confdef` alongside it so a conffile the operator has NOT customised still takes the new default. Without that, any future template edit is an aborted transaction on every customised box.
+  **And the template change itself was reverted, because it bought nothing it could not get elsewhere.** `database.timeout_ms` is documented in `src/config.hpp` and in `api/llms.txt`, and it defaults to the value that was previously hardcoded, so shipping it in a conffile only bought one prompt per box. **An OPTIONAL key with a correct default does not belong in a conffile**; a conffile should hold what a deployment must set, not a catalogue of what it may.
+
 ## Deploy / publish
 
 **`VERSION` and `api/openapi.json`'s `info.version` must agree, and `packaging/build.sh` now refuses to build unless they do** (`scripts/check-version-sync.sh`, run at the top level so it covers the local, Docker and publish paths alike). They drifted once: 0.10.0 was published with the docs claiming 0.9.2, and since `openapi.json` ships in the server package and is served at `/openapi.json`, the stale value was live. **Correcting it cost a whole release**, because a published version number is never reused for different content - which is why 0.10.0 exists but must never be deployed. A release step that relies on remembering is a release step that gets skipped, so it is a check rather than a checklist line.

+ 1 - 1
config/config.json

@@ -1,5 +1,5 @@
 {
   "log_level": "info",
   "http": { "bind_address": "0.0.0.0", "port": 8080 },
-  "database": { "address": "localhost:9004", "timeout_ms": 5000 }
+  "database": { "address": "localhost:9004" }
 }