Skip to content

[feat] canvas: notify Agent and canvas task outcomes (#535) - #584

Open
LynPtl wants to merge 6 commits into
ThinkFlowLab:mainfrom
LynPtl:feat/task-notifications
Open

LynPtl wants to merge 6 commits into
ThinkFlowLab:mainfrom
LynPtl:feat/task-notifications

Conversation

@LynPtl

@LynPtl LynPtl commented Nov 29, 2026 •

Copy link
Copy Markdown

Summary

Adds task notifications for user-started Agent turns and canvas generations. Refs #535.

  • A user-started Agent turn announces once when it completes, fails, or enters an authoritative waiting decision state.
  • Decision notifications consume the host-owned ask_user / opendirector ask-user interaction, not a question-mark heuristic.
  • A canvas generation the user started announces once when it completes or fails.
  • Jobs submitted by an Agent (agentRunId) do not notify on their own; the owning turn reports the result.
  • Cancelled/stopped turns and jobs do not notify.
  • Adds separate Task sound and Task popup settings, plus a 0–100% volume slider and preview button.
  • Announced task identities are persisted, so reloads and reconnects replaying the same event do not notify again.
  • Adds matching zh-CN and en-US catalogs.

The decision contract is:

  • pending interaction + awaiting_decision → decision
  • answered or cancelled interaction → no decision notification
  • completed reply ending in ?/? → completed
  • completed reply containing approval-like wording but no interaction → completed

Local checks:

  • npm test — 1040 passed.
  • npm run build — passed.
  • npm run check:i18n — 3484 keys, 0 problems.
  • pytest tests/test_agent_interactions.py tests/test_assistant_conversations.py tests/test_cli.py — 84 passed.
  • pytest tests/test_native_runtime.py -k 'ask_user or bundled_model_declares or rejects_removed_runtime' — 2 passed, 1 skipped (real OpenCode path environment-gated).
  • Browser E2E against isolated fixture services for the notification/settings surface was run previously; it predates the authoritative decision card. Browser and audio playback for the new decision card are not claimed as verified here.

Evidence that it works

Recordings (real UI; the chime is mixed at the actual trigger time). These cover the notification/settings surface and predate the authoritative decision card:

Scenario Recording
zh-CN: settings + generation completion + Agent completion zh-CN.mp4
en-US: settings + generation completion + Agent completion en-US.mp4
zh-CN: generation failure failure-zh-CN.mp4
en-US: generation failure failure-en-US.mp4

Decision interactions are covered by tests/taskNotifications.test.ts, tests/test_agent_interactions.py, the API lifecycle tests and the bundled harness gate test.

Provider verification

  • No real-provider requests were made for this PR.
  • Generation paths used the isolated fixture provider.
  • The failure path used a loopback HTTP service returning 500.
  • No claim is made that real providers, OS notification permissions or desktop packaging have been verified.

Bilingual UI

  • Both zh-CN and en-US catalogs are updated for settings, task notification copy and decision UI copy.

Implementation notes

  • Job.agentRunId is projected into the canvas job row to distinguish user-started generation from Agent-submitted work.
  • User canvas tasks are non-tool jobs without agentRunId.
  • Agent-submitted generation jobs are filtered out of canvas task notifications.
  • TaskNotificationLedger persists announced identities in localStorage, bounded to avoid growth.
  • Notification identity includes task ID, status and execution revision.
  • InteractionGate owns one turn's authoritative question. ask_user and the CLI bridge persist the interaction before publishing it; the message becomes awaiting_decision only while that interaction is pending.
  • The turn releases its Agent write lease while waiting and reacquires it after a valid answer. The pending event is published after the lease pause, and closing during that pause cancels the question.
  • An answer is validated against the interaction's options/free-text policy. The first valid answer claims the interaction before awaiting resume/persistence; a concurrent answer returns HTTP 409. A failed persist rolls the in-memory answer back so the user can retry.
  • answer and close share one gate lock. Closing while an answer is in flight waits for that settlement instead of racing a cancelled persist against an answered state.
  • A server restart marks an orphaned pending interaction cancelled and its message interrupted; no stale decision notification is inferred.
  • The chime is synthesized with Web Audio; no audio asset is added.
  • Volume maps 0–100% to 0–0.4 peak gain. The default 30% reproduces the previous 0.12 peak.
  • The toast reuses the existing canvas notification stack and adds an optional title, detail and action.

Scope decisions and limitations

  • In-app only. Native background/minimized notifications are not part of this PR because cross-platform permission, packaging and notification-identity testing would require platforms this contribution cannot verify.
  • Authoritative decision contract. A harness must expose ask_user or the opendirector ask-user CLI to produce a waiting decision. Harnesses without either path do not get an authoritative decision notification; a completed question is not treated as one.
  • Tool tasks are excluded. Per the task-notification scope, canvas tool tasks do not create task sounds/popups. Existing generic tool-failure feedback is unchanged.
  • Recordings include reconstructed audio. The visual UI is real; the audio track is rebuilt from actual chime trigger times. The new decision card was not re-recorded in a browser.
  • No OS-level notification claim. Browser permission prompts and desktop notification behavior are not part of this PR.

Follow-ups

  • Add native desktop notifications with click-through to the originating conversation or canvas node.
  • Add a browser/audio regression for the authoritative decision card.
  • Evaluate whether the browser background notification feature is necessary.

@LynPtl
LynPtl marked this pull request as ready for review November 29, 2026 12:53
@github-actions github-actions Bot added area:agent Agent runtime, assistant chat and tools area:canvas Canvas, nodes and direct manipulation area:i18n Localisation and bilingual UI type:feat New capability or behaviour labels Nov 29, 2026

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

REQUEST CHANGES 6818188 Refs #535

Dot, acting for @david6666666. Non-voting review.

The inline finding is about the decision notification contract, not the sound or popup controls.

Ran: inspected the pinned diff and the Release checks run; it requires maintainer action and is not green.
Not run: independent browser or audio playback. No total: reviewed head is behind current main.

Comment thread src/canvas/taskNotifications.ts Outdated
): TaskOutcome | null {
if (message.role !== "assistant") return null;
if (message.status === "complete")
return asksForDecision(message.text) ? "decision" : "completed";

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.

This treats a completed reply ending in a question as an actual wait for a decision. A completed reply can end with a follow-up offer, and a genuine approval request need not end with a question mark. #535 calls for the authoritative waiting state. Could the decision notification consume that state (or be deferred until it is available), with regression coverage for both cases?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Thanks for catching this. Updated the branch to consume the authoritative interaction state instead of inferring from the reply text.

  • ask_user / opendirector ask-user creates a host-owned interaction. The host persists it and sets the assistant message to awaiting_decision only while interaction.status === "pending".
  • agentTaskOutcome now returns decision only for:
    status === "awaiting_decision" && interaction.status === "pending".
  • A completed reply ending in ? — including a follow-up offer — remains completed.
  • Approval-like wording without an interaction remains completed; a genuine approval request must come through ask_user/the CLI bridge.
  • Answered or cancelled interactions do not trigger a decision notification.
  • Closing or restarting the turn cancels a pending interaction and marks the message interrupted.
  • The pending interaction event is published after the Agent lease pause; closing during that pause cancels it.
  • Removed the old asksForDecision question-mark heuristic.

Regression coverage:

  • tests/taskNotifications.test.ts: pending, answered, null, question-ending complete, and approval-like complete cases.
  • tests/test_agent_interactions.py: ask, option validation, close, pause/resume and close-during-pause.
  • tests/test_assistant_conversations.py and tests/test_cli.py: API lifecycle and CLI bridge.
  • tests/test_native_runtime.py: native gate coverage; the real OpenCode case is environment-gated and skipped locally.

Local checks:

  • npm test: 1040 passed
  • npm run build: passed
  • npm run check:i18n: 3484 keys, 0 problems
  • Python interaction/API/CLI tests: 82 passed
  • Native gate: 2 passed, 1 skipped

The branch is rebased onto current main in 6467e326. I did not re-record the new decision card in a browser/audio session, so I am not claiming that as verified.

Could you re-review the updated commit?

- Announce user-started Agent turns when they finish, fail, or ask a question.
- Announce canvas generations the user started; keep agent-submitted jobs with their turn.
- Add a short chime, project/task/status toast, and an action back to the conversation or node.
- Persist announced task identities so reloads and reconnects do not repeat a chime.
- Cover the decision rule, origin filtering, and reload dedupe with tests.
- Add zh-CN and en-US catalogs.

Fixes ThinkFlowLab#535
- Add separate task sound and popup switches.
- Add a persisted 0-100% volume slider with an in-settings preview.
- Keep the previous loudness at the 30% default.
- Gate task chimes and toasts independently.
- Cover preference parsing and volume bounds with unit tests.
- Add an ask_user tool and CLI command that wait for an explicit user answer.
- Persist pending interactions with the owning turn and expose answer endpoints.
- Release and reacquire the Agent write lease while waiting for the user.
- Mark unanswered interactions interrupted after a restart.
- Render an in-chat decision card and notify from the authoritative state.
- Add gate, CLI bridge, API lifecycle, notification and browser coverage.
- Verify the bundled OpenCode harness waits for ask-user with a mock model.
- Register the pending future before releasing the project lease.
- Publish the pending interaction only after the lease is released, so an answer cannot race the resume path.
- Cancel a question closed during pause without leaving the ask call stranded.
- Cover pause/event ordering and close-during-pause.
@LynPtl
LynPtl force-pushed the feat/task-notifications branch from 6818188 to 6467e32 Compare November 30, 2026 08:04

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

REQUEST CHANGES 6467e32 Refs #535

Dot,代表 @david6666666。

当前证据暂定 45/100(非批准分)。 范围 3/3,正确性 2/3,验证 2/3,主张证据 0/3,简洁性 0/3。

上次的问号误判已修:现在只在宿主确实有待答交互时通知。新入口还需要确保同一个问题只能结算一次,我把并发回答的疑问留在对应代码处。作者报告前后端定向测试通过,但 Release checks 仍需维护者操作,现有录像也早于新决策卡。补并发回归后,建议再录一次「收到提醒 → 打开决策卡 → 回答后续跑」。我没重跑测试。解释性代码注释按量表记零。

English summary: 45/100 provisional. The authoritative wait-state fix is in place. Serialize concurrent answers and attach current-tip decision workflow evidence.

if not text and not option_id:
raise ProjectError('请输入回答或选择选项。', 422)
if self.resume_after_user is not None:
await self.resume_after_user()

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.

这里检查 future.done() 之后,会先等租约、再等持久化。两个标签页如果几乎同时答同一个问题,可能都越过前面的检查,后一个回答覆盖前一个,或在 set_result() 时碰到已经结算的 future。能否在第一次 await 前先认领这一条回答,并让第二次稳定返回 409?建议用可暂停的租约或持久化回调写一个并发回归。

- Claim the interaction before resume or persistence so concurrent tabs cannot both settle it.
- Let the losing answer return False and the API map it to 409.
- Roll the in-memory answer back if persistence fails, allowing a retry.
- Add a concurrent-answer regression that pauses the resume callback.
- Guard answer and close with one gate lock so a question cannot settle twice.
- Keep the in-flight answer while close waits, rather than racing a cancelled persist against answered.
- Add close-during-answer regression coverage.

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

WITHHOLD 7970f06 Refs #535

Dot,代表 @david6666666。

当前证据暂定 53/100(非批准)。 范围、正确性、验证、证据、简洁性依次为 3/3、3/3、2/3、0/3、0/3。

之前提的双标签页同时回答已修:回答和关闭串行,新增用例确认只接收一次回答、只恢复一次。我没发现同一处还有需要再标的代码问题。Release checks 仍需维护者操作,新决策卡也还没录到真实流程。下一步补「收到通知、回答、任务续跑」的录像;我没有重跑浏览器。

English summary: 53/100. Concurrent-answer handling is covered by a targeted regression. Release checks and the decision-card recording are still outstanding.

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

area:agent Agent runtime, assistant chat and tools area:canvas Canvas, nodes and direct manipulation area:i18n Localisation and bilingual UI type:feat New capability or behaviour

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants