`echo "$x" | grep -q PAT` under `set -o pipefail` can report "not found"
for text that IS there: grep -q exits on its first match and closes the
pipe, the writer takes SIGPIPE (141), and pipefail makes the pipeline
status 141. An `if` then takes the else branch on a successful match.
#587 found this in one file and noted it "only fires when the payload
exceeds the ~4KB pipe buffer". That is not so, and the belief is why
82 copies in 22 scripts survived. Measured today on retire-site's real
1,158-byte plan output with has()'s exact pattern, 3,000 calls each:
'DRY RUN' line 3 of 20 echo|grep -q 2/3000 false misses
'apps.conf row' line 11 of 20 echo|grep -q 2/3000 false misses
last phrase line 20 of 20 echo|grep -q 0/3000
'DRY RUN' here-string 0/3000
Rare per call, but verify makes hundreds of these calls, and the
retire-site suite went red on those two exact phrases twice this week,
passing every rerun. It is worse in a NEGATIVE check - hasnt() read a
false miss as a PASS. And several copies are not tests: deploy-hetzner.sh
exits 1 on a false miss, and the sshd drift watch would raise a false
security alert.
All 82 rewritten to `grep -q PAT <<<"$x"` (a here-string is not a
pipeline, so there is no writer to signal) by a script that only touched
the simple quoted-variable form and reported anything else. Checked: all
22 files pass `bash -n`, every file is a 1:1 line swap (82 lines), and
the 20 line-continuation sites keep the here-string before the trailing
backslash (the first draft of the rewrite got those wrong; caught in a
dry-run diff before anything was written).
#587's comment is corrected so it stops teaching the wrong threshold.
Gate: scripts/test/no-grep-q-in-a-pipe.ts ratchets it repo-wide,
including forms the rewrite skipped (e.g. "$(cmd)" | grep -q), and
self-tests that its detector still fires. Proven by restoring the
original deploy-hetzner.sh line.
Co-authored-by: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
The product, its assistant, the repo, the host and every unit on the box now
share one name. 638 files, ~3,000 mentions: UI copy, config, env keys
(FLEETCROWN_* -> LOKI_*), systemd units (fleetcrown-* -> loki-*), docs,
articles, the deploy workflow other repos reuse, and nine file names.
- Three article slugs carried the old name and had been shared; permanent
redirects keep those links alive (next.config.ts).
- test-no-retired-name.sh now also forbids the old product name across the
whole repo, so the rename cannot creep back through templates and examples.
- ASSISTANT_STACK collapses the product and the assistant into one entry,
because they are now the same name.
Infra was cut over ahead of this merge: /opt/loki, loki-* units, the `loki`
database and role, loki.orangecat.ch (old host 308s to it; /api, /widget,
/embed keep proxying), GitHub repos bitbaum/loki and bitbaum/loki-releases.
The Resend sending domain stays fleetcrown.orangecat.ch until the new domain
is verified in DNS.
Claude-Session: https://claude.ai/code/session_016YJVAanfj8keVSXyZnTemh
Co-authored-by: Claude Fable 5.1 <noreply@anthropic.com>
The first site the fleet created without a human at a terminal. Dispatched as a
`hosted_new_site` command (#598), claimed by the hosted runner 0.75 s later,
executed in 37 s with ok:true: repo bitbaum/factory-sep11-0040, Caddy vhost,
release 20260911-003309-c9d257c, unit factory-sep11-0040-app active, and the
promoted day-zero page served on :4029.
The register row it appended did not survive. The runner was pointed at
/opt/fleetcrown/app/scripts/hetzner/new-site.sh — Next's standalone output,
which deploy-hetzner.sh rsyncs with --delete on every ship. The vhost was
written at 00:32:53; app/ was re-synced at 00:34:12; the row was gone. A site
running on the box with no register entry is the camille failure again, eight
days of it compressed into eighty seconds. This restores the row by hand and
records what the runner should have been able to keep.
Also ships scripts/new-site-dispatch.ts to the runner: deploy-hetzner.sh syncs an
explicit list of scripts into /opt/fleetcrown/runner and the dispatch CLI was
not on it, so the only way to enqueue a site from the box was to copy the file
there by hand — which is how this one was enqueued.
Gates: test-port-alloc (6), test-register-reality (10), check-client-ledger
(demo kind, no terms owed) all pass with the row.
Claude-Session: https://claude.ai/code/session_018Z7YRpgsEtNjRqr1usHMQY
Co-authored-by: Claude Fable 5.1 <noreply@anthropic.com>
fleetcrown-reindex has been dying every night at 03:30 on
`Cannot find module 'bip-kit'` — imported via src/lib/thoughts-content.ts.
The module is not the bug. The bug is that the deploy re-syncs the runner's
src/ on every ship and has never once shipped its manifest.
/opt/fleetcrown/runner/package.json is a snapshot from original provisioning:
31 dependencies, no bip-kit. Meanwhile src/ arrives fresh every deploy. So the
moment any file under src/ gains a new import, the runner breaks at its next
run — and the deploy reports green, because nothing checks.
- package.json, package-lock.json and vendor/ now sync alongside the code.
vendor/ is part of the manifest, not an extra: package.json carries
"@orangecat/sdk": "file:vendor/...tgz", so bumping that version without
shipping the tarball fails the install for a path that exists only locally.
- When any of them actually changed, install on the box and mark the runner
changed so the new deps reach a fresh process via the existing
drain-then-restart (which waits for in-flight agents first).
- A failed install FAILS the deploy. Warn-and-continue is exactly how this
stayed invisible for weeks: the runner was broken and the pipeline was green.
Two things this must not do, both found by testing against the real box:
- NOT `npm ci`, and NOT `--omit=dev`. tsx is a devDependency and it is the
runner's own ExecStart (node_modules/.bin/tsx). `ci` deletes node_modules
wholesale, so for the duration of the install the cloud builder's runtime
does not exist; `--omit=dev` deletes it outright. Incremental install keeps
the always-on executor runnable throughout.
- HUSKY=0 is required, not cosmetic. package.json's `prepare` runs husky, the
runner dir is not a git repo, and without the opt-out npm exits 127 — which,
given the failure is now fatal, would have broken every future deploy.
Verified with a REAL install in a scratch dir on the box, not a dry-run: a
dry-run passes `prepare` vacuously because husky is never installed, so it
cannot see the 127 at all. Full install returned exit 0, "HUSKY=0 skip
install", 864 packages, with both bip-kit and tsx present — so this resolves
the reindex crash and keeps the runner alive. Scratch dir removed; box disk
unchanged at 15G free.
The box is deliberately NOT patched by hand: three visitor-feedback runs are
executing on it right now, and this deploy remediates it through the drain
path instead.
Co-authored-by: t <t@t.t>
Co-authored-by: Claude Opus 5 <noreply@anthropic.com>
Merge→live measured 14–27 minutes. The irreducible work in that window is
about 80 seconds: build 66s, rsync 4s, restart 4s, verify 7s. Nearly all
of the rest was waiting, so nearly all of the fix is removing waits
rather than making anything faster.
Two waits, measured:
1. The runner drain, 480 of the ship step's 570 seconds. The deploy
watched one in-flight agent, then restarted anyway at the cap. The
web app had been live and verified for eight of those minutes. Two
systems with opposite needs were sharing one job's wall-clock — the
app wants to be live now, the runner wants to not kill anyone's work
— and the runner won every time.
A shorter timeout would only kill agents sooner. The wait itself is
fine; the place it happened is what cost. Waiting is expensive in CI
and free on the box, so it now happens on the box: the deploy
schedules a detached systemd-run unit and returns as soon as the app
is verified. The drain gets *longer* (1800s, not 480) and cheaper at
the same time, because nothing is holding a runner open for it.
2. The CD reconciler, up to 10 minutes and 18.6 of #284's 26.8. Deploy
chains off CI via workflow_run, which never fires for a CI run that
GITHUB_TOKEN started — i.e. for every auto-merged PR, the only path
that merges code here. The sweep covered that by reconciling on its
next tick: correct, self-healing, and late.
A dispatch is not a push, so it is not subject to the no-cascade
rule. ci.yml now dispatches Deploy itself the moment main goes green.
The sweep keeps its reconciler as the safety net, which is the right
shape for "did something get missed?" and the wrong one for "did
something just happen?".
Also caches .next/cache across deploys — the build is the one part of
this that is genuinely work, so it is the one part worth shrinking.
Not done, and worth saying: I thought CI and Deploy each built the app,
so the tested artifact was never the shipped one. That was wrong. ci.yml
deliberately skips `next build` because App-Router pages query Postgres
during pre-render; the build happens once, in Deploy. There was no
discarded build and no artifact to pass.
The decoupling has a test, and it asserts the property rather than the
patch: the deploy must not block on a drain, the restart must be
detached, the script must be shipped before it is invoked, and the drain
must stay bounded. Verified the first two assertions fail against the
previous version (4 blocking markers, 0 systemd-run) rather than merely
passing against this one.
Co-authored-by: t <t@t.t>
Co-authored-by: Claude Opus 5 <noreply@anthropic.com>
#289 fixed the command that killed three deploys with no output. This is
about the ten seconds it took to see that, versus the investigation it
actually took.
deploy-hetzner.sh runs under `set -euo pipefail` and several of its commands
redirect both streams to /dev/null, because they are questions about the box
rather than steps of the deploy. When one of those exits non-zero the script
dies where it stands, and the operator's entire trace is:
→ deploy FAILED (exit 1): 6b6cff0 — see /tmp/push-deploy-fleetcrown.log
That names the commit, and points at a log file which — in CI, where this
failed — lives on a runner that no longer exists. It does not name the step,
so the only way to find the dead command was to read the script and reason
about which line between the last successful echo and the trap could exit 1
without printing. That is the diagnosis this line should have handed over.
DEPLOY_STEP names the current phase and the failure message carries it:
→ deploy FAILED (exit 1) during [reading the live build marker]: 6b6cff0
Four phases are marked — the two gates, the marker read, and the rsync. The
helper is a bare assignment to a variable: no subshell, no pipeline, no
substitution, nothing `set -e` can trip over. A diagnostic that can fail the
thing it diagnoses would be a liability, which is the same lesson #289 landed.
Tests assert the property rather than the edit, and both were verified to FAIL
against the broken shape: dropping ${DEPLOY_STEP} from the message, and adding
a phase without a step() call before it. The first assertion I wrote passed
against a COMMENT quoting the old message — so it now skips comment lines,
because a test that matches prose lets the real line drift while staying green.
Co-authored-by: t <t@t.t>
Co-authored-by: Claude Opus 5 <noreply@anthropic.com>
My own regression, shipped in #285 and broken within minutes: deploys
of 15faf227 and 6b6cff07 both failed, silently, with no output between
"✓ table ownership reconciled" and the error.
deploy-hetzner.sh runs under `set -euo pipefail`. Reading the box's
build-ref marker is a QUESTION, not a step of the deploy — but written
as a bare pipeline it behaves like one: if the marker is absent `cat`
exits 1, `pipefail` propagates that through the substitution, and
`set -e` kills the script. The guard that would have explained itself
never got to run, so the deploy died with nothing printed at all.
`|| true` on both sides — the remote command and the local
substitution — turns an unanswerable question back into an answer of
"don't know". check-not-behind.sh already treats an empty marker as
"cannot tell, ship anyway", which is the correct behaviour and was
never reached.
The lesson is the one the gate itself is built on: a check that can
fail closed on its own plumbing is worse than no check. It must be
impossible for this guard to stop a deploy for any reason other than
an actual backwards ship.
Three tests, since asserting the fix is not the same as asserting the
property: the real line must stay `|| true`-guarded (verified this
assertion fails against the broken version rather than merely passing
against the fixed one), the shape must survive a non-zero read under
`set -euo pipefail`, and an empty marker must reach the ship-anyway
path rather than the refusal.
Co-authored-by: t <t@t.t>
Co-authored-by: Claude Opus 5 <noreply@anthropic.com>
Production was rolled back today and self-healed before anyone looked.
CI shipped main at 09:47 and verified it live at 09:48 — the deploy log
says "live build is fe9395b950 — the commit this deploy shipped". Ten
minutes later /opt/fleetcrown/app was overwritten with a tree ~25
commits old, and for the next ten minutes production served the
previous day's code, including a health endpoint too old to report
which commit it was running. The next unrelated deploy quietly put main
back.
check-deploy-ref.sh was supposed to have ended this class, and it
cannot: it asks "are you on main?", which every commit that ever landed
on main answers yes to, forever. A checkout sitting on last week's main
walks straight through it. The build-ref marker added in #279 makes the
damage visible after the fact, which is how this was found, but nothing
made it impossible.
So gate on the direction of the move instead of the name of the branch:
the commit currently live must be an ANCESTOR of the commit being
shipped, i.e. a deploy may only ever add history. An older commit, or a
sideways jump onto unrelated history, is refused with the two subjects
printed and the fix spelled out. ALLOW_ROLLBACK=1 is the override, so a
deliberate rollback is one word, not a workaround.
Undecidable cases warn and allow on purpose — no marker on the box, a
SHA this checkout has not fetched. This gate must never be the reason a
box that is already broken cannot be repaired.
The gate is its own script rather than a branch inside deploy-hetzner.sh
so it can be tested without deploying anything: ten cases over throwaway
git repos, covering the exact regression, the fast-forward it must not
slow down, the override, and every undecidable path.
Co-authored-by: t <t@t.t>
Co-authored-by: Claude Opus 5 <noreply@anthropic.com>
Two flaws in #279, found before its deploy ran.
1. The stamp preferred GITHUB_SHA over the checked-out commit. deploy.yml's
workflow_run path checks out `workflow_run.head_sha`, which is not always the
run's GITHUB_SHA, so the marker could name a commit that was never compiled.
Since the deploy compares the live marker against the shipped ref, a lying
marker manufactures a false alarm. Git HEAD is literally what was built, so
it now comes first; GITHUB_SHA is the last resort for checkouts with no .git.
2. A mismatch rolled the box back. The realistic cause of a mismatch is a second
deploy landing behind this one — and reverting to app.prev would discard the
NEWER build, turning a benign race into exactly the incident the check exists
to catch. It now reports loudly and leaves the running build alone. What was
missing before was never the ability to revert; it was ever being TOLD that
the box serves something else. That, plus /api/health, is the fix.
Both are pinned by tests, including one asserting the mismatch path does not
call rollback_box.
Co-authored-by: t <t@t.t>
Co-authored-by: Claude Opus 5 <noreply@anthropic.com>
/api/health advertised a `version` field that is `npm_package_version` — always
null under systemd — and the box kept no deploy marker anywhere. The only way to
answer "is prod on main?" was to ssh in and grep the compiled bundle for a symbol
you knew was in the new source.
That is not cosmetic. A hand-run `npm run deploy` ships whatever branch the
worktree is on, and it has now rolled production back three times. The third was
today, 14:19 UTC, WITH the off-main gate in place — that gate requires the commit
to be *contained in* origin/main, and an ancestor passes it cleanly. Both `app`
and `app.prev` were rotated to the stale build, so the correct CI build was
destroyed, and the fix from #275 was live at 12:40 and gone by 14:20. It surfaced
only because a live probe of /api/control disagreed with the database, and it
cost about fifteen commands to pin down. Every previous occurrence presented the
same way: a fix demonstrably on main, missing at runtime, indistinguishable from
an application bug.
Now the artifact carries its own identity:
- scripts/record-build-ref.sh stamps the commit into .next/standalone at BUILD
time — one writer, so the marker rides both deploy paths (the local script and
the Deploy workflow, which builds the same way then ships with --no-build).
Best-effort: an unresolvable commit degrades to `commit: null`, never a guess,
and never a failed build.
- /api/health reports it, so `curl .../api/health` answers the question.
- The deploy reads the commit back OFF THE LIVE BOX and rolls back if it differs
from what was just shipped. Health returning 200 proves the box is up, not
that it is up on this build — which is precisely how a clobbered deploy passed
verification three times.
scripts/test/build-ref-marker.ts covers the whole chain (stamp → artifact →
health → deploy assertion), because every link is deploy-time-only code, the
kind that rots unnoticed until the incident.
Co-authored-by: t <t@t.t>
Co-authored-by: Claude Opus 5 <noreply@anthropic.com>
* fix(loki,deploy): the approval queue survives a Groq outage; deploys can't ship off-main
"What is pending for approval?" answered "Not in your data." in production while
drafts were waiting. Two independent causes, both fixed here.
1. A hand-run deploy shipped a feature branch to the box — twice, minutes
apart — rotating the correct CI build out through app.prev and reverting
three merged PRs. Prod served a Loki with no approval-queue tool while main
had shipped it hours earlier. The symptom was indistinguishable from an
application bug and was chased through the app first.
scripts/ci/check-deploy-ref.sh now refuses any deploy whose commit is not
contained in origin/main, naming both the unreviewed commits and the ones it
would roll back. Override is explicit and announces itself. deploy-hetzner.sh
calls it before the schema step, so a refusal leaves the box untouched.
The existing --ref guard only ever covered HEAD drift DURING a build; this is
the invariant that was missing. Second occurrence of this class — see the
comment it replaces.
2. Even on the right build the answer was wrong, because the queue was reachable
ONLY by tool call. Groq's org-wide TPM window is exhausted: both the 70B and
the 8B step-down 429 on every call, the bounded retry expires, the tool loop
dies, and Loki answers from seed facts on a TOOLLESS fallback model — which
cannot see a tool-only table, so it truthfully reports nothing.
pendingApprovalFacts() moves to sources.ts and is seeded into the grounded
context on an approval cue, so the question is answerable with the tool loop
entirely unavailable. The tool now calls the same function: one definition,
both paths. Approvals lead the fact list — the seed is head-sliced, so the
subject of the turn must not sit in the tail.
Tests: deploy-ref-gate.sh (7) covers the incident shape directly — an off-main
branch is refused, an ancestor of main is not. approval-cues.ts (24) pins the
cue against the operator's real phrasings, including the typo from the report,
because a missed cue is silent and reads as a truthful "nothing is pending".
Also folds the duplicated dateLabel (handlers.ts + an inline copy in sources.ts)
into one exported helper.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
* fix(loki): drop the now-unused getPendingActions import
The tool handler delegates to pendingApprovalFacts, so the direct query import
is dead. tsc does not flag unused imports; eslint does.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
---------
Co-authored-by: test <test@test>
Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com>
The terminal knew a tab was called "Tab #1" and nothing else. The runner has
been pushing full pane topology (tab, cwd, agentCli) in every runtime snapshot
all along; nothing joined it to the tab strip. Now /api/terminal/context does:
- Tab strip shows the resolved project name plus a badge naming the agent CLI
actually running in that tab ("claude", "grok", "claude+codex"). Tab→project
resolves by name first, then by pane cwd prefix against a project's dirPath —
which also recovers `dir` for generically named tabs, un-breaking the agent
switcher there.
- Empty state can start an agent instead of only telling you to go elsewhere.
TerminalLaunch reuses /api/agent/launch with the same eligibility rule as
Control (projects with a linked directory) and pins the builder channel you
are looking at, so the session appears on the terminal you started it from.
- A ?tab=X deep link that matches no live session says so, instead of silently
showing Tab #1 and letting you type into the wrong agent.
- box-runner reads its version from desktop/package.json (the code it actually
runs). The systemd unit pinned box-0.8.9 across three releases, so Settings
reported a version the box was not running. Env demoted to fallback; deploy
ships desktop/package.json alongside the modules.
Co-authored-by: test <test@test>
Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
git_head returns a full 40-char SHA, so passing a short SHA to --ref
always failed the literal HEAD compare and skipped the deploy even when
the tree was on exactly that commit. Resolve the ref once at parse time;
the guard compare and FLEETCROWN_DEPLOY_REF passthrough work unchanged.
Co-authored-by: test <test@test>
Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
Every deploy from a de_CH.UTF-8 laptop aborted at the schema-drift step with
"comm: input is not in sorted order" (exit 1) — even when the box schema was
perfectly in sync (verified: 0 missing tables/columns). glibc UTF-8 locales
order some `table.column` strings inconsistently, so `sort` produced output that
`comm` (same locale) then rejected as unsorted. Under `set -euo pipefail` that
killed the whole deploy script before the event-bridge sync ran — the app was
already live, so it looked "deployed" while silently skipping later steps.
Pin LC_ALL=C on all four sorts and both comms in the block: byte-order collation
is deterministic and self-consistent between sort and comm. Reproduced the
failure against the real box (550 declared / 552 box columns) and confirmed the
fix clears it. bash -n clean.
Tier-3 schema tooling. Two coupled fixes so a schema change no longer
means hand-writing DDL (the reflex that caused the box-ownership rollbacks):
1. `npm run db:generate` works again. drizzle/meta had no snapshots, so
generate couldn't diff — new migrations were hand-numbered by hand.
Reconstructed the current-schema snapshot (meta/0039_snapshot.json) and
aligned the journal idx (1..39, was 0..38, which collided at 0039).
Proven: baseline diff is empty; adding a column emits exactly
`0040_*.sql` with the right ALTER; clean revert. This is pure local
tooling — apply-schema.sh is filename-based and ignores meta, so zero
prod-deploy risk.
2. Deploy self-heals table ownership. apply-schema.sh (shared infra) runs
DDL as the postgres superuser, so a migrated table would be owned by
postgres and invisible to the fleetcrown app role — the class that
rolled back deploys. An idempotent reassignment now runs after the
schema step: on a healthy box it touches zero tables; it hands any
postgres-owned object to the app role before the drift-check. Verified
live: it found + fixed 1 real mis-owned table on the box, then re-ran
to 0 (idempotent).
Flow now: edit schema → `npm run db:generate` → review 0040_*.sql →
commit → deploy applies it (forward-only) and reconciles ownership.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Until now Hermes only ran as an automatic offline-fallback; there was no way to
say 'run this on Hermes on purpose.' This CLI resolves a project's git URL and
enqueues a hosted_dispatch that the timer drains → clone → Hermes → PR. Synced
to the runner dir on deploy.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
The hosted Hermes path (inject-core auto-routes offline coding dispatches →
scripts/hosted-runner.ts → runHermesTask, drained by fleetcrown-hosted-runner.timer)
ran with zero Activity visibility: successes went only to console + the project
dev log, failures went to console ALONE. 'Is Hermes being used' required DB
archaeology.
- Instrument the path into orchestration_events (the SSOT Activity already reads):
producer marks the offline→hosted routing (source=hosted-runner, adapter=hermes,
deduped by command id); consumer emits task_started/task_completed/task_failed
for both hosted_dispatch (Hermes) and hosted_analyze, attributing the real
executor. Adapter recorded via a localized "hermes" as AdapterId cast — the same
pattern close-sweep already uses for adapters outside ORCHESTRATION_ADAPTER_IDS.
- Fix failure-invisibility: hosted failures now also append to the project dev log,
not just console.
- Reconcile the stale agents/index.ts comment: it claimed runHermesTask is unwired
and the CLI 'isn't installed anywhere' — both false. Interactive adapter is parked
(out of ALL_ADAPTERS by design); the HOSTED executor is wired + installed (box
v0.17.0). Distinguish the two clearly.
- deploy: sync scripts/hosted-runner.ts to the runner dir (the timer runs it there;
it was never being updated on deploy).
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Every deploy unconditionally restarted fleetcrown-box-runner, whose systemd
cgroup includes any claude/hermes the runner launched for a live dispatch —
so an app-only deploy silently killed running agent work (an AI-review run
died this way; I hand-checked 'any in-flight runs?' before ~6 deploys this
session to work around it). Two guards:
- Skip the restart entirely when no runner code changed (src/desktop/home/
box-runner scripts/tsconfig) — detected via rsync -i itemize. Most deploys
touch only the app, so this alone ends the needless kills.
- When runner code DID change, drain first: poll the runner cgroup for
claude/hermes/codex/cursor-agent/grok processes and wait (cap 8min,
FLEETCROWN_RUNNER_DRAIN_SECS) for them to finish before restarting. Idle
runner drains instantly (cgroup holds only its 2 node procs). Best-effort,
never fails the deploy; restarts anyway on timeout so a real fix still lands.
Verified: drain detection returns 0 against the live idle box.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Journal is what drizzle-kit generate orders against; the box schema history
(public._deploy_schema_history, applied by scripts/hetzner/apply-schema.sh)
is untouched. Regenerated via bootstrap-migration-ledger.ts --write-journal.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Four DevOps hardening pieces (A+ run):
- ci-gate.sh + hook template: push-deploys WAIT for GitHub CI on the pushed
commit and are BLOCKED on red — prod only receives what CI verified
(was: deploy raced CI; only bypassable local hooks gated prod).
- deploy.sh: releases layout — /opt/<name>/releases/<ts>-<sha> + atomic
app-symlink swap (units unchanged), shared/{.env,launch.sh}, keep-3 prune,
AUTO-ROLLBACK on failed health check. Legacy dirs migrate in place.
- rollback.sh: one-command flip to previous/named release + restart + health.
- apply-schema.sh: prisma branch (prisma migrate deploy when prisma/migrations
exists) — covers aoz/datacat (tracked) + reparaturbonus/solon (baselined +
resolved on prod today).
- deploy-hetzner.sh: fleetcrown itself now schema-gates via the shared applier
(39-file set; drizzle journal desync documented in-line — number new
migrations by hand 0040+ until reconciled).
Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Final audit wave (three fix agents died at the session limit mid-flight;
completed by hand):
- box-workspace: token no longer embedded in remote URLs — auth moves to a
per-invocation http.extraheader (actions/checkout pattern) and legacy
embedded credentials are scrubbed from origin on every workspace prep
- ORCH_STATE keyed constants adopted at every raw run-state literal
(dispatch-status, activity-status, presenters, run route writes,
inject-core, openclaw execution, queries incl. the SQL literal)
- lib/palette.ts: single JS mirror of the design tokens for contexts that
cannot read CSS vars (satori OG x3, email HTML, themeColor, xterm base,
mermaid fallbacks, brand-mark) — zero rendered values changed
- HTTP/EXEC timeout tiers in constants/time.ts adopted across LLM and
subprocess callers; widget polls join REFRESH_CADENCE
- scripts: Hetzner IP exists exactly once (hetzner/_box-env.sh); all
15 scripts source it (bash -n clean, heredoc output byte-identical)
- storage keys centralized in brand-storage (values unchanged);
ControlDispatchButton's dead 'control:prefill' write replaced with the
real ?focus= deep-link; investors copy no longer hardcodes a fleet count;
bare exhaustive-deps disables annotated
Not done, deliberately: public-git-history rewrite — the GitHub account ID
(41178744) links the old and new handles regardless of history, so a
3-repo force-push would break the live fleet for cosmetic-only gain; real
pseudonymity requires a fresh account (operator decision, see AUDIT_REPORT).
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Three improvement-loop roadmap goals:
1. Deploy on origin/main + rollback/alert: deploy_alert() pings the operator on
Telegram when a ship fails or rolls back (silent broken ships + silent
rollbacks left the box in an unknown state). Schema-drift now rolls back +
alerts too. Auto-rollback already existed. (Auto-applying prod schema stays a
deliberate manual step — the loud gate + rollback is safer than auto-DDL.)
2. Runner stall: auto-recovery & alerting: new check-runner-stall cron (every
30m) runs getRunnerExecutionStall per autopilot user; on a stall it reclaims
stuck claims (safe re-dispatch), raises one deduped in-app alert
(insertActiveAlertOnce), and pings Telegram. Detection already existed but
only ran when a human loaded /control — now it's on the clock.
3. One context assembler: close the cloud-orchestration bypass — Control's
dispatch / Next-best path enqueued renderTaskForAdapter() raw, with no exit
contract, so box agents finished work, wrote no handoff, and were reaped as
timeouts. Append the same exit contract inject-prompt.ts uses so every
dispatch path lands a session handoff.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_016g8LdPdzoEbVwQ1SdYW5RY
A deploy wedged for 15+ min at 'rsync standalone → box': 0 bytes/s, box fully
reachable — a dead TCP channel that never timed out. The restart-ssh already had
ServerAlive guards (after a documented 47-min hang); the rsync calls did not.
Add `-e "ssh -o ConnectTimeout=10 -o ServerAliveInterval=15 -o ServerAliveCountMax=6"`
to the standalone, bridge, and runner rsyncs so a silent connection drops after
~90s and the deploy can be rerun instead of hanging past every downstream timeout.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_016g8LdPdzoEbVwQ1SdYW5RY
- deploy-hetzner.sh: sync scripts/reindex-knowledge.ts to the box runner so the
nightly fleetcrown-reindex uses current (dossier-aware) code — it was pinned to
a 2026-06-25 copy while src/ shipped daily, so project_profile embeddings never
picked up the richer shared-dossier text.
- deploy-hetzner.sh: poll /sign-in for readiness (up to 20s) instead of one
immediate curl, so a slow-to-stop old Next process no longer rolls back a build
that is actually fine.
- systemd units (box-units + sync-infra): TimeoutStopSec=15 + KillMode=mixed so a
`systemctl restart` can't block on Next draining keep-alive connections.
- authenticated-smoke: add SH01–SH09 share-lifecycle probes (create → public
render → update → revoke → public 404 → clean), non-destructive on already-
shared projects. Validated green against production.
- CLAUDE.md: note the per-project dossier + shareable public link.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
The stronger version of the blast-radius fix, beyond the InaccessiblePaths
drop-in: run the box-runner as an unprivileged `fcrunner` that owns only its own
dir instead of `ubuntu` (which owns every app's files).
- scripts/hetzner/migrate-box-runner-to-fcrunner.sh: creates fcrunner, copies the
agent runtime (.claude auth + credentials.json, the claude CLI in .local, .npm,
.gitconfig, runner token) from /home/ubuntu → /home/fcrunner (NOT .ssh), chowns
the runner dir, and installs a systemd drop-in (User=fcrunner + HOME/PATH
repointed + InaccessiblePaths hiding ALL of /home/ubuntu and every co-tenant
/opt/<app>). --dry-run / --revert. Idempotent. Prints the claude-auth
verification + creds-copy fallback.
- deploy-hetzner.sh + install-box-runner.sh now honor FLEETCROWN_RUNNER_OWNER
(default ubuntu, so no change until you migrate) — otherwise the per-deploy
runner chown would silently revert ownership to ubuntu.
- Apply guide updated with the migration steps + the coupling reminder.
Still NOT applied. bash -n clean; dry-run verified against the box.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Addresses the DevOps panel's release-engineering findings on scripts/deploy-hetzner.sh:
- flock(1) serialization around the whole deploy — two near-simultaneous main
pushes each background a deploy; without a lock both run `next build` in the
shared .next and collide ("Another next build process is already running"),
and the older ref could win. Blocking lock (-w 900) serializes so the newest
ref ships last; every step is idempotent so waiting is always safe.
- Rollback: snapshot the current box build to app.prev (excl. backups) before
rsync; if the restart or post-deploy verification fails, restore app.prev and
restart — a broken ship no longer strands the box.
- Deploy-result sink: a trap on EXIT reports every outcome (success/failure) as
a final status line, a desktop notification, and a row in the box debug_logs
(source=deploy) so a failed background deploy surfaces on /system instead of
dying silently in /tmp with an exit code nobody reads.
bash -n clean; flock confirmed present. Not triggered against prod (would ship).
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Claude Code writes live per-PID status to ~/.claude/sessions/<pid>.json
(status idle|working, cwd). Three fixes hang off it:
- Dispatch verify: isPtyBusy was fooled by boot-screen redraw — on a
fresh clone the trust-folder dialog ate the injected paste and six
agents were acked 'launched + injected' while idle at an empty
composer. waitForAgentGenerating() now polls the CLI's own status
(fallback to isPtyBusy for agents without live status files) and
re-injects once when verifiably idle.
- Pusher lifecycle: readFastState synthesizes the direct_terminal
observation from live status, so headless PTY agents mid-task read
as Working instead of 'process detected, no lifecycle signal'
(the producer the presenter test always described but nothing built).
- Deploy hardening: the restart ssh runs under timeout 180 +
keep-alives after hanging 47 minutes post-restart and freezing the
deploy before verification and the runner sync.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Browser-first onboarding and executor-copy SSOT; Loki imperatives and move-forward
route to the same builder queue as Control with cloud-first Terminal links; fleet-kick
queues when offline; deploy script syncs box-runner.
Co-authored-by: Cursor <cursoragent@cursor.com>
The pinned-deploy guard protected the box but not local. deploy-hetzner.sh
--ref checks HEAD==REF after the build and aborts the BOX rsync on drift — but
`npm run build`'s postbuild (deploy-local.sh) had already restarted the LOCAL
systemd service with the just-built (possibly torn) standalone. So a `git
checkout` mid-build left local prod on a torn tree even though the box was safe,
and the "not shipping a torn tree" abort message was misleading.
Fix: deploy-hetzner.sh exports FLEETCROWN_DEPLOY_REF into the build env;
deploy-local.sh skips the local restart when that's set and HEAD has drifted
from it. Now a mid-build branch switch restarts nothing — local and box
consistent — and the abort message says so. (Root cause was running git ops
during a backgrounded deploy; the guard is now airtight against it on both ends.)
bash -n clean on both scripts.
Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
The push-deploy hook backgrounds the box deploy with `sleep 5 & disown`, then
deploy-hetzner ran `npm run build` on the floating working tree. If you switched
branches in that window, it built+shipped the WRONG ref — it once shipped an
off-main feature branch to the production box.
The hook now captures HEAD at push time and passes it as --ref. deploy-hetzner
guards on it: build only when the working tree is STILL on that commit, and
re-check HEAD after the build so a switch mid-build can't ship a torn tree; on
drift it skips loudly with recovery instructions rather than shipping wrong code.
(An isolated git worktree would auto-recover the right ref, but Turbopack rejects
an out-of-root node_modules symlink, so we guard in-place instead.)
Verified: --ref to a non-HEAD sha skips before building (exit 1, no box touch);
matching ref takes the unchanged build+rsync+verify path.
Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
The pre-push schema-drift guard (#16) runs against the LAPTOP database, but the
Hetzner box has its own Postgres — so a table added in code but never pushed to
the box would silently 500 the first feature that queries it on prod (the same
failure that took down /prompts, /loki and System cron locally). deploy-hetzner
had no schema step at all.
- check-schema-drift.ts gains a `--print` mode: emit the schema-declared table
names (no DB needed) so a remote deploy can compare against a database the
laptop can't reach directly.
- deploy-hetzner.sh post-deploy verification now prints the declared tables,
fetches the box's public tables over ssh (box reads its own DATABASE_URL),
diffs them, and fails LOUDLY listing any missing — telling the operator to run
drizzle-kit push rather than trusting a half-broken deploy.
Verified on a live deploy: "✓ schema: all 45 declared tables present on box".
Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Make the recurring silent-failure class loud and fast instead of
user-reported days later (the X-login saga). Additive hardening, no
rewrite of working auth.
- src/lib/env.ts: boot-time config sanity check — flags missing/whitespace-
corrupted secrets (the \n-corruption incident), half-set provider key pairs
(the X-saga shape), and prod email/URL gaps. Logged at boot via
instrumentation.ts; surfaced in /api/health.
- /api/health: returns 503 when env has a fatal/error issue (deploy + smoke
go red); detailed issues gated behind CRON_SECRET.
- deploy-hetzner.sh: post-deploy verification asserts /sign-in 200, env health
200, and that github/google/x-1a/email-password are actually mounted —
fails the deploy loudly otherwise. This is the guard that would have caught
the X provider silently un-mounting.
- x-oauth1.ts: ticket signing now trims AUTH_SECRET and throws if empty (no
forgeable empty-key tickets, no silent \n mismatch).
- email.ts: every send logs success/failure to debug_logs (answerable 'did
the reset email go out?').
- auth.ts: GitHub provider conditionally mounted like Google/X.
Verified live: deploy self-verification passed; /api/health env clean (0 issues).
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
- swap dead fleetcrown.vercel.app for fleetcrown.orangecat.ch across src/,
desktop/, README (Vercel team blocked for fair-use; serving 402s)
- scripts/deploy-hetzner.sh: build + rsync standalone + restart the
fleetcrown-app unit on the bitbaum box (Caddy already vhosts the domain)
- brand.ts APP_DOMAIN remains the SSOT; historical thoughts essays keep the
old domain as written
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>