Skip to content

[bugfix] agent: distinguish wait mode and zero-duration queries in waitOutcome and tool counts (#449) - #701

Open
Redivesue wants to merge 3 commits into
ThinkFlowLab:mainfrom
Redivesue:fix/449-wait-outcome-modes
Open

Redivesue wants to merge 3 commits into
ThinkFlowLab:mainfrom
Redivesue:fix/449-wait-outcome-modes

Conversation

@Redivesue

@Redivesue Redivesue commented Dec 5, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Follow-up fix to #681 addressing the waitOutcome and execution-record count edge cases raised in review (#681#pullrequestreview-6192347681):

  1. Record requested wait mode, duration, and satisfaction from the validated Query (tools.py, gateway.py, cli_transport.py)

    • Extracts shared parse_query() in tools.py so ToolGateway.execute() validates query calls once via TypeAdapter(Query) and derives ToolResult.wait_outcome from the exact validated JobStatusQuery / CanvasStatusQuery instance (wait_outcome_for_query()), forwarding the normalized query dict to AgentTools.execute() and carrying ToolResult.wait_outcome into cli_transport.py. Standalone wait_outcome() also validates via JobStatusQuery / CanvasStatusQuery so coerced numeric strings (e.g., waitSeconds: "1" -> 1.0) match business execution identically.
    • waitOutcome records waitSeconds, until ("all" | "any" for job.status), and satisfied alongside settled and statuses/status.
    • satisfied matches CreationCanvas.wait_jobs() / wait_item_status() semantics:
      • waitSeconds <= 0 (immediate status query): satisfied = True (never treated as an expired wait window).
      • until == "any" with at least one terminal job (succeeded/failed/cancelled/interrupted): satisfied = True even when other jobs are still running (settled = False).
      • until == "all" with waitSeconds > 0 and unfinished jobs: satisfied = False, settled = False.
    • Existing settled semantics stay unchanged for backward compatibility with saved records and scripts/trace_job_queries.py.
  2. Count completed calls by tool return status and separate expired waits from still-running observations (assistantActivity.ts, AssistantReply.tsx, chat.ts, i18n, docs/architecture/agent-runtime.md)

    • toolCounts() counts every status === "complete" call in {done}/{total} complete / {done}/{total} 已完成 rather than subtracting successful until="any", waitSeconds=0, or timed-out until="all" calls.
    • Completed calls with waitOutcome.settled === false are split into two mutually exclusive display states:
      • unsettled (satisfied === false, expired wait window): row badge Not finished / 未结束 (is-unsettled), summary {count} wait not finished / {count} waits not finished ({count} 次等待未结束).
      • jobsRunning (satisfied === true, e.g., until="any" satisfied or waitSeconds=0 status query while jobs are still running): row badge Jobs running / 仍有任务运行 (is-jobs-running), summary {count} with jobs still running ({count} 次返回时仍有任务运行).
    • Legacy #681 records without satisfied infer jobsRunning when arguments.waitSeconds === 0 or arguments.until === "any" with a terminal status present, and older records without waitOutcome remain Complete / 已完成.
  3. Add all requested regressions

    • until="any" satisfied (1 succeeded + 1 running), until="all" wait window expired, waitSeconds=0 zero-duration query, and numeric-string vs numeric waitSeconds ("1" vs 1, "0.05" vs 0.05, "0" vs 0) across unit & POSIX transport tests (tests/test_wait_outcome.py), end-to-end cli_transport -> ToolGateway -> agent.py save -> fresh create_app reopen persistence tests (tests/test_assistant_conversations.py), frontend state tests (tests/assistantActivity.test.ts), and bilingual Playwright browser test (tests/browser/assistant_wait_outcome.mjs).

Linked issue

Refs #449.

  • Fixes #N or Refs #N is included, or no issue applies

Labels

Proposed: type:bug, area:agent, area:canvas, area:i18n, area:docs (fork PR without label write permission).

  • Labels applied

Test plan

  • Local (on exact tip 0d4ab243decdd43a97943a103210920d45f7c115 over base 322f98c317322c1ac12541093719c890507b51b0; only 3 lines in cli_transport.py changed since d3490c73 to read outcome.wait_outcome via getattr for stub outcomes in test_agent_timing.py):
    • pytest tests/test_agent_timing.py tests/test_wait_outcome.py tests/test_agent_gateway.py tests/test_assistant_conversations.py: 86 passed, 0 failed (including test_agent_timing.py 10/10 and test_cli_transport_wait_outcome_persists_identically_for_numeric_string_and_number_across_reopen).
    • Hosted CI on prior tip d3490c73 (identical frontend, desktop, core/media python, and browser tests): Windows desktop, macOS desktop, frontend, all 3 browser lanes (including tests/browser/assistant_wait_outcome.mjs), Python (core and media), static, CodeQL (Python & JS), and DSH plugin checks all passed; only checks / python (agent-cli) failed on test_agent_timing.py (fixed in 0d4ab243).
  • Left to CI: hosted Release checks workflow, CodeQL, and DSH plugin checks on exact tip 0d4ab243decdd43a97943a103210920d45f7c115.
  • Independent pre-review: 93/100, 0 blocking findings. Reviewed base 322f98c317322c1ac12541093719c890507b51b0, head 0d4ab243decdd43a97943a103210920d45f7c115. Material validation gaps: hosted Release checks / CodeQL / DSH have not yet run on 0d4ab243, in-app bilingual screenshots/MP4 were captured on the identical frontend tree at 4b48bf23 (zero frontend changes between 4b48bf23 and 0d4ab243), and no live external model provider calls were made.

Evidence that it works

In-app OpenDirector walkthrough video & bilingual screenshots (4b48bf23)

Captured directly in the running OpenDirector application (create_app isolated backend + Vite frontend, project Wait Mode Semantics Demo) with a persisted 5-call turn written through agent.py:

  1. until="all", waitSeconds=60, 2 running -> Not finished / 未结束 (is-unsettled)
  2. until="any", waitSeconds=60, 1 succeeded + 1 running -> Jobs running / 仍有任务运行 (is-jobs-running)
  3. waitSeconds=0, 1 running -> Jobs running / 仍有任务运行 (is-jobs-running)
  4. until="all", waitSeconds=60, 2 succeeded -> Complete / 已完成 (is-complete)
  5. Legacy project show (no waitOutcome) -> Complete / 已完成 (is-complete)

Before this fix, the same 5-call turn displayed as 2/5 complete · 3 returned before jobs finished / 2/5 已完成 · 3 次返回时任务未结束, with rows 2 (until="any" satisfied) and 3 (waitSeconds=0 query) both marked Not finished / 未结束. With this fix, all 5 calls count as completed tool calls (5/5 complete / 5/5 已完成), with summary 5/5 complete · 1 wait not finished · 2 with jobs still running / 5/5 已完成 · 1 次等待未结束 · 2 次返回时仍有任务运行.

Locale In-app OpenDirector screenshot (Wait Mode Semantics Demo, right-hand AI Assistant expanded)
en-US en-US wait mode semantics
zh-CN zh-CN wait mode semantics
  • Applicable evidence attached and any visual N/A explained

Provider verification

No real-provider calls were made. All tests exercise local ToolGateway, POSIX CLI transport, in-process ASGI conversation persistence, and frontend state/rendering fixtures.

  • Real-provider calls are described honestly, or none were made

Bilingual UI

Both zh-CN and en-US entries are updated together (assistant.reply.status.jobsRunning, assistant.reply.jobsRunningCount, and pluralized assistant.reply.unsettledCount), tests/browser/assistant_wait_outcome.mjs and the live in-app walkthrough verify zero cross-language leakage, and npm run check:i18n passes with 0 problems.

  • Both locales are updated, or no user-facing copy changed

Quick local verification case for reviewers

On this PR branch (gh pr checkout 701):

# 1. Verify all 3 regressions (any-satisfied, all-expired, zero-duration) in backend & SSE persistence
pytest tests/test_wait_outcome.py tests/test_assistant_conversations.py -k "wait_outcome or transport_records" -vv

# 2. Verify frontend counts, display states, i18n, and architecture boundaries
node --test tests/assistantActivity.test.ts
npm run check:i18n
npm run check:browser-manifest
npm run check:browser-locale
python scripts/generate_contracts.py --check
lint-imports

# 3. With Vite running (`npx vite --host 127.0.0.1 --port 5179`) and playwright-core installed:
CREATION_WEB_URL=http://127.0.0.1:5179 node tests/browser/assistant_wait_outcome.mjs

Expected highlights:

  • until="any" (1 succeeded + 1 running, waitSeconds=60) and waitSeconds=0 (1 running) both report satisfied: true, settled: false, count in 5/5 complete / 5/5 已完成, and render as Jobs running / 仍有任务运行 rather than Not finished / 未结束.
  • until="all" (waitSeconds=60, 2 running) reports satisfied: false, settled: false, counts in 5/5 complete / 5/5 已完成, and renders as Not finished / 未结束 with summary 1 wait not finished / 1 次等待未结束.

@david6666666 david6666666 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.

COMMENT 92c468f Refs #449

75/100,建议修改后复审(非表决)(范围 3、正确性 2、验证 2、主张证据 2、简洁度 3)。区分工具已返回、等待条件已满足、还有 job 在跑,这个方向对。但现在业务层按校验后的时长执行,记录层却重新读原始参数。CLI transport 收到数字字符串时,业务模型会把它转成正数,记录层却按 0 秒写成 satisfied=true。因此等待到期仍可能显示成普通的“仍有任务运行”。建议复用已校验的查询参数,加一条 transport → 保存 → 重开回归。

下载并解码了 17 秒录像和两张中英文图,三个 blob 都与证据提交一致,能看见五条记录的分类。实录是作者标注的较早版本,不把它当成本 SHA 独立跑通。当前 Release 的 Python、浏览器、macOS、CodeQL 和 DSH 均绿;Windows 桌面任务 在 runtime 准备阶段报 spawnSync uv ENOENT,不是本次等待断言失败,也不是绿灯。

Dot,代表 @david6666666。

return None
kind = arguments.get('type')
raw_wait = arguments.get('waitSeconds', 0)
wait_seconds = raw_wait if isinstance(raw_wait, (int, float)) and not isinstance(raw_wait, bool) and raw_wait >= 0 else 0

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.

这里用的是 transport 原始参数,不是 Query 校验后的值。waitSeconds: "1" 会被业务层转成 1 秒,但这里落到 0 秒;全未终态时,本来未满足的等待会被记成 satisfied=true。请让记录使用同一份校验结果,并补数字字符串与数字的落盘/重开对照。

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Addressed in d3490c73: extracted shared parse_query() in tools.py, validated query calls once in ToolGateway.execute(), derived ToolResult.wait_outcome directly from that validated JobStatusQuery/CanvasStatusQuery instance (and forwarded the normalized query dict to AgentTools.execute()), and updated cli_transport.py to consume outcome.wait_outcome directly (with standalone wait_outcome() also validating via JobStatusQuery/CanvasStatusQuery). Added numeric-string vs numeric assertions in tests/test_wait_outcome.py and a full cli_transport -> ToolGateway -> agent.py save -> fresh create_app reopen comparison test (test_cli_transport_wait_outcome_persists_identically_for_numeric_string_and_number_across_reopen).

@david6666666 david6666666 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.

PASS 0d4ab24 Refs #449

90/100,非表决(范围 3、正确性 3、验证 3、主张证据 2、简洁度 3)。上一轮行内问题已解决:waitOutcome 取校验后的 Query,而不是 transport 的原始时长;老的 transport fallback 也按同一模型解析。新增回归让 "1" 和 1 走 CLI → 保存 → fresh app 重开,得到相同的等待时长和未满足状态。

同 SHA Release 已全绿,Windows 也通过;CodeQL / DSH 通过。我核对了增量和测试断言,没有自行启动 OpenDirector。此前下载的双语录像仍是较早版本,只作界面分类的佐证;新边界由当前回归覆盖。

Dot,代表 @david6666666。Coordinator: 由仓库授权角色核对合入。

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

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants