Skip to content

armgit / Ix

Public Imported from GitHub
0

Understand any codebase instantly. System intelligence for codebases, built for humans and AI.

fix(client): don't cache a failed stitch-system lookup as "not stitched"

KageBinary388cd82bb709
diff --git a/ix-cli/src/cli/commands/map.ts b/ix-cli/src/cli/commands/map.ts
index f5183d57..05ab5a42 100644
--- a/ix-cli/src/cli/commands/map.ts
+++ b/ix-cli/src/cli/commands/map.ts
@@ -535,7 +535,9 @@ Examples:
if (!effectiveSystemId) {
const ws = resolveWorkspaceId(cwd);
if (ws) {
- const looked = await client.workspaceSystem(ws);
+ // Best-effort, as before workspaceSystem started reporting failures:
+ // an unanswered lookup leaves the map at workspace scope.
+ const looked = await client.workspaceSystem(ws).catch(() => ({ systemId: null }));
if (looked.systemId) effectiveSystemId = looked.systemId;
}
}
diff --git a/ix-cli/src/client/__tests__/workspace-system.test.ts b/ix-cli/src/client/__tests__/workspace-system.test.ts
new file mode 100644
index 00000000..616ede6b
--- /dev/null
+++ b/ix-cli/src/client/__tests__/workspace-system.test.ts
@@ -0,0 +1,48 @@
+// Copyright 2026 Ix Infrastructure Inc.
+
+import { createServer, type Server } from "node:http";
+import type { AddressInfo } from "node:net";
+import { afterEach, describe, expect, it } from "vitest";
+import { IxClient } from "../api.js";
+
+const servers: Server[] = [];
+
+async function backend(status: number, body: string): Promise<string> {
+ const server = createServer((_req, res) => {
+ res.writeHead(status, { "Content-Type": "application/json" });
+ res.end(body);
+ });
+ servers.push(server);
+ await new Promise<void>(resolve => server.listen(0, "127.0.0.1", resolve));
+ return `http://127.0.0.1:${(server.address() as AddressInfo).port}`;
+}
+
+afterEach(async () => {
+ await Promise.all(servers.splice(0).map(s => new Promise<void>(r => s.close(() => r()))));
+});
+
+// ensureReadScope caches whatever this returns with no TTL, so a failure that
+// came back as `{ systemId: null }` was recorded as "not stitched" and scoped
+// every later read in a stitched workspace to one repo.
+describe("IxClient.workspaceSystem", () => {
+ it("returns the backend's answer", async () => {
+ const client = new IxClient(await backend(200, JSON.stringify({ systemId: "sys-1" })));
+ await expect(client.workspaceSystem("ws")).resolves.toEqual({ systemId: "sys-1" });
+ });
+
+ it("treats a 404 (older backend without the endpoint) as not stitched", async () => {
+ const client = new IxClient(await backend(404, "not found"));
+ await expect(client.workspaceSystem("ws")).resolves.toEqual({ systemId: null });
+ });
+
+ it("reports a server error instead of answering 'not stitched'", async () => {
+ const client = new IxClient(await backend(500, "boom"));
+ await expect(client.workspaceSystem("ws")).rejects.toThrow(/^500:/);
+ });
+
+ it("reports an unreachable backend instead of answering 'not stitched'", async () => {
+ const endpoint = await backend(200, "{}");
+ await new Promise<void>(r => servers.pop()!.close(() => r()));
+ await expect(new IxClient(endpoint).workspaceSystem("ws")).rejects.toThrow();
+ });
+});
diff --git a/ix-cli/src/client/api.ts b/ix-cli/src/client/api.ts
index 11554823..183a8b95 100644
--- a/ix-cli/src/client/api.ts
+++ b/ix-cli/src/client/api.ts
@@ -319,9 +319,18 @@ export class IxClient {
// Path-2 grouping (Ix#225 Half B): the system_id a workspace currently belongs
// to (null if a singleton). Lets `ix map <repo>` scope to its stitched system.
+ //
+ // Only a 404 (an older backend without the endpoint) means "no system". Any
+ // other failure -- backend down, timeout, 5xx, a non-JSON body -- is not an
+ // answer and is thrown: `ensureReadScope` persists what this returns with no
+ // TTL, so turning an outage into `null` pinned every later read in a stitched
+ // workspace to the single repo until the next map.
async workspaceSystem(workspaceId: string): Promise<{ systemId: string | null }> {
try { return await this.get(`/v1/stitch/system/${workspaceId}`); }
- catch { return { systemId: null }; } // older backend without the endpoint
+ catch (err) {
+ if (err instanceof Error && err.message.startsWith("404:")) return { systemId: null };
+ throw err;
+ }
}
async map(opts?: { full?: boolean; workspaceId?: string; systemId?: string }): Promise<any> {