Skip to content

feat(ch12): phase 0 — snapshot rewire + workspace-trust gate - #30

Merged
agentforce314 merged 1 commit into
mainfrom
feat/ch12/phase0
May 9, 2026
Merged

feat(ch12): phase 0 — snapshot rewire + workspace-trust gate#30
agentforce314 merged 1 commit into
mainfrom
feat/ch12/phase0

Conversation

@ericleepi314

@ericleepi314 ericleepi314 commented May 9, 2026

Copy link
Copy Markdown
Collaborator

Summary

Phase 0 of the ch12 (extensibility) chapter port. Closes the chapter's hard-fix-first blocker: the hook executor now reads the frozen HookConfigSnapshot via tool_use_context.hook_config_manager rather than the live tool_use_context.options.hooks. Adds workspace-trust gate that strips non-policy hooks under untrusted workspace.

What's new in this phase

  • src/hooks/hook_executor.py_get_hooks_from_snapshot; both bypass sites rewired; legacy _get_hooks_from_settings now a back-compat alias emitting DeprecationWarning.
  • src/hooks/trust_gate.py — new should_skip_hook_due_to_trust predicate; gate at top of _run_hooks_for_event strips non-policy hooks when workspace_trusted=False.
  • src/tool_system/context.py — adds hook_config_manager: Any | None and workspace_trusted: bool.
  • 15 new tests: 8 in test_snapshot_freezing.py (including on-disk TOCTOU regression where settings.json is mutated after snapshot), 7 in test_trust_gate.py.
  • pytest-asyncio>=1.3.0 pinned in deps.

Test plan

  • pytest tests/test_snapshot_freezing.py tests/test_trust_gate.py → 15/15
  • pytest -k hook → all green
  • Full sweep: 27 pre-existing env failures only (zero new)

First of 10 PRs in the ch12 phase series. Each phase builds on the prior one (cumulative diff against main).

🤖 Generated with Claude Code

…rkspace-trust gate

Closes the gap analysis' hard-fix-first blocker: the hook executor now reads
the frozen HookConfigSnapshot via tool_use_context.hook_config_manager rather
than the live tool_use_context.options.hooks. Both bypass sites (has_hook_for_event,
_run_hooks_for_event) are converted; _get_hooks_from_settings remains as a
back-compat alias that emits DeprecationWarning. Removal slated two CHANGELOG
entries after the rename.

Also scaffolds the workspace-trust gate (src/hooks/trust_gate.py): when
workspace_trusted is False, _run_hooks_for_event strips non-policy hooks before
execution, so untrusted-workspace settings.json cannot inject hooks. Trusted
workspaces and HookSource.POLICY entries pass through unchanged.

Tests:
- test_snapshot_freezing.py (8): includes the regression that wins the
  on-disk TOCTOU case (mutate settings.json after snapshot, executor still
  fires the snapshotted hook) and the conflict case (real hook in snapshot
  + bogus hook in options.hooks -> snapshot wins).
- test_trust_gate.py (7): full (trusted x policy) matrix plus the predicate
  fail-safe (missing workspace_trusted attr -> treated as untrusted).

15/15 new tests green; 88/88 hook tests green. Adds pytest-asyncio>=1.3.0
to deps (asyncio_mode = "auto" was already configured).

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
@agentforce314
agentforce314 merged commit 0a6f623 into main May 9, 2026
singlaamitesh pushed a commit to singlaamitesh/clawcodex that referenced this pull request Jul 7, 2026
feat(ch12): phase 0 — snapshot rewire + workspace-trust gate
peroxider pushed a commit to peroxider/clawcodex that referenced this pull request Jul 20, 2026
feat(orchestrator): F-118 task decomposition and F-124 issue clarifier MVP

Created-by: qq_49552963
Commit-by: wukong;yeyunyao
Merged-by: chadwweng
Description: ## 这次做了什么

### F-124:信息不够就先问,不再直接猜

