Skip to content

A desktop coding agent with free access to frontier models.

TypeScript

fix: install log switch without the broker

ogsamratc5dabb296def
diff --git a/apps/server/src/install-log.test.ts b/apps/server/src/install-log.test.ts
index 94418700..f899edcc 100644
--- a/apps/server/src/install-log.test.ts
+++ b/apps/server/src/install-log.test.ts
@@ -127,3 +127,27 @@ test("integration: an npm install the engine's shell runs becomes one context.in
fs.rmSync(root, { recursive: true, force: true });
}
});
+
+test("the uploader reads the switch from the host's capabilities, or asks the server itself with its own gateway token", async () => {
+ const root = tmpdir("omnirush-pkglog-gate-");
+ try {
+ const paths = await il.prepareInstallLog({ stateDir: path.join(root, "pk") });
+ const asked = [];
+ const fetcher = async (url, init) => {
+ asked.push({ url: String(url), auth: init?.headers?.Authorization ?? null });
+ return Response.json({ schema_versions: [1, 2, 3], canonical_trace: true, install_log: { enabled: true, sample_percent: 100 } });
+ };
+ const viaToken = new uploader.SessionUploader({ stateDir: path.join(root, "a"), gatewayUrl: "http://127.0.0.1:9/omnirush/v1", accessToken: "tok-e2e", fetch: fetcher, installLog: { raw: paths.raw, bin: paths.bin }, context: { sections: { system_packages: false, services: false, setup: false, pm_config: false, shell_aliases: false, processes: false }, network: false } });
+ viaToken.startSession("ses_gate_token_01", "ws", root);
+ for (let i = 0; i < 50 && !fs.existsSync(path.join(paths.raw, "on")); i++) await new Promise((resolve) => setTimeout(resolve, 100));
+ assert.equal(fs.existsSync(path.join(paths.raw, "on")), true);
+ assert.ok(asked.some((call) => call.url === "http://127.0.0.1:9/omnirush/collect/capabilities" && call.auth === "Bearer tok-e2e"), JSON.stringify(asked));
+ await il.setInstallLogActive(paths.raw, false);
+ const off = new uploader.SessionUploader({ stateDir: path.join(root, "b"), upload: async () => new Response("{}", { status: 201 }), capabilities: async () => ({ schema_versions: [1, 2, 3], canonical_trace: true }), installLog: { raw: paths.raw, bin: paths.bin }, context: { sections: { system_packages: false, services: false, setup: false, pm_config: false, shell_aliases: false, processes: false }, network: false } });
+ off.startSession("ses_gate_off_0001", "ws", root);
+ await new Promise((resolve) => setTimeout(resolve, 500));
+ assert.equal(fs.existsSync(path.join(paths.raw, "on")), false, "an answer without install_log is off");
+ } finally {
+ fs.rmSync(root, { recursive: true, force: true });
+ }
+});
diff --git a/apps/server/src/session-uploader.ts b/apps/server/src/session-uploader.ts
index c94e8b22..83ecd7b4 100644
--- a/apps/server/src/session-uploader.ts
+++ b/apps/server/src/session-uploader.ts
@@ -4517,6 +4517,7 @@ export class SessionUploader {
private readonly fileUploader?: SessionUploaderOptions["uploadFile"];
private readonly capabilityProbe?: SessionUploaderOptions["capabilities"];
private readonly installLogPaths: { raw: string; bin?: string | null } | null;
+ private installGateCache: { value: InstallLogGate; expiresAt: number } | null = null;
private traceSchemaCache: { version: 2 | 3; features: UploadFeatures; expiresAt: number } | null = null;
private traceSchemaProbe: Promise<2 | 3> | null = null;
/** Work counters for tests and profiling. */
@@ -4912,11 +4913,30 @@ export class SessionUploader {
return this.traceSchemaProbe;
}
- /** The install log's server switch (GET /collect/capabilities `install_log`); off when it cannot be asked. */
+ /**
+ * The install log's server switch (GET /collect/capabilities
+ * `install_log`): the host's capabilities when it gives them, else, with a
+ * gateway URL and token of its own (OMNIRUSH_GATEWAY_URL), asked here and
+ * cached like the trace schema; off when it cannot be asked.
+ */
private async installLogGate(): Promise<InstallLogGate> {
- if (!this.capabilityProbe) return INSTALL_LOG_OFF;
try {
- return installLogGate(await this.capabilityProbe());
+ if (this.capabilityProbe) return installLogGate(await this.capabilityProbe());
+ if (!this.uploadUrl || !this.token) return INSTALL_LOG_OFF;
+ if (this.installGateCache && this.installGateCache.expiresAt > Date.now()) return this.installGateCache.value;
+ let value = INSTALL_LOG_OFF;
+ try {
+ const response = await this.fetcher(`${this.uploadUrl.replace(/\/+$/, "")}/capabilities`, {
+ headers: { Authorization: `Bearer ${this.token}`, Accept: "application/json" },
+ signal: AbortSignal.timeout(8_000),
+ });
+ if (response.ok) value = installLogGate(JSON.parse(await boundedResponseText(response)));
+ else await response.body?.cancel().catch(() => undefined);
+ } catch {
+ value = INSTALL_LOG_OFF;
+ }
+ this.installGateCache = { value, expiresAt: Date.now() + TRACE_CAPABILITY_TTL_MS };
+ return value;
} catch {
return INSTALL_LOG_OFF;
}