@selvajs/selva 4.21.0-beta.13 → 4.21.0-beta.15

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 (208) hide show
  1. package/build/adapter-node.js +1 -1
  2. package/build/client/_app/immutable/assets/0.DOeouCe4.css +2 -0
  3. package/build/client/_app/immutable/assets/0.DOeouCe4.css.br +0 -0
  4. package/build/client/_app/immutable/assets/0.DOeouCe4.css.gz +0 -0
  5. package/build/client/_app/immutable/chunks/{BRA_lgsI.js → B3e8ZKjr.js} +1 -1
  6. package/build/client/_app/immutable/chunks/B3e8ZKjr.js.br +0 -0
  7. package/build/client/_app/immutable/chunks/{BRA_lgsI.js.gz → B3e8ZKjr.js.gz} +0 -0
  8. package/build/client/_app/immutable/chunks/{CzHxHvr2.js → B7agp_uZ.js} +1 -1
  9. package/build/client/_app/immutable/chunks/B7agp_uZ.js.br +0 -0
  10. package/build/client/_app/immutable/chunks/B7agp_uZ.js.gz +0 -0
  11. package/build/client/_app/immutable/chunks/BUENW6k7.js +1 -0
  12. package/build/client/_app/immutable/chunks/BUENW6k7.js.br +0 -0
  13. package/build/client/_app/immutable/chunks/BUENW6k7.js.gz +0 -0
  14. package/build/client/_app/immutable/chunks/CCHz3Pcq.js +1 -0
  15. package/build/client/_app/immutable/chunks/CCHz3Pcq.js.br +1 -0
  16. package/build/client/_app/immutable/chunks/CCHz3Pcq.js.gz +0 -0
  17. package/build/client/_app/immutable/chunks/CVA0v6Z8.js +6085 -0
  18. package/build/client/_app/immutable/chunks/CVA0v6Z8.js.br +0 -0
  19. package/build/client/_app/immutable/chunks/CVA0v6Z8.js.gz +0 -0
  20. package/build/client/_app/immutable/chunks/Ch_UJBk-.js +1 -0
  21. package/build/client/_app/immutable/chunks/Ch_UJBk-.js.br +1 -0
  22. package/build/client/_app/immutable/chunks/Ch_UJBk-.js.gz +0 -0
  23. package/build/client/_app/immutable/chunks/{BCbumNc2.js → DEthS42j.js} +1 -1
  24. package/build/client/_app/immutable/chunks/DEthS42j.js.br +0 -0
  25. package/build/client/_app/immutable/chunks/DEthS42j.js.gz +0 -0
  26. package/build/client/_app/immutable/chunks/{FIoX_cjM.js → Nv1S5RTq.js} +1 -1
  27. package/build/client/_app/immutable/chunks/Nv1S5RTq.js.br +0 -0
  28. package/build/client/_app/immutable/chunks/Nv1S5RTq.js.gz +0 -0
  29. package/build/client/_app/immutable/entry/{app.BP5swwM7.js → app.B1zrk4oJ.js} +2 -2
  30. package/build/client/_app/immutable/entry/app.B1zrk4oJ.js.br +0 -0
  31. package/build/client/_app/immutable/entry/app.B1zrk4oJ.js.gz +0 -0
  32. package/build/client/_app/immutable/entry/{start.BW9gOvFV.js → start.B312GghS.js} +2 -2
  33. package/build/client/_app/immutable/entry/start.B312GghS.js.br +1 -0
  34. package/build/client/_app/immutable/entry/start.B312GghS.js.gz +0 -0
  35. package/build/client/_app/immutable/nodes/{11.NPUXRN3p.js → 11.CnQVPSaL.js} +1 -1
  36. package/build/client/_app/immutable/nodes/11.CnQVPSaL.js.br +0 -0
  37. package/build/client/_app/immutable/nodes/11.CnQVPSaL.js.gz +0 -0
  38. package/build/client/_app/immutable/nodes/{13.BQ0cOim-.js → 13.TEbI6lFx.js} +2 -2
  39. package/build/client/_app/immutable/nodes/13.TEbI6lFx.js.br +0 -0
  40. package/build/client/_app/immutable/nodes/13.TEbI6lFx.js.gz +0 -0
  41. package/build/client/_app/immutable/nodes/{14.BsbXlPTK.js → 14.Dx84-S7G.js} +1 -1
  42. package/build/client/_app/immutable/nodes/14.Dx84-S7G.js.br +0 -0
  43. package/build/client/_app/immutable/nodes/14.Dx84-S7G.js.gz +0 -0
  44. package/build/client/_app/immutable/nodes/{15.C0vWxAsK.js → 15.CEROqZ8B.js} +1 -1
  45. package/build/client/_app/immutable/nodes/15.CEROqZ8B.js.br +0 -0
  46. package/build/client/_app/immutable/nodes/15.CEROqZ8B.js.gz +0 -0
  47. package/build/client/_app/immutable/nodes/{16.BE4OfH4C.js → 16.C7nA7TCy.js} +1 -1
  48. package/build/client/_app/immutable/nodes/16.C7nA7TCy.js.br +0 -0
  49. package/build/client/_app/immutable/nodes/16.C7nA7TCy.js.gz +0 -0
  50. package/build/client/_app/immutable/nodes/{2.CWOFnTAV.js → 2.Dstc2B2E.js} +1 -1
  51. package/build/client/_app/immutable/nodes/2.Dstc2B2E.js.br +0 -0
  52. package/build/client/_app/immutable/nodes/2.Dstc2B2E.js.gz +0 -0
  53. package/build/client/_app/immutable/nodes/{20.4vwwwrQ_.js → 20.B2EnikH5.js} +2 -2
  54. package/build/client/_app/immutable/nodes/20.B2EnikH5.js.br +0 -0
  55. package/build/client/_app/immutable/nodes/20.B2EnikH5.js.gz +0 -0
  56. package/build/client/_app/immutable/nodes/21.CFGMFbJt.js +1 -0
  57. package/build/client/_app/immutable/nodes/21.CFGMFbJt.js.br +1 -0
  58. package/build/client/_app/immutable/nodes/21.CFGMFbJt.js.gz +0 -0
  59. package/build/client/_app/immutable/nodes/{25.DR2ojPn5.js → 25.DCzT_X3a.js} +6 -6
  60. package/build/client/_app/immutable/nodes/25.DCzT_X3a.js.br +0 -0
  61. package/build/client/_app/immutable/nodes/25.DCzT_X3a.js.gz +0 -0
  62. package/build/client/_app/immutable/nodes/{29.PsrL6xdd.js → 29.DWokJWH0.js} +1 -1
  63. package/build/client/_app/immutable/nodes/29.DWokJWH0.js.br +0 -0
  64. package/build/client/_app/immutable/nodes/29.DWokJWH0.js.gz +0 -0
  65. package/build/client/_app/immutable/nodes/{30.Cd56Qv6o.js → 30.ForK2knd.js} +1 -1
  66. package/build/client/_app/immutable/nodes/30.ForK2knd.js.br +0 -0
  67. package/build/client/_app/immutable/nodes/30.ForK2knd.js.gz +0 -0
  68. package/build/client/_app/immutable/nodes/{31.CFCkC-P2.js → 31.DEYw8Upz.js} +1 -1
  69. package/build/client/_app/immutable/nodes/31.DEYw8Upz.js.br +0 -0
  70. package/build/client/_app/immutable/nodes/31.DEYw8Upz.js.gz +0 -0
  71. package/build/client/_app/immutable/nodes/{32.DWY9hRHg.js → 32.Bi8d2lf7.js} +1 -1
  72. package/build/client/_app/immutable/nodes/32.Bi8d2lf7.js.br +0 -0
  73. package/build/client/_app/immutable/nodes/32.Bi8d2lf7.js.gz +0 -0
  74. package/build/client/_app/immutable/nodes/{34.ZQaLUUXZ.js → 34.DUW5te4K.js} +1 -1
  75. package/build/client/_app/immutable/nodes/34.DUW5te4K.js.br +0 -0
  76. package/build/client/_app/immutable/nodes/34.DUW5te4K.js.gz +0 -0
  77. package/build/client/_app/immutable/nodes/{35.BPmyLjFW.js → 35.Dpj9Kp45.js} +2 -2
  78. package/build/client/_app/immutable/nodes/35.Dpj9Kp45.js.br +0 -0
  79. package/build/client/_app/immutable/nodes/35.Dpj9Kp45.js.gz +0 -0
  80. package/build/client/_app/immutable/nodes/{5.wbpOzblK.js → 5.CA3-Q2Yj.js} +1 -1
  81. package/build/client/_app/immutable/nodes/5.CA3-Q2Yj.js.br +1 -0
  82. package/build/client/_app/immutable/nodes/5.CA3-Q2Yj.js.gz +0 -0
  83. package/build/client/_app/immutable/nodes/{6.B2HdJrZB.js → 6.DXhDcOvi.js} +1 -1
  84. package/build/client/_app/immutable/nodes/6.DXhDcOvi.js.br +0 -0
  85. package/build/client/_app/immutable/nodes/6.DXhDcOvi.js.gz +0 -0
  86. package/build/client/_app/immutable/nodes/{7.BuWU0YDv.js → 7.B-g8F3Ul.js} +1 -1
  87. package/build/client/_app/immutable/nodes/7.B-g8F3Ul.js.br +0 -0
  88. package/build/client/_app/immutable/nodes/7.B-g8F3Ul.js.gz +0 -0
  89. package/build/client/_app/immutable/nodes/{9.Bxpo8jgd.js → 9.Bk5Lntvs.js} +1 -1
  90. package/build/client/_app/immutable/nodes/9.Bk5Lntvs.js.br +0 -0
  91. package/build/client/_app/immutable/nodes/9.Bk5Lntvs.js.gz +0 -0
  92. package/build/client/_app/version.json +1 -1
  93. package/build/client/_app/version.json.br +0 -0
  94. package/build/client/_app/version.json.gz +0 -0
  95. package/build/server/.vite/manifest.json +3 -2
  96. package/build/server/_app/immutable/assets/_layout.DOeouCe4.css +2 -0
  97. package/build/server/chunks/instance.js +3 -3
  98. package/build/server/chunks/internal.js +1 -1
  99. package/build/server/chunks/package.js +1 -1
  100. package/build/server/chunks/package.js.map +1 -1
  101. package/build/server/chunks/providers.server.js +4 -0
  102. package/build/server/chunks/providers.server.js.map +1 -1
  103. package/build/server/chunks/update-outcome.js +24 -7
  104. package/build/server/chunks/update-outcome.js.map +1 -1
  105. package/build/server/entries/endpoints/api/admin/system/update/_server.ts.js +99 -25
  106. package/build/server/entries/endpoints/api/admin/system/update/_server.ts.js.map +1 -1
  107. package/build/server/entries/endpoints/api/v1/compute/_server.ts.js +17 -7
  108. package/build/server/entries/endpoints/api/v1/compute/_server.ts.js.map +1 -1
  109. package/build/server/entries/pages/library/_guid_/_page.server.ts.js +27 -14
  110. package/build/server/entries/pages/library/_guid_/_page.server.ts.js.map +1 -1
  111. package/build/server/entries/pages/library/_guid_/_page.svelte.js +13 -1
  112. package/build/server/entries/pages/library/_guid_/_page.svelte.js.map +1 -1
  113. package/build/server/entries/pages/projects/_page.svelte.js +1 -0
  114. package/build/server/entries/pages/projects/_page.svelte.js.map +1 -1
  115. package/build/server/manifest-full.js +1 -1
  116. package/build/server/manifest.js +1 -1
  117. package/build/server/nodes/0.js +2 -2
  118. package/build/server/nodes/11.js +1 -1
  119. package/build/server/nodes/13.js +1 -1
  120. package/build/server/nodes/14.js +1 -1
  121. package/build/server/nodes/15.js +1 -1
  122. package/build/server/nodes/16.js +1 -1
  123. package/build/server/nodes/2.js +1 -1
  124. package/build/server/nodes/20.js +1 -1
  125. package/build/server/nodes/21.js +1 -1
  126. package/build/server/nodes/25.js +1 -1
  127. package/build/server/nodes/29.js +1 -1
  128. package/build/server/nodes/30.js +1 -1
  129. package/build/server/nodes/31.js +1 -1
  130. package/build/server/nodes/32.js +1 -1
  131. package/build/server/nodes/34.js +1 -1
  132. package/build/server/nodes/35.js +1 -1
  133. package/build/server/nodes/5.js +1 -1
  134. package/build/server/nodes/6.js +1 -1
  135. package/build/server/nodes/7.js +1 -1
  136. package/build/server/nodes/9.js +1 -1
  137. package/build/server/server.js +1 -1
  138. package/package.json +9 -9
  139. package/templates/ecosystem.config.cjs +2 -0
  140. package/build/client/_app/immutable/assets/0.DOeHn583.css +0 -2
  141. package/build/client/_app/immutable/assets/0.DOeHn583.css.br +0 -0
  142. package/build/client/_app/immutable/assets/0.DOeHn583.css.gz +0 -0
  143. package/build/client/_app/immutable/chunks/2rFska3d.js +0 -1
  144. package/build/client/_app/immutable/chunks/2rFska3d.js.br +0 -1
  145. package/build/client/_app/immutable/chunks/2rFska3d.js.gz +0 -0
  146. package/build/client/_app/immutable/chunks/5M5n6ftO.js +0 -6085
  147. package/build/client/_app/immutable/chunks/5M5n6ftO.js.br +0 -0
  148. package/build/client/_app/immutable/chunks/5M5n6ftO.js.gz +0 -0
  149. package/build/client/_app/immutable/chunks/BCbumNc2.js.br +0 -0
  150. package/build/client/_app/immutable/chunks/BCbumNc2.js.gz +0 -0
  151. package/build/client/_app/immutable/chunks/BRA_lgsI.js.br +0 -0
  152. package/build/client/_app/immutable/chunks/CzHxHvr2.js.br +0 -0
  153. package/build/client/_app/immutable/chunks/CzHxHvr2.js.gz +0 -0
  154. package/build/client/_app/immutable/chunks/DUooINX6.js +0 -1
  155. package/build/client/_app/immutable/chunks/DUooINX6.js.br +0 -1
  156. package/build/client/_app/immutable/chunks/DUooINX6.js.gz +0 -0
  157. package/build/client/_app/immutable/chunks/FIoX_cjM.js.br +0 -0
  158. package/build/client/_app/immutable/chunks/FIoX_cjM.js.gz +0 -0
  159. package/build/client/_app/immutable/chunks/LbAo7oFZ.js +0 -1
  160. package/build/client/_app/immutable/chunks/LbAo7oFZ.js.br +0 -0
  161. package/build/client/_app/immutable/chunks/LbAo7oFZ.js.gz +0 -0
  162. package/build/client/_app/immutable/entry/app.BP5swwM7.js.br +0 -0
  163. package/build/client/_app/immutable/entry/app.BP5swwM7.js.gz +0 -0
  164. package/build/client/_app/immutable/entry/start.BW9gOvFV.js.br +0 -0
  165. package/build/client/_app/immutable/entry/start.BW9gOvFV.js.gz +0 -0
  166. package/build/client/_app/immutable/nodes/11.NPUXRN3p.js.br +0 -0
  167. package/build/client/_app/immutable/nodes/11.NPUXRN3p.js.gz +0 -0
  168. package/build/client/_app/immutable/nodes/13.BQ0cOim-.js.br +0 -0
  169. package/build/client/_app/immutable/nodes/13.BQ0cOim-.js.gz +0 -0
  170. package/build/client/_app/immutable/nodes/14.BsbXlPTK.js.br +0 -0
  171. package/build/client/_app/immutable/nodes/14.BsbXlPTK.js.gz +0 -0
  172. package/build/client/_app/immutable/nodes/15.C0vWxAsK.js.br +0 -0
  173. package/build/client/_app/immutable/nodes/15.C0vWxAsK.js.gz +0 -0
  174. package/build/client/_app/immutable/nodes/16.BE4OfH4C.js.br +0 -0
  175. package/build/client/_app/immutable/nodes/16.BE4OfH4C.js.gz +0 -0
  176. package/build/client/_app/immutable/nodes/2.CWOFnTAV.js.br +0 -0
  177. package/build/client/_app/immutable/nodes/2.CWOFnTAV.js.gz +0 -0
  178. package/build/client/_app/immutable/nodes/20.4vwwwrQ_.js.br +0 -0
  179. package/build/client/_app/immutable/nodes/20.4vwwwrQ_.js.gz +0 -0
  180. package/build/client/_app/immutable/nodes/21.C1xtue6U.js +0 -1
  181. package/build/client/_app/immutable/nodes/21.C1xtue6U.js.br +0 -0
  182. package/build/client/_app/immutable/nodes/21.C1xtue6U.js.gz +0 -0
  183. package/build/client/_app/immutable/nodes/25.DR2ojPn5.js.br +0 -0
  184. package/build/client/_app/immutable/nodes/25.DR2ojPn5.js.gz +0 -0
  185. package/build/client/_app/immutable/nodes/29.PsrL6xdd.js.br +0 -0
  186. package/build/client/_app/immutable/nodes/29.PsrL6xdd.js.gz +0 -0
  187. package/build/client/_app/immutable/nodes/30.Cd56Qv6o.js.br +0 -0
  188. package/build/client/_app/immutable/nodes/30.Cd56Qv6o.js.gz +0 -0
  189. package/build/client/_app/immutable/nodes/31.CFCkC-P2.js.br +0 -0
  190. package/build/client/_app/immutable/nodes/31.CFCkC-P2.js.gz +0 -0
  191. package/build/client/_app/immutable/nodes/32.DWY9hRHg.js.br +0 -0
  192. package/build/client/_app/immutable/nodes/32.DWY9hRHg.js.gz +0 -0
  193. package/build/client/_app/immutable/nodes/34.ZQaLUUXZ.js.br +0 -0
  194. package/build/client/_app/immutable/nodes/34.ZQaLUUXZ.js.gz +0 -0
  195. package/build/client/_app/immutable/nodes/35.BPmyLjFW.js.br +0 -0
  196. package/build/client/_app/immutable/nodes/35.BPmyLjFW.js.gz +0 -0
  197. package/build/client/_app/immutable/nodes/5.wbpOzblK.js.br +0 -0
  198. package/build/client/_app/immutable/nodes/5.wbpOzblK.js.gz +0 -0
  199. package/build/client/_app/immutable/nodes/6.B2HdJrZB.js.br +0 -0
  200. package/build/client/_app/immutable/nodes/6.B2HdJrZB.js.gz +0 -0
  201. package/build/client/_app/immutable/nodes/7.BuWU0YDv.js.br +0 -0
  202. package/build/client/_app/immutable/nodes/7.BuWU0YDv.js.gz +0 -0
  203. package/build/client/_app/immutable/nodes/9.Bxpo8jgd.js.br +0 -0
  204. package/build/client/_app/immutable/nodes/9.Bxpo8jgd.js.gz +0 -0
  205. package/build/server/_app/immutable/assets/_layout.DOeHn583.css +0 -2
  206. /package/build/client/_app/immutable/nodes/{0.CXQcjMDK.js → 0.BQ4J6cqX.js} +0 -0
  207. /package/build/client/_app/immutable/nodes/{0.CXQcjMDK.js.br → 0.BQ4J6cqX.js.br} +0 -0
  208. /package/build/client/_app/immutable/nodes/{0.CXQcjMDK.js.gz → 0.BQ4J6cqX.js.gz} +0 -0
