Repository navigation
feat(operator-queue): an operator answer can wake a parked agent (ent#329) - #2312
Conversation
…#329) An operator's response reaches the agent's queue file within ~5s, but it is only PROCESSED at the agent's next turn. An agent with a schedule has one; an agent started by a one-shot webhook or chat task does not, so an approved action silently never executes until somebody re-triggers it by hand. #1402 documented that and told agents to embed resume instructions in prose; this is the platform-side fix, and the prerequisite ent#364's Workspace asks are gated on (ent#430). Opt-in per AGENT, default OFF. A dispatch spends money, so it is never unconditional — a respond-storm must not fan out executions. It is not a per-request flag the agent sets, because that lets an agent decide that answering costs the answerer money, which is unacceptable once the answerer is an external Workspace client (ent#430 AC #3). One dispatch surface: everything goes through execute_task with triggered_by="operator_response", so capacity admission, the dispatch breaker, cost accounting and the terminal appliers are the platform's existing ones. The call hangs off the respond CAS *win* — the 409 for a lost race is raised first, so an answer that was never recorded can never spend (the #1083 rule). Idempotent over (item id, answer) per Invariant #18; a failed dispatch is a FAILED row plus an audit entry that carries ids and status but never the answer text. The new trigger is registered in all three places a trigger must exist: _VALID_TRIGGERS, _TRIGGER_BUCKETS (its own "Operator queue" bucket — unmapped triggers silently become "Other") and _AUTONOMOUS_TRIGGERS. #2048's tripwire correctly demanded it be classified for pull mode: it is STRANDED, dispatched by a direct backend call and never by POST /task, so _derive_task_trigger cannot emit it. Owner-only knob at GET/PUT /api/agents/{name}/operator-resume, surfaced as a toggle in ReliabilityPanel.vue. Verified on a real PostgreSQL: the full Alembic chain applies, the column lands with default 0, and re-running is a no-op. The revision is guarded because 0001_baseline emits the same DDL as init_schema_postgres — which this change edits — so on a fresh PG the column exists before the revision runs and an unguarded add_column would abort boot. Related to Abilityai/trinity-enterprise#329 Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
|
Resolve by running |
|
Resolve by merging |
Two conflicts, both from dev moving ahead by 12 commits: 1. db/migrations.py MIGRATIONS list — both sides appended. Kept BOTH, with dev's two entries first and this branch's last, so the runner applies them in the order they landed. 2. Alembic multi-head — dev added 0039_operator_queue_addressed_to and 0040_rl_events_failure_kind while this branch carried its own 0039 off the same 0038 parent. Two heads make `alembic upgrade head` apply ZERO revisions (Invariant #3), so every revision since the fork silently stops arriving. Renamed 0039_agent_ownership_operator_resume -> 0041_… and re-parented it onto 0040_rl_events_failure_kind. check_alembic_heads now reports one head. NOTE: PR #2330 also claims 0041 (0041_secret_settings_encryption, same 0040 parent). Whichever of the two merges second must re-parent onto the other — scripts/ci/check_alembic_heads.py is a required, unconditional gate, so it fails loudly rather than shipping a silently-inert migration chain.
CI unblocked — merged
|
…esponse-resume # Conflicts: # src/backend/db/migrations.py
vybe
left a comment
There was a problem hiding this comment.
Validated via /validate-pr: security scans clean, docs updated (architecture.md), tests present incl. the #2048 pull-pilot tripwire and test_ent329_operator_resume.py, all 23 checks green.
Alembic revision re-parented by the reviewer during merge: 0041_agent_ownership_operator_resume -> 0042, chained off 0041_secret_settings_encryption (#2330), since three PRs each claimed 0041 off 0040_rl_events_failure_kind. dev has strict:false, so a stale PR is not re-checked and the fork would not have been caught by check_alembic_heads at merge time. pg-migrations and schema-parity both pass on the re-parented chain. Cross-tracker ent#329 needs a manual status-in-dev bump.
An operator's answer reaches the agent's queue file in ~5s, but is only processed at the agent's next turn. A scheduled agent has one. An agent started by a one-shot webhook or chat task does not — so an approved action silently never runs until somebody re-triggers it by hand. trinity#1402 documented the gap and told agents to work around it in prose; this is the platform-side fix.
It is also the hard prerequisite for ent#430 / ent#364: every Workspace ask no-ops without it, which is why that flag ships OFF.
Shape
Opt-in, per agent, default OFF. A dispatch spends money, so it is never unconditional — a respond-storm must not fan out executions. Deliberately not a per-request
resume: truethe agent sets: that lets an agent decide that answering costs the answerer money, which is unacceptable once the answerer is an external Workspace client (ent#430 AC #3). Confirmed with the maintainer before building.One dispatch surface. Everything runs through
execute_task(triggered_by="operator_response"), so capacity admission, the dispatch breaker, cost accounting and the terminal appliers are the ones the platform already uses. No queue- or workspace-specific execution path.Hangs off the CAS win. The respond endpoint raises 409 when the item left
pendingunder the caller; the dispatch sits after that raise, so an answer that was never recorded can never spend (the #1083 rule that side effects follow the CAS result, not the attempt).Idempotent over (item id, answer) per Invariant #18. Never silent: a failed dispatch is a FAILED execution row plus an
operator_resume_dispatchaudit entry carrying ids and status — never the answer text, since that row is broadly readable and the answer is whatever a client typed.Trigger registration
operator_responseis added to all three sets a trigger must appear in:_VALID_TRIGGERS(Executions filter),_TRIGGER_BUCKETS(its own Operator queue bucket — unmapped triggers silently become "Other", which then quietly means "resumes"), and_AUTONOMOUS_TRIGGERS.#2048's tripwire fired and demanded the pull-mode classification, correctly. It is stranded: dispatched by a direct backend call, never by
POST /task, so_derive_task_triggercan never emit it — same shape asscheduleandreminder.Verified on real PostgreSQL
The full Alembic chain applies on a fresh PG database, the column lands with default
0, and a re-run is a no-op. The revision is guarded, and that guard is load-bearing:0001_baselineemits the same DDL asinit_schema_postgres, which this change edits — so on a fresh PG the column exists before the revision runs, and an unguardedadd_columnaborts boot withDuplicateColumn(exactly the failure #2300 hit before its guard).devdoes not yet carry #2300's0039_operator_queue_addressed_to, so both PRs currently claim0039. Whichever merges second must be re-pointed (renamed to0040,down_revisionchained onto the other) or the two become sibling heads and boot fails. I'll do that rather than leave it to CI.Verification
vite buildcleanOne honest note on the tests: three of them initially passed alone and failed in a full run.
sys.modulesstubbing is not enough once another test has really importedservices.x— the parent package attribute shadows it, the real service runs, raises, and the module's own except-clause swallows it. The harness now patches both, and the previously-failing slice passes.Related to Abilityai/trinity-enterprise#329
🤖 Generated with Claude Code