Files
CatoandClaude Fable 5.2 54a7024cdc fix(queue, runs, chat, ops): an idle run is closed before the next task starts; a blocked pull request is said in the thread; an address to Loki is not the loki project; the builder can be given a memory ceiling (#1678)
* fix(check): the on-demand loop check signs in on the box, and is red when it cannot ask

The first run of loki-loop-check.yml (2026-11-12, run 43188095136) printed
"down: loki e2e could not mint a session on the box" two seconds in, and
the job was green. Three things were wrong:

- The deploy ships the runner a fixed list of scripts and nothing under
  scripts/test, so on the box there was no test to run and no token
  script. The workflow now carries the check's own files with it.
- The check minted an Auth.js session cookie. Sign-in moved to AccountKit
  on 2026-11-01, where that cookie is no session. It now signs in the way
  a runner does: scripts/test/mint-check-token.ts mints an agent token for
  the operator that expires in two hours, the check uses it as a bearer
  and removes it on exit. The cookie mint stays as the fallback.
- A check that could not sign in exited 0. With the verdict asked for, it
  exits 1, and it says why (long strings masked).

scripts/test/loop-check-signs-in.ts pins all of it.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_019MDtmt4p1jMfJnbJtpeNhi

* docs(handoff): what production showed after the first fix, and why the check could not sign in

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_019MDtmt4p1jMfJnbJtpeNhi

* fix(check): the loop check prints Loki's own reason for a task that does not start

Its first full run on the live site (2026-11-12, run 43191224470) ended
"still queued (Queued) after 35 min" and then guessed at the builder's
sign-in. The run route already answers the track's sentence for an open
run (detail), and the chat's reply says where the task went: the check
prints both, right after the dispatch and again when it gives up.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_019MDtmt4p1jMfJnbJtpeNhi

* docs(handoff): the first full check on the live site, 4 of 5

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_019MDtmt4p1jMfJnbJtpeNhi

* docs(handoff): why the probe did not start, in Loki's own words

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_019MDtmt4p1jMfJnbJtpeNhi

* fix(chat): an address to Loki is not the loki project; the loop check reaches the project it was sent to

A project named in a message outranks the selected project, on purpose
(lib/loki-fleet-commands). The assistant is called Loki and so is one of
the projects, so "Loki, add a dark mode toggle" typed with orangecat
selected was sent to the loki project.

Found through the loop check on the live site (2026-11-12, run
43198552471): asked for project orangecat, it came back "Sent loki to the
cloud runner", because its marker was "[loki-e2e]". Three runs in a row
had waited behind the loki project's open run while reporting on a
project the probe never reached.

- project-mention: withoutAddressTo removes an address to the assistant
  before matching: the name at the start followed by punctuation, after a
  greeting, "@loki", or set off by a comma at the end. "Loki's sidebar",
  "in loki" and a bare "Loki fix the header" still name the project.
- loki-loop-e2e: the marker is "[e2e-probe]" and names no project, and the
  check fails at once when Loki dispatched to another project than the
  one it asked for.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_019MDtmt4p1jMfJnbJtpeNhi

* docs(handoff): the probe had been going to the loki project; the routing fix

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_019MDtmt4p1jMfJnbJtpeNhi

* fix(queue): a run that has gone silent gives its project to the waiting message

A project's shared session takes one message at a time: the claim gate holds
the next one until the run ahead has closed. A run closes when its agent
reports. An agent that ended its turn without reporting still has a process
at its prompt, and the reaper shelters a run with a live process for up to
MAX_RUN_HOURS, so the next message could wait twelve hours behind a session
that was doing nothing. On the live site (2026-11-12) messages sent through
Loki's chat read "This project is still on an earlier task" and were still
queued 25 to 35 minutes later.

- lib/orchestration/quiet-lane: the rule, pure. The runner beats while the
  terminal prints and while the agent waits at a sign-in or an approval. No
  beat for 20 minutes (twice the window after which every surface says
  Stalled), not waiting for a person, no command outstanding, and still so
  90 seconds after it was first seen: release. The second look covers a
  runner that could not beat for a while and whose first request back is
  the claim.
- db/queries/quiet-lane: reads those facts for the run at the head of each
  lane a message waits in, through olderOpenRunSql, and closes it with the
  reaper's own verdict (partial with the handoff note, else timeout with the
  sentence), ended at its last beat. No escalation.
- claimNextPendingCommand calls it before the gate, so the message is
  claimed in the request that closed the run.
- The waiting sentence carries the bound.

A working agent prints, so its beat is seconds old at any age and it keeps
its lane. Nothing is closed when nobody is waiting.

