Repository navigation
feat(dsh): resume LoopX-driven Sessions after a host restart - #9303
xiaobaifly7 wants to merge 5 commits into
Conversation
…cross Driver replacement A GoalBar Pause retired queued work, but after the paused Turn ended the next idle evaluation still probed `quota should-run`, and a Driver replacement (plugin reload/HMR) started from an unpaused state. A typed Core rejection at the pre-step recheck was folded into a plain mismatch: nothing was recorded at the rejected step, and the Driver re-probed Core immediately and again on every idle. The admission-failure projection also lived on the per-Driver state and was lost on replacement. - Keep the GoalBar Pause flag and the admission-failure category in the process-local per-Session retention that already survives Driver replacement. Pause fences readiness until an explicit Start. - Treat a non-ok binding or quota payload at the pre-step recheck as a typed failure: record it for the GoalBar and, for `admission_rejected`, hold automatic continuation until human input or a verified Start. - Route error-pause writes through one helper and clear an `admission_rejected` failure only on human input or Start. Related to loopx-project#8505. Signed-off-by: xiaobaifly7 <[email protected]> Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ite failure Review of the GoalBar Pause fence change found that every `quota.ok=false` became an `admission_rejected` pause that only human input or Start clears. When Core cannot persist the Turn's heartbeat receipt it returns its own typed action `heartbeat_receipt_write_failed` with a `write_failed` receipt for that exact `--turn-instance-id`, and asks for a retry after the writeback is repaired. `main` retried on the next idle; the Pause fence change stalled until a human acted. Classify the failure from Core's payload: a `heartbeat_receipt_write_failed` action whose receipt is `write_failed` for the same Turn is recoverable. It is still recorded for the GoalBar, but it no longer latches the Session pause, at initial admission and at the pre-step recheck. The next successful evaluation clears it, as on `main`. Every other typed rejection and explicit Pause keep the hard stop. Signed-off-by: xiaobaifly7 <[email protected]> Co-Authored-By: Claude Opus 5.5 <[email protected]>
… inputs on rejection When a Turn completed while host jobs it started were still running, the Driver immediately admitted the next LoopX Turn. A `tool-jobs` completion notice was then treated as competing input, which fenced or rejected the continuation that the notice was meant to wake. On a pre-step rejection or downstream failure, inputs that the host had already claimed into the rejected batch (for example a job notice) were dropped instead of being put back. - After a completed Turn, wait up to 10 minutes while the Agent owns running or stopping jobs (optional `jobs` host service). The deadline is kept per completed Turn in the process-local Session retention, so a command or Driver replacement does not restart it; a new Turn does. - A plan built while jobs are still running is deferred with its Core Turn identity and revalidated through `quota should-run` before it is queued, instead of minting a new Turn. Human input, Pause, a binding change or a typed Core failure discards the deferred plan. - `tool-jobs` notices wake an idle Driver and are allowed beside the continuation in its step; other automatic input stays fenced. - Restore every claimed input on each pre-step rejection or downstream failure exactly once, without waking the Agent when the step was aborted. Depends on the GoalBar Pause fence change (draft/dsh-pause-fence-typed-rejection). Signed-off-by: xiaobaifly7 <[email protected]> Co-Authored-By: Claude Opus 5.5 <[email protected]>
When automatic continuation stops, the only trace today is a Cordis warn line, which many DSH installs do not keep, and nothing records why the Driver considered a Session not ready. Diagnosing a stalled Goal required attaching a debugger. - Append one JSON object per event to `<DSH home>/logs/dsh-loopx-driver.jsonl`, where the DSH home follows the `@deepseek-ai/dsh-home-paths` rules (`DSH_HOME`, `~` expansion, default `~/.dsh`). Records: driver start/dispose, observe, skipped requests, the exact readiness blockers, the built plan (binding status and Core `effective_action`/`state`/`reason`), queued Turn identity, host-job waits, and every existing warn line with its Session id. - Identical `not_ready` blocker sets for a Session are written at most once per 60 seconds. The file rotates to `.1` at 5 MiB. The file is created with mode 0600. Write failures are swallowed so logging never changes admission. - Tests isolate `DSH_HOME` so the suite never writes into the real home. Records carry ids, states, categories and the existing warn text; the Turn task body and message contents are not written. Depends on draft/dsh-host-job-wait (logs its wait and tool-job notice filtering). Signed-off-by: xiaobaifly7 <[email protected]> Co-Authored-By: Claude Opus 5.5 <[email protected]>
After DSH restarts, only Sessions that the user reopens get a live Agent, so a Goal that LoopX was driving stays idle until someone opens its Session. A new Agent also rebuilds the Driver's error pause from Session history alone, so a pause that has no matching Session event (an `agent/error`, a pre-step or downstream rejection, a typed Core rejection) was lost on restart, as was a Turn that ended with `error`. - On hosts that provide the optional `sessionQuery` and `sessionController` services (DSH 0.2.2-rc.3), inspect up to 32 persisted, non-subagent Sessions that are not loaded, and load through `sessionController.resolveAgent` only those that were LoopX-activated, are not paused by GoalBar or by an error pause, have no active native DSH goal, resolve to exactly one binding that is unchanged across the Core lifecycle read, and whose Goal Core reports active (read-only lifecycle readback). Admission then follows the normal `agent/created` path. Older hosts keep driving only live Agents. - Persist the error pause per Session (sha256 of the Session id) under `<DSH home>/dsh-loopx-driver-pauses/` with the event seq it covers, so a restart honors it; later human input still clears it. A Turn that ends with reason `error` now also counts as a pause in that history fold. - Fence automatic continuation while a native DSH goal is active (`goal/change` phase `active`) and re-evaluate when it pauses. - Each skip reason is written to the Driver diagnostics log. Depends on draft/dsh-driver-diagnostics. Signed-off-by: xiaobaifly7 <[email protected]> Co-Authored-By: Claude Opus 5.5 <[email protected]>
1b0e3b9 to
e6689b8
Compare
loopx-agent
left a comment
There was a problem hiding this comment.
Reviewer: model_agent · gpt-6.2-sol · OpenAI · runtime_reported · xhigh
[P2] 暂停写入失败后仍可在冷启动自动恢复。 setErrorPause 更新内存 latch,失败时只写诊断。sessionErrorPause 找不到文件便只折叠 Session 历史。 使用可验证的持久停点。遇到暂停写入失败或恢复状态无法确认时,保持冷启不自动加载,直至可读回的恢复或显式用户操作。 准确头源码
[P2] 可恢复回执重验失败会更换已暂存的 Turn。 evaluate 对任意 typed_failure 清除 deferredPlan,下一次 buildPlan 生成新 Turn。 可恢复重验应保留暂存计划,直到原 Turn 得到明确准入结果、绑定失效或用户停止。 准确头源码
[P2] 未激活 Session 的观察被同步日志阻塞。 observeAgent 和 requestEvaluation 都在调用栈内进入 logDiagnostic 与 appendFileSync。 把写入移出宿主观察回调,使用有界异步输送并验证慢盘下的即时返回。 准确头源码
动机 / Motivation
使用 DSH 托管 LoopX Goal 的用户希望重启后恢复合格的会话,同时保留已触发的暂停。 基线只能接续已打开的 Agent,重启不会自动装载一个冷 Session。 新 Driver 查找冷 Session,读取激活、原生 Goal、暂停与当前 Core 状态,再通过既有 Host controller 申请装载。 使用真实 DSH JSONL 和 SessionQuery。暂停成功写盘的对照没有加载请求。暂停目录暂不可写时,只记录写失败。恢复目录权限后换新 Driver 和查询实例,真实 Core 的两次绑定解析和生命周期查询均通过,Driver 请求加载同一个已暂停的 Session。 既有 Core 的额度与结算语义保持原路径。
以 2026-11-23T06:31:23Z 的问题说明核对 COLD_RESUME、PAUSE_PERSISTENCE 和 OBSERVABILITY。这里评估启动恢复及前两层依赖在当前头的实际行为。 问题
改动思路 / Approach
使用 DSH 已有的 Session 加载所有者。Core 继续裁决绑定、准入与结算。恢复需要可确认的暂停状态,诊断应留在观察边界。 使用可验证的持久停点。遇到暂停写入失败或恢复状态无法确认时,保持冷启不自动加载,直至可读回的恢复或显式用户操作。 诊断移出宿主回调,回执重验保留原 Turn。 Driver 原有契约
具体改动 / Changes
实际合并基点到准确头是 3 files +1521/-120。本次最后一个提交接在 4c841b7 后,整份 PR 仍包含未合并的等待和诊断变更。当前 main 中被修改的包与该合并基点同源码,合成无冲突。
关键代码讲解
- sessionErrorPause 合并磁盘停点和实际 Session 事件序号。 准确头源码
- resumePersistedSessions 在 Host 查询与二次绑定确认后选择冷启候选。 准确头源码
- setErrorPause 落盘停点并记录失败,进程内 latch 立即生效。 准确头源码
- evaluate 后台工作结束后重验暂存计划。 准确头源码
- logDiagnostic 把观察与停止记录写入本地 JSONL。 准确头源码
对主干的风险 / Risks
PASS。成功持久化的 Pause 在新 DSH 冷读中阻止加载。包内用例还覆盖未激活、活动原生 Goal、绑定变化和 Core Stop。 准确头 417 项包测试、TypeScript、打包、隔离 profile 和真实 DSH 0.2.2-rc.3 运行烟测均通过。当前 main 对所改包与实际合并基点同 blob,合成无冲突。
FAIL。拒写支线由真实文件权限触发,查询在新宿主上下文重开,复验了 Core 的两个绑定读取。实测 guard 依次为 Turn 1、Turn 1、Turn 2,队列使用 Turn 2,任务正文读取两次。 为每次追加注入 80 ms 延迟,观察回调返回前写两次,本轮耗时 238 ms。未进入 Core 准入。
语义与 CI 对齐
真实 DSH 持久化、冷读和 Core 验证都参与了写失败反例。最终 Host loader 在该测试中只记录请求。打包 DSH Web 烟测另行覆盖安装、Start/Pause 和卸载。实际加载后的模型工作、Windows、浏览器挂载点击待验证。 冷启动读取生命周期使用 dry run。未咨询 CI。
我的整体评价 / Verdict
启动恢复需要一条可读回的暂停依据。当前写失败路径丢失停点,同一准确头的堆叠也保留两个可重现的行为变化。使用 DSH 已有的 Session 加载所有者。Core 继续裁决绑定、准入与结算。恢复需要可确认的暂停状态,诊断应留在观察边界。
English verdict: REQUEST_CHANGES at e6689b8. The same persisted Session can reach the cold loader after a failed pause write. This exact head also reproduces the inherited deferred-Turn replacement and blocking diagnostic writes.
| writeFileSync(pending, JSON.stringify({ throughSeq, paused }), { mode: 0o600 }) | ||
| renameSync(pending, file) | ||
| } catch { | ||
| this.logDiagnostic('resume_pause_write_failed', session.id) |
There was a problem hiding this comment.
[P2] 暂停写入失败后仍可在冷启动自动恢复。 使用真实 DSH JSONL 和 SessionQuery。暂停成功写盘的对照没有加载请求。暂停目录暂不可写时,只记录写失败。恢复目录权限后换新 Driver 和查询实例,真实 Core 的两次绑定解析和生命周期查询均通过,Driver 请求加载同一个已暂停的 Session。
使用可验证的持久停点。遇到暂停写入失败或恢复状态无法确认时,保持冷启不自动加载,直至可读回的恢复或显式用户操作。 用同一个持久化记录对照写失败、成功写入及用户恢复,断言冷启不会越过暂停。
| this.warn(`dsh-loopx-driver: admission_failed stage=${stage} ${cliErrorFields(error)} signal_aborted=${admissionSignal?.aborted ?? controller.signal.aborted} elapsed_ms=${Math.round(performance.now() - startedAt)}`) | ||
| this.recordAdmissionFailure(state, admissionFailureCategory(error)) | ||
| if (error instanceof LoopXCliError && error.kind === 'typed_failure') { | ||
| this.clearDeferredPlan(state, jobWait.deferredPlan) |
There was a problem hiding this comment.
[P2] 可恢复回执重验失败会更换已暂存的 Turn。 实测 guard 依次为 Turn 1、Turn 1、Turn 2,队列使用 Turn 2,任务正文读取两次。
可恢复重验应保留暂存计划,直到原 Turn 得到明确准入结果、绑定失效或用户停止。 在工作等待结束后的第二次 guard 注入同一 Turn 的 write_failed,再核对第三次 guard 和排队仍使用 Turn 1。
| const size = statSync(file, { throwIfNoEntry: false })?.size | ||
| if (size === undefined) mkdirSync(logs, { recursive: true }) | ||
| else if (size + bytes > DIAGNOSTIC_LOG_MAX_BYTES) renameSync(file, `${file}.1`) | ||
| appendFileSync(file, line, { mode: 0o600 }) |
There was a problem hiding this comment.
[P2] 未激活 Session 的观察被同步日志阻塞。 为每次追加注入 80 ms 延迟,观察回调返回前写两次,本轮耗时 238 ms。未进入 Core 准入。
把写入移出宿主观察回调,使用有界异步输送并验证慢盘下的即时返回。 在未激活 Session 上阻塞诊断 sink,核对观察回调及 Core 调用计数。
|
This pull request has merge conflicts with Choose the remote for the base repository, not an out-of-date fork. git fetch upstream
git rebase upstream/main
# Resolve each conflict, git add the resolved files, then git rebase --continue.
git push --force-with-lease origin HEADFor a same-repository clone whose Keep the DCO |
Goal And Delivered Outcome
agent/error, a pre-step or downstream rejection, a typed Core rejection) was lost on restart, as was a Turn that ended witherror.sessionQueryandsessionController(DSH 0.2.2-rc.3), up to 32 persisted non-subagent Sessions are inspected. Only those that pass every check below are loaded throughsessionController.resolveAgent, and admission then follows the normalagent/createdpath. The checks:<DSH home>/dsh-loopx-driver-pauses/with the event seq it covers. Later human input still clears it.goal/changephaseactive): automatic continuation is fenced and re-evaluated when the native goal pauses.main.Author Declaration
Implemented against
agent/createdresumePersistedSessionsresumePersistedSessionsRESUME_SESSION_LIMIT,applyctx.injecterrorPauseFile,sessionErrorPause,setErrorPausenativeGoalChange,readyBlockers,reservationIsCurrentsessionQuery/sessionController; it was not run against a real DSH restart in this branch.Scope And Continuation
Validation
unitpassedtests/driver.spec.ts185/185unitpassedmainat a6872bb (17 pre-existing on Windows: closeout fixture, path separators, timing), except thecli.spec.tsoutput-limit termination timing test, which also fails onmainin 3 of 3 isolated rerunsstaticpassedpnpm run typecheckreal_backendnot_runsessionQuery/sessionControllershapes come from DSH 0.2.2-rc.3 and are mocked here.Frontend / Visual Evidence
Type of Change
LoopX Area
Technical Direction
Shared-authority RFC fixture impact
N/A
Boundary Checklist
none.Signed-off-bytrailer (git commit -s).🤖 Generated with Claude Code