- Issue 明确写了“细节未定 / 不要猜”时,先暂停派发并向作者追问。
- 只接受作者在追问之后的新回复;GitCode 评论按时间重新排序,避免把新回复当旧评论跳过。
- 机器人评论带隐藏 marker,即使机器人账号和 issue 作者是同一个,也不会把自己的追问当成作者回答。
- POST 没返回 comment ID 时不再靠相同正文猜游标;拿不到可靠游标就保持阻塞。
- GitCode token 改走 `Authorization: Bearer`,不再出现在 URL 和访问日志里。

### F-118:真的拆任务、派 worker,并检查证据

- complex issue 会生成 task graph 和 wave;`mode:swarm` 会启动 coordinator。
- headless 现在不仅过滤工具,还会注入 coordinator 角色提示和 worker 能力上下文,因此模型会调用 `Agent`,不会反复撞不存在的 `Bash/Write`。
- 每个 task 由 write-capable worker 写独立的 `.orchestrator_control/task_evidence/task-N.json`,并行任务不会争写同一个文件。
- validator 检查状态、非空证据和依赖顺序;执行顺序使用 h144 文件系统记录的 evidence mtime,不信任模型自报的时间。
- swarm 未闭环时不会被 workspace-idle 早停抢先判完成。

### 长工具调用不会再被误杀

- 内层 turn timeout 看到 `tool_use` 尚未对应 `tool_result` 时暂停。
- 外层 stream-stall watchdog 复用同一份 pending-tool 状态,不再把 worker 正在运行误判成 provider 卡死。
- 普通模型静默、单工具超时和总运行预算仍然保留。

## click 仓实测

### F-124:先追问,再继续实现

- Issue:[click agentforce314#30](https://gitcode.com/qq_49552963/click/issues/30)
- 实际 PR:[click !24](https://gitcode.com/qq_49552963/click/merge_requests/24)
- 页面上能看到来源 issue、实际分支、commit 和 `Verification: passed`。

![F-124 click 实测](https://raw.gitcode.com/qq_49552963/clawcodex_7420/raw/1f9363ce757b1a57afe08bb0d464dfacde4798ac/docs/assets/orchestrator-demo/f124-issue-clarification.png)

### F-118:四步 swarm 从 issue 跑到 PR

- Issue:[click agentforce314#36](https://gitcode.com/qq_49552963/click/issues/36)
- 实际 PR:[click !31](https://gitcode.com/qq_49552963/click/merge_requests/31)
- 实际生成 4 个 task / 4 个 wave、4 份 task evidence;最终 `tests/test_testing.py` 为 `44 passed, 1 skipped`。
- 为了主动压测误杀问题,h144 上把 turn timeout 临时降到 30 秒;运行中多次记录 timeout deferred,worker 继续工作,最后 session complete、validator 通过并创建 PR。

![F-118 click 实测](https://raw.gitcode.com/qq_49552963/clawcodex_7420/raw/1f9363ce757b1a57afe08bb0d464dfacde4798ac/docs/assets/orchestrator-demo/f118-task-decomposition.png)

## h144 验证

- 环境:openEuler Linux / aarch64,Python 3.11;没有使用 Windows pytest。
- 最终相关回归:`251 passed in 65.64s`。
- click agentforce314#36 实际任务:`44 passed, 1 skipped`,session complete,创建 click PR !31。
- 更大范围回归:`1649 passed, 2 skipped, 18 subtests passed`;另有 3 个与本 MR 无关的既有环境/隔离失败(Linux 登录名假设、临时 session 路径补丁、无测试仓库 regression-guard 期望)。
- Python 编译、`git diff --check`、GitCode push hooks 通过。h144 环境未安装 Ruff,因此不把 Ruff 写成已通过。

## 仍然保留的边界

- task 的状态和测试说明仍由 worker 写入;orchestrator 用独立文件、host mtime 和 fail-closed validator 复核,不把模型一句“完成了”当结果。
- 总运行预算和 per-tool timeout 仍会终止真正卡死的任务;本次只暂停会误伤健康 in-flight 工具的 stall/turn timeout。


See merge request: chadwweng/clawcodex!86
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.

2 participants