Skip to content

Service assistant tests drive the scripted driver as Pi works a turn instead of Native - #1303

Merged
zhaozhaozz merged 4 commits into
agent-CI-Infra:mainfrom
zhaozhaozz:feat/issue-1256-service-scripted
Nov 24, 2026
Merged

zhaozhaozz merged 4 commits into
agent-CI-Infra:mainfrom
zhaozhaozz:feat/issue-1256-service-scripted

Conversation

@zhaozhaozz

@zhaozhaozz zhaozhaozz commented Nov 24, 2026 •

Copy link
Copy Markdown
Collaborator

Fixes #1256

Third and last of three PRs for #1256; #1289 and #1291 are merged. The service-assistant tests (management assistant, bound groups) no longer run the control-plane Native loop: they drive the test-only scripted driver, which now works a service turn the way Pi does in production. After this PR, Native runs in tests only where a case checks what only Native does; #1257 removes those with Native.

Maintainers' decisions on the Issue: 1 (choose the Pi service-turn protocol by a declared driver capability) and 2 (accept Pi's handling of refused tool calls).

What changes

Steering by declared capability (src/roles/harness.ts, src/harness/service-session.ts, src/management/agent.ts, src/channels/service-session.ts):

  • Before: serviceHarnessTurn gave its steering (messages merged during the turn, streamed text, a restart after an edit, stay_silent as the ending) only to the driver whose id is pi. Every other driver got a finish tool and none of it. The management assistant's empty-answer check and the group assistant's choice of path also compared the id with pi.
  • Now a driver declares steered_turns: true in its registration and the three places read that (steersServiceTurns). Pi declares it, so production behaves as before. The scripted test driver declares it too.

Own tasks on a harness get their context once (src/service-roles/own-tasks.ts): an own task's context is already a JSON string, and on a harness (Pi, Codex, Claude Code) it went through JSON.stringify again, so the session got an escaped string instead of the object. The migrated test personal-management "works a side question in its own task" found it (it reads instruction from the prompt).

Group binding PUT (src/channels/service-bindings.ts): as for a service role's PATCH, a request that omits harness keeps the saved backend without checking it against the console's list; a backend the request names must still be one the console offers. A test saves a binding through the API and then switches it to scripted in the store, and later re-saves must still pass.

The scripted driver's service turn (test/fixtures/scripted-driver.mjs): a spec from serviceHarnessTurn (the only one with the assistant environment profile) runs a loop of its own, modelled on runner/pi-entry.mjs and src/agent/pi.ts:

Fixtures: management-fixture, channel-fixture (boundGroup) and onboarding-fixture (assistantModel) put the management assistant and bound groups on scripted. Their turns, and those of identity-fixture, borrow an empty session workspace from the assistant computers the fixtures lack. scriptedGroup switches a saved binding. The fixture model's default answer reports an error observation instead of claiming success, since refusals now reach it. native-roles.mjs keeps only nativeServiceAssistants, for the Native-only cases below.

Changed assertions

Only assertions that described Native's behavior change, to what Pi does in production:

  • Refused tool calls (decision 2): a 403 or business-state 409 comes back to the management assistant as an observation and the turn completes; 401 and internal failures still end it. The refused call still does nothing, and each case still checks that. Cases: management-tool-recovery (2), personal-management (read-only and out-of-scope), channels (3), feishu-collaborators (Read collaborator), repository-onboarding-requests (decided meanwhile). managementOutcome gains refused, the last refused call's code.
  • A refused stay_silent is invalid_submission with code reply_required (channel-silent-turns).
  • An own task on a harness is also offered finish (personal-management).
  • A harness turn takes its owner's computer as it starts (助手电脑预热:Pi 服务助手的每一轮不再等冷启动 #1254), so the checks that memory tools and a read-only operator start no container now check that no command ran on it (channel-assistant-computer, service-roles); service-roles waits for both computers to go idle.
  • Group turns record no model_done (assistant-model-retry).
  • channel-service-bindings, channel-conversation and two e2e specs (channel-console, channel-conversation) saved bindings as native for the fixture model; they use scriptedGroup now.

Left on Native until #1257

Cases that check what only the native loop does, pinned with nativeServiceAssistants or a binding saved as native:

Not in this PR, per #1291's rule that tests configuring native explicitly for project roles stay until #1257: channel-task-engine runs a group employee's project role and QA on Native (harness_ref: native). #1257 should move it to the scripted driver rather than delete it, since it covers shared task execution.

Tests