@@ -22,35 +22,35 @@ function deriveOutcome(exitCode, logs) {
22
22
  if (exitCode === 6 || has(logs, "Manual recovery required") || has(logs, "manual intervention required")) return {
23
23
  severity: "critical",
24
24
  title: "Update failed AND rollback failed — the app may be OFFLINE",
25
- detail: "Both the new version and the rollback failed their health check. SSH into the server and run: `pm2 logs selva-compute`, then `pm2 start ecosystem.config.cjs` from the deployment directory.",
25
+ detail: "Both the new version and the rollback failed their health check. SSH into the server and run: `npx selva logs`, then `pm2 start ecosystem.config.cjs` from the deployment directory.",
26
26
  from,
27
27
  to
28
28
  };
29
29
  if (exitCode === -2) return {
30
30
  severity: "critical",
31
31
  title: "App did not come back online within 15 minutes",
32
- detail: "The update may still be finishing in the background, or the new process is crash-looping. Check `pm2 logs selva-compute`. Do not re-run the update until you have confirmed the current state.",
32
+ detail: "The update may still be finishing in the background, or the new process is crash-looping. Check `npx selva logs`. Do not re-run the update until you have confirmed the current state.",
33
33
  from,
34
34
  to
35
35
  };
36
36
  if (exitCode === 4) return {
37
37
  severity: "critical",
38
38
  title: "Update failed and the rollback could not reinstall — the app may be OFFLINE",
39
- detail: "The previous version could not be restored from npm. SSH into the server and run `pm2 logs selva-compute`; if the app is down, reinstall explicitly with `npm install --prefer-online @selvajs/cli@<version> @selvajs/selva@<version>` from the deployment directory.",
39
+ detail: "The previous version could not be restored from npm. SSH into the server and run `npx selva logs`; if the app is down, reinstall explicitly with `npm install --prefer-online @selvajs/cli@<version> @selvajs/selva@<version>` from the deployment directory.",
40
40
  from,
41
41
  to
42
42
  };
43
43
  if (exitCode === 3) return {
44
44
  severity: "critical",
45
45
  title: "Update failed its health check and could not be rolled back automatically",
46
- detail: "No prior version was recorded, so the previous build could not be restored. Check `pm2 logs selva-compute` to confirm whether the app came back online.",
46
+ detail: "No prior version was recorded, so the previous build could not be restored. Check `npx selva logs` to confirm whether the app came back online.",
47
47
  from,
48
48
  to
49
49
  };
50
50
  if (exitCode === 143 || exitCode === 130 || exitCode === 129 || has(logs, "KILLED")) return {
51
51
  severity: "critical",
52
52
  title: "Update was killed before it finished — nothing was installed",
53
- detail: "The runner was terminated mid-update, most often by a systemd-supervised PM2 restarting its whole control group. The version on disk is unchanged. Check `pm2 logs selva-compute` and confirm the app is online before retrying; if a global pm2 owns the daemon, reconcile that first.",
53
+ detail: "The runner was terminated mid-update, most often by a systemd-supervised PM2 restarting its whole control group. The version on disk is unchanged. Check `npx selva logs` and confirm the app is online before retrying; if a global pm2 owns the daemon, reconcile that first.",
54
54
  from,
55
55
  to
56
56
  };
@@ -61,6 +61,23 @@ function deriveOutcome(exitCode, logs) {
61
61
  from,
62
62
  to
63
63
  };
64
+ if (exitCode === 11 || has(logs, "PM2_NAME_TAKEN")) {
65
+ const owner = firstMatch(logs, /PM2_NAME_TAKEN: pm2's '[^']*' runs from (\S+),/);
66
+ return {
67
+ severity: "warning",
68
+ title: `Update cancelled — another Selva install${owner ? ` (${owner})` : ""} uses this install's PM2 app name. The app is untouched.`,
69
+ detail: "PM2 finds an app by name, so this update would have stopped the other install and left this one running on replaced files. Nothing was installed. On the server, give this install its own `name` in its ecosystem.config.cjs, run `npx selva start` from its directory, then retry the update here.",
70
+ from,
71
+ to
72
+ };
73
+ }
74
+ if (exitCode === 12 || has(logs, "NOT_STOPPED")) return {
75
+ severity: "warning",
76
+ title: "Update cancelled — the app kept answering after PM2 stopped it. Nothing was installed.",
77
+ detail: "Either this install's PM2 does not run the process that is serving (another PM2 daemon, a systemd unit or a shell started it), or it did not exit. Updating would have replaced its files without restarting it. On the server, find what holds the port (`ss -ltnp`), stop it there, run `npx selva start` from the deployment directory, then retry.",
78
+ from,
79
+ to
80
+ };
64
81
  if (exitCode === 10 || has(logs, "DATA_FORMAT:")) {
65
82
  const target = firstMatch(logs, /reads data format (\d+),/);
66
83
  const installed = firstMatch(logs, /this deployment is on format (\d+)\./);
@@ -124,7 +141,7 @@ function deriveOutcome(exitCode, logs) {
124
141
  if (has(logs, "PM2_RESYNC_NEEDED")) return {
125
142
  severity: "warning",
126
143
  title: `Updated${to ? ` to ${to}` : ""}, but the pm2 daemon still runs the old pm2.`,
127
- detail: "The app is online. On the server, run `npx pm2 update` in the deployment directory, let it finish, then check `npx pm2 list` shows selva-compute online.",
144
+ detail: "The app is online. On the server, run `npx pm2 update` in the deployment directory, let it finish, then check `npx pm2 list` shows the app online.",
128
145
  from,
129
146
  to
130
147
  };
@@ -172,7 +189,7 @@ function deriveOutcome(exitCode, logs) {
172
189
  return {
173
190
  severity: "critical",
174
191
  title: `Update failed (exit code ${exitCode}).`,
175
- detail: "The update did not complete cleanly. Review the log below, and check `pm2 logs selva-compute` to confirm whether the app is currently online.",
192
+ detail: "The update did not complete cleanly. Review the log below, and check `npx selva logs` to confirm whether the app is currently online.",
176
193
  from,
177
194
  to
178
195
  };
@@ -1 +1 @@
1
- {"version":3,"file":"update-outcome.js","names":[],"sources":["../../../src/lib/update-outcome.ts"],"sourcesContent":["// ============================================================================\n// Update-outcome derivation\n// ============================================================================\n//\n// The update runner (admin/api/system/update/+server.ts) emits structured log\n// lines and a small set of meaningful exit codes; `deriveOutcome` turns those\n// into a severity an operator can act on without reading the log. Ranking:\n// anything that leaves the app DOWN is `critical`; a safe rollback is\n// `warning`, not an error, because the site is still serving.\n\nexport type OutcomeSeverity = 'success' | 'info' | 'warning' | 'critical' | 'pending';\n\n/**\n * Synthetic exit code for a run that never reported one — the SSE handler's\n * 15-minute group-kill, or the reconciler giving up on a missing [EXIT] marker.\n * Outside the 0-255 range a real process can produce, so it can't collide.\n */\nexport const TIMED_OUT = -2;\n\nexport interface UpdateOutcome {\n\tseverity: OutcomeSeverity;\n\t/** Must be unambiguous about app up/down state. */\n\ttitle: string;\n\t/** What to do next when something is off. */\n\tdetail?: string;\n\tfrom?: string;\n\tto?: string;\n}\n\nfunction firstMatch(logs: string, re: RegExp): string | undefined {\n\tconst m = re.exec(logs);\n\treturn m ? m[1] : undefined;\n}\n\nfunction parseVersions(logs: string): { from?: string; to?: string } {\n\t// Pre-flight transition line, printed before npm runs — the only source of a\n\t// target version when the update fails early or is a no-op, e.g.\n\t// \"[INFO] Target (beta): 4.2.0 → 4.2.1-beta.1\". `Available:` is the\n\t// pre-channel spelling, kept so logs from an older runner still parse.\n\tconst version = String.raw`\\d+\\.\\d+\\.\\d+[^\\s]*`;\n\tconst transition = new RegExp(\n\t\tString.raw`(?:Target \\([^)]*\\)|Available):\\s*(${version})\\s*(?:→|->)\\s*(${version})`\n\t);\n\tconst arrow = transition.exec(logs);\n\n\t// The post-install lines are authoritative for what actually landed — prefer\n\t// them over the pre-flight target, which is only ever an intent.\n\tconst from = firstMatch(logs, /Current @selvajs\\/selva:\\s*v?(\\d+\\.\\d+\\.\\d+[^\\s]*)/) ?? arrow?.[1];\n\tconst to = firstMatch(logs, /New @selvajs\\/selva:\\s*v?(\\d+\\.\\d+\\.\\d+[^\\s]*)/) ?? arrow?.[2];\n\treturn { from, to };\n}\n\nfunction has(logs: string, needle: string): boolean {\n\treturn logs.includes(needle);\n}\n\nexport function deriveOutcome(exitCode: number | null, logs: string): UpdateOutcome {\n\tconst { from, to } = parseVersions(logs);\n\n\tif (exitCode === null) {\n\t\treturn { severity: 'pending', title: 'Update in progress…' };\n\t}\n\n\t// --- Critical: app is or may be DOWN. Rank these first. -------------------\n\tif (\n\t\texitCode === 6 ||\n\t\thas(logs, 'Manual recovery required') ||\n\t\thas(logs, 'manual intervention required')\n\t) {\n\t\treturn {\n\t\t\tseverity: 'critical',\n\t\t\ttitle: 'Update failed AND rollback failed — the app may be OFFLINE',\n\t\t\tdetail:\n\t\t\t\t'Both the new version and the rollback failed their health check. ' +\n\t\t\t\t'SSH into the server and run: `pm2 logs selva-compute`, then ' +\n\t\t\t\t'`pm2 start ecosystem.config.cjs` from the deployment directory.',\n\t\t\tfrom,\n\t\t\tto\n\t\t};\n\t}\n\t// The SSE handler's 15-minute group-kill, and the reconciler's own poll cap.\n\t// Neither is an exit code the runner chose, so they carry no [EXIT] marker.\n\tif (exitCode === TIMED_OUT) {\n\t\treturn {\n\t\t\tseverity: 'critical',\n\t\t\ttitle: 'App did not come back online within 15 minutes',\n\t\t\tdetail:\n\t\t\t\t'The update may still be finishing in the background, or the new ' +\n\t\t\t\t'process is crash-looping. Check `pm2 logs selva-compute`. Do not ' +\n\t\t\t\t're-run the update until you have confirmed the current state.',\n\t\t\tfrom,\n\t\t\tto\n\t\t};\n\t}\n\t// Exit 4: the rollback's own npm install failed, so node_modules is\n\t// half-written and the EXIT trap's restart is the only thing that may have\n\t// brought the app back. Same urgency as a failed rollback restart.\n\tif (exitCode === 4) {\n\t\treturn {\n\t\t\tseverity: 'critical',\n\t\t\ttitle: 'Update failed and the rollback could not reinstall — the app may be OFFLINE',\n\t\t\tdetail:\n\t\t\t\t'The previous version could not be restored from npm. SSH into the ' +\n\t\t\t\t'server and run `pm2 logs selva-compute`; if the app is down, reinstall ' +\n\t\t\t\t'explicitly with `npm install --prefer-online @selvajs/cli@<version> ' +\n\t\t\t\t'@selvajs/selva@<version>` from the deployment directory.',\n\t\t\tfrom,\n\t\t\tto\n\t\t};\n\t}\n\t// Exit 3: unhealthy with no recorded prior version, so no rollback was even\n\t// attempted. The EXIT trap tried to restart whatever is on disk.\n\tif (exitCode === 3) {\n\t\treturn {\n\t\t\tseverity: 'critical',\n\t\t\ttitle: 'Update failed its health check and could not be rolled back automatically',\n\t\t\tdetail:\n\t\t\t\t'No prior version was recorded, so the previous build could not be ' +\n\t\t\t\t'restored. Check `pm2 logs selva-compute` to confirm whether the app ' +\n\t\t\t\t'came back online.',\n\t\t\tfrom,\n\t\t\tto\n\t\t};\n\t}\n\n\t// Killed mid-run (128+signal). Nothing was installed, and whether the app\n\t// came back depends on how far the EXIT trap got before it died too. Rank\n\t// with the criticals: an unattended half-update is worse than a clean\n\t// failure.\n\tif (exitCode === 143 || exitCode === 130 || exitCode === 129 || has(logs, 'KILLED')) {\n\t\treturn {\n\t\t\tseverity: 'critical',\n\t\t\ttitle: 'Update was killed before it finished — nothing was installed',\n\t\t\tdetail:\n\t\t\t\t'The runner was terminated mid-update, most often by a systemd-supervised ' +\n\t\t\t\t'PM2 restarting its whole control group. The version on disk is unchanged. ' +\n\t\t\t\t'Check `pm2 logs selva-compute` and confirm the app is online before retrying; ' +\n\t\t\t\t'if a global pm2 owns the daemon, reconcile that first.',\n\t\t\tfrom,\n\t\t\tto\n\t\t};\n\t}\n\n\t// --- Warning: update did not fully succeed, but the app IS up. ------------\n\t// Aborted at the systemd guard, before `pm2 update` could recycle the\n\t// daemon and take this runner down with it.\n\tif (exitCode === 9 || has(logs, 'SYSTEMD_PM2')) {\n\t\treturn {\n\t\t\tseverity: 'warning',\n\t\t\ttitle:\n\t\t\t\t'Update cancelled — PM2 needs a resync that only a shell can do safely. The app is untouched.',\n\t\t\tdetail:\n\t\t\t\t\"This deployment's PM2 runs under systemd, where `pm2 update` restarts the \" +\n\t\t\t\t'unit and kills the update mid-run. Nothing was installed and the app is ' +\n\t\t\t\t'still serving. SSH in and run `./node_modules/.bin/pm2 update` from the ' +\n\t\t\t\t'deployment directory, then retry the update here.',\n\t\t\tfrom,\n\t\t\tto\n\t\t};\n\t}\n\t// Aborted at the data format check, before anything was stopped.\n\tif (exitCode === 10 || has(logs, 'DATA_FORMAT:')) {\n\t\tconst target = firstMatch(logs, /reads data format (\\d+),/);\n\t\tconst installed = firstMatch(logs, /this deployment is on format (\\d+)\\./);\n\t\treturn {\n\t\t\tseverity: 'warning',\n\t\t\ttitle: `Update cancelled — ${to ?? 'the target version'} cannot read this deployment's data. The app is untouched.`,\n\t\t\tdetail:\n\t\t\t\t(target && installed\n\t\t\t\t\t? `It reads data format ${target}; this deployment is on format ${installed}. `\n\t\t\t\t\t: '') +\n\t\t\t\t'Installing it would leave stored data, such as Compute API keys, unreadable. ' +\n\t\t\t\t'Switch the release channel back to stay on the installed version. To go back ' +\n\t\t\t\t'anyway, follow \"Going back to an older release\" in the admin guide.',\n\t\t\tfrom,\n\t\t\tto\n\t\t};\n\t}\n\t// Aborted at the pm2 skew check, before anything was stopped — nothing was\n\t// installed and the app never went down.\n\tif (exitCode === 8 || has(logs, 'PM2_SKEW')) {\n\t\tconst daemon = firstMatch(logs, /daemon \\(v(\\d+\\.\\d+\\.\\d+)\\)/);\n\t\tconst local = firstMatch(logs, /deployment's pm2 \\(v(\\d+\\.\\d+\\.\\d+)\\)/);\n\t\treturn {\n\t\t\tseverity: 'warning',\n\t\t\ttitle:\n\t\t\t\tdaemon && local\n\t\t\t\t\t? `Update cancelled — a global PM2 (v${daemon}) owns the daemon, not this deployment's (v${local}). The app is untouched.`\n\t\t\t\t\t: 'Update cancelled — a conflicting global PM2 owns the daemon. The app is untouched.',\n\t\t\tdetail:\n\t\t\t\t'Resyncing would have downgraded the daemon and dropped its process ' +\n\t\t\t\t'table, so the update stopped before taking the app down. On the server: ' +\n\t\t\t\t'`which -a pm2`, `pm2 -v`, `pm2 ping` — remove or align the global pm2, then retry.',\n\t\t\tfrom,\n\t\t\tto\n\t\t};\n\t}\n\t// A rollback whose cause is the DATABASE, not the release. Ranked ahead of\n\t// the generic rollback case: \"review the log before retrying\" is actively\n\t// misleading here, because the log holds nothing about the new version —\n\t// it is fine, and retrying without touching the database repeats verbatim.\n\tif (has(logs, 'SCHEMA_SKEW')) {\n\t\tconst expected = firstMatch(logs, /expects database migration head (\\S+?),/);\n\t\tconst actual = firstMatch(logs, /this database is at (\\S+?)\\./);\n\t\tconst skew =\n\t\t\texpected && actual ? ` The database is at ${actual}; ${to ?? 'it'} needs ${expected}.` : '';\n\t\t// `latest` is the stable line, which ships none of a beta's migrations.\n\t\tconst providerTag =\n\t\t\tfirstMatch(logs, /@selvajs\\/supabase-provider@([\\w.-]+)/) ??\n\t\t\t(has(logs, 'channel: beta') ? 'beta' : 'latest');\n\t\treturn {\n\t\t\tseverity: 'warning',\n\t\t\ttitle: `Update rolled back — the database migrations for ${to ?? 'the new version'} have not been applied.${skew} The app is online${from ? ` on ${from}` : ''}.`,\n\t\t\tdetail:\n\t\t\t\t'Nothing is wrong with the new version. Selva does not apply migrations ' +\n\t\t\t\t'during an update, because they cannot be rolled back — auto-migrating ' +\n\t\t\t\t'and then rolling the code back would leave the app and database on ' +\n\t\t\t\t'different heads. Apply them on the server, then re-run this update: ' +\n\t\t\t\t`\\`npm install --prefer-online @selvajs/supabase-provider@${providerTag}\\`, then ` +\n\t\t\t\t'`npx selva-supabase`, then `npx supabase db push`. The provider install ' +\n\t\t\t\t'is not optional — the migration SQL ships inside that package, and the ' +\n\t\t\t\t'update only moves @selvajs/cli and @selvajs/selva, so a sync without it ' +\n\t\t\t\t'copies nothing and the push reports \"up to date\" having done nothing. ' +\n\t\t\t\t'Retrying without this will fail in exactly the same way.',\n\t\t\tfrom,\n\t\t\tto\n\t\t};\n\t}\n\t// Same shape: the rollback was caused by host configuration, not the release.\n\tif (has(logs, 'AT_REST_SECRETS')) {\n\t\treturn {\n\t\t\tseverity: 'warning',\n\t\t\ttitle: `Update rolled back — stored compute server keys do not decrypt under this host's SELVA_AT_REST_KEY. The app is online${from ? ` on ${from}` : ''}.`,\n\t\t\tdetail:\n\t\t\t\t'This is a configuration problem on the server, not a fault in the new ' +\n\t\t\t\t'version, so retrying alone will fail identically. Re-enter the affected ' +\n\t\t\t\t'keys at /admin/compute, or restore the SELVA_AT_REST_KEY the values were ' +\n\t\t\t\t'encrypted with, then re-run the update.',\n\t\t\tfrom,\n\t\t\tto\n\t\t};\n\t}\n\tif (exitCode === 5 || has(logs, 'Rolled back')) {\n\t\treturn {\n\t\t\tseverity: 'warning',\n\t\t\ttitle: `Update failed — safely rolled back${from ? ` to ${from}` : ''}. The app is online.`,\n\t\t\tdetail:\n\t\t\t\t'The new version failed its health check, so the previous version ' +\n\t\t\t\t'was restored and is serving normally. Review the log below for why ' +\n\t\t\t\t'the new version failed before retrying.',\n\t\t\tfrom,\n\t\t\tto\n\t\t};\n\t}\n\t// The install completed and the app is up, but on a Node the release doesn't\n\t// support. The health probe passes (it exercises nothing version-specific),\n\t// so this would otherwise read as a clean success right up until a real\n\t// request hits a newer API and throws (issue #176).\n\tif (has(logs, 'ENGINE_MISMATCH') || has(logs, 'EBADENGINE')) {\n\t\tconst required = firstMatch(logs, /requires Node ([^\\s]+(?:\\s*[<>=]+\\s*[\\d.]+)*)/);\n\t\tconst running = firstMatch(logs, /this host runs v?(\\d+\\.\\d+\\.\\d+)/);\n\t\treturn {\n\t\t\tseverity: 'warning',\n\t\t\ttitle: running\n\t\t\t\t? `Updated${to ? ` to ${to}` : ''}, but this release needs Node ${required ?? '(newer)'} — the host runs v${running}. Expect runtime failures.`\n\t\t\t\t: `Updated${to ? ` to ${to}` : ''}, but this release requires a newer Node than the host provides. Expect runtime failures.`,\n\t\t\tdetail:\n\t\t\t\t'npm installed it anyway (engine-strict is off) and the health check ' +\n\t\t\t\t'passed, but it does not exercise the newer APIs — routes that do will ' +\n\t\t\t\t'throw at request time. Upgrade Node on the server, then re-run the update.',\n\t\t\tfrom,\n\t\t\tto\n\t\t};\n\t}\n\t// The runner moved pm2 to the release's pin but could not swap the daemon\n\t// (refused under systemd, or `pm2 update` failed). The app runs; the next\n\t// pm2 command warns about the skew until someone runs the swap by hand.\n\tif (has(logs, 'PM2_RESYNC_NEEDED')) {\n\t\treturn {\n\t\t\tseverity: 'warning',\n\t\t\ttitle: `Updated${to ? ` to ${to}` : ''}, but the pm2 daemon still runs the old pm2.`,\n\t\t\tdetail:\n\t\t\t\t'The app is online. On the server, run `npx pm2 update` in the deployment ' +\n\t\t\t\t'directory, let it finish, then check `npx pm2 list` shows selva-compute online.',\n\t\t\tfrom,\n\t\t\tto\n\t\t};\n\t}\n\tif (has(logs, 'PM2_PIN_FAILED')) {\n\t\treturn {\n\t\t\tseverity: 'warning',\n\t\t\ttitle: `Updated${to ? ` to ${to}` : ''}, but pm2 stayed on the previous version.`,\n\t\t\tdetail:\n\t\t\t\t'The app is online on the old pm2. On the server, run `npx selva migrate` in ' +\n\t\t\t\t'the deployment directory to move it to the pinned version.',\n\t\t\tfrom,\n\t\t\tto\n\t\t};\n\t}\n\tif (has(logs, 'npm cache may be stale') || has(logs, 'No version change')) {\n\t\treturn {\n\t\t\tseverity: 'warning',\n\t\t\ttitle: 'No version change — npm installed the same version.',\n\t\t\tdetail:\n\t\t\t\t'Your npm cache may be stale. On the server: `npm cache clean --force`, ' +\n\t\t\t\t'remove node_modules + package-lock.json, then `npm install --prefer-online`.',\n\t\t\tfrom,\n\t\t\tto\n\t\t};\n\t}\n\n\t// --- Success variants -----------------------------------------------------\n\tif (exitCode === 0) {\n\t\t// \"Already on the 'beta' channel version (4.2.0)\" — the channel name is\n\t\t// interpolated, so match the stable prefix rather than a whole line.\n\t\tif (has(logs, 'Already on the') || has(logs, 'Nothing to do')) {\n\t\t\treturn {\n\t\t\t\tseverity: 'info',\n\t\t\t\ttitle: `Already up to date${from ? ` (${from})` : ''} — nothing to install.`,\n\t\t\t\tdetail: 'No changes were made and the app was not restarted.',\n\t\t\t\tfrom,\n\t\t\t\tto\n\t\t\t};\n\t\t}\n\t\tif (from && to && from !== to) {\n\t\t\treturn {\n\t\t\t\tseverity: 'success',\n\t\t\t\ttitle: `Updated ${from} → ${to}. The app is back online.`,\n\t\t\t\tfrom,\n\t\t\t\tto\n\t\t\t};\n\t\t}\n\t\tif (to) {\n\t\t\treturn {\n\t\t\t\tseverity: 'success',\n\t\t\t\ttitle: `Update complete — now on ${to}. The app is back online.`,\n\t\t\t\tfrom,\n\t\t\t\tto\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\tseverity: 'success',\n\t\t\ttitle: 'Update completed and the app is back online.',\n\t\t\tfrom,\n\t\t\tto\n\t\t};\n\t}\n\n\t// --- Anything else: a non-zero exit we don't have a named case for. -------\n\t// Be explicit that we couldn't classify it rather than implying success.\n\treturn {\n\t\tseverity: 'critical',\n\t\ttitle: `Update failed (exit code ${exitCode}).`,\n\t\tdetail:\n\t\t\t'The update did not complete cleanly. Review the log below, and check ' +\n\t\t\t'`pm2 logs selva-compute` to confirm whether the app is currently online.',\n\t\tfrom,\n\t\tto\n\t};\n}\n"],"mappings":"AA6BA,SAAS,WAAW,MAAc,IAAgC;CACjE,MAAM,IAAI,GAAG,KAAK,IAAI;CACtB,OAAO,IAAI,EAAE,KAAK,KAAA;AACnB;AAEA,SAAS,cAAc,MAA8C;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BAAoB,QAAQ,8BAClH,UAAU,KAAK,OAAO,OAAO,GAAG;GACnC,QACC;GAGD;GACA;EACD;CACD;CAIA,IAAI,IAAI,MAAM,mBAAmB,GAChC,OAAO;EACN,UAAU;EACV,OAAO,UAAU,KAAK,OAAO,OAAO,GAAG;EACvC,QACC;EAED;EACA;CACD;CAED,IAAI,IAAI,MAAM,gBAAgB,GAC7B,OAAO;EACN,UAAU;EACV,OAAO,UAAU,KAAK,OAAO,OAAO,GAAG;EACvC,QACC;EAED;EACA;CACD;CAED,IAAI,IAAI,MAAM,wBAAwB,KAAK,IAAI,MAAM,mBAAmB,GACvE,OAAO;EACN,UAAU;EACV,OAAO;EACP,QACC;EAED;EACA;CACD;CAID,IAAI,aAAa,GAAG;EAGnB,IAAI,IAAI,MAAM,gBAAgB,KAAK,IAAI,MAAM,eAAe,GAC3D,OAAO;GACN,UAAU;GACV,OAAO,qBAAqB,OAAO,KAAK,KAAK,KAAK,GAAG;GACrD,QAAQ;GACR;GACA;EACD;EAED,IAAI,QAAQ,MAAM,SAAS,IAC1B,OAAO;GACN,UAAU;GACV,OAAO,WAAW,KAAK,KAAK,GAAG;GAC/B;GACA;EACD;EAED,IAAI,IACH,OAAO;GACN,UAAU;GACV,OAAO,4BAA4B,GAAG;GACtC;GACA;EACD;EAED,OAAO;GACN,UAAU;GACV,OAAO;GACP;GACA;EACD;CACD;CAIA,OAAO;EACN,UAAU;EACV,OAAO,4BAA4B,SAAS;EAC5C,QACC;EAED;EACA;CACD;AACD"}
1
+ {"version":3,"file":"update-outcome.js","names":[],"sources":["../../../src/lib/update-outcome.ts"],"sourcesContent":["// ============================================================================\n// Update-outcome derivation\n// ============================================================================\n//\n// The update runner (admin/api/system/update/+server.ts) emits structured log\n// lines and a small set of meaningful exit codes; `deriveOutcome` turns those\n// into a severity an operator can act on without reading the log. Ranking:\n// anything that leaves the app DOWN is `critical`; a safe rollback is\n// `warning`, not an error, because the site is still serving.\n\nexport type OutcomeSeverity = 'success' | 'info' | 'warning' | 'critical' | 'pending';\n\n/**\n * Synthetic exit code for a run that never reported one — the SSE handler's\n * 15-minute group-kill, or the reconciler giving up on a missing [EXIT] marker.\n * Outside the 0-255 range a real process can produce, so it can't collide.\n */\nexport const TIMED_OUT = -2;\n\nexport interface UpdateOutcome {\n\tseverity: OutcomeSeverity;\n\t/** Must be unambiguous about app up/down state. */\n\ttitle: string;\n\t/** What to do next when something is off. */\n\tdetail?: string;\n\tfrom?: string;\n\tto?: string;\n}\n\nfunction firstMatch(logs: string, re: RegExp): string | undefined {\n\tconst m = re.exec(logs);\n\treturn m ? m[1] : undefined;\n}\n\nfunction parseVersions(logs: string): { from?: string; to?: string } {\n\t// Pre-flight transition line, printed before npm runs — the only source of a\n\t// target version when the update fails early or is a no-op, e.g.\n\t// \"[INFO] Target (beta): 4.2.0 → 4.2.1-beta.1\". `Available:` is the\n\t// pre-channel spelling, kept so logs from an older runner still parse.\n\tconst version = String.raw`\\d+\\.\\d+\\.\\d+[^\\s]*`;\n\tconst transition = new RegExp(\n\t\tString.raw`(?:Target \\([^)]*\\)|Available):\\s*(${version})\\s*(?:→|->)\\s*(${version})`\n\t);\n\tconst arrow = transition.exec(logs);\n\n\t// The post-install lines are authoritative for what actually landed — prefer\n\t// them over the pre-flight target, which is only ever an intent.\n\tconst from = firstMatch(logs, /Current @selvajs\\/selva:\\s*v?(\\d+\\.\\d+\\.\\d+[^\\s]*)/) ?? arrow?.[1];\n\tconst to = firstMatch(logs, /New @selvajs\\/selva:\\s*v?(\\d+\\.\\d+\\.\\d+[^\\s]*)/) ?? arrow?.[2];\n\treturn { from, to };\n}\n\nfunction has(logs: string, needle: string): boolean {\n\treturn logs.includes(needle);\n}\n\nexport function deriveOutcome(exitCode: number | null, logs: string): UpdateOutcome {\n\tconst { from, to } = parseVersions(logs);\n\n\tif (exitCode === null) {\n\t\treturn { severity: 'pending', title: 'Update in progress…' };\n\t}\n\n\t// --- Critical: app is or may be DOWN. Rank these first. -------------------\n\tif (\n\t\texitCode === 6 ||\n\t\thas(logs, 'Manual recovery required') ||\n\t\thas(logs, 'manual intervention required')\n\t) {\n\t\treturn {\n\t\t\tseverity: 'critical',\n\t\t\ttitle: 'Update failed AND rollback failed — the app may be OFFLINE',\n\t\t\tdetail:\n\t\t\t\t'Both the new version and the rollback failed their health check. ' +\n\t\t\t\t'SSH into the server and run: `npx selva logs`, then ' +\n\t\t\t\t'`pm2 start ecosystem.config.cjs` from the deployment directory.',\n\t\t\tfrom,\n\t\t\tto\n\t\t};\n\t}\n\t// The SSE handler's 15-minute group-kill, and the reconciler's own poll cap.\n\t// Neither is an exit code the runner chose, so they carry no [EXIT] marker.\n\tif (exitCode === TIMED_OUT) {\n\t\treturn {\n\t\t\tseverity: 'critical',\n\t\t\ttitle: 'App did not come back online within 15 minutes',\n\t\t\tdetail:\n\t\t\t\t'The update may still be finishing in the background, or the new ' +\n\t\t\t\t'process is crash-looping. Check `npx selva logs`. Do not ' +\n\t\t\t\t're-run the update until you have confirmed the current state.',\n\t\t\tfrom,\n\t\t\tto\n\t\t};\n\t}\n\t// Exit 4: the rollback's own npm install failed, so node_modules is\n\t// half-written and the EXIT trap's restart is the only thing that may have\n\t// brought the app back. Same urgency as a failed rollback restart.\n\tif (exitCode === 4) {\n\t\treturn {\n\t\t\tseverity: 'critical',\n\t\t\ttitle: 'Update failed and the rollback could not reinstall — the app may be OFFLINE',\n\t\t\tdetail:\n\t\t\t\t'The previous version could not be restored from npm. SSH into the ' +\n\t\t\t\t'server and run `npx selva logs`; if the app is down, reinstall ' +\n\t\t\t\t'explicitly with `npm install --prefer-online @selvajs/cli@<version> ' +\n\t\t\t\t'@selvajs/selva@<version>` from the deployment directory.',\n\t\t\tfrom,\n\t\t\tto\n\t\t};\n\t}\n\t// Exit 3: unhealthy with no recorded prior version, so no rollback was even\n\t// attempted. The EXIT trap tried to restart whatever is on disk.\n\tif (exitCode === 3) {\n\t\treturn {\n\t\t\tseverity: 'critical',\n\t\t\ttitle: 'Update failed its health check and could not be rolled back automatically',\n\t\t\tdetail:\n\t\t\t\t'No prior version was recorded, so the previous build could not be ' +\n\t\t\t\t'restored. Check `npx selva logs` to confirm whether the app ' +\n\t\t\t\t'came back online.',\n\t\t\tfrom,\n\t\t\tto\n\t\t};\n\t}\n\n\t// Killed mid-run (128+signal). Nothing was installed, and whether the app\n\t// came back depends on how far the EXIT trap got before it died too. Rank\n\t// with the criticals: an unattended half-update is worse than a clean\n\t// failure.\n\tif (exitCode === 143 || exitCode === 130 || exitCode === 129 || has(logs, 'KILLED')) {\n\t\treturn {\n\t\t\tseverity: 'critical',\n\t\t\ttitle: 'Update was killed before it finished — nothing was installed',\n\t\t\tdetail:\n\t\t\t\t'The runner was terminated mid-update, most often by a systemd-supervised ' +\n\t\t\t\t'PM2 restarting its whole control group. The version on disk is unchanged. ' +\n\t\t\t\t'Check `npx selva logs` and confirm the app is online before retrying; ' +\n\t\t\t\t'if a global pm2 owns the daemon, reconcile that first.',\n\t\t\tfrom,\n\t\t\tto\n\t\t};\n\t}\n\n\t// --- Warning: update did not fully succeed, but the app IS up. ------------\n\t// Aborted at the systemd guard, before `pm2 update` could recycle the\n\t// daemon and take this runner down with it.\n\tif (exitCode === 9 || has(logs, 'SYSTEMD_PM2')) {\n\t\treturn {\n\t\t\tseverity: 'warning',\n\t\t\ttitle:\n\t\t\t\t'Update cancelled — PM2 needs a resync that only a shell can do safely. The app is untouched.',\n\t\t\tdetail:\n\t\t\t\t\"This deployment's PM2 runs under systemd, where `pm2 update` restarts the \" +\n\t\t\t\t'unit and kills the update mid-run. Nothing was installed and the app is ' +\n\t\t\t\t'still serving. SSH in and run `./node_modules/.bin/pm2 update` from the ' +\n\t\t\t\t'deployment directory, then retry the update here.',\n\t\t\tfrom,\n\t\t\tto\n\t\t};\n\t}\n\t// Aborted at the ownership check, before anything was stopped: pm2's app of this\n\t// name belongs to another install on the same machine.\n\tif (exitCode === 11 || has(logs, 'PM2_NAME_TAKEN')) {\n\t\tconst owner = firstMatch(logs, /PM2_NAME_TAKEN: pm2's '[^']*' runs from (\\S+),/);\n\t\treturn {\n\t\t\tseverity: 'warning',\n\t\t\ttitle: `Update cancelled — another Selva install${owner ? ` (${owner})` : ''} uses this install's PM2 app name. The app is untouched.`,\n\t\t\tdetail:\n\t\t\t\t'PM2 finds an app by name, so this update would have stopped the other install ' +\n\t\t\t\t'and left this one running on replaced files. Nothing was installed. On the ' +\n\t\t\t\t'server, give this install its own `name` in its ecosystem.config.cjs, run ' +\n\t\t\t\t'`npx selva start` from its directory, then retry the update here.',\n\t\t\tfrom,\n\t\t\tto\n\t\t};\n\t}\n\t// Aborted after the stop, before npm ran: something still answered this\n\t// install's port, so the update could not have replaced it.\n\tif (exitCode === 12 || has(logs, 'NOT_STOPPED')) {\n\t\treturn {\n\t\t\tseverity: 'warning',\n\t\t\ttitle:\n\t\t\t\t'Update cancelled — the app kept answering after PM2 stopped it. Nothing was installed.',\n\t\t\tdetail:\n\t\t\t\t\"Either this install's PM2 does not run the process that is serving (another \" +\n\t\t\t\t'PM2 daemon, a systemd unit or a shell started it), or it did not exit. Updating ' +\n\t\t\t\t'would have replaced its files without restarting it. On the server, find what ' +\n\t\t\t\t'holds the port (`ss -ltnp`), stop it there, run `npx selva start` from the ' +\n\t\t\t\t'deployment directory, then retry.',\n\t\t\tfrom,\n\t\t\tto\n\t\t};\n\t}\n\t// Aborted at the data format check, before anything was stopped.\n\tif (exitCode === 10 || has(logs, 'DATA_FORMAT:')) {\n\t\tconst target = firstMatch(logs, /reads data format (\\d+),/);\n\t\tconst installed = firstMatch(logs, /this deployment is on format (\\d+)\\./);\n\t\treturn {\n\t\t\tseverity: 'warning',\n\t\t\ttitle: `Update cancelled — ${to ?? 'the target version'} cannot read this deployment's data. The app is untouched.`,\n\t\t\tdetail:\n\t\t\t\t(target && installed\n\t\t\t\t\t? `It reads data format ${target}; this deployment is on format ${installed}. `\n\t\t\t\t\t: '') +\n\t\t\t\t'Installing it would leave stored data, such as Compute API keys, unreadable. ' +\n\t\t\t\t'Switch the release channel back to stay on the installed version. To go back ' +\n\t\t\t\t'anyway, follow \"Going back to an older release\" in the admin guide.',\n\t\t\tfrom,\n\t\t\tto\n\t\t};\n\t}\n\t// Aborted at the pm2 skew check, before anything was stopped — nothing was\n\t// installed and the app never went down.\n\tif (exitCode === 8 || has(logs, 'PM2_SKEW')) {\n\t\tconst daemon = firstMatch(logs, /daemon \\(v(\\d+\\.\\d+\\.\\d+)\\)/);\n\t\tconst local = firstMatch(logs, /deployment's pm2 \\(v(\\d+\\.\\d+\\.\\d+)\\)/);\n\t\treturn {\n\t\t\tseverity: 'warning',\n\t\t\ttitle:\n\t\t\t\tdaemon && local\n\t\t\t\t\t? `Update cancelled — a global PM2 (v${daemon}) owns the daemon, not this deployment's (v${local}). The app is untouched.`\n\t\t\t\t\t: 'Update cancelled — a conflicting global PM2 owns the daemon. The app is untouched.',\n\t\t\tdetail:\n\t\t\t\t'Resyncing would have downgraded the daemon and dropped its process ' +\n\t\t\t\t'table, so the update stopped before taking the app down. On the server: ' +\n\t\t\t\t'`which -a pm2`, `pm2 -v`, `pm2 ping` — remove or align the global pm2, then retry.',\n\t\t\tfrom,\n\t\t\tto\n\t\t};\n\t}\n\t// A rollback whose cause is the DATABASE, not the release. Ranked ahead of\n\t// the generic rollback case: \"review the log before retrying\" is actively\n\t// misleading here, because the log holds nothing about the new version —\n\t// it is fine, and retrying without touching the database repeats verbatim.\n\tif (has(logs, 'SCHEMA_SKEW')) {\n\t\tconst expected = firstMatch(logs, /expects database migration head (\\S+?),/);\n\t\tconst actual = firstMatch(logs, /this database is at (\\S+?)\\./);\n\t\tconst skew =\n\t\t\texpected && actual ? ` The database is at ${actual}; ${to ?? 'it'} needs ${expected}.` : '';\n\t\t// `latest` is the stable line, which ships none of a beta's migrations.\n\t\tconst providerTag =\n\t\t\tfirstMatch(logs, /@selvajs\\/supabase-provider@([\\w.-]+)/) ??\n\t\t\t(has(logs, 'channel: beta') ? 'beta' : 'latest');\n\t\treturn {\n\t\t\tseverity: 'warning',\n\t\t\ttitle: `Update rolled back — the database migrations for ${to ?? 'the new version'} have not been applied.${skew} The app is online${from ? ` on ${from}` : ''}.`,\n\t\t\tdetail:\n\t\t\t\t'Nothing is wrong with the new version. Selva does not apply migrations ' +\n\t\t\t\t'during an update, because they cannot be rolled back — auto-migrating ' +\n\t\t\t\t'and then rolling the code back would leave the app and database on ' +\n\t\t\t\t'different heads. Apply them on the server, then re-run this update: ' +\n\t\t\t\t`\\`npm install --prefer-online @selvajs/supabase-provider@${providerTag}\\`, then ` +\n\t\t\t\t'`npx selva-supabase`, then `npx supabase db push`. The provider install ' +\n\t\t\t\t'is not optional — the migration SQL ships inside that package, and the ' +\n\t\t\t\t'update only moves @selvajs/cli and @selvajs/selva, so a sync without it ' +\n\t\t\t\t'copies nothing and the push reports \"up to date\" having done nothing. ' +\n\t\t\t\t'Retrying without this will fail in exactly the same way.',\n\t\t\tfrom,\n\t\t\tto\n\t\t};\n\t}\n\t// Same shape: the rollback was caused by host configuration, not the release.\n\tif (has(logs, 'AT_REST_SECRETS')) {\n\t\treturn {\n\t\t\tseverity: 'warning',\n\t\t\ttitle: `Update rolled back — stored compute server keys do not decrypt under this host's SELVA_AT_REST_KEY. The app is online${from ? ` on ${from}` : ''}.`,\n\t\t\tdetail:\n\t\t\t\t'This is a configuration problem on the server, not a fault in the new ' +\n\t\t\t\t'version, so retrying alone will fail identically. Re-enter the affected ' +\n\t\t\t\t'keys at /admin/compute, or restore the SELVA_AT_REST_KEY the values were ' +\n\t\t\t\t'encrypted with, then re-run the update.',\n\t\t\tfrom,\n\t\t\tto\n\t\t};\n\t}\n\tif (exitCode === 5 || has(logs, 'Rolled back')) {\n\t\treturn {\n\t\t\tseverity: 'warning',\n\t\t\ttitle: `Update failed — safely rolled back${from ? ` to ${from}` : ''}. The app is online.`,\n\t\t\tdetail:\n\t\t\t\t'The new version failed its health check, so the previous version ' +\n\t\t\t\t'was restored and is serving normally. Review the log below for why ' +\n\t\t\t\t'the new version failed before retrying.',\n\t\t\tfrom,\n\t\t\tto\n\t\t};\n\t}\n\t// The install completed and the app is up, but on a Node the release doesn't\n\t// support. The health probe passes (it exercises nothing version-specific),\n\t// so this would otherwise read as a clean success right up until a real\n\t// request hits a newer API and throws (issue #176).\n\tif (has(logs, 'ENGINE_MISMATCH') || has(logs, 'EBADENGINE')) {\n\t\tconst required = firstMatch(logs, /requires Node ([^\\s]+(?:\\s*[<>=]+\\s*[\\d.]+)*)/);\n\t\tconst running = firstMatch(logs, /this host runs v?(\\d+\\.\\d+\\.\\d+)/);\n\t\treturn {\n\t\t\tseverity: 'warning',\n\t\t\ttitle: running\n\t\t\t\t? `Updated${to ? ` to ${to}` : ''}, but this release needs Node ${required ?? '(newer)'} — the host runs v${running}. Expect runtime failures.`\n\t\t\t\t: `Updated${to ? ` to ${to}` : ''}, but this release requires a newer Node than the host provides. Expect runtime failures.`,\n\t\t\tdetail:\n\t\t\t\t'npm installed it anyway (engine-strict is off) and the health check ' +\n\t\t\t\t'passed, but it does not exercise the newer APIs — routes that do will ' +\n\t\t\t\t'throw at request time. Upgrade Node on the server, then re-run the update.',\n\t\t\tfrom,\n\t\t\tto\n\t\t};\n\t}\n\t// The runner moved pm2 to the release's pin but could not swap the daemon\n\t// (refused under systemd, or `pm2 update` failed). The app runs; the next\n\t// pm2 command warns about the skew until someone runs the swap by hand.\n\tif (has(logs, 'PM2_RESYNC_NEEDED')) {\n\t\treturn {\n\t\t\tseverity: 'warning',\n\t\t\ttitle: `Updated${to ? ` to ${to}` : ''}, but the pm2 daemon still runs the old pm2.`,\n\t\t\tdetail:\n\t\t\t\t'The app is online. On the server, run `npx pm2 update` in the deployment ' +\n\t\t\t\t'directory, let it finish, then check `npx pm2 list` shows the app online.',\n\t\t\tfrom,\n\t\t\tto\n\t\t};\n\t}\n\tif (has(logs, 'PM2_PIN_FAILED')) {\n\t\treturn {\n\t\t\tseverity: 'warning',\n\t\t\ttitle: `Updated${to ? ` to ${to}` : ''}, but pm2 stayed on the previous version.`,\n\t\t\tdetail:\n\t\t\t\t'The app is online on the old pm2. On the server, run `npx selva migrate` in ' +\n\t\t\t\t'the deployment directory to move it to the pinned version.',\n\t\t\tfrom,\n\t\t\tto\n\t\t};\n\t}\n\tif (has(logs, 'npm cache may be stale') || has(logs, 'No version change')) {\n\t\treturn {\n\t\t\tseverity: 'warning',\n\t\t\ttitle: 'No version change — npm installed the same version.',\n\t\t\tdetail:\n\t\t\t\t'Your npm cache may be stale. On the server: `npm cache clean --force`, ' +\n\t\t\t\t'remove node_modules + package-lock.json, then `npm install --prefer-online`.',\n\t\t\tfrom,\n\t\t\tto\n\t\t};\n\t}\n\n\t// --- Success variants -----------------------------------------------------\n\tif (exitCode === 0) {\n\t\t// \"Already on the 'beta' channel version (4.2.0)\" — the channel name is\n\t\t// interpolated, so match the stable prefix rather than a whole line.\n\t\tif (has(logs, 'Already on the') || has(logs, 'Nothing to do')) {\n\t\t\treturn {\n\t\t\t\tseverity: 'info',\n\t\t\t\ttitle: `Already up to date${from ? ` (${from})` : ''} — nothing to install.`,\n\t\t\t\tdetail: 'No changes were made and the app was not restarted.',\n\t\t\t\tfrom,\n\t\t\t\tto\n\t\t\t};\n\t\t}\n\t\tif (from && to && from !== to) {\n\t\t\treturn {\n\t\t\t\tseverity: 'success',\n\t\t\t\ttitle: `Updated ${from} → ${to}. The app is back online.`,\n\t\t\t\tfrom,\n\t\t\t\tto\n\t\t\t};\n\t\t}\n\t\tif (to) {\n\t\t\treturn {\n\t\t\t\tseverity: 'success',\n\t\t\t\ttitle: `Update complete — now on ${to}. The app is back online.`,\n\t\t\t\tfrom,\n\t\t\t\tto\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\tseverity: 'success',\n\t\t\ttitle: 'Update completed and the app is back online.',\n\t\t\tfrom,\n\t\t\tto\n\t\t};\n\t}\n\n\t// --- Anything else: a non-zero exit we don't have a named case for. -------\n\t// Be explicit that we couldn't classify it rather than implying success.\n\treturn {\n\t\tseverity: 'critical',\n\t\ttitle: `Update failed (exit code ${exitCode}).`,\n\t\tdetail:\n\t\t\t'The update did not complete cleanly. Review the log below, and check ' +\n\t\t\t'`npx selva logs` to confirm whether the app is currently online.',\n\t\tfrom,\n\t\tto\n\t};\n}\n"],"mappings":"AA6BA,SAAS,WAAW,MAAc,IAAgC;CACjE,MAAM,IAAI,GAAG,KAAK,IAAI;CACtB,OAAO,IAAI,EAAE,KAAK,KAAA;AACnB;AAEA,SAAS,cAAc,MAA8C;CAKpE,MAAM,UAAU,OAAO,GAAG;CAI1B,MAAM,QAAQ,IAHS,OACtB,OAAO,GAAG,sCAAsC,QAAQ,kBAAkB,QAAQ,EAErE,CAAA,CAAW,KAAK,IAAI;CAMlC,OAAO;EAAE,MAFI,WAAW,MAAM,oDAAoD,KAAK,QAAQ;EAEhF,IADJ,WAAW,MAAM,gDAAgD,KAAK,QAAQ;CACvE;AACnB;AAEA,SAAS,IAAI,MAAc,QAAyB;CACnD,OAAO,KAAK,SAAS,MAAM;AAC5B;AAEA,SAAgB,cAAc,UAAyB,MAA6B;CACnF,MAAM,EAAE,MAAM,OAAO,cAAc,IAAI;CAEvC,IAAI,aAAa,MAChB,OAAO;EAAE,UAAU;EAAW,OAAO;CAAsB;CAI5D,IACC,aAAa,KACb,IAAI,MAAM,0BAA0B,KACpC,IAAI,MAAM,8BAA8B,GAExC,OAAO;EACN,UAAU;EACV,OAAO;EACP,QACC;EAGD;EACA;CACD;CAID,IAAI,aAAA,IACH,OAAO;EACN,UAAU;EACV,OAAO;EACP,QACC;EAGD;EACA;CACD;CAKD,IAAI,aAAa,GAChB,OAAO;EACN,UAAU;EACV,OAAO;EACP,QACC;EAID;EACA;CACD;CAID,IAAI,aAAa,GAChB,OAAO;EACN,UAAU;EACV,OAAO;EACP,QACC;EAGD;EACA;CACD;CAOD,IAAI,aAAa,OAAO,aAAa,OAAO,aAAa,OAAO,IAAI,MAAM,QAAQ,GACjF,OAAO;EACN,UAAU;EACV,OAAO;EACP,QACC;EA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QAAQ,MAAM,SAAS,IAC1B,OAAO;GACN,UAAU;GACV,OAAO,WAAW,KAAK,KAAK,GAAG;GAC/B;GACA;EACD;EAED,IAAI,IACH,OAAO;GACN,UAAU;GACV,OAAO,4BAA4B,GAAG;GACtC;GACA;EACD;EAED,OAAO;GACN,UAAU;GACV,OAAO;GACP;GACA;EACD;CACD;CAIA,OAAO;EACN,UAAU;EACV,OAAO,4BAA4B,SAAS;EAC5C,QACC;EAED;EACA;CACD;AACD"}
@@ -89,6 +89,31 @@ TAG=${shellQuote(tag)}
89
89
  PM2="$(dirname "$ECOSYSTEM")/node_modules/.bin/pm2"
90
90
  [ -x "$PM2" ] || PM2=pm2
91
91
 
92
+ # pm2 finds an app by name alone, and the name is whatever this install's
93
+ # ecosystem file declares. Two installs under one pm2 daemon need different ones.
94
+ APP=$(node -p "require(process.argv[1]).apps[0].name" "$ECOSYSTEM" 2>/dev/null)
95
+ case "$APP" in ''|undefined|null) APP=selva-compute ;; esac
96
+ HERE=$(cd "$(dirname "$ECOSYSTEM")" 2>/dev/null && pwd -P)
97
+
98
+ # Read PORT from .env the same way scripts/update.sh does, so non-default
99
+ # ports are respected.
100
+ PORT=$(grep "^PORT=" .env 2>/dev/null \\
101
+ | head -1 \\
102
+ | cut -d'=' -f2 \\
103
+ | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//' -e 's/^["'"'"']//' -e 's/["'"'"']$//' -e 's/[[:space:]]*#.*//')
104
+ PORT=\${PORT:-3000}
105
+
106
+ # Prints one string field of the /api/health body on stdin.
107
+ json_field() {
108
+ grep -o '"'"$1"'":"[^"]*"' | head -1 | cut -d'"' -f4
109
+ }
110
+
111
+ # Prints the instanceId of whatever answers this install's port, or nothing while
112
+ # the port is silent.
113
+ serving_instance() {
114
+ curl -sS --max-time 5 "http://localhost:$PORT/api/health" 2>/dev/null | json_field instanceId
115
+ }
116
+
92
117
  # Under systemd, \`pm2 update\` kills and respawns the daemon. systemd sees its
93
118
  # unit's main process die and, with the default KillMode=control-group,
94
119
  # SIGTERMs everything in the cgroup — including this runner. setsid escapes
@@ -118,25 +143,37 @@ pm2_under_systemd() {
118
143
  # single failure path; fd 0 rather than /dev/stdin because the latter isn't a
119
144
  # readable pipe everywhere.
120
145
  app_status() {
121
- "$PM2" jlist 2>/dev/null | node -e "
146
+ "$PM2" jlist 2>/dev/null | SELVA_APP="$APP" node -e "
122
147
  try {
123
148
  const list = JSON.parse(require('fs').readFileSync(0,'utf8'));
124
- const app = list.find(p => p.name === 'selva-compute');
149
+ const app = list.find(p => p.name === process.env.SELVA_APP);
125
150
  process.stdout.write(app ? app.pm2_env.status : 'missing');
126
151
  } catch { process.stdout.write('error'); }
127
152
  " 2>/dev/null
128
153
  }
129
154
 
155
+ # Prints the directory pm2 runs this app from, or nothing when pm2 has no app of
156
+ # that name.
157
+ app_dir() {
158
+ "$PM2" jlist 2>/dev/null | SELVA_APP="$APP" node -e "
159
+ try {
160
+ const list = JSON.parse(require('fs').readFileSync(0,'utf8'));
161
+ const app = list.find(p => p.name === process.env.SELVA_APP);
162
+ process.stdout.write((app && app.pm2_env.pm_cwd) || '');
163
+ } catch {}
164
+ " 2>/dev/null
165
+ }
166
+
130
167
  wait_until_stopped() {
131
168
  for i in $(seq 1 20); do
132
169
  STATUS=$(app_status)
133
170
  if [ "$STATUS" != "stopping" ]; then
134
171
  return 0
135
172
  fi
136
- echo "[INFO] selva-compute still draining (attempt $i/20) — waiting for SIGKILL escalation"
173
+ echo "[INFO] $APP still draining (attempt $i/20) — waiting for SIGKILL escalation"
137
174
  sleep 1
138
175
  done
139
- echo "[WARN] selva-compute stuck in 'stopping' after 20s — continuing anyway"
176
+ echo "[WARN] $APP stuck in 'stopping' after 20s — continuing anyway"
140
177
  return 1
141
178
  }
142
179
 
@@ -150,7 +187,7 @@ start_app() {
150
187
  return 0
151
188
  fi
152
189
  echo "[WARN] pm2 start failed — dropping the stale process entry and retrying"
153
- "$PM2" delete selva-compute >/dev/null 2>&1 || true
190
+ "$PM2" delete "$APP" >/dev/null 2>&1 || true
154
191
  "$PM2" start "$ECOSYSTEM" --update-env
155
192
  }
156
193
 
@@ -168,9 +205,9 @@ on_exit() {
168
205
  STATUS=$(app_status)
169
206
  fi
170
207
  if [ "$STATUS" != "online" ]; then
171
- echo "[RECOVER] selva-compute is '$STATUS' — starting from ecosystem.config.cjs"
208
+ echo "[RECOVER] $APP is '$STATUS' — starting from ecosystem.config.cjs"
172
209
  start_app >/dev/null 2>&1 || \\
173
- echo "[RECOVER] pm2 start failed — manual intervention required: cd $(dirname "$ECOSYSTEM") && ./node_modules/.bin/pm2 delete selva-compute; ./node_modules/.bin/pm2 start ecosystem.config.cjs"
210
+ echo "[RECOVER] pm2 start failed — manual intervention required: cd $(dirname "$ECOSYSTEM") && ./node_modules/.bin/pm2 delete $APP; ./node_modules/.bin/pm2 start ecosystem.config.cjs"
174
211
  fi
175
212
  # Terminal marker: the restarted app's outcome reconciler greps this to turn
176
213
  # the run into an audit event (selfUpdate.server.ts). Keep the format stable.
@@ -313,7 +350,27 @@ if echo "$PING_OUT" | grep -q "out-of-date"; then
313
350
  fi
314
351
 
315
352
  # ---------------------------------------------------------------------------
316
- # 3. Stop selva-compute BEFORE npm rewrites build/.
353
+ # 2b. This install must own the pm2 app it is about to stop.
354
+ # ---------------------------------------------------------------------------
355
+ # With two installs under one daemon and one name, the stop below takes the
356
+ # OTHER install down while this one keeps serving, and npm then rewrites build/
357
+ # under it.
358
+ OWNER=$(app_dir)
359
+ OWNER_REAL=
360
+ if [ -n "$OWNER" ]; then
361
+ OWNER_REAL=$(cd "$OWNER" 2>/dev/null && pwd -P)
362
+ fi
363
+ if [ -n "$OWNER" ] && [ -n "$HERE" ] && [ "\${OWNER_REAL:-$OWNER}" != "$HERE" ]; then
364
+ echo "[FATAL] PM2_NAME_TAKEN: pm2's '$APP' runs from $OWNER, not from this install ($HERE)."
365
+ echo "[FATAL] Two installs share one pm2 app name, so this update would have stopped the other one."
366
+ echo "[FATAL] Give this install its own name: change 'name' in $ECOSYSTEM, then from a shell:"
367
+ echo "[FATAL] cd $HERE && npx selva start"
368
+ echo "[FATAL] Aborting WITHOUT stopping the app — it is still running."
369
+ exit 11
370
+ fi
371
+
372
+ # ---------------------------------------------------------------------------
373
+ # 3. Stop the app BEFORE npm rewrites build/.
317
374
  # ---------------------------------------------------------------------------
318
375
  # SvelteKit's node adapter lazy-imports chunks from build/server/chunks/ on
319
376
  # every request. Letting npm rewrite build/ while the old process still
@@ -325,15 +382,40 @@ fi
325
382
  # This is also where the SSE connection to the frontend dies — selva-compute
326
383
  # IS the SSE server. From here on, the user sees output via the log-file
327
384
  # polling fallback in the admin UI, not over SSE.
328
- echo "[STEP] Stopping selva-compute"
329
- if ! "$PM2" stop selva-compute; then
330
- echo "[WARN] pm2 stop failed — selva-compute may not be running yet. Continuing."
385
+ echo "[STEP] Stopping $APP"
386
+ if ! "$PM2" stop "$APP"; then
387
+ echo "[WARN] pm2 stop failed — $APP may not be running yet. Continuing."
331
388
  fi
332
389
 
333
390
  # pm2 stop returns before the process is actually gone. Everything below —
334
391
  # npm rewriting build/, then the restart — must happen outside the drain window.
335
392
  wait_until_stopped
336
393
 
394
+ # ---------------------------------------------------------------------------
395
+ # 3b. Nothing may answer the port once the app is stopped.
396
+ # ---------------------------------------------------------------------------
397
+ # A process this pm2 does not run (another pm2 daemon, a systemd unit, a shell)
398
+ # survives the stop above, and so does one that outlived its kill timeout. Either
399
+ # would keep rendering pages that name the old build's files after npm has
400
+ # replaced them, and would answer the health probe below, so the update would
401
+ # report success with nothing restarted.
402
+ SURVIVOR=
403
+ for i in $(seq 1 5); do
404
+ SURVIVOR=$(serving_instance)
405
+ if [ -z "$SURVIVOR" ]; then
406
+ break
407
+ fi
408
+ sleep 1
409
+ done
410
+ if [ -n "$SURVIVOR" ]; then
411
+ echo "[FATAL] NOT_STOPPED: something still answers on port $PORT after 'pm2 stop $APP'."
412
+ echo "[FATAL] Either this install's pm2 does not run that process, or it did not exit."
413
+ echo "[FATAL] Nothing was installed. Find what holds the port, stop it there, then start the app from this install:"
414
+ echo "[FATAL] ss -ltnp | grep ':$PORT '"
415
+ echo "[FATAL] cd $HERE && npx selva start"
416
+ exit 12
417
+ fi
418
+
337
419
  # ---------------------------------------------------------------------------
338
420
  # 4. Run npm update.
339
421
  # ---------------------------------------------------------------------------
@@ -373,7 +455,7 @@ if [ -n "$PM2_PIN" ] && [ "$PM2_PIN" != "$PM2_DECLARED" ]; then
373
455
  echo "[WARN] PM2_RESYNC_NEEDED: pm2 is now $PM2_PIN, but its daemon still runs the old version."
374
456
  echo "[WARN] Swapping it here would restart the systemd unit and kill this runner. From a shell:"
375
457
  echo "[WARN] cd $(dirname "$ECOSYSTEM") && npx pm2 update && npx pm2 list"
376
- echo "[WARN] Let it finish: interrupting it leaves selva-compute unregistered."
458
+ echo "[WARN] Let it finish: interrupting it leaves $APP unregistered."
377
459
  elif ! "$PM2" update; then
378
460
  echo "[WARN] PM2_RESYNC_NEEDED: 'pm2 update' failed — the daemon still runs the old pm2."
379
461
  echo "[WARN] cd $(dirname "$ECOSYSTEM") && npx pm2 update && npx pm2 list"
@@ -390,23 +472,15 @@ fi
390
472
  # Start from ecosystem.config.cjs, NOT \`pm2 start selva-compute\` — the latter
391
473
  # requires selva-compute to already be in pm2's in-memory process list, which
392
474
  # a \`pm2 update\` (step 2) isn't guaranteed to preserve.
393
- echo "[STEP] Starting selva-compute with new build"
475
+ echo "[STEP] Starting $APP with new build"
394
476
  if ! start_app; then
395
- echo "[FATAL] pm2 start failed — investigate with \\\`pm2 logs selva-compute\\\`"
477
+ echo "[FATAL] pm2 start failed — investigate with \\\`pm2 logs $APP\\\`"
396
478
  exit 2
397
479
  fi
398
480
 
399
481
  # ---------------------------------------------------------------------------
400
482
  # 6. Health probe the new process.
401
483
  # ---------------------------------------------------------------------------
402
- # Read PORT from .env the same way scripts/update.sh does, so non-default
403
- # ports are respected.
404
- PORT=$(grep "^PORT=" .env 2>/dev/null \\
405
- | head -1 \\
406
- | cut -d'=' -f2 \\
407
- | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//' -e 's/^["'"'"']//' -e 's/["'"'"']$//' -e 's/[[:space:]]*#.*//')
408
- PORT=\${PORT:-3000}
409
-
410
484
  echo "[STEP] Health-probing the new process on port $PORT"
411
485
  # mktemp for the same reason as the runner itself: /tmp is shared. Without one
412
486
  # the probe still runs; only the rollback loses the body it names the cause from.
@@ -474,7 +548,7 @@ if [ -s "$HEALTH_BODY" ]; then
474
548
  echo "[FATAL] SELVA_AT_REST_KEY, then re-run the update."
475
549
  else
476
550
  echo "[FATAL] The health endpoint did not report a known cause. Inspect the body above and"
477
- echo "[FATAL] \\\`pm2 logs selva-compute\\\` for what the new version failed on."
551
+ echo "[FATAL] \\\`pm2 logs $APP\\\` for what the new version failed on."
478
552
  fi
479
553
 
480
554
  rm -f "$HEALTH_BODY"
@@ -496,7 +570,7 @@ if [ "$AFTER_FORMAT" -gt "$INSTALLED_FORMAT" ]; then
496
570
  fi
497
571
 
498
572
  echo "[STEP] Rolling back @selvajs/selva to $BEFORE"
499
- "$PM2" stop selva-compute >/dev/null 2>&1 || true
573
+ "$PM2" stop "$APP" >/dev/null 2>&1 || true
500
574
  wait_until_stopped >/dev/null 2>&1
501
575
  # Restore @selvajs/cli alongside the runtime: the forward step installs both at
502
576
  # the channel tag, so reverting only the runtime leaves a version pair that was
@@ -515,7 +589,7 @@ if [ "$ROLLBACK_CODE" = "200" ]; then
515
589
  fi
516
590
 
517
591
  echo "[FATAL] Rollback restart also failed health check (HTTP $ROLLBACK_CODE)"
518
- echo "[FATAL] Manual recovery required. Check: pm2 logs selva-compute"
592
+ echo "[FATAL] Manual recovery required. Check: pm2 logs $APP"
519
593
  exit 6
520
594
  `;
521
595
  }