feat(task): give polling hooks a real query context, host HTTP classification, and bounded poll failures
Plugin polling hooks previously ran against a hollow context: parseTaskResult
and parseBatchResult received {} / nil, buildQueryRequest received a
{task_id, action} map under the misleading name requestBody, and batch hooks
saw only bare task ids. The per-task poller also never looked at the upstream
HTTP status, and every built-in plugin papered over unrecognized bodies with
`|| "IN_PROGRESS"`, so a 404, a revoked key, or a shape the plugin did not
know would sit in IN_PROGRESS for the full 24h TASK_TIMEOUT_MINUTES while
holding the user's pre-charged quota.
Contract (docs/plugin-api v1.d.ts, v1.md, v1.schema.json):
- TaskQueryContext is declared separately from DriverContext and rebuilt from
the persisted Task row: taskId, publicTaskId, action, model, upstreamModel,
baseUrl, apiKey, authHeader, auth, data, state. Query-side requestBody is
removed; the original request is not persisted and hooks that need a
request-derived value must save it into state at submit time.
- parseTaskResult / parseBatchResult receive a third {status, headers}
argument. Batch hooks receive tasks[] with one TaskQueryContext per task.
- NormalizedTaskResult accepts status "UNKNOWN" meaning "I do not recognize
this body". Falling back to IN_PROGRESS for unknown shapes is forbidden;
`plugin lint` warns on the literal.
- parseSubmitResponse / parseTaskResult / parseBatchResult may return `state`.
Task.Data remains a per-round snapshot overwritten on every valid parse;
state is plugin-owned, persisted in TaskPrivateData.PluginState, preserved
when a hook omits it, byte-capped like taskData, and never exposed through
presenter views.
Host (service/task_polling.go, relay/channel/task/jsplugin/adaptor.go):
- TaskPollingAdaptor / BatchTaskPollingAdaptor take *model.Task and the
*http.Response so the adaptor can build the full context; jsplugin is the
only implementation.
- HTTP classification before the plugin sees the body: 2xx -> plugin;
404/410 -> FAILURE and refund; 401/403 -> poll failure plus a channel-scoped
warning, no auto-disable; 429/5xx/transport -> poll failure; other 4xx ->
plugin with the status visible, counted as unrecognized if the plugin still
reports a non-terminal state.
- TaskPrivateData.PollFailures counts consecutive poll failures (transient
HTTP, auth, transport, hook error, UNKNOWN). It is persisted through the
existing UpdateWithStatus CAS so a concurrent terminal transition on another
instance is never clobbered, and reset on any valid 2xx non-terminal parse.
Reaching TASK_POLL_MAX_FAILURES (default 20, <= 0 disables) fails the task
with the last classification and HTTP code in fail_reason and runs the
existing settle/refund chain exactly once. sweepTimedOutTasks and its
1440-minute default are unchanged as the outer backstop.
- Unrecognized bodies are logged at WARN with a bounded redacted copy since
Task.Data is intentionally not overwritten on that path.
Plugins (all ten bumped one patch version):
- jimeng persists the outbound req_key in state and reads it back in
buildQueryRequest, replacing dead reads of ctx.data / ctx.requestBody that
never resolved.
- sunoapi batch hooks read tasks[] instead of the removed requestBody.
- hailuo treats base_resp.status_code != 0 as FAILURE before the status table.
- kling, vidu, sora, alibaba, doubao, hailuo, jimeng return UNKNOWN with the
raw upstream status in reason on table miss.
- google and vertex-ai treat a missing `done` as in-progress: Google
long-running operations omit proto3 default fields, so a running Veo
operation has no `done` key at all. Only a body without an operation name is
UNKNOWN. plugins/veo_poll_test.go locks this so the poll-failure cutoff can
never fail a rendering Veo task.
Tests cover the classification table end to end against a real DB (404
immediate refund, 429xN refund, 401 increments without status change, 2xx
reset, UNKNOWN increments, state preserved vs replaced, PollFailures survives
the CAS write), the query-context shape, UNKNOWN on unrecognized bodies, and
the absence of PluginState/PollFailures from TaskView. Controller tests derive
the kling factory version from the embedded manifest instead of hardcoding it.
| Name |
Last commit
|
Last Update |
|---|---|---|
| .. | ||
| authz | Loading commit data... | |
| passkey | Loading commit data... | |
| audio.go | Loading commit data... | |
| auth_cleanup.go | Loading commit data... | |
| auth_session.go | Loading commit data... | |
| auth_session_test.go | Loading commit data... | |
| auth_token.go | Loading commit data... | |
| auth_token_test.go | Loading commit data... | |
| billing.go | Loading commit data... | |
| billing_session.go | Loading commit data... | |
| billing_usage.go | Loading commit data... | |
| channel.go | Loading commit data... | |
| channel_affinity.go | Loading commit data... | |
| channel_affinity_template_test.go | Loading commit data... | |
| channel_affinity_usage_cache_test.go | Loading commit data... | |
| channel_select.go | Loading commit data... | |
| channel_select_auto_groups_test.go | Loading commit data... | |
| channel_select_test.go | Loading commit data... | |
| codex_channel_models.go | Loading commit data... | |
| codex_credential_refresh.go | Loading commit data... | |
| codex_credential_refresh_task.go | Loading commit data... | |
| codex_models.go | Loading commit data... | |
| codex_oauth.go | Loading commit data... | |
| codex_wham_usage.go | Loading commit data... | |
| convert.go | Loading commit data... | |
| convert_test.go | Loading commit data... | |
| download.go | Loading commit data... | |
| epay.go | Loading commit data... | |
| error.go | Loading commit data... | |
| error_test.go | Loading commit data... | |
| file_decoder.go | Loading commit data... | |
| file_service.go | Loading commit data... | |
| funding_source.go | Loading commit data... | |
| group.go | Loading commit data... | |
| group_auto_groups_test.go | Loading commit data... | |
| http.go | Loading commit data... | |
| http_client.go | Loading commit data... | |
| http_client_transport_test.go | Loading commit data... | |
| http_transport_policy.go | Loading commit data... | |
| http_transport_sharded.go | Loading commit data... | |
| image.go | Loading commit data... | |
| log_info_generate.go | Loading commit data... | |
| midjourney.go | Loading commit data... | |
| notify-limit.go | Loading commit data... | |
| openai_chat_responses_compat.go | Loading commit data... | |
| openai_chat_responses_mode.go | Loading commit data... | |
| protected_fetch_client.go | Loading commit data... | |
| protected_fetch_client_test.go | Loading commit data... | |
| quota.go | Loading commit data... | |
| quota_saturation_test.go | Loading commit data... | |
| rankings.go | Loading commit data... | |
| request_converter.go | Loading commit data... | |
| response_converter.go | Loading commit data... | |
| return_path.go | Loading commit data... | |
| return_path_test.go | Loading commit data... | |
| sensitive.go | Loading commit data... | |
| str.go | Loading commit data... | |
| subscription_reset_task.go | Loading commit data... | |
| system_instance.go | Loading commit data... | |
| system_task.go | Loading commit data... | |
| system_task_test.go | Loading commit data... | |
| task.go | Loading commit data... | |
| task_artifact_access.go | Loading commit data... | |
| task_artifact_access_test.go | Loading commit data... | |
| task_artifact_store.go | Loading commit data... | |
| task_artifact_store_test.go | Loading commit data... | |
| task_billing.go | Loading commit data... | |
| task_billing_test.go | Loading commit data... | |
| task_plugin_audit.go | Loading commit data... | |
| task_plugin_view.go | Loading commit data... | |
| task_plugin_view_test.go | Loading commit data... | |
| task_polling.go | Loading commit data... | |
| task_polling_test.go | Loading commit data... | |
| text_quota.go | Loading commit data... | |
| text_quota_test.go | Loading commit data... | |
| tiered_settle.go | Loading commit data... | |
| tiered_settle_test.go | Loading commit data... | |
| token_counter.go | Loading commit data... | |
| token_estimator.go | Loading commit data... | |
| tokenizer.go | Loading commit data... | |
| usage_helpr.go | Loading commit data... | |
| user_notify.go | Loading commit data... | |
| violation_fee.go | Loading commit data... | |
| waffo_pancake.go | Loading commit data... | |
| webhook.go | Loading commit data... |