Skip to content

fix(setup): provision the Agent workspace before the runtime probe - #214

Open
itswl wants to merge 1 commit into
eddiearc:mainfrom
itswl:fix/setup-provision-workspace-before-runtime-probe
Open

itswl wants to merge 1 commit into
eddiearc:mainfrom
itswl:fix/setup-provision-workspace-before-runtime-probe

Conversation

@itswl

@itswl itswl commented Sep 12, 2026

Copy link
Copy Markdown
Contributor

What

Fresh installs have no <root>/agents/<App ID> yet — the daemon's host-shell reconciles it at first start. The interactive setup probe spawned the runtime with that missing directory as its cwd, so the spawn failed with ENOENT and surfaced as a catalog/protocol failure (#212).

Reworked after review: the probe now uses a directory that is guaranteed to exist — the Agent workspace when present, otherwise the config root (CFG_DIR), with a one-line note when falling back. Workspace creation stays owned by the host-shell: setup.ts imports no workspace-service/reconcileAgentWorkspace, so the single-owner boundary asserted by test/integration/setup/setup-cli.test.mjs stays green. The readiness cwd guard is kept as the other half.

Change

  • src/app/setup.ts: probeCwd = exists(workspaceDir) ? workspaceDir : CFG_DIR (+ note when falling back); the workspace-service import from the previous revision is gone.
  • src/runtime/runtime-readiness.ts (kept): probeNativeRuntimeReadiness reports a missing working directory as its own unavailable cause instead of letting the spawn ENOENT masquerade as a runtime/protocol failure.
  • test/unit/runtime/runtime-readiness.test.mjs: covers the missing-workspace readiness result.

Validation

Fixes #212

🤖 Generated with Claude Code

@eddiearc eddiearc left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

REQUEST_CHANGES / HOLD(Fable 5.1 审合)

症状对:#212 在 missing cwd 上会被伪装成 catalog/protocol 失败;probeNativeRuntimeReadiness 的 cwd guard 半边是好的。

Blocker:test/integration/setup/setup-cli.test.mjs 明确断言 setup.ts 不得引用 workspace-service|reconcileAgentWorkspace(host-shell 单一所有者边界)。本 PR 会踩红这条护栏;PR 体只跑了 unit,没跑这条 integration。

建议重做:保留 readiness cwd guard;setup 探测改用保证存在的目录(如 workspace 缺失时回退 CFG_DIR),或拿 Owner 书面批准后再改护栏。不要为了过测放松该边界。

@itswl
itswl force-pushed the fix/setup-provision-workspace-before-runtime-probe branch from b27459f to 0d335b9 Compare September 13, 2026 15:15
@itswl

itswl commented Sep 13, 2026

Copy link
Copy Markdown
Contributor Author

按建议重做了,两点都照办:

  • 保留 readiness cwd guardprobeNativeRuntimeReadiness 对缺失 cwd 报自身原因那一半不动);
  • setup 探测改用必然存在的目录:工作区存在就用它,缺失则回退 CFG_DIR,并打一行提示说明"工作区由 daemon 启动时 reconcile"。setup.ts 不再 import workspace-service/reconcileAgentWorkspace——单一所有权边界保持原样。

