@marktrue/dsh-mobile-remote 3.2.4-alpha.17 → 3.2.4-alpha.18
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/CHANGELOG.md +39 -0
- package/lib/host-update-capabilities.js +7 -1
- package/lib/index.js +46 -8
- package/lib/plugin-self-update.js +17 -3
- package/lib/plugin-update-controller.js +9 -3
- package/lib/plugin-update-transaction.js +38 -2
- package/lib/update-lock-arbiter.js +46 -6
- package/lib/update-supervisor.js +38 -5
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,44 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## v3.2.4-alpha.18(build 50,issues #110)— rc.2 更新通道恢复与 restart-pending 收尾
|
|
4
|
+
|
|
5
|
+
> 插件 `3.2.4-alpha.18` / App `3.2.4+50` / 载体 `3.2.4-alpha.18-app`。
|
|
6
|
+
|
|
7
|
+
### DSH 0.2.2-rc.2 插件更新通道(#110)
|
|
8
|
+
|
|
9
|
+
- `hostManagerAcceptsBundle` 同时接受 rc.1 `updatable===true` 与 rc.2 `update==='registry'|'git'`;存在 `update` 字段时以其为准,仍拒绝 `readOnlyReason`;
|
|
10
|
+
- rc.2 + HMR 重新走 host-manager 通道,不再静默降级为重启方式更新;App 的「电脑端插件更新尚未确认」卡住问题随之恢复。
|
|
11
|
+
|
|
12
|
+
### restart-pending 启动认领与失败收敛(#110)
|
|
13
|
+
|
|
14
|
+
- 新增 `/proc/<pid>/stat` starttime 身份判活(不再只靠 `kill(0)`);holder worker/supervisor 任一存活才视为活;
|
|
15
|
+
- `reportPendingUpdate`:restart-pending + 运行内容等于 target + holder 已死 → `adoptable`,启动路径用 transaction lease 调 `finishOwnedTerminal` 结算 settled(`matched=loaded-target-content-adopted`),保留 artifact/snapshot 元数据并清 holder;holder 还活着时仍只报告 matched;
|
|
16
|
+
- 启动认领 finish 失败(holder null / lease-lost)→ 有界重试 3 次后回退 `convergeStaleTransaction(staleMs:0, localContentSha256)`,不再永久 pending;
|
|
17
|
+
- 死 holder + stale 收敛:内容匹配 → settled(如实标注已生效,不假称回滚成功);不匹配 → failed `confirmation-lost`,不再无限 pending;缺时间戳按 stale 处理;
|
|
18
|
+
- `fixed-version-deployed`(localContent 不等于 target)不 adopt,stale 后明确 failed `confirmation-lost`,不假称 settled、不重试死循环;
|
|
19
|
+
- submit 收敛传 `localContentSha256` 并接受 settled 动作,旧 restart-pending 内容已生效时不再一律 failed。
|
|
20
|
+
|
|
21
|
+
### holder 判活与重启参数(#110)
|
|
22
|
+
|
|
23
|
+
- arbiter `available` / P1-C `active` 改用 holderAlive,兼容 legacy `holder.pid`:有 starttime 比 starttime,无 `/proc` 时回退 `kill(pid,0)` 保守判活;活 legacy holder + restart-pending/stale 保持 active、不 settle、不清 holder,acquire 仍返回 update-busy;
|
|
24
|
+
- 宿主 workerOptions 写入 `respawnCommandOf(host process argv)` 随事务持久化;supervisor `defaultRestart` 优先 `tx.respawnCommand`,其次读 `/proc/<hostPid>/cmdline`;都拿不到时明确 `restart-command-missing`,不再猜 `dsh web --profile web`(避免端口漂移);
|
|
25
|
+
- 新增真实 supervisor 路径测试:事务保留原命令(含 `--port 3082`);无原命令明确失败。
|
|
26
|
+
|
|
27
|
+
### 重要说明
|
|
28
|
+
|
|
29
|
+
- 本版针对「插件已更新到 alpha.17、但 App 卡在电脑端更新尚未确认」的现场:用户 App 已完成更新,**现场 failed 事务无需恢复**;新版本更新统一走 host-manager 通道;
|
|
30
|
+
- 恢复 runbook 已追加到 issue #110(备份 → alpha.17 内容哈希校验 → converge/finish → 确认 settled → 再部署修复版),脚本未自动执行,未改写现场 `~/.dsh`。
|
|
31
|
+
|
|
32
|
+
### 文档
|
|
33
|
+
|
|
34
|
+
- 本次发布范围为更新链路修复,未改 API 契约;issue #110 note 含一次性恢复 runbook。
|
|
35
|
+
|
|
36
|
+
### 验证
|
|
37
|
+
|
|
38
|
+
- 本机发布门禁:node 测试 **1193**(1180 通过 / 13 跳过 / 0 失败)、flutter test **1450** 全绿、flutter analyze 0 error/warning(24 条既有 info);首轮 node 全量 1 例 host-canary 已知时序 flake(#40),单文件 46/46 与全量重跑均全绿;
|
|
39
|
+
- 真机/320/深色、5/10/all、图片授权、trigger 卡、动态 margin、折叠与贴底列为本版验收项(发布后按验收清单执行)。
|
|
40
|
+
|
|
41
|
+
|
|
3
42
|
## v3.2.4-alpha.17(build 49,issues #103 / #104 / #109)— 展开贴底、简洁折叠与空会话过滤
|
|
4
43
|
|
|
5
44
|
> 插件 `3.2.4-alpha.17` / App `3.2.4+49` / 载体 `3.2.4-alpha.17-app`。
|
|
@@ -110,7 +110,13 @@ export function hostManagerAcceptsBundle(bundle) {
|
|
|
110
110
|
if (!bundle || typeof bundle !== "object") {
|
|
111
111
|
return { ok: false, reason: HOST_MANAGER_REASON.NOT_UPDATABLE };
|
|
112
112
|
}
|
|
113
|
-
|
|
113
|
+
// DSH 0.2.2-rc.1:`updatable: boolean`;rc.2:`update?: 'registry' | 'git'`,
|
|
114
|
+
// 不再提供 updatable。两种行契约都接受,否则 rc.2 会静默降级到重启通道。
|
|
115
|
+
// 有 rc.2 的 update 字段时以它为准;只有旧行才看 updatable,避免两字段冲突时误放行。
|
|
116
|
+
const updatable = bundle.update !== undefined
|
|
117
|
+
? (bundle.update === "registry" || bundle.update === "git")
|
|
118
|
+
: bundle.updatable === true;
|
|
119
|
+
if (!updatable) {
|
|
114
120
|
return { ok: false, reason: HOST_MANAGER_REASON.NOT_UPDATABLE };
|
|
115
121
|
}
|
|
116
122
|
if (bundle.readOnlyReason !== undefined) {
|
package/lib/index.js
CHANGED
|
@@ -80,11 +80,11 @@ import {
|
|
|
80
80
|
acquireLock,
|
|
81
81
|
convergeStaleTransaction,
|
|
82
82
|
dependencyKeysFor,
|
|
83
|
-
|
|
83
|
+
finishOwnedTerminal,
|
|
84
|
+
lockHolderAlive,
|
|
84
85
|
findProfileDir,
|
|
85
86
|
newOperationId,
|
|
86
87
|
profileSpecifierOf,
|
|
87
|
-
readLock,
|
|
88
88
|
readTransaction,
|
|
89
89
|
releaseLock,
|
|
90
90
|
transactionFile,
|
|
@@ -4011,20 +4011,56 @@ export function apply(ctx, config, runtime = {}) {
|
|
|
4011
4011
|
pid: process.pid,
|
|
4012
4012
|
});
|
|
4013
4013
|
// 监督器是否还在照看(用锁的持有者进程是否存活判断)
|
|
4014
|
-
const supervisorAlive = () =>
|
|
4015
|
-
const holder = readLock(pluginUpdateLockFile);
|
|
4016
|
-
return Boolean(holder && holder.pid && defaultIsPidAlive(holder.pid));
|
|
4017
|
-
};
|
|
4014
|
+
const supervisorAlive = () => lockHolderAlive(pluginUpdateLockFile);
|
|
4018
4015
|
{
|
|
4019
4016
|
// 事务报告(**只读**):回滚由外部监督器负责,不再依赖新版插件能否加载(评审 R1)。
|
|
4020
4017
|
// 这里只处理"监督器已消失且明显超时"的收敛,避免手机永久等待。
|
|
4018
|
+
const holderAlive = supervisorAlive();
|
|
4021
4019
|
const reported = reportPendingUpdate({
|
|
4022
4020
|
stateFile: pluginUpdateStateFile,
|
|
4023
4021
|
lockPath: pluginUpdateLockFile,
|
|
4024
4022
|
localContentSha256: selfContentSha256,
|
|
4025
|
-
|
|
4023
|
+
holderAlive,
|
|
4024
|
+
supervisorAlive: holderAlive,
|
|
4026
4025
|
});
|
|
4027
|
-
if (reported.action === "
|
|
4026
|
+
if (reported.action === "adoptable") {
|
|
4027
|
+
// issue #110 P1-B:当前运行内容已经是 target,且 holder 已死(按 /proc starttime)。
|
|
4028
|
+
// 新宿主认领并结算 restart-pending,释放 holder;保留事务里的 artifact/snapshot 元数据。
|
|
4029
|
+
let adopted = false;
|
|
4030
|
+
let lastError = null;
|
|
4031
|
+
for (let attempt = 0; attempt < 3 && !adopted; attempt += 1) {
|
|
4032
|
+
try {
|
|
4033
|
+
finishOwnedTerminal(pluginUpdateStateFile, {
|
|
4034
|
+
phase: "settled",
|
|
4035
|
+
result: { ok: true, matched: "loaded-target-content-adopted" },
|
|
4036
|
+
expectedPhases: ["restart-pending"],
|
|
4037
|
+
}, {
|
|
4038
|
+
lockPath: pluginUpdateLockFile,
|
|
4039
|
+
lease: reported.transaction?.lease,
|
|
4040
|
+
currentFile: pluginUpdateStateFile,
|
|
4041
|
+
});
|
|
4042
|
+
adopted = true;
|
|
4043
|
+
} catch (error) {
|
|
4044
|
+
lastError = error;
|
|
4045
|
+
}
|
|
4046
|
+
}
|
|
4047
|
+
if (adopted) {
|
|
4048
|
+
ctx.logger.info?.("mobile-remote: 插件自更新已由启动认领结算(loaded target content)");
|
|
4049
|
+
} else {
|
|
4050
|
+
// holder 已缺失/lease 失效时不能永久 pending:退回有界收敛(P1-C)。
|
|
4051
|
+
try {
|
|
4052
|
+
const converged = convergeStaleTransaction({
|
|
4053
|
+
stateFile: pluginUpdateStateFile,
|
|
4054
|
+
lockPath: pluginUpdateLockFile,
|
|
4055
|
+
localContentSha256: selfContentSha256,
|
|
4056
|
+
staleMs: 0,
|
|
4057
|
+
});
|
|
4058
|
+
ctx.logger.warn?.(`mobile-remote: 启动认领失败已转收敛:${converged.action}${converged.error ? `(${converged.error})` : ""}`);
|
|
4059
|
+
} catch (convergeError) {
|
|
4060
|
+
ctx.logger.warn?.(`mobile-remote: 启动认领/收敛均失败(不影响运行):${lastError?.message ?? lastError} / ${convergeError?.message ?? convergeError}`);
|
|
4061
|
+
}
|
|
4062
|
+
}
|
|
4063
|
+
} else if (reported.action === "matched") {
|
|
4028
4064
|
ctx.logger.info?.("mobile-remote: 插件自更新已生效");
|
|
4029
4065
|
} else if (reported.action === "expired") {
|
|
4030
4066
|
ctx.logger.warn("mobile-remote: 插件自更新未确认生效且监督器已退出;请在电脑上确认插件状态");
|
|
@@ -4187,6 +4223,8 @@ export function apply(ctx, config, runtime = {}) {
|
|
|
4187
4223
|
// 内部 worker 永远用**受信回环定位 + 有效口令**(自动生成的口令同样要带上,否则 401)
|
|
4188
4224
|
auth: { token: authToken, trustedOrigin: `http://127.0.0.1:${ctx.webServer.port}`, basePath },
|
|
4189
4225
|
workerOptions: { installedRoot: pluginRootDir, pluginRoot: pluginRootDir, needsEscape: systemdManaged(),
|
|
4226
|
+
// issue #110 P2:事务记录宿主原始 argv,supervisor 重启时使用(其自身 argv 不含宿主参数)。
|
|
4227
|
+
respawnCommand,
|
|
4190
4228
|
restartForm: restartFormOf(), hostPid: process.pid, port: ctx.webServer.port, basePath,
|
|
4191
4229
|
token: authToken, profile: process.env.DSH_PROFILE || "web", dshCommand: process.env.DSH_BIN || "dsh" },
|
|
4192
4230
|
// DSH 0.2.2+:宿主原生插件管理器可用时,更新走「进程内卸载→安装」,不重启宿主。
|
|
@@ -1063,20 +1063,34 @@ export async function runSelfUpdate({
|
|
|
1063
1063
|
* 但**任何非终态**(staging / installing / restart-pending)在持有者已死且超时后
|
|
1064
1064
|
* 都必须收敛为 FAILED,否则后续更新会永久 busy。
|
|
1065
1065
|
*/
|
|
1066
|
-
export function reportPendingUpdate({ stateFile, lockPath = "", localContentSha256 = "", supervisorAlive = false, timeoutMs = 10 * 60 * 1000, now = () => Date.now() } = {}) {
|
|
1066
|
+
export function reportPendingUpdate({ stateFile, lockPath = "", localContentSha256 = "", holderAlive = false, supervisorAlive = false, timeoutMs = 10 * 60 * 1000, now = () => Date.now() } = {}) {
|
|
1067
1067
|
const tx = readTransaction(stateFile);
|
|
1068
1068
|
if (!tx) return { action: "none", reason: "no-transaction", transaction: null };
|
|
1069
1069
|
if (isTerminalPhase(tx.phase)) return { action: "none", reason: `phase-${tx.phase}`, transaction: tx };
|
|
1070
1070
|
if (tx.phase === TRANSACTION_PHASE.RESTART_PENDING) {
|
|
1071
1071
|
const target = String(tx.targetContentSha256 ?? "").toLowerCase();
|
|
1072
1072
|
if (target !== "" && String(localContentSha256 ?? "").toLowerCase() === target) {
|
|
1073
|
+
// issue #110 P1-B:内容已生效且 holder 已死 → 启动方可认领并结算;
|
|
1074
|
+
// holder 仍活着时插件只报告,不抢监督器。
|
|
1075
|
+
if (!holderAlive) {
|
|
1076
|
+
return { action: "adoptable", reason: "loaded-target-content-adopted", transaction: tx };
|
|
1077
|
+
}
|
|
1073
1078
|
return { action: "matched", reason: "loaded-target-content", transaction: tx };
|
|
1074
1079
|
}
|
|
1075
1080
|
}
|
|
1076
1081
|
if (!lockPath) return { action: "waiting", reason: "no-lock-path", transaction: tx };
|
|
1077
|
-
const converged = convergeStaleTransaction({
|
|
1082
|
+
const converged = convergeStaleTransaction({
|
|
1083
|
+
stateFile,
|
|
1084
|
+
lockPath,
|
|
1085
|
+
localContentSha256,
|
|
1086
|
+
now,
|
|
1087
|
+
staleMs: timeoutMs,
|
|
1088
|
+
});
|
|
1089
|
+
if (converged.action === "settled") {
|
|
1090
|
+
return { action: "matched", reason: "loaded-target-content-adopted", transaction: converged.transaction };
|
|
1091
|
+
}
|
|
1078
1092
|
if (converged.action === "converged") {
|
|
1079
|
-
return { action: "expired", reason: "holder-gone", transaction: converged.transaction };
|
|
1093
|
+
return { action: "expired", reason: "converged-after-holder-gone", transaction: converged.transaction };
|
|
1080
1094
|
}
|
|
1081
1095
|
if (converged.action === "active") {
|
|
1082
1096
|
return { action: "waiting", reason: supervisorAlive ? "supervisor-running" : "update-in-progress", transaction: tx };
|
|
@@ -87,8 +87,9 @@ export function createPluginUpdateController(options) {
|
|
|
87
87
|
} catch { /* cleanup is best-effort; never disrupt update checks */ }
|
|
88
88
|
};
|
|
89
89
|
cleanupPreparedUpdates();
|
|
90
|
+
const localContentNow = () => (typeof localContentSha256 === 'function' ? localContentSha256() : localContentSha256);
|
|
90
91
|
const checking = () => checkForUpdate({ configValue, packageName, npmCwd: profileDir, npmPackageView,
|
|
91
|
-
localVersion: typeof localVersion === 'function' ? localVersion() : localVersion, localContentSha256,
|
|
92
|
+
localVersion: typeof localVersion === 'function' ? localVersion() : localVersion, localContentSha256: localContentNow(),
|
|
92
93
|
capabilities: capabilities(), fetchImpl, auth });
|
|
93
94
|
// issue #96:检查快照 + 有界异步任务(只读、内存、不持久化)。
|
|
94
95
|
const checkService = createUpdateCheckService({
|
|
@@ -182,8 +183,13 @@ export function createPluginUpdateController(options) {
|
|
|
182
183
|
if (old && body.opId === old.opId) return { status: 200, body: { ok: true, action: 'accepted', opId: old.opId,
|
|
183
184
|
transaction: publicTransaction(old, view), check: { ...status, release: clientReleaseView(status.release, view) } } };
|
|
184
185
|
if (old && !isTerminalPhase(old.phase)) {
|
|
185
|
-
|
|
186
|
-
|
|
186
|
+
// issue #110 P3:收敛时带上当前运行内容哈希,避免把已生效的旧 restart-pending 一律 failed。
|
|
187
|
+
const convergence = convergeStaleTransaction({
|
|
188
|
+
stateFile: currentFile,
|
|
189
|
+
lockPath,
|
|
190
|
+
localContentSha256: localContentNow() ?? '',
|
|
191
|
+
});
|
|
192
|
+
if (!['converged','settled','terminal'].includes(convergence.action)) return { status: 409, body: {
|
|
187
193
|
error: convergence.action === 'recovery-required' ? 'recovery-required' : 'update-busy', transaction: publicTransaction(old, view) } };
|
|
188
194
|
}
|
|
189
195
|
let checked = await checkService.checkForSubmit(); Object.assign(status, checked);
|
|
@@ -105,8 +105,8 @@ export function clearTransaction(file) {
|
|
|
105
105
|
}
|
|
106
106
|
|
|
107
107
|
/** Converge only under the same OS arbitration as acquire/release/state writes. */
|
|
108
|
-
export function convergeStaleTransaction({ stateFile, lockPath, expectedLease, now = () => Date.now(), staleMs = 600_000 } = {}) {
|
|
109
|
-
const result = arbitrate(lockPath, { operation: "converge", stateFile, expectedLease, now: now(), staleMs });
|
|
108
|
+
export function convergeStaleTransaction({ stateFile, lockPath, expectedLease, localContentSha256 = "", now = () => Date.now(), staleMs = 600_000 } = {}) {
|
|
109
|
+
const result = arbitrate(lockPath, { operation: "converge", stateFile, expectedLease, localContentSha256, now: now(), staleMs });
|
|
110
110
|
if (!result.ok) return { action: "blocked", error: result.error, transaction: readTransaction(stateFile) };
|
|
111
111
|
return result;
|
|
112
112
|
}
|
|
@@ -198,6 +198,42 @@ export function defaultIsPidAlive(pid) {
|
|
|
198
198
|
if (!Number.isInteger(pid) || pid <= 0) return false;
|
|
199
199
|
try { process.kill(pid, 0); return true; } catch(e) { return e.code === "EPERM"; }
|
|
200
200
|
}
|
|
201
|
+
|
|
202
|
+
/** `/proc/<pid>/stat` 的 starttime(field 22);读不到返回 null。 */
|
|
203
|
+
export function processStartTime(pid) {
|
|
204
|
+
if (!Number.isInteger(pid) || pid <= 0) return null;
|
|
205
|
+
try {
|
|
206
|
+
const text = readFileSync(`/proc/${pid}/stat`, "utf8");
|
|
207
|
+
return text.slice(text.lastIndexOf(")") + 2).split(" ")[19] ?? null;
|
|
208
|
+
} catch {
|
|
209
|
+
return null;
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
/**
|
|
214
|
+
* issue #110 P1:按 `/proc/<pid>/stat` starttime 判断记录里的进程身份是否仍存活,
|
|
215
|
+
* 不能只用 kill(pid,0)(容器重建后 pid 会被复用)。
|
|
216
|
+
* - 记录带 start:必须与当前 starttime 完全一致;
|
|
217
|
+
* - 旧 holder 无 start:只能保守认为可能存活(不据此认领);
|
|
218
|
+
* - procfs 不可读:视为不存活。
|
|
219
|
+
*/
|
|
220
|
+
export function processIdentityAlive(person) {
|
|
221
|
+
if (!person || !Number.isInteger(person.pid) || person.pid <= 0) return false;
|
|
222
|
+
const current = processStartTime(person.pid);
|
|
223
|
+
// 无 procfs(或 /proc/<pid> 读不到)时退回 kill(pid,0):宁可保守判活,不能误认领。
|
|
224
|
+
if (current === null) return defaultIsPidAlive(person.pid);
|
|
225
|
+
if (!person.start) return true;
|
|
226
|
+
return String(person.start) === String(current);
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
/** 锁 holder(worker/supervisor 任一)是否仍存活;用于启动认领判定。 */
|
|
230
|
+
export function lockHolderAlive(dir) {
|
|
231
|
+
const holder = readLock(dir);
|
|
232
|
+
if (!holder) return false;
|
|
233
|
+
if ([holder.worker, holder.supervisor].some(processIdentityAlive)) return true;
|
|
234
|
+
// 旧 holder 只写 pid(无 starttime):按 pid 保守判活,避免把活监督器当死。
|
|
235
|
+
return Number.isInteger(holder.pid) && processIdentityAlive({ pid: holder.pid, start: holder.start });
|
|
236
|
+
}
|
|
201
237
|
export function lockHeld(dir) { return readLock(dir) !== null; }
|
|
202
238
|
export function acquireLock(dir, { opId, pid = process.pid, now = Date.now(), lease, stateFile } = {}) {
|
|
203
239
|
if (!validOperationId(opId)) return { ok: false, error: "invalid-operation-id" };
|
|
@@ -14,10 +14,23 @@ function identity(pid) {
|
|
|
14
14
|
try { const text = readFileSync(`/proc/${pid}/stat`, 'utf8'); return { pid, start: text.slice(text.lastIndexOf(')') + 2).split(' ')[19] }; }
|
|
15
15
|
catch { return { pid, start: null }; }
|
|
16
16
|
}
|
|
17
|
+
function killAlive(pid) {
|
|
18
|
+
try { process.kill(pid, 0); return true; } catch(e) { return e.code === 'EPERM'; }
|
|
19
|
+
}
|
|
17
20
|
function alive(person) {
|
|
18
21
|
if (!person?.pid || !Number.isInteger(person.pid)) return false;
|
|
19
|
-
|
|
20
|
-
|
|
22
|
+
const current = identity(person.pid).start;
|
|
23
|
+
// 无 /proc 平台:回退 kill(pid,0) 保守判活,与 processIdentityAlive 口径一致。
|
|
24
|
+
if (current === null) return killAlive(person.pid);
|
|
25
|
+
if (!person.start) return true;
|
|
26
|
+
return String(person.start) === String(current);
|
|
27
|
+
}
|
|
28
|
+
function holderAlive(holder) {
|
|
29
|
+
if (!holder) return false;
|
|
30
|
+
const candidates = [holder.worker, holder.supervisor];
|
|
31
|
+
// 旧 holder 兼容:只有顶层 pid/starttime。
|
|
32
|
+
if (Number.isInteger(holder.pid)) candidates.push({ pid: holder.pid, start: holder.start });
|
|
33
|
+
return candidates.some(alive);
|
|
21
34
|
}
|
|
22
35
|
function owns(holder, lease) { return !!lease?.generation && holder?.generation === lease.generation && holder.opId === lease.opId; }
|
|
23
36
|
function fence(holder, lease) { if (!owns(holder, lease)) throw new Error('lease-lost'); }
|
|
@@ -27,7 +40,7 @@ function execute(input) {
|
|
|
27
40
|
const { lockPath, operation, lease, stateFile } = input;
|
|
28
41
|
const holderFile = join(lockPath, 'holder.json');
|
|
29
42
|
let holder = read(holderFile);
|
|
30
|
-
const available = !holder
|
|
43
|
+
const available = !holderAlive(holder);
|
|
31
44
|
if (operation === 'acquire') {
|
|
32
45
|
if (holder && owns(holder, lease)) return { ok: true, lease, holder, reentrant: true };
|
|
33
46
|
// Missing publication is not evidence of owner death. Legacy half-locks require manual repair.
|
|
@@ -154,10 +167,37 @@ function execute(input) {
|
|
|
154
167
|
if (!tx) return { ok: true, action: 'none', transaction: null };
|
|
155
168
|
if (terminal(tx.phase)) return { ok: true, action: 'terminal', transaction: tx };
|
|
156
169
|
if (input.expectedLease && !owns(holder, input.expectedLease)) return { ok: true, action: 'superseded', transaction: tx };
|
|
157
|
-
if (holder
|
|
158
|
-
|
|
170
|
+
if (holderAlive(holder)) return { ok: true, action: 'active', transaction: tx };
|
|
171
|
+
// holder.json 缺失:restart-pending 仍需按 stale 结算(不能因缺 holder 永久 recent);
|
|
172
|
+
// 其他阶段维持保守 recent。
|
|
173
|
+
if (existsSync(lockPath) && !existsSync(holderFile) && tx.phase !== 'restart-pending') {
|
|
174
|
+
return { ok: true, action: 'recent', transaction: tx };
|
|
175
|
+
}
|
|
176
|
+
// issue #110 P1-C:restart-pending + holder 全死 + stale:
|
|
177
|
+
// - 运行内容 == target → settled(保留 artifact/snapshot 元数据,不假称回滚成功);
|
|
178
|
+
// - 内容不匹配 → failed(confirmation-lost),不无限 pending。
|
|
179
|
+
if (tx.phase === 'restart-pending') {
|
|
180
|
+
const startedAt = Date.parse(tx.startedAt ?? tx.updatedAt ?? '');
|
|
181
|
+
// 缺时间戳视为 stale:restart-pending 不能因坏元数据永久 pending。
|
|
182
|
+
const stale = Number.isFinite(startedAt) ? input.now - startedAt >= input.staleMs : true;
|
|
183
|
+
if (!stale) return { ok: true, action: 'recent', transaction: tx };
|
|
184
|
+
const target = String(tx.targetContentSha256 ?? '').toLowerCase();
|
|
185
|
+
const local = String(input.localContentSha256 ?? '').toLowerCase();
|
|
186
|
+
const matched = target !== '' && local === target;
|
|
187
|
+
const next = {
|
|
188
|
+
...tx,
|
|
189
|
+
phase: matched ? 'settled' : 'failed',
|
|
190
|
+
result: matched
|
|
191
|
+
? { ok: true, matched: 'loaded-target-content-adopted' }
|
|
192
|
+
: { ok: false, reason: 'confirmation-lost' },
|
|
193
|
+
updatedAt: new Date(input.now).toISOString(),
|
|
194
|
+
};
|
|
195
|
+
atomic(stateFile, next);
|
|
196
|
+
if (holder) atomic(holderFile, null);
|
|
197
|
+
return { ok: true, action: matched ? 'settled' : 'converged', transaction: next };
|
|
198
|
+
}
|
|
159
199
|
// Never relabel a possibly damaged install as an ordinary terminal failure.
|
|
160
|
-
if (['installing','
|
|
200
|
+
if (['installing','rolling-back'].includes(tx.phase)) return { ok: true, action: 'recovery-required', transaction: tx };
|
|
161
201
|
if (input.now - Date.parse(tx.startedAt) < input.staleMs) return { ok: true, action: 'recent', transaction: tx };
|
|
162
202
|
if (tx.lease && holder && !owns(holder, tx.lease)) return { ok: true, action: 'superseded', transaction: tx };
|
|
163
203
|
const next = { ...tx, phase: 'failed', result: { ok: false, reason: 'holder-gone' } };
|
package/lib/update-supervisor.js
CHANGED
|
@@ -35,7 +35,7 @@ import {
|
|
|
35
35
|
} from "./plugin-update-transaction.js";
|
|
36
36
|
import { pluginContentDigest } from "./plugin-content-digest.js";
|
|
37
37
|
import { verifyFrozenPackage } from "./runtime-dependency-snapshot.js";
|
|
38
|
-
import { restartPlan } from "./plugin-self-update.js";
|
|
38
|
+
import { restartPlan, respawnCommandOf } from "./plugin-self-update.js";
|
|
39
39
|
import { shellOptions } from "./tool-process.js";
|
|
40
40
|
|
|
41
41
|
/** 等待宿主的默认超时:足够冷启动(含语料预热),又不至于让用户无限等。 */
|
|
@@ -138,14 +138,47 @@ export function portKillSnippet(port, fallbackPid = null) {
|
|
|
138
138
|
* 默认重启器:**按当前实例**(端口占用者)终止,而不是事务里记的旧 PID;
|
|
139
139
|
* 前台形态自行重新拉起。**返回结果不再被忽略**(F3)。
|
|
140
140
|
*/
|
|
141
|
-
|
|
142
|
-
|
|
141
|
+
/** 从 `/proc/<pid>/cmdline` 还原宿主原命令行(supervisor 的 argv 不是宿主 argv)。 */
|
|
142
|
+
export function respawnCommandFromProc(pid) {
|
|
143
|
+
if (!Number.isInteger(pid) || pid <= 0) return "";
|
|
144
|
+
try {
|
|
145
|
+
const parts = readFileSync(`/proc/${pid}/cmdline`, "utf8").split("\0").filter((part) => part !== "");
|
|
146
|
+
return respawnCommandOf(parts);
|
|
147
|
+
} catch {
|
|
148
|
+
return "";
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
export function defaultRestart({
|
|
153
|
+
restartForm,
|
|
154
|
+
port,
|
|
155
|
+
pid = null,
|
|
156
|
+
hostPid = null,
|
|
157
|
+
profile = "web",
|
|
158
|
+
dshCommand = "dsh",
|
|
159
|
+
respawnCommand = "",
|
|
160
|
+
log = () => {},
|
|
161
|
+
spawnSyncImpl = spawnSync,
|
|
162
|
+
}) {
|
|
163
|
+
// issue #110 P2:supervisor 的 process.argv 是 `update-supervisor.js --state`,
|
|
164
|
+
// 不能拿它当宿主命令行;优先事务写入的 respawnCommand,其次 `/proc/<hostPid>/cmdline`。
|
|
165
|
+
let originalCommand = respawnCommand;
|
|
166
|
+
if (originalCommand === "" && Number.isInteger(hostPid)) originalCommand = respawnCommandFromProc(hostPid);
|
|
167
|
+
if (originalCommand === "") originalCommand = respawnCommandOf(process.argv);
|
|
168
|
+
const plan = restartPlan({ form: restartForm, pid: null, profile, dshCommand, respawnCommand: originalCommand });
|
|
143
169
|
if (plan.mode === "unsupported") return { ok: false, error: "restart-unsupported" };
|
|
144
170
|
const kill = portKillSnippet(port, pid);
|
|
171
|
+
// 保留原始 argv(如 --port 3082 / --no-open),不能落回 `dsh web --profile web`。
|
|
172
|
+
const respawn = plan.mode === "respawn"
|
|
173
|
+
? (plan.commands?.[plan.commands.length - 1] ?? "")
|
|
174
|
+
: "";
|
|
175
|
+
if (plan.mode === "respawn" && (respawn === "" || originalCommand === "")) {
|
|
176
|
+
return { ok: false, error: "restart-command-missing" };
|
|
177
|
+
}
|
|
145
178
|
const script = plan.mode === "respawn"
|
|
146
|
-
? `sleep 1; ${kill}; sleep 2; nohup ${
|
|
179
|
+
? `sleep 1; ${kill}; sleep 2; nohup ${respawn} >/dev/null 2>&1 &`
|
|
147
180
|
: `sleep 1; ${kill}`;
|
|
148
|
-
const r =
|
|
181
|
+
const r = spawnSyncImpl("bash", ["-lc", script], { encoding: "utf8" });
|
|
149
182
|
if (r.error) return { ok: false, error: r.error.message };
|
|
150
183
|
if (r.status !== 0) return { ok: false, error: `restart-script-exit-${r.status}: ${(r.stderr || "").trim()}` };
|
|
151
184
|
log(`supervisor: 已安排重启(${plan.mode},目标=当前端口占用者)`);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@marktrue/dsh-mobile-remote",
|
|
3
|
-
"version": "3.2.4-alpha.
|
|
3
|
+
"version": "3.2.4-alpha.18",
|
|
4
4
|
"description": "DSH Mobile:把 DeepSeek Harness 变成随身控制台——手机远程发消息派活、看进度、收通知、审批决策、管理会话;配套 Flutter App(当前 Android 端,iOS 未开发)",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "lib/index.js",
|
|
@@ -52,7 +52,7 @@
|
|
|
52
52
|
"qrcode"
|
|
53
53
|
],
|
|
54
54
|
"optionalDependencies": {
|
|
55
|
-
"@marktrue/dsh-mobile-remote-app": "npm:@marktrue/dsh-mobile-remote@3.2.4-alpha.
|
|
55
|
+
"@marktrue/dsh-mobile-remote-app": "npm:@marktrue/dsh-mobile-remote@3.2.4-alpha.18-app"
|
|
56
56
|
},
|
|
57
57
|
"peerDependencies": {
|
|
58
58
|
"@deepseek-ai/dsh-credentials": ">=0.1.0-rc.6 <=0.2.2 || >=0.2.0-0 <0.2.0 || >=0.2.1-0 <0.2.1 || >=0.2.2-0 <0.2.2",
|