Skip to content

A desktop coding agent with free access to frontier models.

TypeScript

fix: send the current upload format on first run

ogsamratff0dc2511322
diff --git a/apps/server/src/context/PARITY.sha256 b/apps/server/src/context/PARITY.sha256
index 5a711513..4e25ac7e 100644
--- a/apps/server/src/context/PARITY.sha256
+++ b/apps/server/src/context/PARITY.sha256
@@ -19,4 +19,4 @@ d8c0636406c8cd9d55f9fb06af8827b3d1b73247393f48aaca2ef053ccf5a1ff services.ts
d51d434283f757f0ed45bb6996a74fb5bf9e1d56f34146e99df3c392cde5ea19 shell-aliases.ts
5af6e3e4d75e62e0dfc0fee53c583f34463871f9a4d5693e4bc13f688ed2142e system-packages.ts
4208574258fc043bc0cbb1770c718bfec22d996a44da493489d74d8a05bd7684 tool-events.ts
-76ad182f21e1a7805d4986f1b3dad160ecf62f07224d23a438554efc98b44ca2 upload-format.ts
+06eb1f248102f02007b4e797b2f361e50b18318b28e3de57d945e447eab57cda upload-format.ts
diff --git a/apps/server/src/context/upload-format.ts b/apps/server/src/context/upload-format.ts
index c5f94e79..2685a511 100644
--- a/apps/server/src/context/upload-format.ts
+++ b/apps/server/src/context/upload-format.ts
@@ -7,8 +7,12 @@
// a 5xx, a timeout, no network) keeps the format the server last advertised
// instead of falling back. Only an explicit refusal of schema 3 by /collect
// (422 unsupported_schema: unsupported()) moves a known server back to schema
-// 2. With nothing known and a failed check the upload goes out as schema 2,
-// and the server is asked again after RETRY_MS rather than RECHECK_MS.
+// 2. With nothing known and a failed check (a fresh install's first upload)
+// the upload goes out as schema 3, which every current server takes: a server
+// that refuses it answers 422 and the same batch goes again as schema 2, and
+// this process then keeps schema 2 for that server until it advertises 3. The
+// server is asked again after RETRY_MS rather than RECHECK_MS. A server with no
+// capabilities route at all (404) is an old one: schema 2, like its answer.
import { mkdirSync, readFileSync, renameSync, rmSync, writeFileSync } from "node:fs";
import { dirname } from "node:path";
@@ -49,6 +53,12 @@ export function advertisesSchema3(answer: UploadFormatAnswer | null | undefined)
&& answer!.schema_versions.includes(3);
}
+/** A check the server answered 404: it has no capabilities route (an old server), not a failed check. */
+function routeMissing(error: unknown): boolean {
+ if (error && typeof error === "object" && (error as { status?: unknown }).status === 404) return true;
+ return error instanceof Error && /\bstatus 404\b/.test(error.message);
+}
+
/** The key a server is remembered under: its URL without a trailing slash. */
export function uploadFormatServerKey(server: string): string {
return server.trim().replace(/\/+$/, "").toLowerCase() || "default";
@@ -59,6 +69,8 @@ export class UploadFormat<Answer extends UploadFormatAnswer = UploadFormatAnswer
private pending: { server: string; promise: Promise<UploadSchema> } | null = null;
private generation = 0;
private memory: Stored = { servers: {} };
+ /** Servers that refused schema 3 in this process (unsupported()) and have not advertised it since. */
+ private readonly refused = new Set<string>();
private readonly now: () => number;
constructor(private readonly options: UploadFormatOptions<Answer>) {
@@ -88,6 +100,7 @@ export class UploadFormat<Answer extends UploadFormatAnswer = UploadFormatAnswer
this.generation += 1;
this.pending = null;
this.cache = { server, version: 2, until: this.now() + RECHECK_MS };
+ this.refused.add(server);
const stored = this.read();
if (!stored.servers[server]) return;
delete stored.servers[server];
@@ -114,12 +127,15 @@ export class UploadFormat<Answer extends UploadFormatAnswer = UploadFormatAnswer
try {
answer = await this.options.probe();
} catch (error) {
- const remembered = this.remembers(server);
+ if (routeMissing(error)) return { version: this.remembers(server) ? 3 : 2, recheckMs: RECHECK_MS };
+ // Remembered: schema 3. Nothing known: schema 3 too (an old server's 422 turns the batch back to 2).
+ // Only a refusal this process saw keeps schema 2.
+ const version: UploadSchema = this.remembers(server) || !this.refused.has(server) ? 3 : 2;
this.options.log?.("warn", "OmniRush session upload: the upload format check failed", {
error: error instanceof Error ? error.message : "unknown",
- schema: remembered ? 3 : 2,
+ schema: version,
});
- return { version: remembered ? 3 : 2, recheckMs: RETRY_MS };
+ return { version, recheckMs: RETRY_MS };
}
try {
this.options.onAnswer?.(answer);
@@ -127,6 +143,7 @@ export class UploadFormat<Answer extends UploadFormatAnswer = UploadFormatAnswer
/* the answer still counts */
}
if (advertisesSchema3(answer)) {
+ this.refused.delete(server);
this.remember(server);
return { version: 3, recheckMs: RECHECK_MS };
}
diff --git a/apps/server/src/upload-format.test.ts b/apps/server/src/upload-format.test.ts
index b0e639ae..898e28d6 100644
--- a/apps/server/src/upload-format.test.ts
+++ b/apps/server/src/upload-format.test.ts
@@ -80,11 +80,16 @@ describe("the upload format when the capabilities check fails", () => {
expect(await runTraces(stateDir, { schema_versions: [1, 2], canonical_trace: false })).toEqual([[3, false]]);
expect(await runTraces(stateDir, "ok", { refuse3: true })).toEqual([[3, true], [2, false]]);
expect(JSON.parse(await readFile(join(stateDir, UPLOAD_FORMAT_FILE), "utf8")).servers).toEqual({});
- expect(await runTraces(stateDir, "fail")).toEqual([[2, false]]);
+ // Nothing known any more (a new process): a failed check tries schema 3, which this server takes.
+ expect(await runTraces(stateDir, "fail")).toEqual([[3, false]]);
+ }, 30_000);
+
+ test("a fresh install whose first check fails still sends schema 3", async () => {
+ expect(await runTraces(await temp("omnirush-format-state-"), "fail")).toEqual([[3, false]]);
}, 30_000);
- test("a fresh install whose first check fails sends schema 2", async () => {
- expect(await runTraces(await temp("omnirush-format-state-"), "fail")).toEqual([[2, false]]);
+ test("a fresh install whose first check fails, on a server without schema 3: the batch goes again as schema 2", async () => {
+ expect(await runTraces(await temp("omnirush-format-state-"), "fail", { refuse3: true })).toEqual([[3, true], [2, false]]);
}, 30_000);
});
@@ -113,7 +118,7 @@ describe("UploadFormat (context/upload-format.ts)", () => {
}
});
- test("an explicit 422 unsupported_schema downgrades; nothing known and a failed check is schema 2", async () => {
+ test("an explicit 422 unsupported_schema downgrades, and a failed check keeps schema 2 until the server advertises 3", async () => {
const time = clock();
let fail = false;
const format = new UploadFormat({ file: null, server: () => "gateway", now: time.now, probe: async () => { if (fail) throw new Error("down"); return SCHEMA_3; } });
@@ -134,9 +139,22 @@ describe("UploadFormat (context/upload-format.ts)", () => {
const down = async (): Promise<TraceCapabilities> => { throw new Error("503"); };
expect(await new UploadFormat({ file, server: () => "gateway", now: time.now, probe: async () => SCHEMA_3 }).version()).toBe(3);
expect(await new UploadFormat({ file, server: () => "gateway", now: time.now, probe: down }).version()).toBe(3);
- expect(await new UploadFormat({ file, server: () => "other", now: time.now, probe: down }).version()).toBe(2);
+ expect(new UploadFormat({ file, server: () => "gateway", now: time.now, probe: down }).remembers("gateway")).toBe(true);
+ expect(new UploadFormat({ file, server: () => "other", now: time.now, probe: down }).remembers("other")).toBe(false);
time.advance(REMEMBER_MS + 1);
- expect(await new UploadFormat({ file, server: () => "gateway", now: time.now, probe: down }).version()).toBe(2);
+ expect(new UploadFormat({ file, server: () => "gateway", now: time.now, probe: down }).remembers("gateway")).toBe(false);
+ });
+
+ test("nothing known and a failed check is schema 3, asked again after RETRY_MS", async () => {
+ const time = clock();
+ let fail = true;
+ let asked = 0;
+ const format = new UploadFormat({ file: null, server: () => "gateway", now: time.now, probe: async () => { asked += 1; if (fail) throw new Error("401"); return SCHEMA_3; } });
+ expect(await format.version()).toBe(3);
+ fail = false;
+ time.advance(RETRY_MS + 1);
+ expect(await format.version()).toBe(3);
+ expect(asked).toBe(2);
});
});