Files
loki/scripts/ci
c8415a348b fix(loki,deploy): the approval queue survives a Groq outage; deploys can't ship off-main (#262)
* 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>
2026-08-14 03:30:31 +02:00
..