Skip to content

The cross-harness, self-improving memory layer for AI agents. Join our community: https://discord.com/invite/zdNChS2fBu

Fix: roll back SDK state when patch() throws during initialize()

Cursor Agent0b9ad0cd92f2
diff --git a/packages/asymptote-observe-js/src/index.ts b/packages/asymptote-observe-js/src/index.ts
index 8599a88f..6932cda0 100644
--- a/packages/asymptote-observe-js/src/index.ts
+++ b/packages/asymptote-observe-js/src/index.ts
@@ -204,7 +204,14 @@ export function initialize(options: InitializeOptions = {}): void {
state = { instrumentations, provider, mode: resolved.mode, observeUrl: resolved.observeUrl };
if (options.instrumentModules) {
- patch(options.instrumentModules);
+ try {
+ patch(options.instrumentModules);
+ } catch (error) {
+ instrumentations.forEach(i => i.disable());
+ provider.shutdown().catch(() => {});
+ state = undefined;
+ throw error;
+ }
}
}