Skip to content

feat(dsh): write Driver diagnostics as JSONL under the resolved DSH home - #9302

Open
xiaobaifly7 wants to merge 4 commits into
loopx-project:mainfrom
xiaobaifly7:feat/dsh-driver-diagnostics
Open

xiaobaifly7 wants to merge 4 commits into
loopx-project:mainfrom
xiaobaifly7:feat/dsh-driver-diagnostics

Conversation

@xiaobaifly7

@xiaobaifly7 xiaobaifly7 commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

Goal And Delivered Outcome

  • Outcome basis / optional anchor: concrete maintenance outcome. A stalled DSH Goal could not be diagnosed after the fact because the only trace is a Cordis warn line, and nothing records why the Driver considered a Session not ready.
  • Goal/source and gap: no durable, per-Session record of Driver decisions.
  • Observable before → after: before, no file. After, <DSH home>/logs/dsh-loopx-driver.jsonl receives one JSON object per event: driver start/dispose, observe, skipped request, exact readiness blockers, built plan (binding status and Core effective_action/state/reason), queued Turn id, host-job wait, and every existing warn line with its Session id. DSH home follows @deepseek-ai/dsh-home-paths (DSH_HOME, ~ expansion, default ~/.dsh).
  • Issue/task and intended base: [Feature]: DSH Driver diagnostics log and resume of LoopX-driven Sessions after a host restart #9299. Stacked on fix(dsh): wait for owned host jobs before continuing and keep claimed inputs on rejection #9301; until that PR merges, this diff also shows its commits, and the change here is the last commit. Base main.

Author Declaration

  • Written by: model_agent, Anthropic Claude (Opus 5.5) in Claude Code, operated by the commit author.

Implemented against

  • Specification and revision: no written specification; the request in this PR is the basis.
  • Criteria:
Criterion (spec clause) Disposition Symbol / path Test or command
Log under the resolved DSH home, including the default implemented resolveDshHome, logDiagnostic "writes diagnostics to the default DSH home when DSH_HOME is unset"
Exact blockers, duplicates suppressed for 60 s implemented readyBlockers, NOT_READY_LOG_INTERVAL_MS "persists exact readiness blockers and suppresses duplicates for 60 seconds"
Rotate at 5 MiB to .1 implemented DIAGNOSTIC_LOG_MAX_BYTES "rotates the diagnostics log at 5 MiB and replaces the previous archive"
Logging failure never changes admission implemented logDiagnostic try/catch "queues normally with an unusable diagnostics home and logs after filesystem recovery"
Warn lines and skipped requests are recorded implemented warn, requestEvaluation "writes skipped requests and safe admission warnings to the diagnostics log"
Host-job wait is recorded implemented checkHostJobWait "looks up an optional jobs service after Driver attachment and logs the actual wait"
  • Self-check before submission: the 6 new tests fail on the base Driver and pass here. Records carry ids, states, categories and the existing warn text; the Turn task body and message contents are not written. The file is created with mode 0600. Tests stub DSH_HOME, and a full run left no file in the real home.

Scope And Continuation

  • Completed scope and remaining work: complete within this scope. README documentation of the log location is not included.
  • Slice boundary / successor: the restart resume PR builds on this one.

Validation

  • Tested revision: 4c841b7
  • Run state: finished
  • Input classes: synthetic
Check kind Result Public-safe evidence / limitation
unit passed tests/driver.spec.ts 177/177
unit passed Full package suite: 409 tests, 385 passed, 18 failed, 6 skipped; failures identical by name to main at a6872bb (17 pre-existing on Windows: closeout fixture, path separators, timing), except the cli.spec.ts output-limit termination timing test, which also fails on main in 3 of 3 isolated reruns
static passed pnpm run typecheck
real_backend not_run No live DSH host run.
  • Coverage and gaps: the 0600 mode is not asserted (not meaningful on Windows). admission-closeout only gains DSH_HOME isolation; 11 of its 14 cases fail on the Windows author host on main as well.

Frontend / Visual Evidence

  • UI impact: none

Type of Change

  • New feature

