oficina / base Public

A turn that failed for its files says why (Task 9)

Human

Prompt

Build Base's half of files in Ask, slice 1, task by task from the approved plan, tests first.

From this commit's own message. The prompt ledger has no entries for it — which is what a squashed, rebased or amended commit looks like, and what every commit looks like in a repo without a ledger.

Summary

attachment_unavailable, runner_storage_full and runner_too_old each get their own status line: live in ask.js, and read afresh (the page without scripts and /ask/state's status) when the person's newest message's turn failed so. Other failures keep their line. Fake: FailTurnFor.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
claude agent, operated by paul@keymail.dev 667433d8f37a17ae3f544a24f376c001406621e9 parent 10bc21d
6 files changed, +122 −3
  • docs/api/base-native-v1.md +5 −1
  • internal/browsertest/attach_test.go +43 −1
  • internal/equipo/equipotest/chat.go +4 −0
  • internal/look/static/ask.js +8 −1
  • internal/web/ask.go +20 −0
  • internal/webtest/ask_files_test.go +42 −0
diff --git a/docs/api/base-native-v1.md b/docs/api/base-native-v1.md
index d2a29a5..ddc1135 100644
--- a/docs/api/base-native-v1.md
+++ b/docs/api/base-native-v1.md
@@ -119,7 +119,11 @@ for a form). Every answer is `no-store`.
- `turn` is the newest turn the person sees running (never a quiet
`team_update` one), or `null`. `status` is the line under the
conversation while it runs: `"Thinking…"`, `"Ask Base can't answer right
- now. It will as soon as it can."` (turn `waiting`), or `""`.
+ now. It will as soon as it can."` (turn `waiting`), or `""`. With no
+ turn running, it says why the turn of the person's newest message
+ failed for its files (Turn `reason` `attachment_unavailable`,
+ `runner_storage_full` or `runner_too_old`), as a live `turn` event with
+ that reason should too.
- `cursor` is where `/ask/events` starts.
- `renew_after` (RFC 3339, UTC) is set when Ask was connected with Oficina
ID: from then on, the app sets Ask up again with a fresh assertion
diff --git a/internal/browsertest/attach_test.go b/internal/browsertest/attach_test.go
index ffd6853..47dcd8d 100644
--- a/internal/browsertest/attach_test.go
+++ b/internal/browsertest/attach_test.go
@@ -238,7 +238,9 @@ func TestAskAttachPicker(t *testing.T) {
// Files with no words send, once the answer is in.
drive(t, rig, chromedp.WaitVisible(chromedp.CSS(`#ask-panel button.attach`)))
- waitFor(t, "the turn ended", func() bool { return harness.Evaluate[bool](rig, `document.querySelector("#ask-panel button.stop").hidden`) })
+ waitFor(t, "the turn ended", func() bool {
+ return harness.Evaluate[bool](rig, `document.querySelector("#ask-panel button.stop").hidden`)
+ })
pick(t, rig, paths["note.md"])
waitChips(t, rig, "done", allDone(1))
drive(t, rig, chromedp.Click(chromedp.CSS(`#ask-panel button.send`)))
@@ -620,3 +622,43 @@ func TestAskAttachMobile(t *testing.T) {
noOverflow(t, rig, "/ask with four chips")
mobileShot(t, rig, "attach-mobile")
}
+
+// A turn that fails for its files says why in the status line, live and
+// read afresh; any other failure keeps its line.
+func TestAskAttachTurnFailures(t *testing.T) {
+ rig, f := attachReady(t)
+ f.Hold = true
+ status := `document.querySelector("#ask-panel .ask-status").textContent`
+ for _, tc := range []struct{ reason, want string }{
+ {"attachment_unavailable", "A file didn't arrive whole. Attach it again."},
+ {"runner_storage_full", "There's no room left for these files. Try fewer or smaller ones."},
+ {"runner_too_old", "Files can't be read right now. Send it again without them."},
+ {"model_error", "That didn't get an answer. Try again."},
+ } {
+ drive(t, rig, chromedp.SendKeys(chromedp.CSS(`#ask-panel textarea`), "about "+tc.reason), chromedp.Click(chromedp.CSS(`#ask-panel button.send`)),
+ chromedp.WaitVisible(chromedp.CSS(`#ask-panel button.stop`)))
+ var id string
+ waitFor(t, "the turn running", func() bool {
+ snap := harness.Evaluate[string](rig, `document.querySelector("#ask-panel form.cancel").getAttribute("action")`)
+ id = strings.TrimSuffix(strings.TrimPrefix(snap, "/ask/turns/"), "/cancel")
+ return id != snap && f.Turn(id) == "running"
+ })
+ f.FailTurnFor(id, tc.reason)
+ drive(t, rig, chromedp.Poll[chromedp.Void](status+` === `+strconv.Quote(tc.want), chromedp.WithPollingTimeout(5*time.Second)))
+ }
+ // Read afresh, a generic failure has no line, and a file's keeps its own.
+ openPanel(t, rig)
+ if got := harness.Evaluate[string](rig, status); got != "" {
+ t.Errorf("read afresh after a generic failure: %q", got)
+ }
+ drive(t, rig, chromedp.SendKeys(chromedp.CSS(`#ask-panel textarea`), "one more"), chromedp.Click(chromedp.CSS(`#ask-panel button.send`)),
+ chromedp.WaitVisible(chromedp.CSS(`#ask-panel button.stop`)))
+ action := harness.Evaluate[string](rig, `document.querySelector("#ask-panel form.cancel").getAttribute("action")`)
+ id := strings.TrimSuffix(strings.TrimPrefix(action, "/ask/turns/"), "/cancel")
+ waitFor(t, "the turn running", func() bool { return f.Turn(id) == "running" })
+ f.FailTurnFor(id, "attachment_unavailable")
+ openPanel(t, rig)
+ if got := harness.Evaluate[string](rig, status); got != "A file didn't arrive whole. Attach it again." {
+ t.Errorf("read afresh after a file's failure: %q", got)
+ }
+}
diff --git a/internal/equipo/equipotest/chat.go b/internal/equipo/equipotest/chat.go
index 1ef54ea..3463eb4 100644
--- a/internal/equipo/equipotest/chat.go
+++ b/internal/equipo/equipotest/chat.go
@@ -654,6 +654,10 @@ func (f *Fake) RunTurn(id string) { f.setTurn(id, "running", "") }
// FailTurn ends the turn with id unanswered: failed.
func (f *Fake) FailTurn(id string) { f.setTurn(id, "failed", "") }
+// FailTurnFor ends the turn with id unanswered for reason, such as
+// attachment_unavailable.
+func (f *Fake) FailTurnFor(id, reason string) { f.setTurn(id, "failed", reason) }
+
// WaitTurn puts the turn with id in the waiting state: saved, with nothing
// yet able to answer it.
func (f *Fake) WaitTurn(id string) { f.setTurn(id, "waiting", "") }
diff --git a/internal/look/static/ask.js b/internal/look/static/ask.js
index b030de0..2daecf5 100644
--- a/internal/look/static/ask.js
+++ b/internal/look/static/ask.js
@@ -1467,6 +1467,11 @@ function start(root) {
}
const ended = (s) => s === "replied" || s === "failed" || s === "cancelled";
+ const failedFiles = {
+ attachment_unavailable: "A file didn't arrive whole. Attach it again.",
+ runner_storage_full: "There's no room left for these files. Try fewer or smaller ones.",
+ runner_too_old: "Files can't be read right now. Send it again without them.",
+ };
// The field's end holds Stop while a turn runs, else Send once something
// is typed, else nothing. A button that goes while it has focus hands it
@@ -1517,7 +1522,9 @@ function start(root) {
if (t && turn && t.id !== turn.id) return;
turn = null;
paint();
- status.textContent = t && t.state === "failed" ? "That didn't get an answer. Try again." : "";
+ // A turn that failed for its files says why (ask.go, failedFiles); read
+ // afresh with nothing running, the server's line stands.
+ status.textContent = t && t.state === "failed" ? failedFiles[t.reason] || "That didn't get an answer. Try again." : t ? "" : line || "";
settle(t);
}
// settle ends the drafts of turn t (every draft when there is none): a
diff --git a/internal/web/ask.go b/internal/web/ask.go
index b7ffb21..da16f2c 100644
--- a/internal/web/ask.go
+++ b/internal/web/ask.go
@@ -425,6 +425,16 @@ func turnStatus(t *equipo.Turn) string {
return "Thinking…"
}
+// failedFiles are the words for a turn that failed for its files, by
+// Equipo's reason (copy review 13, pending); ask.js has the same
+// (failedFiles). Any other failure keeps "That didn't get an answer. Try
+// again.", which only the panel's script says, as it happens.
+var failedFiles = map[string]string{
+ "attachment_unavailable": "A file didn't arrive whole. Attach it again.",
+ "runner_storage_full": "There's no room left for these files. Try fewer or smaller ones.",
+ "runner_too_old": "Files can't be read right now. Send it again without them.",
+}
+
// fill puts a snapshot in the view: the messages, the jobs in the
// snapshot's order with the cards that belong to each under it, every
// other card to show, and the newest turn that has not ended, of those the
@@ -474,6 +484,16 @@ func (v *askView) fill(s equipo.Snapshot) {
}
}
v.Status = turnStatus(v.Turn)
+ // With nothing running, the turn of the person's newest message, if it
+ // failed for its files, unanswered, says so (the page without scripts, and the panel
+ // as it reads the conversation afresh).
+ if v.Turn == nil && len(s.Messages) > 0 && s.Messages[len(s.Messages)-1].Role == "person" {
+ for _, t := range s.Turns {
+ if t.ID == s.Messages[len(s.Messages)-1].TurnID && t.State == equipo.TurnFailed {
+ v.Status = failedFiles[t.Reason]
+ }
+ }
+ }
}
// askSnapshot reads the member's conversation into v, moving v.State to
diff --git a/internal/webtest/ask_files_test.go b/internal/webtest/ask_files_test.go
index 5a9d2c4..bc675f8 100644
--- a/internal/webtest/ask_files_test.go
+++ b/internal/webtest/ask_files_test.go
@@ -6,6 +6,7 @@ import (
"context"
"encoding/json"
"fmt"
+ "html"
"image"
"image/color"
"image/png"
@@ -14,6 +15,7 @@ import (
"net"
"net/http"
"net/url"
+ "regexp"
"strings"
"sync"
"testing"
@@ -755,3 +757,43 @@ func TestAskThreadDrawsFiles(t *testing.T) {
t.Error("the page links a file somewhere other than Base")
}
}
+
+// A turn that failed for its files says why under the conversation,
+// without scripts too; any other failure says nothing new there.
+func TestAskTurnFailedForFiles(t *testing.T) {
+ a, f := newAskApp(t)
+ a.connectEquipo(f)
+ f.Hold = true
+ for reason, want := range map[string]string{
+ "attachment_unavailable": "A file didn't arrive whole. Attach it again.",
+ "runner_storage_full": "There's no room left for these files. Try fewer or smaller ones.",
+ "runner_too_old": "Files can't be read right now. Send it again without them.",
+ "model_error": "",
+ } {
+ r := a.postJSON("/ask/messages", url.Values{"text": {"about " + reason}})
+ var sent struct{ Turn struct{ ID string } }
+ if json.Unmarshal([]byte(r.Body), &sent) != nil || sent.Turn.ID == "" {
+ t.Fatalf("send: %s", r.Body)
+ }
+ waitTurn := func(state string) {
+ for i := 0; f.Turn(sent.Turn.ID) != state; i++ {
+ if i > 200 {
+ t.Fatalf("turn %s", f.Turn(sent.Turn.ID))
+ }
+ time.Sleep(10 * time.Millisecond)
+ }
+ }
+ waitTurn("running")
+ f.FailTurnFor(sent.Turn.ID, reason)
+ page := a.get("/ask").Body
+ got := regexp.MustCompile(`<p class="ask-status" role="status">([^<]*)</p>`).FindStringSubmatch(page)
+ if got == nil || html.UnescapeString(got[1]) != want {
+ t.Errorf("%s: status %q, want %q", reason, got, want)
+ }
+ var st struct{ Status string }
+ _ = json.Unmarshal([]byte(a.get("/ask/state").Body), &st)
+ if st.Status != want {
+ t.Errorf("%s: state status %q", reason, st.Status)
+ }
+ }
+}