Skip to content
Python

fix(memhub): keep diagnostics from blocking startup

kristinhe617e2d0ba636
diff --git a/memhub/apps/cli/src/log-report.ts b/memhub/apps/cli/src/log-report.ts
index 0e5fbe8..02c3e55 100644
--- a/memhub/apps/cli/src/log-report.ts
+++ b/memhub/apps/cli/src/log-report.ts
@@ -59,6 +59,7 @@ const SAFE_DETAIL_KEYS = new Set([
"revised_count",
"skipped_count",
"error_count",
+ "restart_streak",
"pending_count",
"prepared_count",
"queue_depth",
diff --git a/memhub/apps/desktop/src/main.ts b/memhub/apps/desktop/src/main.ts
index 1b60266..edb4aa5 100644
--- a/memhub/apps/desktop/src/main.ts
+++ b/memhub/apps/desktop/src/main.ts
@@ -1098,7 +1098,7 @@ async function initialize(isQuitting: () => boolean): Promise<void> {
? "blocked"
: "skipped",
...(migration.code === undefined ? {} : { error_code: migration.code }),
- details: { state: migration.state },
+ details: { runtime_state: migration.state },
});
requireCompletedStartupSdkMigration(migration);
};
diff --git a/memhub/package.json b/memhub/package.json
index fe4c042..cc2bc33 100644
--- a/memhub/package.json
+++ b/memhub/package.json
@@ -2,7 +2,7 @@
"name": "one-memory",
"version": "1.0.5",
"release": {
- "build_number": 14,
+ "build_number": 15,
"macos_min_version": "13.0",
"app_update": "manual",
"runtime_manifest_schema": 1,
diff --git a/memhub/packages/host-bridge/src/recall-broker.test.ts b/memhub/packages/host-bridge/src/recall-broker.test.ts
index cc01269..8a019ec 100644
--- a/memhub/packages/host-bridge/src/recall-broker.test.ts
+++ b/memhub/packages/host-bridge/src/recall-broker.test.ts
@@ -192,16 +192,12 @@ describe("RecallBroker", () => {
level: "error",
component: "host.broker",
outcome: "failed",
- details: expect.objectContaining({
- action: "host",
- code: "connection_control_unavailable",
- error_type: "Error",
- }),
+ error_code: "connection_control_unavailable",
+ error_type: "Error",
+ details: { action: "host" },
});
- expect(typeof exception?.details).toBe("object");
- const details = exception?.details as Record<string, unknown>;
- expect(typeof details.stack_origin).toBe("string");
- expect(details.stack_origin).toContain("recall-broker");
+ expect(exception?.details).not.toHaveProperty("message");
+ expect(exception?.details).not.toHaveProperty("stack_origin");
});
it.each(["recall", "ask"])(
"answers %s without waiting for a slow diagnostic write",
diff --git a/memhub/packages/host-bridge/src/recall-broker.ts b/memhub/packages/host-bridge/src/recall-broker.ts
index 0a73bca..fcae69b 100644
--- a/memhub/packages/host-bridge/src/recall-broker.ts
+++ b/memhub/packages/host-bridge/src/recall-broker.ts
@@ -702,20 +702,10 @@ export class RecallBroker {
event: "connection_control.exception",
outcome: "failed",
instance_id: this.options.instanceId,
- details: {
- action: action ?? "invalid",
- code,
- error_type:
- error instanceof Error ? error.constructor.name : typeof error,
- message:
- error instanceof Error
- ? error.message.slice(0, 256)
- : String(error).slice(0, 256),
- stack_origin:
- error instanceof Error && error.stack
- ? (error.stack.split("\n").at(1)?.trim() ?? "").slice(0, 256)
- : null,
- },
+ error_code: code,
+ error_type:
+ error instanceof Error ? error.constructor.name : typeof error,
+ details: { action: action ?? "invalid" },
});
}
const fingerprint = `error:${code}`;
diff --git a/memhub/packages/runtime-control/src/core-supervisor.ts b/memhub/packages/runtime-control/src/core-supervisor.ts
index d7a2488..59a22ab 100644
--- a/memhub/packages/runtime-control/src/core-supervisor.ts
+++ b/memhub/packages/runtime-control/src/core-supervisor.ts
@@ -680,7 +680,7 @@ export class CoreSupervisor {
outcome: "failed",
instance_id: this.activeInstanceId,
error_code: "core_restart_circuit_open",
- details: { streak: this.restartStreak },
+ details: { restart_streak: this.restartStreak },
});
return;
}
@@ -765,7 +765,7 @@ export class CoreSupervisor {
outcome: "failed",
instance_id: this.activeInstanceId,
error_code: "core_restart_exhausted",
- details: { attempts: budget, streak: this.restartStreak },
+ details: { attempts: budget, restart_streak: this.restartStreak },
});
await this.options.diagnostics?.log({
level: "error",
@@ -774,7 +774,7 @@ export class CoreSupervisor {
outcome: "failed",
instance_id: this.activeInstanceId,
error_code: "core_restart_circuit_open",
- details: { streak: this.restartStreak },
+ details: { restart_streak: this.restartStreak },
});
}
} finally {
diff --git a/memhub/packages/runtime-control/src/diagnostic-log.test.ts b/memhub/packages/runtime-control/src/diagnostic-log.test.ts
index 80ac749..a6cbb92 100644
--- a/memhub/packages/runtime-control/src/diagnostic-log.test.ts
+++ b/memhub/packages/runtime-control/src/diagnostic-log.test.ts
@@ -202,6 +202,37 @@ describe("diagnostic log", () => {
).toThrow("diagnostic_stack_invalid");
});
+ it("drops malformed logger events without interrupting later writes", async () => {
+ const dataDir = await root();
+ const logger = new DiagnosticLogger({
+ dataDir,
+ service: "desktop",
+ sessionId: "11111111-1111-4111-8111-111111111111",
+ });
+
+ await expect(
+ logger.log({
+ level: "info",
+ component: "desktop.sdk_migration",
+ event: "sdk_migration.startup",
+ outcome: "succeeded",
+ details: { state: "cutover" },
+ }),
+ ).resolves.toBeUndefined();
+ await logger.log({
+ level: "info",
+ component: "desktop.sdk_migration",
+ event: "sdk_migration.startup",
+ outcome: "succeeded",
+ details: { runtime_state: "cutover" },
+ });
+
+ const result = await readDiagnosticEvents(dataDir);
+ expect(result.invalid_lines).toBe(0);
+ expect(result.events).toHaveLength(1);
+ expect(result.events[0].details).toEqual({ runtime_state: "cutover" });
+ });
+
it("keeps code locations but strips exception messages and absolute prefixes", () => {
const secret = "secret-token-918273";
const error = new Error(secret);
diff --git a/memhub/packages/runtime-control/src/diagnostic-log.ts b/memhub/packages/runtime-control/src/diagnostic-log.ts
index 26394af..8a2979b 100644
--- a/memhub/packages/runtime-control/src/diagnostic-log.ts
+++ b/memhub/packages/runtime-control/src/diagnostic-log.ts
@@ -128,6 +128,7 @@ const DETAIL_KEYS = new Set([
"revised_count",
"skipped_count",
"error_count",
+ "restart_streak",
"pending_count",
"prepared_count",
"queue_depth",
@@ -207,18 +208,26 @@ export class DiagnosticLogger {
}
log(input: DiagnosticInput): Promise<void> {
- const event = diagnosticEvent({
- // A package build stamps its identity into the environment at the shared
- // spawn point; copy it onto every event so one chain can be attributed to
- // one package. A source run leaves them unset and writes nothing.
- ...buildIdentityFromEnvironment(),
- ...input,
- service: this.options.service,
- session_id: this.sessionId,
- timestamp:
- input.timestamp ??
- (this.options.now ?? (() => new Date()))().toISOString(),
- });
+ let event: DiagnosticEventV1;
+ try {
+ event = diagnosticEvent({
+ // A package build stamps its identity into the environment at the shared
+ // spawn point; copy it onto every event so one chain can be attributed to
+ // one package. A source run leaves them unset and writes nothing.
+ ...buildIdentityFromEnvironment(),
+ ...input,
+ service: this.options.service,
+ session_id: this.sessionId,
+ timestamp:
+ input.timestamp ??
+ (this.options.now ?? (() => new Date()))().toISOString(),
+ });
+ } catch {
+ // Diagnostics are observational. A malformed event must be dropped rather
+ // than turn a logging mistake into a product outage. The pure validator
+ // stays strict so tests and export paths can still reject unsafe records.
+ return this.tail;
+ }
this.tail = this.tail.then(() => this.write(event)).catch(() => undefined);
return this.tail;
}