LoopX Area

  • Host or runtime integration

Technical Direction

  • Direction / acceptance reference, when applicable: N/A

Shared-authority RFC fixture impact

N/A

Boundary Checklist

  • Neither the diff nor this PR body/comments/attachments disclose private state, credentials, raw traces or verifier output, internal links, or local machine paths.
  • I did not duplicate maintainer-owned benchmark work unless a maintainer split out a public issue for it.
  • I kept the change scoped to the linked issue/task.
  • No paired RFC changed.
  • UI impact none.
  • Every commit includes a DCO Signed-off-by trailer (git commit -s).

🤖 Generated with Claude Code

xiaobaifly7 and others added 4 commits November 23, 2026 15:43
…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]>
@xiaobaifly7
xiaobaifly7 force-pushed the feat/dsh-driver-diagnostics branch from 8858ebc to 4c841b7 Compare November 23, 2026 07:52

@loopx-agent loopx-agent left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewer: model_agent · gpt-6.2-sol · OpenAI · runtime_reported · xhigh

[P2] 诊断同步写盘阻塞未激活的 Session。 observeAgent 和 requestEvaluation 在激活前调用 logDiagnostic,stat、mkdir、轮换和 append 都在宿主事件回调内同步执行。 同一个未激活 Session 的受控慢写对照里,上游头返回前没有写入,当前头同步写两次并在 308 毫秒后返回。每次写入的注入等待为 80 毫秒。 保住未激活时的被动边界。确需记录的事件交给有容量上限的异步诊断写入器,并验证慢写、失败及轮换时关键宿主回调仍能返回。 准确提交的调用点

[P2] 可恢复重验失败丢弃已暂存的原 Turn。 evaluate 把同一 Turn 的可恢复错误送进 typed_failure 分支并清除 deferredPlan。下一次 buildPlan 因此生成新 Turn 和第二份任务正文。 Driver 对照记录的三次 guard Turn 依次为 1、1、2,排队消息绑定 Turn 2,heartbeat 读取由一次增为两次。 在 recoverable typed_failure 下保留已暂存计划,按原 Turn 重验;只有真实拒绝、绑定失效或用户停止才清除。 准确提交的调用点

动机 / Motivation

在 DSH 里排查自动续跑停滞的用户需要持久诊断,也需要开着诊断时 Session 仍能及时接收事件。 上游 Driver 只将警告交给原宿主日志,启动时没有这份 JSONL,未激活的观察不触发持久文件写入。 新版本把停滞原因写入本地 JSONL。当文件变慢时,连尚未启用 LoopX 的 Session 都会在观察回调上等待。 同一个未激活 Session 的受控慢写对照里,上游头返回前没有写入,当前头同步写两次并在 308 毫秒后返回。每次写入的注入等待为 80 毫秒。 这是 DSH 本地诊断及其父提交的评审。重启接管单独在后续 PR。

改动思路 / Approach

这是 DSH 本地诊断及其父提交的评审。重启接管单独在后续 PR。 Core 持有准入和回执,DSH jobs 持有后台任务生命周期,Driver 持有本 Session 的观察、计时和队列。 日志是本地观察者。 等待和重验沿用现有 Session 保留状态及 typed notice。保住未激活时的被动边界。确需记录的事件交给有容量上限的异步诊断写入器,并验证慢写、失败及轮换时关键宿主回调仍能返回。

具体改动 / Changes

实际 merge base 到准确提交共有 3 个文件,增加 1135 行,删除 106 行。Driver 新增 JSONL、精确就绪原因、写入失败吞吐保护及轮换,用例补充默认目录、重写旧归档、写入失败和恢复。 admission-closeout 集成测试只隔离诊断目录。父提交增加请求恢复及 jobs 等待。

规范版本 a6872bba63df5e4a7af5a58fc1cbebc17b8769a7。SAME_SESSION 已实现。TURN_IDENTITY 未满足。PASSIVE_BEFORE_ACTIVATION 未满足。 同 Session Driver 和重试契约

