A Start that fails answers 202 only when the row reads installing
Fable's code review of api/store-people (d178fc3), should-fix 1. The
real Start returns an error only before its claim, so a row reading
failed after one is an earlier failure: the owner's Try again never
started, and the app was told 202 with the old failure. Now 202 needs the
row to read installing (another request claimed it); anything else is 503
unavailable. The test's fake no longer marks the row failed and errors,
which the real installer can't do: a failed row's retry that can't start
is 503, and a claim by another request is 202. The docs table, plan P2
(and Task 3's test list) and spec 7.4 say the same.
The cheap nits too:
- 1: invite inside the CSRF check, with no Origin and another site's.
- 2: one write through the owner's web cookie session.
- 3: People's and invite's 503 at the route (an unreadable member row; a
trigger refusing inserts).
Nits 4 (member ids visible to every member) and 5 (Start returning nil
without claiming while another install holds the lock) are left as the
review describes them.
Gate: go test -p 4 ./internal/webtest -run 'TestAPIStore|TestAPIPeople|TestAPITeam': ok;
the old rule put back fails TestAPIStoreInstall ("retry not started: 202").
staticcheck and budget size: ok.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Summary
Review fix: failed Start answers 202 only when installing; invite CSRF, web-cookie write and route 503 tests
5 files changed,
+64
−22
docs/api/base-native-v1.md+1 −1docs/superpowers/plans/2026-11-28-native-slice2-part1.md+3 −3docs/superpowers/specs/2026-11-23-base-native-design.md+4 −2internal/web/api_team.go+6 −4internal/webtest/api_team_test.go+50 −12
CI passed — run details
CI log
=== build === CGO_ENABLED=0 go build ./... === vet === go vet ./... === fmt-check === === staticcheck === go run honnef.co/go/tools/cmd/staticcheck@v0.7.0 ./... === govulncheck === go run golang.org/x/vuln/cmd/govulncheck@v1.8.0 ./... No vulnerabilities found. === gitleaks === [90m7:38PM[0m [32mINF[0m [1mUnknown SCM platform. Use --platform to include links in findings.[0m [36mhost=[0mamadan.net [90m7:39PM[0m [32mINF[0m [1m1 commits scanned.[0m [90m7:39PM[0m [32mINF[0m [1mscanned ~2846469 bytes (2.85 MB) in 350ms[0m [90m7:39PM[0m [32mINF[0m [1mno leaks found[0m === budget === go run amadan.net/rastrillo/rastrillo/cmd/rastrillo budget size budget size: 22 directories within budget === script-test === scripts/prepare-apps_test.sh ok releases lookup failure stops before ship ok app owned elsewhere stops the script ok apps listing failure stops before create ok ambiguous release dir is refused ok explicit version resolves the ambiguity ok releases match is exact, not substring ok shipped version is only promoted, existing app not created ok fresh account creates, ships, promotes to edge, enables ok failing promote stops the script ok ship is retried while uploads are rate limited all passed hack/fonts_test.sh fonts_test: ok === test === go run amadan.net/rastrillo/rastrillo/cmd/rastrillo budget test -count=1 ./... receipt: test step 10.174s against a 60s target (the gate's other steps are not in this figure) receipt: 16 packages ran, 0 cached, 6 without tests, 0 failed receipt: slow package 9.083s amadan.net/oficina/base/internal/webtest receipt: slow package 916ms amadan.net/oficina/base/internal/issuer receipt: slow package 631ms amadan.net/oficina/base/internal/equipo receipt: slow package 599ms amadan.net/oficina/base/internal/operations receipt: slow package 207ms amadan.net/oficina/base/internal/consumer receipt: slow test 1.52s amadan.net/oficina/base/internal/webtest TestHomeDoesNotWaitOnAStalledSnapshot receipt: slow test 1.09s amadan.net/oficina/base/internal/webtest TestAskZoneIsToldOnce receipt: slow test 640ms amadan.net/oficina/base/internal/issuer TestAuthorizeSignsForInstalledApp receipt: slow test 620ms amadan.net/oficina/base/internal/webtest TestAskUploadStalledBodyFreesItsSlot receipt: slow test 510ms amadan.net/oficina/base/internal/equipo TestUploadRefusals === native === strings: copy review's strings.json is not here (git-ignored); its comparison skipped strings: 120 in the catalog, 117 used worktree-lib_test: ok
diff --git a/docs/api/base-native-v1.md b/docs/api/base-native-v1.md| index 8f50d7a..e94af98 100644 |
| --- a/docs/api/base-native-v1.md |
| +++ b/docs/api/base-native-v1.md |
| @@ -143,7 +143,7 @@ ignored); an invite takes JSON. |
| | Route | Answers | |
| |---|---| |
| -| `POST /api/v1/store/{app}/install` | `202 {"store": …}` with the app installing: poll `GET /api/v1/store` every 2 s while any row is. An app already installing answers `202`, and one already installed `200`, and neither starts anything. A failed row may be installed again (the page's "Try again"). If the install couldn't be started, the store is read again: a row that now shows installing or failed answers `202` as it stands; otherwise `503 unavailable`, and nothing was claimed. | |
| +| `POST /api/v1/store/{app}/install` | `202 {"store": …}` with the app installing: poll `GET /api/v1/store` every 2 s while any row is. An app already installing answers `202`, and one already installed `200`, and neither starts anything. A failed row may be installed again (the page's "Try again"). If the install couldn't be started, the store is read again: a row that now shows installing (another request started it) answers `202` as it stands; anything else is `503 unavailable`, and nothing was started. A row that still reads failed then shows an earlier failure, not this attempt. | |
| | `POST /api/v1/store/{app}/uninstall` | `200 {"store": …}`, also when it was uninstalled already. `409 {"code":"busy"}` while it is still installing ("This app is still installing. Try again in a moment."). `503 unavailable`. | |
| | `POST /api/v1/people` | Body `{"email": "…"}`, trimmed and lowercased. `200 {"person": …}`, a person as in `GET /api/v1/people`: invited now, or already here (nothing is sent then). `422 {"code":"bad_email"}`: not one plain address. `502 {"code":"mail_failed"}`: they are invited but the email wasn't delivered; invite them again to send it. `415 {"code":"json_only"}` for a body that isn't `application/json`, `413 {"code":"too_large"}` over 4 KiB, `400 {"code":"bad_request"}` for JSON that doesn't parse. `503 unavailable`. | |
diff --git a/docs/superpowers/plans/2026-11-28-native-slice2-part1.md b/docs/superpowers/plans/2026-11-28-native-slice2-part1.md| index 4240420..42566d9 100644 |
| --- a/docs/superpowers/plans/2026-11-28-native-slice2-part1.md |
| +++ b/docs/superpowers/plans/2026-11-28-native-slice2-part1.md |
| @@ -94,7 +94,7 @@ so: 22 numbered tasks, one spike, and one conditional task. |
| | Route | Answers | |
| |---|---| |
| | `GET /api/v1/store` | `200 {owner, rows}`; `503 {"code":"unavailable"}` when the installs can't be read | |
| - | `POST …/install` | `202 {"store"}` with the app installing. An app already installing answers `202` and one already installed answers `200`; neither calls `Start`. When `Start` fails, the store is read again: if the row now shows installing or failed, `202` as it stands; otherwise `503 unavailable`, and nothing was claimed. Also `403 owner_only`, `404 unknown_app` | |
| + | `POST …/install` | `202 {"store"}` with the app installing. An app already installing answers `202` and one already installed answers `200`; neither calls `Start`. When `Start` fails, the store is read again: if the row now shows installing (another request claimed it), `202` as it stands; otherwise `503 unavailable`, and nothing was claimed. `Start` fails only before its claim, so a row reading failed then is an earlier failure (Fable's code review, should-fix 1). Also `403 owner_only`, `404 unknown_app` | |
| | `POST …/uninstall` | `200 {"store"}`, also when already uninstalled; `409 {"code":"busy"}`; `403`; `404`; `503` | |
| | `GET /api/v1/people` | `200 {owner, people: [{id, initial, name, email, role}]}`. `role` is `owner`, `member` or `invited`, so there's no `joined`. `503` when members can't be read | |
| | `POST /api/v1/people` | `200 {"person"}`: the person invited, or already here. Also `422 {"code":"bad_email"}`; `502 {"code":"mail_failed"}` (invite again to retry); `403 owner_only`; `415` for a non-JSON body; `503` | |
| @@ -263,8 +263,8 @@ Base, native/slice2-part1 (native/apple/Sources/BaseKit unless shown) |
| - **`TestAPIStoreInstall`:** |
| - the owner gets `202` with the row installing, and `Start` is called once; |
| - an app already installing gets `202`, and one already installed gets `200`, with `Start` not called; |
| - - a `Start` that fails having claimed the install (the row reads failed) gets `202`; |
| - - a `Start` that fails having claimed nothing gets `503`; |
| + - a `Start` that fails while another request has claimed the install (the row reads installing) gets `202`; |
| + - a `Start` that fails having claimed nothing gets `503`, a failed row's retry included; |
| - a member gets `403 owner_only`, and an unknown app `404 unknown_app`; |
| - no `Origin` gets `403` (CSRF). |
| - **`TestAPIStoreUninstall`:** `200`; `409 busy` (an installer answering `install.ErrBusy`); `200` when already uninstalled; `403`; `404`. |
diff --git a/docs/superpowers/specs/2026-11-23-base-native-design.md b/docs/superpowers/specs/2026-11-23-base-native-design.md| index f3ea002..081c914 100644 |
| --- a/docs/superpowers/specs/2026-11-23-base-native-design.md |
| +++ b/docs/superpowers/specs/2026-11-23-base-native-design.md |
| @@ -681,8 +681,10 @@ same owner checks: |
| - An app already installing answers `202`, and one already installed |
| `200`, both with the store and without starting anything. |
| - If starting the install fails, the store is read again. A row that now |
| - shows installing or failed answers `202` as it stands. Otherwise the |
| - answer is `503 unavailable`, and nothing was claimed. |
| + shows installing (another request started it) answers `202` as it |
| + stands. Otherwise the answer is `503 unavailable`, and nothing was |
| + claimed: starting fails only before its claim, so a row that still |
| + reads failed shows an earlier failure. |
| - **`POST /api/v1/store/{app}/uninstall`:** `200 {store}`, `409 busy` |
| while installing, `403 owner_only` if not the owner. |
| - **`GET /api/v1/people`:** `{owner, people: [{id, initial, name, email, |
diff --git a/internal/web/api_team.go b/internal/web/api_team.go| index 3091a3d..b278838 100644 |
| --- a/internal/web/api_team.go |
| +++ b/internal/web/api_team.go |
| @@ -113,9 +113,11 @@ func (a *app) apiOwner(w http.ResponseWriter, me store.Member, id string) (catal |
| // apiStoreInstall is POST /api/v1/store/{app}/install. It answers 202 with |
| // the app installing, and the app polls the store until it isn't. An app |
| // already installing answers 202 and one installed 200, and neither starts |
| -// anything. When Start fails the store is read again: a row that now shows |
| -// installing or failed is answered 202 as it stands, and otherwise nothing |
| -// was claimed and the answer is 503. |
| +// anything. Start returns an error only from before its claim (install.go), |
| +// so when it fails the store is read again: a row that now reads installing |
| +// was claimed by another request and is answered 202 as it stands, and |
| +// anything else, a failed row included (that failure is an earlier one), |
| +// is 503: this attempt never started. |
| func (a *app) apiStoreInstall(w http.ResponseWriter, r *http.Request) { |
| me, _ := CurrentMember(r) |
| e, ok := a.apiOwner(w, me, chi.URLParam(r, "app")) |
| @@ -145,7 +147,7 @@ func (a *app) apiStoreInstall(w http.ResponseWriter, r *http.Request) { |
| writeJSON(w, http.StatusServiceUnavailable, apiError{Code: "unavailable"}) |
| return |
| } |
| - if row, _ := c.row(e.ID); startErr != nil && row.State != "installing" && row.State != "failed" { |
| + if row, _ := c.row(e.ID); startErr != nil && row.State != "installing" { |
| writeJSON(w, http.StatusServiceUnavailable, apiError{Code: "unavailable"}) |
| return |
| } |
diff --git a/internal/webtest/api_team_test.go b/internal/webtest/api_team_test.go| index cd18947..8390d9c 100644 |
| --- a/internal/webtest/api_team_test.go |
| +++ b/internal/webtest/api_team_test.go |
| @@ -171,6 +171,13 @@ func TestAPIPeople(t *testing.T) { |
| if got := jsonAnswer[apiPeopleShape](t, "web session's people", a.get("/api/v1/people"), 200); !reflect.DeepEqual(got, want) { |
| t.Errorf("web session's people: %+v", got) |
| } |
| + |
| + // A member row that can't be read: the list fails, while the owner's |
| + // own row, which the gate reads, still can be. |
| + if _, err := a.DB.Exec(`INSERT INTO members (id, email, role, invited_at) VALUES ('broken', 'broken@acme.test', 'member', 'not a time')`); err != nil { |
| + t.Fatal(err) |
| + } |
| + refusedWith(t, "members unreadable", a.nativeSignIn("subject-owner").nativeGet("/api/v1/people"), http.StatusServiceUnavailable, "unavailable") |
| } |
| func TestAPITeamRefusesWithoutSession(t *testing.T) { |
| @@ -307,23 +314,27 @@ func TestAPIStoreInstall(t *testing.T) { |
| t.Fatalf("%d Start calls after the repeats, want 1", s) |
| } |
| - // Start failing, having claimed the install, which reads failed: 202 |
| - // with the row as it stands. |
| - inst.start = func(id string) error { |
| - a.setInstall(id, "failed", "The app did not start answering") |
| - return errors.New("platform down") |
| - } |
| - got = jsonAnswer[apiStoreAnswer](t, "start failed, claimed", app.nativePost("/api/v1/store/contra/install", ""), http.StatusAccepted) |
| - if rowState(t, got.Store, "contra") != "failed" { |
| - t.Errorf("start failed, claimed: %+v", got.Store) |
| - } |
| - // Start failing having claimed nothing: 503, and nothing is installing. |
| + // The real Start returns an error only from before its claim, so a |
| + // failed Start never started this attempt. A failed row whose retry |
| + // can't start is 503, not the old failure answered as if it ran. |
| + a.setInstall("contra", "failed", "The app did not start answering") |
| inst.start = func(string) error { return errors.New("database locked") } |
| + refusedWith(t, "retry not started", app.nativePost("/api/v1/store/contra/install", ""), http.StatusServiceUnavailable, "unavailable") |
| + // Nor does an app never installed show anything for it. |
| if _, err := a.DB.Exec(`DELETE FROM installs WHERE app = 'contra'`); err != nil { |
| t.Fatal(err) |
| } |
| refusedWith(t, "start failed, nothing claimed", app.nativePost("/api/v1/store/contra/install", ""), http.StatusServiceUnavailable, "unavailable") |
| - // A failed row's retry starts again. |
| + // Another request claimed it meanwhile: the row reads installing, 202. |
| + inst.start = func(id string) error { |
| + a.setInstall(id, "installing", "") |
| + return errors.New("already claimed") |
| + } |
| + got = jsonAnswer[apiStoreAnswer](t, "claimed by another request", app.nativePost("/api/v1/store/contra/install", ""), http.StatusAccepted) |
| + if rowState(t, got.Store, "contra") != "installing" { |
| + t.Errorf("claimed by another request: %+v", got.Store) |
| + } |
| + // A failed row's retry that starts is 202, installing. |
| a.setInstall("contra", "failed", "") |
| inst.start = func(id string) error { a.setInstall(id, "installing", ""); return nil } |
| got = jsonAnswer[apiStoreAnswer](t, "try again", app.nativePost("/api/v1/store/contra/install", ""), http.StatusAccepted) |
| @@ -454,9 +465,36 @@ func TestAPIPeopleInvite(t *testing.T) { |
| if len(a.mailbox()) != sent { |
| t.Errorf("a refused invite sent mail") |
| } |
| + // Inside the CSRF check: no Origin, or another site's, with a JSON body. |
| + for _, origin := range []string{"", "https://evil.test"} { |
| + req, _ := http.NewRequest(http.MethodPost, a.base+"/api/v1/people", strings.NewReader(`{"email":"carla@acme.test"}`)) |
| + req.Header.Set("Content-Type", "application/json") |
| + req.Header.Set("Accept", "application/json") |
| + if origin != "" { |
| + req.Header.Set("Origin", origin) |
| + } |
| + if r := app.do(req); r.Code != http.StatusForbidden { |
| + t.Errorf("invite with Origin %q: %d %s", origin, r.Code, r.Body) |
| + } |
| + } |
| + if len(a.mailbox()) != sent { |
| + t.Errorf("a refused invite sent mail") |
| + } |
| if _, ok, _ := store.MemberByEmail(t.Context(), a.DB, "carla@acme.test"); ok { |
| t.Error("a refused invite added carla") |
| } |
| + |
| + // The owner's web session (the cookie from signing in on the web) may |
| + // write too: it is the same member gate. |
| + if web := jsonAnswer[apiPersonAnswer](t, "invite from the web session", a.nativePost("/api/v1/people", `{"email":"dana@acme.test"}`), http.StatusOK); web.Person.Email != "dana@acme.test" { |
| + t.Errorf("invite from the web session: %+v", web.Person) |
| + } |
| + |
| + // The members can't be written. |
| + if _, err := a.DB.Exec(`CREATE TRIGGER no_invites BEFORE INSERT ON members BEGIN SELECT RAISE(ABORT, 'locked'); END`); err != nil { |
| + t.Fatal(err) |
| + } |
| + refusedWith(t, "members unwritable", app.nativePost("/api/v1/people", `{"email":"erin@acme.test"}`), http.StatusServiceUnavailable, "unavailable") |
| } |
| // Without a session every write is 401, as the reads are. |