Commit Graph
6 Commits
Author SHA1 Message Date
CatoandClaude Opus 5.5 a1b9d212b2 fix: no silent standing approvals for Loki's own ideas, and no dead-end stalls (#1168)
* fix(approvals): standing approvals cover what you ask for, never Loki's own ideas

The owner saw "✅ Done — Check in with Rajif Rao" on Telegram and feared Loki
had contacted someone without permission. Nothing was sent: a commitment is a
row in the operator's own list. But the path was still wrong. The check-in
producer writes its suggestions as create_commitment rows, so the "Record
commitments I mention" standing approval silently approved one nobody
mentioned, and the confirmation read as if the check-in had happened.

- standing-approval: RAIL 0. Every proposal now carries a required origin
  ("operator" | "loki"); only operator proposals may ride a standing rule.
- enqueueAction takes the origin from every caller and stamps it on the
  payload so the calendar drain's confirmation can say the same thing.
- Check-ins, the night plan and propose calls marked "not asked for" are
  origin "loki"; chat, the agent's propose tool and MCP are "operator".
- A commitment's confirmation now reads "📌 Added to your commitments —
  “Reach out to …”. A reminder for you. Nothing was sent to anyone."
- The Approvals setting says Loki's own suggestions still wait for a yes.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01XXM7KBHBym6au4L6sxShwz

* fix(control): a stalled queue always has a button, and names who holds it

On a phone the owner tapped "Run it in the cloud" under "Waiting for this
computer". The next refresh said "Stalled — 2 dispatches queued for 118m, the
builder is connected but not executing them. Restart the desktop app or check
the cloud builder if this persists", with no button, under a foot line that
read "This computer offline". Three things were wrong:

- The stall clock ran from created_at, so work the cloud had held for seconds
  was reported as 118 minutes stuck. A reroute now stamps reroutedAt and the
  detector measures from it.
- The sentence blamed a desktop app for work the cloud was holding. The stall
  query now counts cloud-held rows too, and the headline names the builder
  that actually has the work and whether it is connected.
- A genuine stall had no way forward. It now offers "Stop waiting"
  (POST /api/control/stop-waiting): the stuck rows close as failed dispatches,
  where Retry sends them again verbatim and Dismiss clears them, and their
  runs close so the project's lane is free. The consequence is stated in the
  headline before the tap.

Both hero queue buttons now report what they did ("Handed 2 dispatches to the
cloud builder.", or why a project stayed put) instead of firing and forgetting.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01XXM7KBHBym6au4L6sxShwz

* fix(loki): a screenshot sent with "fix this" finds the project it shows

On a phone the owner opened a new chat, attached a screenshot of Loki's own
Control page and wrote "Fix this so it works properly". The thread read
"No project — answers only": the text named no project, so the screenshot
fast path could not dispatch, and the picture was only ever described,
never used to decide where the fix should go.

- The vision preflight now opens with one line, "Shown: <app or site, and
  any URL visible>".
- projectShownInScreenshot picks a project only when the evidence points at
  exactly one: a project's live host visible in the analysis (compared whole,
  so loki.orangecat.ch is Loki and not OrangeCat), else a single project
  named on the Shown line. Projects merely listed on the screen do not count,
  and two candidates stay a question for the person.
- When Loki chose the project this way the reply says so and how to pick a
  different one, so a guess never reads as the person's own choice.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01XXM7KBHBym6au4L6sxShwz

* fix(notify): a failed run's Telegram message links to where Retry is

"❌ loki: run error … choose another AI provider and Retry" arrived with
nothing to tap. Failed, partial and timed-out runs now carry one button,
"Open <project> in Control", which lands on the project card where Retry and
the provider switch live. Successes stay buttonless.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01XXM7KBHBym6au4L6sxShwz

---------

