iterate.com / kernel

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

A revocation whose answer was lost reads the list, and the refusal of a token's text claims no more than it does

The reviewer's two findings on pull 6. A second attempt that finds nothing to end asks the
list whether the token is ended, so a revocation that landed is not told as a wrong id. The
comments no longer say that the refusal keeps a token's text off a log: the script's source
is written before it runs.

Session: claude 4bfd7dc5-ae25-44a2-9e97-71e8cda6eb3a on beelink

Tests: core/mind-worker/src/context/cf-artifacts.test.ts
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01NCuxgW9h7bArbVFYcg6ShA

Jonas Templestein, 2026-11-26 16:08 UTC · 4ef65a622d274aed465f4d15e76e0ef6a9be5051 · parent 5e5d27e

3 files changed

M core/lib/src/api.ts
@@ -1089,8 +1089,9 @@
   createToken(scope: "read" | "write", ttlSeconds: number): Promise<ArtifactToken>;
   /** Every token of this repo, the ended ones too, with no token's text. */
   listTokens(): Promise<{ tokens: ArtifactTokenInfo[]; total: number }>;
-  /** Ends one token of this repo, by its id and never by its text. False when the repo has no
-   *  token of that id. */
+  /** Ends one token of this repo, by its id. A token's text is refused: pass none, a script's
+   *  source is on its caller's log. False when the repo has no token of that id that could be
+   *  ended. */
   revokeToken(id: string): Promise<boolean>;
   remote(): Promise<string>;
 }
M core/mind-worker/src/context/cf-artifacts.test.ts
@@ -43,11 +43,24 @@
   expect((await config.listTokens()).tokens[0]!.state).toBe("active");
 });
 
-test("a token's own text is refused before the binding is asked: it would be on the caller's log", async () => {
+test("a revocation whose answer was lost is true when the token is ended, and false for an id that the repo has not", async () => {
   const store = storeOf(["repos--config"]);
   const config = await mindScopedArtifacts({ namespace: store.namespace }).get("/repos/config");
   const minted = await config.createToken("write", 300);
 
+  // Artifacts ends the token, and its answer is the internal error that the proxy tries again on
+  store.loseNextRevokeAnswer();
+  expect(await config.revokeToken(minted.id!)).toBe(true);
+  expect(store.revokeAsked).toEqual([minted.id, minted.id]);
+  store.loseNextRevokeAnswer();
+  expect(await config.revokeToken("tok_9")).toBe(false);
+});
+
+test("a token's own text is refused before the binding is asked, so no caller learns to pass one", async () => {
+  const store = storeOf(["repos--config"]);
+  const config = await mindScopedArtifacts({ namespace: store.namespace }).get("/repos/config");
+  const minted = await config.createToken("write", 300);
+
   for (const text of [minted.plaintext, "art_v1_abc", "", "an id with spaces", "x".repeat(129)])
     await expect(config.revokeToken(text)).rejects.toThrow("takes a token's id");
   expect(store.revokeAsked).toEqual([]);
@@ -71,6 +84,7 @@
   const repos = new Map<string, Row[]>(names.map((name) => [name, []]));
   const revokeAsked: string[] = [];
   let made = 0;
+  let answerIsLost = false;
   const namespace = {
     async get(name: string) {
       const rows = repos.get(name);
@@ -97,11 +111,15 @@
           revokeAsked.push(tokenOrId);
           const row = rows.find((row) => row.id === tokenOrId && row.state === "active");
           if (row) row.state = "revoked";
+          if (answerIsLost) {
+            answerIsLost = false;
+            throw new Error("An internal error occurred.");
+          }
           return Boolean(row);
         },
       };
     },
     // the cast: these tests call `get` alone
   } as unknown as ArtifactsNamespace;
-  return { namespace, revokeAsked };
+  return { namespace, revokeAsked, loseNextRevokeAnswer: () => void (answerIsLost = true) };
 }
M core/mind-worker/src/context/cf-artifacts.ts
@@ -70,19 +70,33 @@
       total,
     };
   }
-  // BY ITS ID ALONE. The binding takes a token's text too, and this refuses one: a script's source
-  // and its arguments are written on the caller's log, where a token's text must never be. The
-  // handle is this repo's, so an id of another repo's token is not found here: false.
+  // BY ITS ID ALONE. The binding takes a token's text too, and this refuses one, so that no caller
+  // learns to pass a token here: a script's source is on the caller's log before this runs, and
+  // nothing here can take a token out of it. The handle is this repo's, so an id of another
+  // repo's token is not found here: false.
   async revokeToken(id: string) {
     if (typeof id !== "string" || !TOKEN_ID.test(id) || id.startsWith("art_"))
       throw refusal(
         "revokeToken takes a token's id, as listTokens() and createToken() answer it, and never the token itself",
       );
-    return await retryingOnePlatformFailure("revokeToken", this.#name, () =>
-      withArtifactRepoHandle(this.#namespace, this.#name, "revokeToken", (handle) =>
-        handle.revokeToken(id),
-      ),
-    );
+    return await retryingOnePlatformFailure("revokeToken", this.#name, async (isRetry) => {
+      const revoked = await withArtifactRepoHandle(
+        this.#namespace,
+        this.#name,
+        "revokeToken",
+        (handle) => handle.revokeToken(id),
+      );
+      // The first attempt's answer was lost, and it may have landed: then the second finds
+      // nothing to end. The list says whether the token is ended.
+      if (revoked || !isRetry) return revoked;
+      const { tokens } = await withArtifactRepoHandle(
+        this.#namespace,
+        this.#name,
+        "listTokens",
+        (handle) => handle.listTokens(),
+      );
+      return tokens.some((token) => token.id === id && token.state === "revoked");
+    });
   }
   async remote() {
     const { remote } = await retryingOnePlatformFailure("remote", this.#name, () =>