iterate.com / git

git clone https://git.iterate.com/repos/git

When the mind does not answer, git is told to try again (503), not that there is no repo (404) (#5)

A failure with the platform's code UNAVAILABLE answers 503 with `retry-after: 10`, for a member and for anyone who reads a repo that worker.ts lists as public. Anyone else still gets the answer that names no repo.

Task: tasks/git-app-answer-503-not-404-when-itx-is-unavailable.md
Session: claude ef590eaa-2914-4af7-9edd-b0cf7fdcb670 on beelink
Iterate-Run: /@1057299

jonas, 2026-11-27 10:45 UTC · 295cda8d3f3e72662d7f4c69636d68096015e843 · parent 3ed0d32

2 files changed

M app.ts
@@ -64,7 +64,7 @@
 // ISOLATES: each read that reaches a new isolate mints one. What stops a push is
 // Artifacts' own limit of 64 MiB a push, with the same words through this app as straight to
 // Artifacts.
-import { reportIssue } from "iterate/lib";
+import { errorCode, reportIssue } from "iterate/lib";
 import { type AppDescription, type IterateConfigEntrypoint, serveFiles } from "iterate/sdk";
 import { openFile } from "@repos/stdlib/open-files.ts";
 import theme from "@repos/stdlib/theme.css";
@@ -286,6 +286,16 @@
       ownToken ?? forPush ?? forRead,
     ]);
   } catch (error) {
+    // THE MIND DID NOT ANSWER (code UNAVAILABLE: an overload, a reset, a lost connection): that is
+    // no word about the repo. A member, and anyone who reads a repo that worker.ts lists as
+    // public, gets 503 and when to ask again, so that a script tries again; a 404 here said "no
+    // repo" of a repo that is there (27 Nov 2026: CI read it as final). Anyone else still gets the
+    // answer that names no repo.
+    if (errorCode(error) === "UNAVAILABLE" && (member || anonymousRead))
+      return new Response("git: the mind did not answer just now. Try again in a few seconds.\n", {
+        status: 503,
+        headers: { "retry-after": "10", "cache-control": "no-store" },
+      });
     // only a member is told that a repo is not there, or was not read
     if (!member) return refusal(request, url, presented);
     const message = error instanceof Error ? error.message : String(error);
M tests/app.test.mjs
@@ -436,6 +436,30 @@
   assert.deepEqual(mind.remotesAsked, ["/repos/kernel"]);
 });
 
+test("when the mind does not answer, a public repo's reader and a member are told to try again; that is no word about the repo", async () => {
+  await using remote = await artifactsRemote();
+  const mind = fakeMind(remote);
+  const git = gitApp({ public: ["/repos/kernel"], ...look });
+  mind.unavailable.add("/repos/kernel").add("/repos/config");
+  const read = (repo, headers = {}) =>
+    git.fetch(new Request(`https://git.example.com/repos/${repo}/info/refs?service=git-upload-pack`, { headers }), mind);
+
+  for (const answer of [await read("kernel"), await read("kernel", asMember), await read("config", asMember)]) {
+    assert.equal(answer.status, 503);
+    assert.equal(answer.headers.get("retry-after"), "10");
+    assert.equal(await answer.text(), "git: the mind did not answer just now. Try again in a few seconds.\n");
+  }
+  // anyone else is told what they are always told of a repo that is not public: nothing of it
+  const stranger = await read("config");
+  assert.equal(stranger.status, 404);
+  assert.match(await stranger.text(), /there is no repo here that you can read/);
+  assert.equal(remote.requests.length, 0);
+
+  // the mind answers again: the same reader reads
+  mind.unavailable.clear();
+  assert.equal((await read("kernel")).status, 200);
+});
+
 test("what is no git request is refused before the mind is asked anything", async () => {
   await using remote = await artifactsRemote();
   const mind = fakeMind(remote);
@@ -491,6 +515,8 @@
   const away = new Set();
   // a repo whose mint never answers
   const stuck = new Set();
+  // a repo for which the mind does not answer, as the platform says it: an error with a code
+  const unavailable = new Set();
   const repos = ["/repos/kernel", "/repos/config"];
   const itx = {
     kv: {
@@ -503,6 +529,11 @@
     cfArtifacts: {
       get: async (repo) => ({
         remote: async () => {
+          if (unavailable.has(repo))
+            throw Object.assign(new Error("Durable Object is overloaded. Requests queued for too long."), {
+              code: "UNAVAILABLE",
+              data: { kind: "overloaded", retryAfterMs: 10_000 },
+            });
           if (!repos.includes(repo)) throw new Error(`Artifacts: repo not found: ${repo}`);
           remotesAsked.push(repo);
           return `${remote.origin}/remote/${repo.split("/").at(-1)}`;
@@ -536,6 +567,7 @@
     kv,
     minted,
     stuck,
+    unavailable,
     repos,
     remotesAsked,
     announced,