Skip to content

Safer install defaults, database timeouts and a cap on model answers - #394

Merged
dillonstreator merged 5 commits into
mainfrom
fix/install-and-runtime-defaults
Nov 28, 2026
Merged

dillonstreator merged 5 commits into
mainfrom
fix/install-and-runtime-defaults

Conversation

@dillonstreator

Copy link
Copy Markdown
Member

Fixes SEC-002, PRIV-001, SEC-004 (part), CONS-002, LLM-001 and TEST-001 from the 2026-11-28 audit. Companion to #393; the branches are independent.

What was wrong

  • SEC-002: a new install wrote SIGNUP_MODE=open and published the web port on every interface. The first account to sign up becomes the admin, so on a VPS whoever reached the address first owned the instance, and later strangers got approved accounts that spend the operator's provider keys.
  • PRIV-001: the installers turned on LLM_TRACE=logs. That writes every account's prompts, which carry transcript text, into the logs and the "Report an issue" zip.
  • SEC-004: the development compose file published MinIO's API and console on every interface with fallback credentials. The installer's compose template fell back to the Postgres password reelsaw.
  • CONS-002: no connection had a statement timeout, so a runaway query held a pool connection until it finished. Boot migrations had no lock timeout. A DDL statement waiting behind a long transaction queues every later query on that table behind it.
  • LLM-001: no model call set maxOutputTokens. A degenerate answer ran to the provider's maximum and was billed.
  • TEST-001: the stack-free tests inherited the developer's shell. With ANTHROPIC_BASE_URL= exported, 15 transcription tests failed with "baseURL must be a non-empty string".

What changed

  • Installers (install.sh and install.ps1, kept identical where CI compares them):
    • New installs write SIGNUP_MODE=approval. The first account is still approved and made admin.
    • New installs write BIND_ADDRESS=127.0.0.1 (choose with REELSAW_BIND). The compose port is ${BIND_ADDRESS:+${BIND_ADDRESS:-}:}${PORT}:3000, so an existing .env without BIND_ADDRESS keeps listening on every interface as before. The installer reads BIND_ADDRESS back on a re-run.
    • LLM_TRACE=logs becomes a commented-out line.
    • The compose template uses POSTGRES_PASSWORD:? with no fallback. The installers have always generated one.
    • The closing message explains approval and the bind.
  • Development docker-compose.yml: MinIO is published on 127.0.0.1 only.
  • Database (db/index.ts):
    • Every pooled connection sets statement_timeout from the new DB_STATEMENT_TIMEOUT_SECONDS (default 300, 0 = off).
    • migrate() turns the statement bound off, takes its advisory lock, then sets lock_timeout = '10s', and restores the pool's settings afterwards. A lock timeout fails the boot with a plain sentence.
    • No migrations were added or changed.
  • Models (ai/registry.ts):
    • A middleware sets maxOutputTokens to LLM_MAX_OUTPUT_TOKENS (default 16384, 0 = off) when a call sets none, and lowers a larger one. Smaller requests are kept.
    • Hosted providers only. Self-hosted servers (the compatible server, or openai with OPENAI_BASE_URL) get no cap, because vLLM and llama.cpp reject a max_tokens larger than their remaining context.
  • Tests: scripts/test-env.mjs drops provider keys, tokens and base URLs from the stack-free run. --stack is unchanged.
  • Docs: README, deploy/README ("Reaching it from other machines"), SECURITY.md and THREAT-MODEL Release #15. Generated config docs were updated through docs:gen. Changeset added (minor).

How it was tested

Each new test fails on origin/main and passes here:

  • installer-defaults.test.ts reads both scripts and the compose file as text.
  • llm-output-cap.test.ts runs a mock model through the middleware.
  • test-env.test.ts
  • db-timeouts.test.ts runs against a real Postgres. It checks show statement_timeout and that pg_sleep is cancelled, and runs migrate() to confirm the settings are restored.

Also checked by hand:

  • I ran docker compose config on the generated compose file. With BIND_ADDRESS set it gives host_ip: 127.0.0.1. With it unset it publishes on every interface and prints no warning. Without POSTGRES_PASSWORD it fails with the message.
  • I ran the .env generation section of install.sh in a scratch folder.

Local gate, with ANTHROPIC_* unset:

  • Passed: pnpm -r typecheck, biome ci (0 errors), pnpm guards, docs:check, and i18n:check for server and web.
  • Stack-free unit tests: 1602 tests, 1600 pass. The 2 failures also fail on origin/main on this machine: the bumper crossfade, which depends on the local ffmpeg, and resources "evicts scratch once…".
  • Postgres suites (db-timeouts, uow-atomic, lifecycle-order, deleted, stage-seq): 31/31 pass on a temporary postgres container on port 55433, which has since been removed.

Needs manual verification

  • install.ps1: there was no PowerShell here, so the edits were checked by reading them, plus the compose-template comparison.
  • Run a real install with REELSAW_DRY_RUN=1, then a full one. Re-run the installer over an older install and confirm the port still listens on every interface.
  • Run an eval against a real hosted model with the 16384 cap, to confirm no step's answer is cut short.

