Commit Graph
2 Commits
Author SHA1 Message Date
CatoandClaude Opus 5 2d80b507ef fix(feedback): ask where a run ACTUALLY went, not where a new one would go (#792)
Risk 3 of the 2026-09-17 review: "Feedback attach-work falls back from
closed pending command to current project routing preference. A current
setting cannot prove where a historical attempt ran."

Exactly right. The channel resolution was:

  pending row (open) ?? pickDispatchChannel(project)

The open row is gone for most of a run's life — the runner stamps
executedAt on its inject-ack, within ~8s of injecting — so in practice
the second half decided almost every finished run. And that half is a
LIVE PREFERENCE. Flip a project from This computer to Cloud and every
finished local run starts claiming it ran on the box, with its offline
verdict computed against a machine it never touched.

The fix needed no new state, because the record already existed. The
executed pending_commands row carries the channel it was handed to, in
its payload, and getInjectAcksByRunIds was already reading exactly those
rows for the same runs — it just never selected the field. So the
immutable execution identity of the attempt was one property away the
whole time.

Now the order is an order of EVIDENCE:

  1. the open pending row  — this attempt, right now
  2. the executed command  — this attempt, recorded when it was handed
  3. the project's setting — where a NEW dispatch would go today

Only the first two are about the attempt being described. The third
stays as the last resort because a run that never reached a builder has
no recorded channel at all, and there the dispatcher's own rule is the
best available guess.

The channel lives in the jsonb payload rather than a column, so it is
validated the same way the open-row reader already validates it: an
unrecognised value is not a channel.

Tests: two cases — a project now set to Cloud whose attempt ran local
(the recorded fact wins, and the offline verdict follows it), and an
attempt with no recorded channel (falls back). Proved by mutation:
restoring the old expression fails "the recorded attempt outranks the
project's current preference". tsc clean, lint 0 errors, test:unit
204/204.

Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-09-18 09:34:52 -07:00
CatoandClaude Opus 5 4c3237c3d1 fix(feedback): give every surface one answer about the builder (#773)
c1165182 made the inbox row honest when a builder goes offline. It did not
reach the three other surfaces that read the same run, and they were already
answering the question three different ways:

- /api/terminal/run kept its own copy of the hydration, and that copy still
  fell back to "any builder will do" when the channel was unknown — the exact
  bug c1165182 fixed in the inbox, reporting a local run healthy whenever the
  cloud box happened to be up.
- /api/feedback/[id]/watch hydrated nothing. A bare snapshot carries no
  presence, so Watch could never see an offline builder: the row said "Needs
  you — Open Fleet Runner" and the panel opened from that row said "Starting".
- /api/feedback/[id]/dispatch hydrated nothing either, and that one is not
  cosmetic. It is Implement's duplicate-guard, and it decides whether to REFUSE
  a retry. A run queued on a Fleet Runner that is switched off read as QUEUED,
  so pressing Implement answered "Already on this" and blocked the very retry
  the row was asking for.

Extract the hydration into src/lib/feedback/run-context.ts and give all four
call sites the same function. The run row carries its own projectId, so
hydrateFeedbackSnapshot resolves the project's stored routing decision itself
rather than making each caller know how builder routing works — which is how
the three of them drifted apart in the first place.

run-context.ts is deliberately free of data access: attach-work.ts does the
querying and calls in. That is what makes the invariant testable at all —
attach-work cannot be imported without a DATABASE_URL, which is why none of
this was covered before.

scripts/test/feedback-run-context.ts pins the four cases that bit: local
builder down with cloud up is OFFLINE, a healthy builder is not stuck, an open
pending row outranks the project default, and a hosted dispatch on the payload
survives a non-hosted pending row.

Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-09-17 08:40:10 -07:00