watch_task returns a snapshot instead of waiting for terminal task state
1. Problem
watch_task is exposed to the Optio assistant as a long-running watch tool, but the executor currently performs a single request to the task detail endpoint and returns that response immediately.
Source anchors:
packages/shared/src/optio-tools.ts:455defines thewatch_tasktool.packages/shared/src/optio-tools.ts:457-460describes it as watching until a terminal state, polling at a configurable interval, and returning the final state.packages/shared/src/optio-tools.ts:471-483exposespollIntervalSecondsandtimeoutMinutesinputs.packages/shared/src/optio-tools.ts:462-463maps the tool toGET /api/tasks/:id.apps/api/src/services/optio-tool-executor.ts:37-64converts path params and appends remaining GET params as a query string.apps/api/src/services/optio-tool-executor.ts:79-84callsapp.inject(...)once and returnsresponse.body.apps/api/src/routes/tasks.ts:326-337definesGET /api/tasks/:idas a single task detail fetch with enrichment, not a polling endpoint.apps/api/src/ws/optio-chat.ts:519-527executes read tools immediately throughexecuteToolCall(...).
Minimal reproduction path:
-
Have a task that is still
queued,pending,waiting_on_deps, orrunning. -
Ask the assistant to watch it, or invoke:
{ "name": "watch_task", "input": { "id": "<task-id>", "pollIntervalSeconds": 5, "timeoutMinutes": 10 } } -
The executor sends one request equivalent to:
GET /api/tasks/<task-id>?pollIntervalSeconds=5&timeoutMinutes=10 -
GET /api/tasks/:idreturns the current enriched task snapshot. There is no server-side polling loop and the tool executor does not poll client-side.
Actual behavior:
watch_taskreturns immediately with the current task snapshot.pollIntervalSecondsandtimeoutMinutesare serialized as query params but are not consumed by the route.- A request that asks Optio to "watch until completion" cannot be reliably fulfilled by this tool contract.
Expected behavior:
- Either
watch_taskshould pollGET /api/tasks/:iduntil the task reaches a terminal state or the timeout expires, or the tool should be renamed/described as a one-shot task detail read. - If the task is already terminal, it can return immediately.
- If the timeout expires, the assistant should receive a clear timeout result that includes the latest observed state.
User impact:
This is not only a wording mismatch. The machine-readable assistant tool contract promises a long-running watch operation with interval and timeout controls, but the runtime behavior is a single snapshot read. Users asking the assistant to wait for a task to finish can get an immediate non-terminal snapshot instead of an actual watch result, and the exposed interval/timeout options are misleading because they have no effect.
2. Existing issue / PR coverage
I checked current open and closed GitHub issues and PRs with these searches:
watch_task pollIntervalSeconds timeoutMinuteswatch_task optio-tool-executorwatch task terminal state
Relevant historical result:
- PR #205,
feat: Optio tool definitions, system-status endpoint, and auth passthrough, touchedpackages/shared/src/optio-tools.ts, but it does not cover the current root cause. The latest source still defineswatch_taskas a polling/final-state tool while the executor performs one request.
Coverage assessment: not covered.
3. Should this be fixed?
Yes. This is a focused contract-drift bug between the tool schema, the generic executor, the task route, and the assistant feedback path. The behavior is deterministic and has a small fix surface.
4. Proposed fix / PR draft
Suggested implementation direction:
- Add dedicated handling for
watch_taskin the tool executor, or route it through a purpose-built watch helper instead of the generic one-shot REST adapter. - Poll
GET /api/tasks/:iduntil the task reaches a terminal state such ascompleted,failed, orcancelled. - Respect
pollIntervalSecondsandtimeoutMinutes, including bounds already documented in the tool input schema. - Return the final task detail when a terminal state is reached.
- Return a clear timeout result with the latest task detail if the timeout expires.
- Add tests for:
- a running task does not return as a successful final watch result immediately;
- an already terminal task returns immediately;
- timeout returns a timeout-shaped result and includes the latest observed state;
- interval and timeout inputs are not silently ignored.
Non-goals:
- This does not require changing the normal
GET /api/tasks/:iddetail endpoint. - This does not require changing unrelated task state semantics.