For the reviewer to decide

  • The defaults: 300 s for statements, 10 s for migration lock waits, 16384 output tokens.
  • Existing installs keep their open bind and their SIGNUP_MODE. Only new installs change.

Left out

  • MinIO fallback credentials: a ${VAR:?} breaks docker compose for every profile, because inactive services are interpolated too. I tested this. Binding to loopback is the mitigation.
  • cap_drop / no-new-privileges: these need entrypoint testing (privilege drop, GPU).
  • CONS-001: Better Auth runs create.after hooks after its own transaction commits, so the sign-up event cannot share the user insert's transaction without replacing Better Auth's adapter path.
  • The rest of the audit is in Require an administering credential for cross-account actions, and key rate limits on the connection address #393 and the companion PRs. GAP-ZAP-001 and billing beyond BILL-001 were out of scope.

… logging by default

A new install wrote SIGNUP_MODE=open and published the web port on every
interface, and the first account to sign up becomes the admin. On a VPS,
whoever reached the address first owned the instance, and anyone after them
got an approved account spending the operator's provider keys. The
installers also turned on LLM_TRACE=logs, which writes every account's
transcript excerpts into the logs and the issue-report zips.

New installs now write SIGNUP_MODE=approval (the first account is still
approved and made admin), BIND_ADDRESS=127.0.0.1 (REELSAW_BIND to choose;
the compose template publishes on BIND_ADDRESS, or every interface when it
is unset, so existing installs keep listening as before), and LLM_TRACE as
a commented-out line. The compose template the installers write no longer
falls back to the password 'reelsaw' for Postgres: the installers always
generate one. The development compose file publishes MinIO on 127.0.0.1
only; its fallback credentials stay, since a required variable would break
compose for every profile.

installer-defaults.test.ts reads both scripts and the compose file and
fails on any of these regressing.

Signed-off-by: dillonstreator <dillonstreator@gmail.com>
No connection set a statement timeout, so a runaway query held one of the
pool's connections until it finished. Migrations run at boot took no lock
timeout: on a live database, a DDL statement queued behind a long
transaction holds every later query on that table behind it for the length
of the wait.

Every pooled connection now starts with statement_timeout from
DB_STATEMENT_TIMEOUT_SECONDS (default 300 s, 0 = never), set the same way as
idle_in_transaction_session_timeout. The migrate connection drops that bound
(waiting for another process's migration and a long index build are
legitimate), takes the migrate advisory lock, then sets lock_timeout to 10 s,
and resets both before going back to the pool. A lock timeout fails the boot
with a sentence saying what happened; the next start tries again. Historical
migrations are unchanged.

db-timeouts.test.ts checks the settings on pooled connections, that a long
statement is cancelled, and that migrate() restores the pool's settings.

Signed-off-by: dillonstreator <dillonstreator@gmail.com>
No model call set maxOutputTokens, so a degenerate answer (a loop, a
model that never stops) ran to the provider's own maximum, 64k tokens and
more for current models, and was billed for.

Every language model handed out by the registry now carries a middleware
that sets maxOutputTokens to LLM_MAX_OUTPUT_TOKENS (default 16384, 0 = off)
when a call gives none, and lowers a larger one; the model test's 8 stays.
Every step's answer is a short JSON object, far under the default. Self-
hosted servers (the compatible server, openai with OPENAI_BASE_URL) get no
ceiling: vLLM and llama.cpp refuse a max_tokens larger than the context
left after the prompt, which would fail long transcripts. The middleware
sits outside the trace, so captured calls show the limit sent.

llm-output-cap.test.ts covers the middleware against a mock model, which
providers it applies to, and the default.

Signed-off-by: dillonstreator <dillonstreator@gmail.com>
scripts/unit-tests.mjs handed its test processes the developer's whole
environment. A shell exporting ANTHROPIC_BASE_URL (empty) and
ANTHROPIC_AUTH_TOKEN, as some local tools do, failed 15 transcription and
word-timestamp tests with "baseURL must be a non-empty string"; an exported
key or base URL would be used by any test that builds a real provider, and
send it requests.

scripts/test-env.mjs drops every model-provider key, token and base URL
(ANTHROPIC_*, OPENAI_*, GOOGLE_GENERATIVE_AI_*, GROQ_*, DEEPGRAM_*,
ASSEMBLYAI_*, AI_GATEWAY_*, OPENCODE_*, LANGFUSE_*, VERCEL_OIDC_TOKEN) from
the stack-free run and names what it left out. The --stack run keeps the
environment, as the in-process stack tests may need it.

test-env.test.ts checks the filter and that unit-tests.mjs uses it.

Signed-off-by: dillonstreator <dillonstreator@gmail.com>
Signed-off-by: dillonstreator <dillonstreator@gmail.com>
@vercel

vercel Bot commented Nov 28, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
reelsaw-website Ready Ready Preview Nov 28, 2026 7:27pm UTC

Request Review

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant