Skip to content

fix(dsh): wait for owned host jobs before continuing and keep claimed inputs on rejection - #9301

Open
xiaobaifly7 wants to merge 3 commits into
loopx-project:mainfrom
xiaobaifly7:fix/dsh-host-job-wait
Open

xiaobaifly7 wants to merge 3 commits into
loopx-project:mainfrom
xiaobaifly7:fix/dsh-host-job-wait

Conversation

@xiaobaifly7

@xiaobaifly7 xiaobaifly7 commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

Goal And Delivered Outcome

  • Outcome basis / optional anchor: reproduced defect in the DSH Driver.
  • Goal/source and gap: When a Turn completed while jobs it started were still running, the Driver admitted the next LoopX Turn at once. The tool-jobs completion notice was then treated as competing input, which fenced or rejected the continuation it was meant to wake. On a pre-step rejection or downstream failure, inputs the host had already claimed into the rejected batch (for example the job notice) were dropped.
  • Observable before → after:
    • Completed Turn with an owned running/stopping job: before, immediate admission; after, a wait of at most 10 minutes. The deadline is kept per completed Turn across commands and Driver replacement, and a new Turn starts a new window.
    • A plan built while jobs run: before, discarded and re-minted; after, deferred with its Core Turn identity and revalidated before queueing.
    • tool-jobs notice: before, competing input; after, it wakes an idle Driver and may share the continuation's step.
    • Rejection or failure: before, claimed inputs lost; after, each restored exactly once, without a wakeup when the step was aborted.
  • Issue/task and intended base: none. Stacked on fix(dsh): keep the GoalBar Pause fence and typed pre-step rejection across Driver replacement #9298; 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. The jobs host service is optional; without it behavior is unchanged.
  • Criteria:
Criterion (spec clause) Disposition Symbol / path Test or command
Wait for owned running/stopping jobs after a completed Turn, bounded at 10 minutes implemented checkHostJobWait, JOB_WAIT_MS "waits ten minutes for %s host jobs…", "keeps the original host-job deadline across %s"
Deferred plan keeps its Core Turn identity; discarded on human input, Pause, binding change or typed failure implemented SessionDriverRetention.jobWait.deferredPlan, buildPlan, queuePlan "reuses the deferred Core Turn identity…", "keeps the deferred Core Turn when quota revalidation is interrupted…", "never queues the deferred Core Turn after %s"
tool-jobs notices are not competing input; other automatic input still is implemented isToolJobNotice, isAllowedStepContext, inboxHasPending "admits beside a pending settled-job notice at %s", "keeps %s/%s input behind the competing-input fence"
Claimed inputs restored once on every rejection or failure implemented onPreStep, restoreCompetingMessages(…, wakeup) "restores the original claimed batch once after downstream %s", "restores a claimed job notice exactly once after downstream %s"
Core recovery attention still wins after an expired wait implemented buildPlan "honors Core recovery attention after an expired host-job wait"
  • Self-check before submission: 23 of the 25 new tests fail on the base Driver. The 2 that pass there pin the unchanged competing-input fence. Not run on a live DSH host.

Scope And Continuation

  • Completed scope and remaining work: complete within this scope.
  • Slice boundary / successor: Driver diagnostics PR builds on this one.

Validation

  • Tested revision: 95f2d6f
  • Run state: finished
  • Input classes: synthetic
Check kind Result Public-safe evidence / limitation
unit passed tests/driver.spec.ts 171/171
unit passed Full package suite: 403 tests, 379 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 with background jobs.
  • Coverage and gaps: the jobs service is exercised through a fake list(agentId); the real DSH jobs service shape (owner, status) is taken from DSH 0.2.2-rc.3 and was not exercised end to end.

Frontend / Visual Evidence

  • UI impact: none

Type of Change

  • Bug fix

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 3 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]>
@xiaobaifly7
xiaobaifly7 force-pushed the fix/dsh-host-job-wait branch from 141bcc0 to 95f2d6f 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] 可恢复重验失败丢弃已暂存的原 Turn。 evaluate 把同一 Turn 的可恢复错误送进 typed_failure 分支并清除 deferredPlan。下一次 buildPlan 因此生成新 Turn 和第二份任务正文。 Driver 对照记录的三次 guard Turn 依次为 1、1、2,排队消息绑定 Turn 2,heartbeat 读取由一次增为两次。 在 recoverable typed_failure 下保留已暂存计划,按原 Turn 重验;只有真实拒绝、绑定失效或用户停止才清除。 准确提交的调用点

动机 / Motivation

在 DSH 托管 LoopX Goal 的用户经常等后台任务收尾,希望完成后自动接续工作。 基线会在仍有本会话后台任务时即刻请求准入。旧段结束和新段开始之间,任务完成通知也可能被当成竞争输入。 新版本可先等本会话后台任务收尾,再接续已准备的工作。如果这次重验短暂写入失败,恢复后会改用另一轮。 Driver 对照记录的三次 guard Turn 依次为 1、1、2,排队消息绑定 Turn 2,heartbeat 读取由一次增为两次。 这是 DSH Driver 同一个 Session 的任务完成、回执重验和已认领消息恢复。

改动思路 / Approach

这是 DSH Driver 同一个 Session 的任务完成、回执重验和已认领消息恢复。 Core 持有准入和回执,DSH jobs 持有后台任务生命周期,Driver 持有本 Session 的观察、计时和队列。 等待和重验沿用现有 Session 保留状态及 typed notice。在 recoverable typed_failure 下保留已暂存计划,按原 Turn 重验;只有真实拒绝、绑定失效或用户停止才清除。

具体改动 / Changes

实际 merge base 到准确提交共有 2 个文件,增加 810 行,删除 67 行。Driver 与其测试加入 jobs 等待、完成通知的输入分类和认领消息恢复。 上游 Pause 与回执失败分类也进入本 PR,覆盖正常准入和 pre-step 的同一 Session。

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

关键代码讲解

  • checkHostJobWait 只看同一 Session 的运行中或停止中的 jobs,按完成的 Turn 保存等待边界。 准确提交的代码
  • buildPlan 取当前绑定和同一 Turn 的准入判断,然后使用已暂存计划。 准确提交的代码
  • restoreCompetingMessages 撤销预备步时恢复真正输入,仍按消息 ID 去重。 准确提交的代码
  • receiptWriteFailed 根据 Core 类型标签和同一 Turn 回执区分可恢复写入失败。 准确提交的代码

对主干的风险 / Risks

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

FAIL。让同一测试 Session 的任务在第一次 guard 中途进入 running,完成后让第二次 guard 返回原 Turn 的 write_failed,恢复后断言第三次 guard 与排队消息仍使用原 Turn。 jobs 使用已安装的真实服务,作者用户消息和后台通知都在宿主夹具内驱动。故障交叉由 Driver 测试注入 Core 的真实已知返回结构。

语义与 CI 对齐

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

我的整体评价 / Verdict

后台等待的主路径已可用。长程续跑还需要在故障解除后交付原计划的结果,操作者才能把后台任务完成与后续进度对齐。修订版本应覆盖后台等待、原身份重验与真实权限拒绝三个相邻分支。 改动位于 Driver 事件消费、队列与本地诊断,页面布局无需验证。

English verdict: REQUEST_CHANGES at 95f2d6f. A recoverable receipt failure discards the deferred plan, so the next idle event mints a second Turn.

}
if (!controller.signal.aborted && !cancelled) {
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