On head 0550ae05 (base main @ 45e5c7df):

  • npm run check: exit 0.
  • The 51 test files that use the management, channel or onboarding fixtures: 508/508.
  • The full suite ran before the last rebase; 45e5c7df only moves task failure guidance into src/agent/failure-actions.ts and shares no file with this PR.

Earlier heads with the same changes:

  • npm test on b36b7d22 (the same head before two test fixes, see below): 2648 of 2657 passed at load average 12–17. Failed sets:
  • On d4eb21f1 (both fixes in): the same 51 files 508/508; service-roles 3 runs at once: pass.
  • e2e on d4eb21f1, 4 workers: the 38 specs that use those fixtures: 179/181. The two failures were channel-console "real messages, steps and binding counts" at both widths: it listed the Native-only "模型已返回" step. After dropping it (2a41d785), that spec 15/15.

Test time (Issue requirement 4):

  • Local npm test, same host, one after the other:
    • main 900ae1f5: 573 s wall, summed set time 6873 s, load average 6.4 at the start;
    • this PR b36b7d22: 700 s wall, summed set time 7464 s, load average 11.8 at the start and up to 17.
    • The host load was not the same: the 255 sets this PR does not touch took 6.1 % longer in the second run, the 51 migrated sets 19.6 % longer.
    • The 51 migrated files alone, back to back at load average 9–15: main 951 s summed (72 s wall), this PR 913 s (69 s wall). The scripted driver's service turn is not slower than Native; the four cases that now run on both drivers add a few seconds.
  • CI unit shards (job time of the slower shard per run): the last five merge-group runs before this PR took 356–511 s, median 459 s (89a5c564: 311 s / 356 s). This PR (0550ae05): 413 s / 521 s. That runner was slower across the board: per the shard artifacts, against 89a5c564's merge group the 255 sets this PR does not touch took 42.3 % longer and the 51 migrated sets 40.7 % longer, so relative to the rest the migrated sets did not slow down. test-set-weights.json is unchanged.

…er capability, not Pi's id

serviceHarnessTurn gave its steering (messages merged during the turn,
streamed text, a restart after an edit, stay_silent as the ending) only to
the driver whose id is `pi`. A driver now declares it with
`steered_turns: true` in its registration; Pi does, so production behaves
as before. The management assistant's empty-answer check and the group
assistant's choice between the steered path and the plain harness turn use
the same declaration (`steersServiceTurns`).

This lets the test-only scripted driver work a service turn as Pi does, so
in-process tests of the assistants check the production semantics.

The design doc also states what a harness turn does with a refused tool
call: 400/403/404/409/413/415 come back to the model and the turn goes on;
401 and internal failures end it.
…s JSON once

The own task's context is already a JSON string. On a harness (Pi, Codex,
Claude Code) it was passed through JSON.stringify again, so the session
received an escaped string instead of the object the native loop sends.
…n the request names one

As for a service role's PATCH, a binding PUT that omits `harness` keeps the
saved backend without checking it against the console's list; a backend
the request names must still be one the console offers.
… driver as Pi works a turn

The management assistant and bound groups in the management, channel and
onboarding fixtures run the test-only scripted driver instead of Native.
It declares `steered_turns` and works a service turn in process as Pi
does: tools through the harness tool dispatcher, messages taken before the
first request and after each tool batch, a streamed answer, a model step
reported as it starts, a restart after an edit, stay_silent as the ending.
Its turns borrow an empty session workspace from the assistant computers
the fixtures lack. A binding is saved through the API, which offers only
the production backends, and then switched in the store (`scriptedGroup`).

Changed assertions follow what Pi does in production:
- refusals (403, business-state 409) come back to the model and the turn
  completes; the refused call still does nothing (maintainers' decision on
  agent-CI-Infra#1256). The fixture model reports an error observation instead of
  claiming success;
- a refused stay_silent is `invalid_submission` with code `reply_required`;
- an own task on a harness is also offered `finish`;
- a harness turn takes its owner's computer as it starts (agent-CI-Infra#1254), so the
  checks that memory tools and a read-only operator start no container now
  check that no command ran on it;
- group turns record no `model_done`.

Cases that check what only the native loop does stay on Native and go
with it in agent-CI-Infra#1257: its image recovery and request fitting (3 in
channel-media), admission closing at a stream's finish marker
(channel-turn-messages), and the Native halves of the agent-CI-Infra#333 batch budget and
agent-CI-Infra#533 refusal cases, which now also run on the scripted driver.
@zhaozhaozz

Copy link
Copy Markdown
Collaborator Author

CI: the first e2e attempt failed on a known flaky spec; the rerun passed

  • Attempt 1 of e2e on 0550ae05: 564 passed, 1 failed. The failure was management/management-reading.spec.mjs:11, "drafting a follow-up pauses automatic scrolling and only new output shows the latest action". At 390 px, after it clicks "↓ 回到最新消息", 最后一条新进展 stayed at viewport ratio 0.
  • This is not caused by this PR. The same assertion (:11:201) failed on Role and task tests drive their fake model through a test-only scripted driver instead of Native #1291's branch run 45212253518, where the management assistant still ran on Native. The sibling test's assertion (:15:279, also toBeInViewport after returning to the latest message) failed on two unrelated PRs' runs: 45151989057 and 45042010451.
  • Locally on 0550ae05, the spec with --repeat-each=6: 12/12.
  • Attempt 2 of e2e (same head): success. All required checks are now green.

The CI unit shard times are now in the description (Test time): that runner was about 42 % slower across all sets, and the migrated sets were no slower than the rest.

@agent-ci-infra-bot

Copy link
Copy Markdown
Contributor

检视结论:1 项必须修复(头部提交的 e2e 必要检查为红)

版本:0550ae05(base 45e5c7df),35 个文件(src/ 7、docs/ 2、fixtures 7、e2e 3,其余 ST)。意图与 PR 说明一致:#1256 的第三个 PR,把服务助手(管理助手、绑定群)的进程内/浏览器测试从控制面 Native 循环切到测试专用 scripted 驱动,并让“是否按 Native 语义跑服务回合”由驱动声明的能力决定,而不是硬编码 pi。

已核对、与意图一致的部分

  • 能力声明代替 id==='pi':src/roles/harness.ts:123 给 Pi 声明 steered_turns:true,src/roles/harness.ts:125 提供 steersServiceTurns(未注册的 id 返回 false);src/harness/service-session.ts:58 只在声明了能力且调用方给了 control 时启用 steering,:86-88 仅在非 steering 时追加 finish 并从工具表里剔除重名项,stay_silent 走 finish.validate,没有工具时按文本收尾——语义与文档一致,生产行为未变(生产中只有 Pi 声明该能力)。
  • 两处服务回合分派:src/channels/service-session.ts:439(非 steering 后端仍走原来的 harnessTurn({}))与 :506(steering 后端复用 Native 循环的上下文、stay_silent、reply 校验和进度预算),src/management/agent.ts:451 的非空校验也改为按能力判断,避免把测试驱动漏在校验外。
  • 绑定保存语义:src/channels/service-bindings.ts:523-525 现在只在请求显式给了 harness 时校验,省略即保留已保存值——与 service role 的 PATCH 语义一致,也修掉了“省略就被判 unknown_role_harness”。scripted 仍不在该 API 的白名单里(src/channels/service-bindings.ts:24),测试通过 test/fixtures/scripted-roles.mjs:24-26 直接改 store 注入,驱动以 listed:false 注册(test/fixtures/scripted-driver.mjs:16),后端列表不会出现它,这个绕过是有意且已注释的。
  • 自有任务上下文:src/service-roles/own-tasks.ts:119 不再把已是 JSON 的上下文二次 JSON.stringify,修正正确。
  • 夹具:test/fixtures/management-fixture.mjs:26-27 切到 scripted 服务助手并借出空会话工作区;test/fixtures/scripted-roles.mjs:26-37 的假工作区 release 为 no-op、call 抛错,只用于不触碰工作区的 scripted 回合,onboarding 侧经 assistantModel(test/fixtures/onboarding-fixture.mjs:91)同样切换,与 docs/design/testing-architecture.md 的描述对得上。
  • 保留的 Native 用例(channel-media 的图片恢复/请求裁剪、channel-turn-messages 的收流时准入、[缺陷] 移除单轮 tool_calls 硬编码数量上限,靠上下文压缩支持跨多项目并发工具调用 #333 的 Native 半边、[治理] 清理 #521 同类过度防御的权限围栏、静默吞错与保守永久锁死(会话/记忆清空、预算 unknown 锁仓、配置死锁) #533 拒绝语义)与 test/fixtures/native-roles.mjs 新注释、PR 说明中的“留给 删除 Native agent 后端 #1257”一致。

无法执行的部分

本工作区没有 node_modules/dist,也没有 Playwright 浏览器缓存,因此未本地复跑 UT/ST/E2E;取 e2e 结果 artifact 时 runner_operation_failed。下文 CI 事实取自 github_read 与 job 138146603940 的日志(read_job_log)。除 e2e 外,头部提交上 unit(20s)、CodeQL 与 Images 工作流为 success。

必须修复:头部提交 0550ae05 的 e2e 必要检查是红的(Checks run 45305014802,job 138146603940:564 passed / 1 failed)。失败点就在本 PR 改变的服务助手路径上:

1) test/e2e/management/management-reading.spec.mjs:11:201 › drafting a follow-up pauses automatic scrolling and only new output shows the latest action
   expect(feed.getByText('最后一条新进展', {exact:true})).toBeInViewport()
   Expected: in viewport / Received: viewport ratio 0   (5s 内 14 次轮询都是 0)