关键代码讲解

  • logDiagnostic 写本地 JSONL,执行轮换和就绪原因去重。 准确提交的代码
  • readyBlockers 保持原就绪谓词,并产生用于诊断的逐项原因。 准确提交的代码
  • evaluate 读同一 Session 的计划、记录诊断,再决定是否排队。 准确提交的代码
  • checkHostJobWait 只看同一 Session 的运行中或停止中的 jobs,按完成的 Turn 保存等待边界。 准确提交的代码
  • buildPlan 取当前绑定和同一 Turn 的准入判断,然后使用已暂存计划。 准确提交的代码

对主干的风险 / Risks

PASS。准确提交的 Driver 测试 177 项及包内 TypeScript 类型检查通过。本地快速预合并的失败项为 python3 examples/canary/dsh-loopx-plugin-validation.py --phase quality。 真实 DSH 0.2.2-rc.3 本地 jobs 服务对照确认,运行中零次 quota、一个 10 分钟计时,结算后一次 quota 和一条续跑。 真实 Core 完整 JSON 故障注入后,下一次 idle 的两次 guard 产出一条续跑。

FAIL。给同一个未激活 Session 的诊断写入注入受控阻塞,并在两版 Driver 上记录 observeAgent 返回前的写入次数、宿主回调和队列状态。 jobs 使用已安装的真实服务,Agent 和决定性延后反例使用隔离的宿主夹具。写盘等待是受控注入,未测生产磁盘时延。

语义与 CI 对齐

复用既有 Core 状态和 Turn 身份,故障回复指向原 Turn 的恢复。上游 #9298 的完整 JSON 普通首次准入已在本头通过。已暂存准入的反例仍会生成第二个 Turn。在 recoverable typed_failure 下保留已暂存计划,按原 Turn 重验;只有真实拒绝、绑定失效或用户停止才清除。 Core 返回契约 上游原评审

我的整体评价 / Verdict

后台等待的主路径已可用。长程续跑还需要在故障解除后交付原计划的结果,操作者才能把后台任务完成与后续进度对齐。诊断仍需要通过慢写条件下的宿主响应验收。 改动位于 Driver 事件消费、队列与本地诊断,页面布局无需验证。

English verdict: REQUEST_CHANGES at 4c841b7. Synchronous diagnostics block passive Session callbacks. The stack also discards the deferred Turn after a recoverable receipt error.

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 })

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[P2] 诊断同步写盘阻塞未激活的 Session。同一个未激活 Session 的受控慢写对照里,上游头返回前没有写入,当前头同步写两次并在 308 毫秒后返回。每次写入的注入等待为 80 毫秒。 保住未激活时的被动边界。确需记录的事件交给有容量上限的异步诊断写入器,并验证慢写、失败及轮换时关键宿主回调仍能返回。

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)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[P2] 可恢复重验失败丢弃已暂存的原 Turn。Driver 对照记录的三次 guard Turn 依次为 1、1、2,排队消息绑定 Turn 2,heartbeat 读取由一次增为两次。 在 recoverable typed_failure 下保留已暂存计划,按原 Turn 重验;只有真实拒绝、绑定失效或用户停止才清除。

@mergify

mergify Bot commented Nov 23, 2026

Copy link
Copy Markdown

This pull request has merge conflicts with main and cannot be merged
until they are resolved. Please rebase or merge the base branch, @xiaobaifly7.

Choose the remote for the base repository, not an out-of-date fork.
For a fork clone, first inspect git remote -v; upstream must point
to https://github.com/loopx-project/loopx.git. If it is absent, add it
with git remote add upstream https://github.com/loopx-project/loopx.git.
Then run:

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 HEAD

For a same-repository clone whose origin points to
https://github.com/loopx-project/loopx.git, use origin instead of
upstream for fetch/rebase. If you prefer merging the base, use
git merge <base-remote>/main and push normally.

Keep the DCO Signed-off-by trailer on every commit when you rebase.
https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/working-with-forks/syncing-a-fork

@mergify mergify Bot added the needs-rebase Mergify: the pull request has merge conflicts with its base branch label Nov 23, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

needs-rebase Mergify: the pull request has merge conflicts with its base branch

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants