foldrun 26.3.1 → 26.3.2

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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/src/browser.mjs +20 -11
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "foldrun",
3
- "version": "26.3.1",
3
+ "version": "26.3.2",
4
4
  "description": "Agents are just folders. Write them, check them, run them — on your machine.",
5
5
  "license": "FSL-1.1-ALv2",
6
6
  "type": "module",
package/src/browser.mjs CHANGED
@@ -138,19 +138,28 @@ function ourChrome(pid, profileRoot) {
138
138
  * when it can be, else asked to quit, else killed — and only when it really is
139
139
  * ours. True when it no longer runs. */
140
140
  async function stopLive(paths, ctx) {
141
- let live = liveRecord(paths);
141
+ const live = liveRecord(paths);
142
142
  if (!live?.alive) return true;
143
- const ours = ourChrome(live.pid, live.root);
144
- if (ours === false) return true; // a stale record: our Chrome is not running, and the pid is left alone
143
+ // The one process checked here is the one signalled: its pid and profile
144
+ // are held, and ownership asked again right before each signal.
145
+ const { pid, root } = live;
146
+ const ours = () => ourChrome(pid, root);
147
+ const first = ours();
148
+ if (first === false) return true; // a stale record: our Chrome is not running, and the pid is left alone
145
149
  if (ctx) await runBrowse(ctx, ["--live", "end"], { timeoutMs: 30_000 });
146
- live = liveRecord(paths);
147
- if (!live?.alive) return true;
148
- if (ours === null) return false; // cannot tell it is ours: the person closes it
149
- const wait = async () => { for (let i = 0; i < 50 && pidAlive(live.pid); i++) await new Promise((r) => setTimeout(r, 100)); };
150
- try { process.kill(live.pid, "SIGTERM"); } catch {}
151
- await wait();
152
- if (pidAlive(live.pid)) { try { process.kill(live.pid, "SIGKILL"); } catch {} await wait(); }
153
- return !pidAlive(live.pid);
150
+ const wait = async () => { for (let i = 0; i < 50 && pidAlive(pid); i++) await new Promise((r) => setTimeout(r, 100)); };
151
+ for (const sig of /** @type {const} */ (["SIGTERM", "SIGKILL"])) {
152
+ if (!pidAlive(pid)) break;
153
+ const now = ours();
154
+ if (now === false) break; // it went, and the pid is another program's now
155
+ if (now === null) return false; // cannot tell it is ours: the person closes it
156
+ try { process.kill(pid, sig); } catch {}
157
+ await wait();
158
+ }
159
+ if (pidAlive(pid) && ours() !== false) return false;
160
+ // A window opened on the profile meanwhile (another call) holds it too.
161
+ const after = liveRecord(paths);
162
+ return !(after?.alive && after.pid !== pid && ourChrome(after.pid, after.root) !== false);
154
163
  }
155
164
 
156
165
  /**