om-memory-system 3.5.0 → 3.6.0-next.37

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -36,7 +36,7 @@ function serveFetch(opts) {
36
36
  hostname: opts.hostname,
37
37
  fetch: opts.fetch,
38
38
  });
39
- return { stop: () => bunHandle.stop() };
39
+ return Promise.resolve({ stop: () => bunHandle.stop() });
40
40
  }
41
41
  // Node path: wrap node:http around the fetch-style handler. The adapter
42
42
  // converts IncomingMessage → Web Request and Web Response → ServerResponse.
@@ -95,30 +95,34 @@ function serveFetch(opts) {
95
95
  }
96
96
  }
97
97
  });
98
- // Surface EADDRINUSE synchronously so callers can detect the
99
- // already-running-instance case the same way they do under Bun.
100
- let listenError;
101
- server.on("error", (err) => {
102
- if (err.code === "EADDRINUSE") {
103
- listenError = err;
104
- }
105
- });
106
- // exclusive: false disables SO_EXCLUSIVEADDRUSE on Windows, allowing
107
- // rebind after a crashed predecessor left orphaned sockets behind.
108
- server.listen({ port: opts.port, host: opts.hostname, reuseAddr: true, exclusive: false });
109
98
  server.unref();
110
99
  server.timeout = NODE_HTTP_IDLE_TIMEOUT_MS;
111
100
  server.keepAliveTimeout = 10000;
112
101
  server.headersTimeout = 11000;
113
- if (listenError) {
114
- throw listenError;
115
- }
116
- return {
117
- stop: () => {
118
- server.closeAllConnections();
119
- server.close();
120
- },
121
- };
102
+ // Node reports EADDRINUSE after listen() returns, so wait for the outcome.
103
+ // Callers then see a busy port the same way they do under Bun.
104
+ return new Promise((resolve, reject) => {
105
+ const onError = (error) => {
106
+ server.off("listening", onListening);
107
+ reject(error);
108
+ };
109
+ const onListening = () => {
110
+ server.off("error", onError);
111
+ // Keep a listener, so a later server error is logged instead of crashing the process.
112
+ server.on("error", (error) => log("Web server error", { error: String(error) }));
113
+ resolve({
114
+ stop: () => {
115
+ server.closeAllConnections();
116
+ server.close();
117
+ },
118
+ });
119
+ };
120
+ server.once("error", onError);
121
+ server.once("listening", onListening);
122
+ // exclusive: false disables SO_EXCLUSIVEADDRUSE on Windows, allowing
123
+ // rebind after a crashed predecessor left orphaned sockets behind.
124
+ server.listen({ port: opts.port, host: opts.hostname, reuseAddr: true, exclusive: false });
125
+ });
122
126
  }
123
127
  const __filename = fileURLToPath(import.meta.url);
124
128
  const __dirname = dirname(__filename);
@@ -192,7 +196,7 @@ export class WebServer {
192
196
  .catch(() => { });
193
197
  assertWebServerNetworkAuth(this.config.host, this.config.apiToken, this.config.auth?.isEnabled() ?? false);
194
198
  try {
195
- this.server = serveFetch({
199
+ this.server = await serveFetch({
196
200
  port: this.config.port,
197
201
  hostname: this.config.host,
198
202
  fetch: this.handleRequest.bind(this),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "om-memory-system",
3
- "version": "3.5.0",
3
+ "version": "3.6.0-next.37",
4
4
  "description": "Opinionated modular memory system for coding agents (OpenCode + Pi)",
5
5
  "type": "module",
6
6
  "main": "dist/plugin.js",