Co-authored-by: Claude <noreply@anthropic.com>
2026-10-12 06:40:51 -07:00
CatoandClaude Opus 5 e3d9024887 fix(orchestration): a closed run tells the thread what the agent actually did (#772)
Both close notifications — the outcome turn in /loki and the push/Telegram
message — read only `payload.resultText`. The hosted runner and openclaw set
it. The local PTY path, which is the one a person watches after typing into
/loki, does not: it closes from the agent's session handoff, and the agent's
own words land in `summary`.

So the main path reported "🟡 **loki** — partly done." and nothing else. The
agent had written `done: e2e ok — no changes`, the judge had written exactly
what it found missing, and none of it reached the thread — which is the trip
out of the product this message exists to prevent.

One shared `runReportText` now answers "what did the agent say", preferring a
runner's own result text and falling back to the handoff: `done`, plus `next`
when it holds something, because on anything short of success `next` carries
the definition-of-done gap and the gap is what the operator must act on.

And the live check stops asserting what its own prompt forbids. The probe says
do NOT change a file, commit, or open a pull request; the judge then correctly
grades the run partial for having no committed change; the check demanded a ✅
and so failed on a perfect run (2026-09-17, run 69cdbdb7: injected 11:56:11,
handoff "e2e ok — no changes" thirty-two seconds later, every leg working).
It now asserts the thing that actually proves the loop — the agent's own
handoff summary coming back into the thread — and still fails on ❌ or on a
turn that carries somebody else's words.

Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-09-17 08:32:35 -07:00
GandClaude Opus 5 caa0e41c3b chore: add a formatter (#449)
* chore: add a formatter, matching the style this repo already writes

singleQuote=false was chosen by counting this repo's own
imports, not by fleet decree. The fleet is genuinely split and the two repos
that already had a .prettierrc disagreed with each other, so there was no
standard to restore. Quote style does not cross repo boundaries; having a
gate does.

Markdown is ignored for now — prettier rewraps prose, which would bury the
real diff.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>

* style: format with prettier (1062 files)

Mechanical. No behaviour change. This SHA is listed in
.git-blame-ignore-revs so `git blame` skips it.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>

* chore: teach git blame to skip the reformat

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>

* fix(lint): reattach two guards the reformat detached

Both effects were one-liners, so a trailing eslint-disable-line covered the
setState call:

  useEffect(() => { setSelected(new Set()); }, [q.length]); // eslint-disable-line ...

prettier expanded the block. The comment stayed on the closing line while the
call moved above it, so the guard protected nothing and the rule its author had
deliberately silenced failed the build.

This is the second shape of the same defect — hirnli had the eslint-disable-NEXT-line
variant. Both come from the same fact: an eslint directive binds to a line
number, so reformatting can silently unbind it, which makes 'mechanical, no
behaviour change' false for any bulk reformat.

* chore(desktop): bump the runner version the reformat requires

desktop-release-drift enforces that anything built into Fleet Runner which
differs from the last released tag must carry a version ahead of that tag —
main read 0.8.15 and fleet-runner-v0.8.15 already shipped.

A whole-repo reformat changes bytes under desktop/, so the gate fires. The
alternative was adding desktop/ to .prettierignore, which would buy a quiet PR
by carving a permanent hole in the formatter's coverage — the precise shape of
silent drift this test was written to catch. Bumping is what the rule asks for
and costs one patch release whose only content is whitespace.

* chore: merge main and re-format

A whole-repo reformat conflicts with any concurrent commit, and a conflicting PR
runs no checks at all while reporting nothing. Conflicts resolved to main,
which is correct because this branch changes formatting and nothing else.

* chore: leave desktop/ out of this reformat

desktop-release-drift is right to refuse this. Everything under desktop/ is
built into Fleet Runner, so changing it means shipping: bump the version AND add
a FLEET_RUNNER_RELEASES entry, whose stated audience is 'person who installed
Fleet Runner and wants to know what changed'. For a whitespace-only build the
honest answer is 'nothing', so that release should not exist — and I should not
write release notes claiming otherwise.

I had bumped to 0.8.16 to get the gate green. That was the wrong direction:
publishing a build to three OS runners to keep a formatting PR quiet. Reverted.

desktop/ is excluded in .prettierignore with the reasoning recorded there, to be
formatted alongside the next real runner change, where the bump and the notes are
true anyway.

---------

Co-authored-by: Claude Opus 5 <noreply@anthropic.com>
2026-08-31 09:23:30 +00:00
4013d7c686 fix(orchestration): the reaper announces its verdicts — failure stops being the quiet outcome (#340)
A run that SUCCEEDS told the operator. A run that DIED said nothing.

updateOrchestrationRun is the funnel every normal close goes through, and it
fires notifyRunClosed on ANY close (line ~82). The reaper closes stale runs
with a raw UPDATE that bypasses that funnel entirely. It already knew to
re-implement one side effect there (advanceEscalation, for the ladder) — but
not the notification. So the single outcome the operator most needed to hear
about was the only one the product kept to itself.

Measured cost of that asymmetry, in prod today: five visitor-feedback items
on orangecat had been sitting "dispatched" for up to a month — Jul 27, Aug 2,
Aug 7, Aug 13 x2 — across three runs the reaper had stamped `timeout` an hour
after dispatch. All three were DELIVERED (the prompt reached an agent), so
this was not a dispatch failure; the agents just never closed. Nobody was ever
told, so the inbox looked busy while the loop was dead.

- cleanupStaleOrchestrationRuns now calls notifyRunClosed for every reaped run,
  alongside the escalation-ladder advance it already did.
- .returning() widened to full rows (notifyRunClosed needs payload +
  finishedAt, not just the reap bookkeeping columns). Both existing consumers
  read only id/userId/outcome, so this is additive.
- Deliberately NOT resolveFeedbackForRun: that helper resolves
  unconditionally and the reaper never stamps success — calling it would mark
  feedback "shipped" because its fix run died. The comment in the funnel now
  says which half of its assumption still holds.

Not a new noise source: formatRunCloseMessage returns null unless
payload.notifyOnClose is set, which only human-initiated dispatches carry, so
autopilot churn stays silent. Verified zero open runs at ship time, so the
first sweep cannot produce a backlog storm.

Test pins the invariant (scripts/test/notify-close.ts): a reaper `timeout`
verdict must produce a message carrying its reason. Proven by mutation —
making the formatter success-only exits 1 with "timeout must produce a
message, got: null"; green when restored.

Co-authored-by: t <t@t.t>
Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
2026-08-24 17:15:06 +00:00
feb998a221 feat(dispatch): tell the operator their dispatch finished (#321)
Clicking Send and hearing nothing back is the complaint. The machinery to
answer it was fully built and switched off, in three independent places.

1. NOTHING EVER SET notifyOnClose. It is plumbed through /api/inject, stored on
   the run payload, formatted by a pure unit-tested function — and the only
   caller that ever set it true was a test fixture. Every dispatch declined to
   announce itself.

2. THE ONE CHANNEL IT WOULD HAVE USED IS UNCONFIGURED. notifyRunClosed sent via
   Telegram and returned early when selfTelegramTarget() was null. In production
   TELEGRAM_BOT_TOKEN is set and TELEGRAM_CHAT_ID is not, so even an opted-in
   run would have gone nowhere, silently.

3. WEB PUSH IS WIRED TO NOTHING. VAPID keys are configured, the service worker,
   the subscribe route, the NotificationsPill and the use-push-subscription hook
   all exist — and the only consumer of the send path is the HTTP endpoint
   itself. The operator's installed PWA could be reached and never was.

So: notifyRunClosed now delivers on EVERY configured channel rather than the
first one that happens to exist, push included — the channel that actually
reaches the phone of someone who dispatched and pocketed the device. The
fan-out is extracted to lib/push-fanout.ts so a server-side caller does not
self-HTTP its own API (same reasoning that pulled inject-core out of the route),
and it reports WHY nothing was sent: "not configured" and "no subscriptions"
need opposite fixes and a silent zero looks identical for both. A run that opted
in and reached nobody is logged as the product failure it is.

WHO GETS TOLD is the interesting decision. "UI dispatches stay silent so the
fleet's normal churn never spams the phone" was protecting something real, but
it assumed a UI dispatch means the operator is watching Control. They are not —
they dispatched and walked away, which is the entire point of an always-on
builder. The honest split is human vs machine, and that is knowable without a
heuristic: getApiActor reports HOW the request authenticated. A cookie session
is a person; a Bearer token is a runner, a hook, or a scheduled loop. Autopilot
stays silent, a click gets an answer, and an explicit value still wins in either
direction so chat can opt in and a noisy loop can opt out.

The rule lives in notify-close-format.ts (pure, shared) rather than inlined at
both dispatch routes, which is where it was about to become two copies that
drift. Negative-tested: disabling it reproduces the shipped silence.

Also fixes a source-level guard it tripped: autopilot-defaults asserted
/api/inject contains the literal "getApiUserId" to prove the route still accepts
a runner Bearer token. getApiActor delegates to it and satisfies the same
property, so the assertion now checks the invariant instead of the name.

Co-authored-by: t <t@t.t>
Co-authored-by: Claude Opus 5 <noreply@anthropic.com>
2026-08-16 16:55:07 +00:00
1cfef1e91e feat(chat-seam): approve-from-chat + chat dispatch outcomes (#251)
Two seams that make Loki (OpenClaw) a first-class operator surface:

- POST /api/actions/[id]/decision — approve/reject a queued action with a
  ck_* bearer token. finalizeApproved extracted to lib (SSOT shared with the
  Approvals page server actions), so chat and UI approval cannot drift.
- GET /api/actions/pending — the read half: chat can enumerate the queue.
- notifyOnClose: chat-originated dispatches (via /api/inject) opt into a
  Telegram push when the run closes, wired at the updateOrchestrationRun
  choke point + the closeRunUndelivered bypass. Message logic is pure
  (notify-close-format.ts) with unit coverage.

Co-authored-by: test <test@test>
Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
2026-08-13 22:05:32 +02:00