ework-daemon 0.4.31 → 0.4.32

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ework-daemon",
3
- "version": "0.4.31",
3
+ "version": "0.4.32",
4
4
  "description": "Issue-driven AI development daemon. Spawns opencode subprocesses to resolve Gitea issues.",
5
5
  "module": "src/index.ts",
6
6
  "type": "module",
package/src/op.ts CHANGED
@@ -260,9 +260,12 @@ export class Store {
260
260
  return rows.map(rowToSession);
261
261
  }
262
262
 
263
- async listSessionsWithPid(): Promise<Array<{ id: string; opencodePid: number }>> {
263
+ async listSessionsWithPid(daemonId: number): Promise<Array<{ id: string; opencodePid: number }>> {
264
264
  const rows = await getDB().all<{ uid: string; opencode_pid: number }>(
265
- "SELECT uid, opencode_pid FROM {{op_sessions}} WHERE opencode_pid IS NOT NULL"
265
+ `SELECT s.uid, s.opencode_pid FROM {{op_sessions}} s
266
+ INNER JOIN {{issues}} i ON i.uid = s.issue_id
267
+ WHERE s.opencode_pid IS NOT NULL AND i.owner_daemon_id = ?`,
268
+ [daemonId]
266
269
  );
267
270
  return rows.map((r) => ({ id: r.uid, opencodePid: r.opencode_pid }));
268
271
  }
package/src/opencode.ts CHANGED
@@ -1716,14 +1716,20 @@ export class Engine {
1716
1716
  private async cleanupGlobalOrphans(): Promise<void> {
1717
1717
  let sessions: Array<{ id: string; opencodePid: number }>;
1718
1718
  try {
1719
- sessions = await this.store.listSessionsWithPid();
1719
+ sessions = await this.store.listSessionsWithPid(this.daemonId);
1720
1720
  } catch { return; }
1721
+ const binaryName = this.cfg.opencode.binary.split("/").pop() ?? "opencode";
1721
1722
  let killed = 0;
1722
1723
  for (const s of sessions) {
1723
1724
  let alive = false;
1724
1725
  try { process.kill(s.opencodePid, 0); alive = true; } catch { /* dead */ }
1725
1726
  if (!alive) continue;
1726
1727
 
1728
+ try {
1729
+ const cmdline = readFileSync(`/proc/${s.opencodePid}/cmdline`, "utf8");
1730
+ if (!cmdline.includes(binaryName) && !cmdline.includes("opencode") && !cmdline.includes("pi")) continue;
1731
+ } catch { continue; }
1732
+
1727
1733
  let ppid = -1;
1728
1734
  try {
1729
1735
  const stat = readFileSync(`/proc/${s.opencodePid}/stat`, "utf8");
@@ -1732,7 +1738,7 @@ export class Engine {
1732
1738
  } catch { continue; }
1733
1739
 
1734
1740
  if (ppid === 1) {
1735
- log.info(`engine: killing global orphan pid=${s.opencodePid} (PPID=1, session ${s.id})`);
1741
+ log.info(`engine: killing orphaned pid=${s.opencodePid} (PPID=1, session ${s.id})`);
1736
1742
  try { this.killProcessTree(s.opencodePid); } catch { /* dead */ }
1737
1743
  killed++;
1738
1744
  }