验证(已 rebase 到含 #219/#227 的 main):

  • bun test test/unit/setup/ test/unit/app/setup-cli.test.mjs test/integration/setup/76 pass / 1 skip / 0 fail,其中就包含此前踩红的 setup-cli.test.mjs 边界断言(此前只跑了 unit、漏了这条 integration,是我的疏忽);
  • test/unit/runtime/runtime-readiness.test.mjs → 20 pass / 0 fail;build/typecheck 通过。

如果"回退 CFG_DIR + 单行提示"的形态还需要调整(例如提示文案、或希望干脆静默回退),说一声我改。

@itswl
itswl force-pushed the fix/setup-provision-workspace-before-runtime-probe branch from 0d335b9 to 6e14d53 Compare September 13, 2026 15:38
@itswl

itswl commented Sep 13, 2026

Copy link
Copy Markdown
Contributor Author

补充:main 合并 #215 后本 PR 出现冲突(#215 与这里都改了 runtime-readiness.ts 与它的测试),已 rebase 到最新 main(含 #215/#228)。

冲突只在 readiness 测试文件,按"两边都保留"处理:classifyRuntimePrerequisite 的三条分类测试(#215 已合并的那侧)+ 本 PR 的 missing-workspace guard 测试。本地复验:test/unit/runtime/runtime-readiness.test.mjs → 23 pass / 0 fail;test/unit/setup/ + test/unit/app/setup-cli.test.mjs + test/integration/setup/ → 76 pass / 1 skip / 0 fail;build 通过。CI 已重新触发。

@eddiearc

Copy link
Copy Markdown
Owner

Maintainer follow-up(Fable 5.1 + GPT-6 Astra 共识)

这条 不按当前实现合。目标仍然成立(fresh setup 不该把 missing cwd 伪装成 catalog/protocol 失败),但 setup 直接调用 reconcileAgentWorkspace 越过了 host-shell 单一所有者边界;setup-cli 护栏和红 CI 都在拦这个。

请改版,不要松护栏:

  1. 保留 probeNativeRuntimeReadiness 的 missing-cwd 诊断(可拆出单独小 PR)。
  2. setup 里 workspace-无关的预检,改用 setup 已拥有且已存在的私有配置目录作 cwd;真正的 workspace provisioning / attach 仍交给 daemon。
  3. 不要为了过测去改 setup-cli 断言或给 setup 开 workspace-service 白名单。

相关:#212#215/#219 已合进 main。

@itswl

itswl commented Sep 14, 2026

Copy link
Copy Markdown
Contributor Author

收到。这条改版在 15:15 已经推上去了(head 6e14d53,CI 现已全绿),逐条对照:

  1. missing-cwd 诊断保留在 probeNativeRuntimeReadiness 未动;如果你希望它单独成一个小 PR,我可以拆出来。
  2. setup 的交互式预检不再 import workspace-service:工作区未创建时改用配置目录(CFG_DIR)作 cwd,并打一行提示("Agent 工作区尚未创建(daemon 启动时会 reconcile):运行时探测改用 …");workspace provisioning / attach 仍全部归 daemon。
  3. 护栏未动、未开白名单——test/integration/setup/setup-cli.test.mjs 原样通过(本地 76 pass / 1 skip / 0 fail,CI source-checks 5m57s pass)。

补充时序以免混淆:14:02 那条 review 之后我先按"reconcile"改过一版;15:15 已按单一所有权边界重做为现在这版;15:38 又 rebase 掉了 #215 带来的冲突(冲突只在 readiness 测试文件,两边测试都保留)。如果你 16:20 这条是对着旧 head 写的、现在这版仍不合意,请指一个具体点我再改。

A fresh Agent's <root>/agents/<App ID> directory does not exist until the
daemon's host-shell reconciles it, so the interactive runtime probe spawned
the runtime in a missing cwd, failed with ENOENT, and surfaced as a
catalog/protocol failure (eddiearc#212). Keep the readiness cwd guard, and give the
probe a directory that is guaranteed to exist: fall back to the config root
when the workspace is missing (with a one-line note). Workspace creation
stays owned by the host-shell — setup imports no workspace-service.

Bumps the package patch version (0.5.9 -> 0.5.10) per the Owner policy.

Co-Authored-By: Claude Code <noreply@anthropic.com>
@itswl

itswl commented Sep 14, 2026

Copy link
Copy Markdown
Contributor Author

已按复审重做(head 1fc5457

  • 保留 probeNativeRuntimeReadiness 的 missing-cwd 诊断:缺目录时返回独立的 unavailable 原因 + nextAction,不再让 spawn ENOENT 伪装成 catalog/protocol 故障。
  • setup.ts 不再引用 workspace-service / reconcileAgentWorkspace:探测 cwd = 工作区存在则用工作区,缺失则回退 CFG_DIR(回落时打一行说明)。真正的 workspace provisioning / attach 仍归 host-shell。
  • 护栏未放松:test/integration/setup/setup-cli.test.mjsdoesNotMatch(setupSource, …workspace-service|reconcileAgentWorkspace…) 原样保留并通过。
  • package.json 已按 Owner 政策补 bump(0.5.9 → 0.5.10)。

本地验证:bun test --max-concurrency 1 test/unit/runtime/runtime-readiness.test.mjs test/unit/setup/ test/unit/app/setup-cli.test.mjs test/integration/setup/ → 99 pass / 1 skip / 0 fail(含该护栏脚本,此前那轮只跑了 unit 的缺口已补上);bun run build / typecheck ✅。CI 已触发。

@itswl
itswl force-pushed the fix/setup-provision-workspace-before-runtime-probe branch from 6e14d53 to 1fc5457 Compare September 14, 2026 14:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: 全新安装的交互式 setup 因 Agent workspace 目录未创建而把 runtime 探测误报为 Claude/Codex 不可用

2 participants