判断依据:

  • 该 spec 本身没改,但它跑的管理助手在本 PR 里换了后端:test/fixtures/management-fixture.mjs:27 现在调 scriptedServiceAssistants(h.store),并且 :26 用 withLentSessionWorkspaces 借空会话工作区。这条用例的模型、text 流与回合收尾都来自这条新路径。
  • base 45e5c7df 的 merge-queue Checks 是绿的,而这里 5 秒内 14 次轮询稳定为 ratio 0(不是一次性的时序抖动):390px 下点击「↓ 回到最新消息」后最后一段仍然完全不在视口。同一文件 :13 的用例在默认视口、同样的点击/回车后断言 toBeInViewport() 是通过的,只有 390px 这条失败。
  • 也就是说,切到 scripted 驱动后,回合结束(src/harness/service-session.ts:88 的 finish/onTurnEnd 组合、src/management/agent.ts 的 reply 写入)与流式文本投递的时序或 DOM 位置,与用例假设的 Native/Pi 行为不一致。本 PR 的目标恰恰是“测试里跑得和生产一样”,所以这要么是 scripted 驱动与 Pi 的可见行为差异需要补齐,要么是该用例需要随新的收尾方式更新。

期望:修复后推新提交让 e2e 转绿;如果判断与这次切换无关,请给出重跑全绿的证据(同一 head 或修好的 head)并在说明里点明原因。

Reviewed commit: 0550ae0
Coverage: PR #1303; 35 changed file(s)

@zhaozhaozz
zhaozhaozz added this pull request to the merge queue Nov 24, 2026
@zhaozhaozz

Copy link
Copy Markdown
Collaborator Author

Enqueued on the reviewed head 0550ae05 (base main @ 45e5c7df) at 2026-11-24T02:00:34Z. The queue entry is position 1 and is now AWAITING_CHECKS (queue head commit e52008a4).

Checks on this head: unit (aggregate and both shards), e2e, the four image builds and CodeQL are all successful, and there are no open code-scanning alerts for this PR.

On the earlier blocking review citing the first e2e attempt: that conclusion is superseded. Attempt 2 of the same required check on the same head passed (job 138154016875, 8m15s). I independently verified the failed assertion is a pre-existing mobile flake of management-reading.spec.mjs, not a regression from the fixture migration:

  • On Role and task tests drive their fake model through a test-only scripted driver instead of Native #1291's head c41acaff, where test/fixtures/management-fixture.mjs still used nativeServiceAssistants, the same assertion failed identically (run 45212253518, management-reading.spec.mjs:11:201, viewport ratio 0).
  • The sibling assertion at :15:279 failed the same way on two unrelated PRs (runs 45151989057 and 45042010451).
  • The spec itself is not changed by this PR; the author also reports --repeat-each=6 passing 12/12 locally.

No blocking code issue remains from my review: the declared steered_turns capability leaves production behavior unchanged (Pi is the only production driver that declares it), a group-binding PUT validates only a backend the request explicitly names, and the own-task context is encoded once. The migrations and the remaining Native-only cases match the documented split.

Non-blocking follow-ups (not required for this merge):

  • src/management/agent.ts records harness: 'pi' on the model_start event for every steering driver, including the test-only scripted driver. Harmless while only Pi steers in production, but the label is not accurate for the scripted turns.
  • The feishu-collaborators case matches the refusal with /forbidden|not_allowed/; the actual observation is capability_forbidden, so an exact assertion would be stronger.

Reviewed commit: 0550ae0
Coverage: PR #1303; 35 changed file(s)

Merged via the queue into agent-CI-Infra:main with commit e52008a Nov 24, 2026
15 of 16 checks passed
@zhaozhaozz
zhaozhaozz deleted the feat/issue-1256-service-scripted branch November 24, 2026 02:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

平台内部调用和测试不再依赖 Native 工具循环

1 participant