scripts/test/quiet-lane.ts, and five scenarios in
scripts/test/lane-and-reaper.ts against a real Postgres (13 of 13 locally).

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_019MDtmt4p1jMfJnbJtpeNhi

* fix(runs): a pull request that cannot merge is said in the thread, with the message that repairs it

The fleet's sweep merges a green pull request and leaves a red or conflicted
one waiting. A task sent from the chat that ended at such a pull request read
"done, it merges on its own" until somebody opened GitHub.

- feedback/fix-shipping: PrBlocker, prBlockerFor (a conflict when GitHub says
  mergeable: false, else the names of the checks that failed; cancelled and
  still-running are not failures), prBlockerNews (once per commit and reason).
- feedback/fix-shipping-refresh: readBlockers on the refresh input; only then
  are the head commit's check runs and statuses read.
- run-follow-notify: the fifteen-minute follower asks, and on news writes one
  line into the thread the task came from and sends one push. The line ends
  with the message to send ("<project>: fix the failing checks on <pull
  request> and push to the same branch."): a message naming a project is a
  task for it.
- Loki does not send the repair itself: no agent run nobody asked for
  (lib/auto-dispatch).

scripts/test/run-follow-notify.ts.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_019MDtmt4p1jMfJnbJtpeNhi

* docs(handoff): the 11:17 rehearsal failed on a slow box: sign-up 504, 96% memory, a 503 window

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_019MDtmt4p1jMfJnbJtpeNhi

* docs(handoff): bots do not answer on the live site (502, 11:39 UTC); OrangeCat #1672; #1678 green

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_019MDtmt4p1jMfJnbJtpeNhi

* fix(queue): only a run whose runner has reported output can be read as having stopped

A runner from before the beat existed reports nothing while its agent works.
Silence since delivery would have closed such a run after twenty minutes and
typed the waiting message into a working session. A run that has never
beaten now keeps its lane; one that truly never printed is the reaper's,
which closes it as never started from the runner's own unverified ack.

scripts/test/quiet-lane.ts, and a sixth scenario in
scripts/test/lane-and-reaper.ts (14 of 14 locally).

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_019MDtmt4p1jMfJnbJtpeNhi

* fix(ops): the box usage report prints the builder's memory budget and finishes on a slow box

On 2026-11-12 the box had 0.6 GiB available and no swap left, and the report
was cancelled at its 20-minute limit inside the first du. Each disk walk now
gets a minute. A new section prints what the runner unit holds, whether it
has a memory ceiling, and which cgroup the sandboxes' processes are in:
sandbox.ts relies on the unit's MemoryMax to bound sealed sessions.

Read-only, names and sizes only.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_019MDtmt4p1jMfJnbJtpeNhi

* docs(handoff): what holds the box's memory, measured; the builder has no ceiling

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_019MDtmt4p1jMfJnbJtpeNhi

* fix(queue): an idle run is closed before the next task starts; the runner's six-hour stop and a turn answered in seconds are read correctly

Three faults in the idle rule (#1680), found by an independent review and
shown failing first in scripts/test/lane-and-reaper.ts against main (13
passed, 4 failed; 17 of 17 after):

- An idle run stopped holding its project but stayed open until the hourly
  reaper. The next task went into the same session, and its ready handoff
  closes every delivered open run of the project, so the idle run was
  recorded as done with the other run's summary. The claim now closes the
  idle run first, with the reaper's own function and sentence, and only when
  a task is waiting in that project (db/queries/idle-run-close).
- The runner stops beating six hours into a run. Half an hour later the run
  read as idle while it printed, and the next prompt went into a working
  session. A last working beat at that horizon is not read as silence
  (RUN_PROGRESS_HORIZON_SECONDS).
- A turn that ended before the runner began reporting on it never had a
  working beat, read as unknown and held its project for up to twelve hours.
  Every beat stamps lastBeatAt; a run the runner reports on that has printed
  no work since delivery is idle after the same half hour. A run with no
  beat of any size keeps its lane, as before.

scripts/test/idle-run-release.ts, scripts/test/lane-and-reaper.ts.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_019MDtmt4p1jMfJnbJtpeNhi

* fix(ops): the box usage report can be asked for memory alone

The disk walks took the whole 20 minutes twice on 2026-11-12, on a box that
was swapping, when only the memory was wanted. what=memory stops after the
memory sections.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_019MDtmt4p1jMfJnbJtpeNhi

* feat(ops): the builder can be given a memory ceiling, read and set from the Sealed builds workflow

Measured on the box, 2026-11-12 12:19 UTC: loki-box-runner.service held 6.3
GiB with MemoryHigh and MemoryMax at infinity, every sandbox process is in
that unit's cgroup, the box had no swap left, and the kernel had stopped 30
processes for memory since boot: the gateway 15 times, a live site 3 times,
a sandbox 3 times. Every site unit has a 1G ceiling; the builder had none,
though sandbox.ts relies on the unit's MemoryMax to bound sealed sessions.

sealed-builds-ctl.sh gains three modes, run from sealed-builds.yml:
- memory: read. What the builder holds, what bounds it, what the box has left.
- memory-set, runs="<GiB>": MemoryMax and MemoryHigh one below it, and the
  builder's processes are marked to give first when the whole box runs out.
  Refused when the ceiling is below what the builder holds now, because that
  stops sessions at once; "force" after the number sets it anyway. Nothing
  is restarted.
- memory-clear: undo.

Nothing is set by a deploy. It is a decision, applied by a person.

scripts/hetzner/test-sealed-builds-memory.sh, in test:ops.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_019MDtmt4p1jMfJnbJtpeNhi

* fix(runs, chat): the blocked pull request notice is said once and its repair reaches the right project; an address to Loki is set off, and is the project when nothing else is

From the independent review of this branch, each finding confirmed by a
second agent told to refute it.

The notice:
- It would have repeated every tick. "Already said" lived in the ledger, the
  ledger is rebuilt on every refresh, and the dispatch card's own refresh
  does not read blockers. It is kept beside the ledger now
  (payload.prBlockerSaid, per reason), written once the line is in the thread.
- Its repair line named the pull request by link. The link carries the
  repository owner's name, and a project of that name won the match: the
  repair for loki went to Bitbaum. The line names the number, opens with
  "In <project>," and uses a verb the chat's own rule takes as a task, for a
  conflict as well. The test sends it through projectMentionedIn and
  looksLikeDispatchTask for four projects and both reasons.
- action_required and stale count as failed: neither turns green by waiting.

The address:
- "ok loki is broken, fix its header", "loki-loop-check is red" and "run the
  tests on @loki" lost the project; "Loki - add a toggle" kept it. An address
  is the name set off from the sentence (a comma, a colon, any dash with
  space around it, "please", "can you"), at the start of any sentence.
- "loki: fix the header" is read as an address, so a selected project gets
  the work; with nothing selected and no other project named, the name is
  the project (projectNamedByAddress, the last resort of both paths).

scripts/test/run-follow-notify.ts, scripts/test/project-mention.ts (114).

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_019MDtmt4p1jMfJnbJtpeNhi

* fix(ops): the builder's ceiling is a ceiling only; docs(handoff): the box's memory, the review's findings, what is ready and not applied

memory-set no longer sets MemoryHigh one below the ceiling: at the moment it
is set the builder holds close to the ceiling, and a mark under what it holds
would slow every session at once.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_019MDtmt4p1jMfJnbJtpeNhi

* docs(handoff): the box's memory now holds up OrangeCat merges: Browser smoke is red on main

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_019MDtmt4p1jMfJnbJtpeNhi

---------

Co-authored-by: Claude <noreply@anthropic.com>
2026-11-12 14:09:49 +01:00

177 lines
8.3 KiB
Bash
Executable File

#!/usr/bin/env bash
# What uses this box's memory and disk. READ-ONLY: it measures and prints.
# Piped to `bash -s` as root from .github/workflows/box-usage.yml (same SSH
# setup as box-doctor.yml and disk-cleanup.yml).
#
# Why it exists: on 2026-11-11 the box sat at 91-95% memory and 91-93% disk,
# both sites reset connections, CI could not sign in against production auth,
# and nothing could say WHAT was using either. disk-cleanup.sh reclaims disk;
# nothing measured memory at all.
#
# THE REPO IS PUBLIC and run logs are too. This prints sizes, counts and
# program NAMES only: `comm`, never a command line, because arguments and
# environments carry tokens. No file contents, no env, no keys.
set -uo pipefail
section() { printf '\n=== %s ===\n' "$1"; }
# On 2026-11-12 the box had 0.6 GiB available and no swap left, and this report
# was cancelled at its 20-minute limit inside the first `du`: the memory facts
# were printed, nothing after them. A disk walk on a box that is swapping can
# take longer than anyone waits, so each one gets a minute and the report goes on.
du() { timeout 60 du "$@"; }
find() { timeout 60 find "$@"; }
section "memory"
free -h
echo
awk '/MemTotal|MemAvailable|SwapTotal|SwapFree/ {printf "%s %.1f GiB\n", $1, $2/1048576}' /proc/meminfo
section "memory by program (resident, summed over its processes)"
ps -eo rss=,comm= | awk '{rss[$2]+=$1; n[$2]++} END {for (p in rss) printf "%8.0f MiB %4d proc %s\n", rss[p]/1024, n[p], p}' | sort -rn | head -25
section "memory by service: who holds it, and what bounds the builder"
# Sealed agent sessions are meant to be bounded by the runner unit's memory
# ceiling (src/lib/agent-execution/sandbox.ts says "MemoryMax still bounds
# them"). This prints whether the unit has one, what it holds now, and which
# cgroup the sandboxes' own processes are in. Names and sizes only.
for unit in loki-box-runner.service; do
systemctl show "$unit" -p MemoryCurrent -p MemorySwapCurrent -p MemoryHigh -p MemoryMax -p OOMPolicy -p OOMScoreAdjust 2>/dev/null \
| awk -F= -v u="$unit" 'BEGIN {printf "%s:", u}
$1 ~ /Current$/ && $2 ~ /^[0-9]+$/ {printf " %s=%.1fGiB", $1, $2/1073741824; next}
{printf " %s=%s", $1, $2}
END {print ""}'
done
echo
echo "sandbox processes by cgroup:"
ps -eo cgroup=,comm= 2>/dev/null | awk '$2 == "gvisor_sentry" {c[$1]++} END {for (k in c) printf "%6d %s\n", c[k], k}' | sort -rn | head -6
echo
timeout 20 systemd-cgtop -b -n 1 --order=memory --depth=3 2>/dev/null | head -16
section "agent CLIs and browsers: how many, how old"
for name in claude gemini grok cursor-agent codex chrome chromium node; do
count="$(pgrep -c -x "$name" 2>/dev/null)"
[ "${count:-0}" = "0" ] && continue
oldest="$(ps -o etimes= -C "$name" 2>/dev/null | sort -rn | head -1 | tr -d ' ')"
mib="$(ps -o rss= -C "$name" 2>/dev/null | awk '{s+=$1} END {printf "%.0f", s/1024}')"
printf '%-14s %4s processes %6s MiB oldest %s h\n' "$name" "$count" "${mib:-0}" "$(( ${oldest:-0} / 3600 ))"
done
section "out-of-memory kills since boot"
journalctl -k -b --no-pager 2>/dev/null | grep -ci 'out of memory' || true
journalctl -k -b --no-pager 2>/dev/null | grep -i 'out of memory' | sed -E 's/.*Killed process [0-9]+ \(([^)]*)\).*/\1/' | sort | uniq -c | sort -rn | head -10
section "containers: memory now"
if command -v docker >/dev/null 2>&1; then
docker stats --no-stream --format '{{.MemUsage}}\t{{.Name}}' 2>/dev/null | sort -rh | head -25
fi
# `memory` as the first argument stops here: the disk walks below took the
# whole 20 minutes on 2026-11-12, twice, when only the memory was wanted.
if [ "${1:-all}" = "memory" ]; then exit 0; fi
section "disk"
df -h / 2>/dev/null
echo
du -xsh /opt /home /var/lib/docker /var/log /root /tmp 2>/dev/null | sort -rh
section "disk: /home/ubuntu, largest"
du -xh --max-depth=1 /home/ubuntu 2>/dev/null | sort -rh | head -15
section "disk: agent workspaces"
for dir in /home/ubuntu/.loki/workspaces /home/ubuntu/dev; do
[ -d "$dir" ] || continue
total="$(du -xsh "$dir" 2>/dev/null | cut -f1)"
count="$(find "$dir" -mindepth 1 -maxdepth 1 -type d 2>/dev/null | wc -l)"
modules="$(find "$dir" -maxdepth 3 -type d -name node_modules -prune 2>/dev/null | wc -l)"
stale="$(find "$dir" -mindepth 1 -maxdepth 1 -type d -mtime +14 2>/dev/null | wc -l)"
printf '%s: %s in %s directories; %s with node_modules; %s untouched for 14 days\n' "$dir" "${total:-?}" "$count" "$modules" "$stale"
done
section "disk: /opt, largest"
du -xh --max-depth=1 /opt 2>/dev/null | sort -rh | head -20
section "disk: docker"
if command -v docker >/dev/null 2>&1; then
docker system df 2>/dev/null
echo
docker volume ls -q 2>/dev/null | while read -r v; do
path="$(docker volume inspect -f '{{.Mountpoint}}' "$v" 2>/dev/null)"
[ -n "$path" ] && printf '%s\t%s\n' "$(du -xsh "$path" 2>/dev/null | cut -f1)" "$v"
done | sort -rh | head -12
fi
section "disk: uploaded files (Supabase Storage)"
find / -xdev -type d -path '*volumes/storage*' -maxdepth 6 2>/dev/null | head -3 | while read -r d; do
printf '%s\t%s\n' "$(du -xsh "$d" 2>/dev/null | cut -f1)" "$d"
done
# One level further into the directories the first report showed were large
# but did not explain (2026-11-11: /opt/solon 18G with two releases, 22G of
# caches under /home/ubuntu, 16G of checkouts). Each listing gets a time
# budget: on a disk full of node_modules an unbounded du runs for minutes.
drill() {
local dir="$1" depth="${2:-1}" rows="${3:-12}"
[ -d "$dir" ] || return 0
section "disk: inside $dir"
timeout 90 du -xh --max-depth="$depth" "$dir" 2>/dev/null | sort -rh | head -"$rows" \
|| echo "(over 90s, skipped)"
}
drill /opt/solon 2 16
drill /opt/loki 2 16
drill /opt/kivvi 2 8
drill /opt/backups 2 8
drill /home/ubuntu/.local 3 14
drill /home/ubuntu/.cache 2 14
drill /home/ubuntu/.loki 2 14
drill /home/ubuntu/dev 1 46
drill /var/lib/containerd 2 8
drill /usr 1 8
# Databases. The first report never looked here, and a table of image bytes
# (Solon keeps place photographs in Postgres) is invisible to a du of /opt.
section "disk: databases"
du -xsh /var/lib/postgresql 2>/dev/null
as_postgres() {
if command -v sudo >/dev/null 2>&1; then sudo -u postgres "$@"; else runuser -u postgres -- "$@"; fi
}
if command -v psql >/dev/null 2>&1; then
as_postgres psql -At -F $'\t' -c \
"SELECT pg_size_pretty(pg_database_size(datname)), datname FROM pg_database WHERE NOT datistemplate ORDER BY pg_database_size(datname) DESC LIMIT 15" 2>/dev/null
# The five largest tables of the three largest databases: names and sizes only.
for db in $(as_postgres psql -At -c \
"SELECT datname FROM pg_database WHERE NOT datistemplate ORDER BY pg_database_size(datname) DESC LIMIT 3" 2>/dev/null); do
echo "-- largest tables in $db"
as_postgres psql -d "$db" -At -F $'\t' -c \
"SELECT pg_size_pretty(pg_total_relation_size(c.oid)), n.nspname || '.' || c.relname FROM pg_class c JOIN pg_namespace n ON n.oid = c.relnamespace WHERE c.relkind = 'r' AND n.nspname NOT IN ('pg_catalog','information_schema') ORDER BY pg_total_relation_size(c.oid) DESC LIMIT 5" 2>/dev/null
done
fi
if command -v docker >/dev/null 2>&1 && docker ps --format '{{.Names}}' 2>/dev/null | grep -qx supabase-db; then
echo "-- supabase-db"
docker exec supabase-db psql -U postgres -At -F $'\t' -c \
"SELECT pg_size_pretty(pg_database_size(datname)), datname FROM pg_database WHERE NOT datistemplate ORDER BY pg_database_size(datname) DESC LIMIT 5" 2>/dev/null
fi
section "disk: database dumps, by database (last 14 days)"
if [ -d /opt/backups/pg ]; then
find /opt/backups/pg -maxdepth 1 -type f -printf '%s %f\n' 2>/dev/null \
| sed -E 's/-[0-9]{8}-[0-9]{6}\.(dump|sql\.gz)$//' \
| awk '{size[$2]+=$1; n[$2]++} END {for (d in size) printf "%8.0f MiB %3d files %s\n", size[d]/1048576, n[d], d}' \
| sort -rn | head -12
fi
section "disk: build output and dependencies inside checkouts"
for kind in node_modules .next .turbo; do
count="$(timeout 60 find /home/ubuntu/dev /home/ubuntu/.loki -maxdepth 6 -type d -name "$kind" -prune 2>/dev/null | wc -l)"
printf '%s directories named %s\n' "$count" "$kind"
done
section "disk: other large files"
ls -lh /swapfile 2>/dev/null | awk '{print $5, $9}'
timeout 60 find / -xdev -type f -size +500M 2>/dev/null | head -15 | while read -r f; do
printf '%s\t%s\n' "$(du -h "$f" 2>/dev/null | cut -f1)" "$f"
done
echo
echo "box-usage: done, nothing changed"