Skip to content

feat(asks): agents wake on an answered ask by default, and a missed wake is delivered on the next start (abilityai/trinity-enterprise#1108) - #4261

Merged
vybe merged 13 commits into
devfrom
feature/ent1108-wake-on-ask-default
Nov 5, 2026
Merged

vybe merged 13 commits into
devfrom
feature/ent1108-wake-on-ask-default

Conversation

@vybe

@vybe vybe commented Nov 5, 2026 •

Copy link
Copy Markdown
Contributor

Summary

The ent#329 "wake on ask ending" switch was per agent and off unless an owner found it; in the 2026-11-05 film an approval in the Inbox moved nothing until the person wrote "go ahead" in the chat. Operator's ruling: on by default, on every instance.

  • Default on. agent_ownership.operator_resume_enabled is tri-state going forward: NULL = platform default (on), 0 = owner's explicit off, 1 = explicit on. The getter resolves NULL to on; register_agent_owner passes NULL explicitly because an upgraded SQLite column keeps its baked DEFAULT 0. Data migration (SQLite operator_resume_default_on + Alembic 0116): every 0 moves to NULL except an agent whose latest audited operator_resume_config toggle said off.
  • AC4 — never dropped silently. operator_queue.wake_state (SQLite + Alembic 0117): pending ("agent not yet woken") when the answer wake found the agent stopped, or when the result is a class in which no turn started on the agent (NO_TURN_ERROR_CODES, spelled from TaskExecutionErrorCode: network, capacity, circuit_open, ephemeral_exhausted, auth, billing; the idempotency claim is released); woken once a turn ran (a timeout is a turn that ran). start_agent_internal spawns redispatch_pending_wakes, which waits for readiness and re-dispatches each pending ask once through the ent#329 path. A turn whose Execution Context ended_asks line lists a pending answer marks it woken at its SUCCESS terminal (note_carried_wakes at compose, mark_carried_wakes off spawn_task_terminal_event), never at compose time — composing proves nothing reached the agent. Capacity pressure is not pending because both wakes now dispatch with execute_task(queue_on_capacity=True): the producer's opt-in puts a wake arriving at capacity on the durable backlog (queue_persistent, pilot or not), the push drain runs it when a slot frees, and dispatch_and_await_terminal waits out the queue; only a full backlog is capacity, and that stays pending.
  • Expiry wakes nobody (product ruling on the merge train). The issue names answers and dismissals; with the wake on by default, the expiry sweep spending an owner's turn is out. _wake_filer returns before the ending spawn on expired; the expired row is still announced and read on the agent's next turn. Cancel and dismiss still wake (operator_ending).
  • Surfaces. Receipt (REST and the MCP OperatorAskReceipt type), Workspace ask payload and Inbox card carry wake_state; the Reliability panel reads "Wakes when an ask ends: on/off" — and "unknown", with the switch disabled, until the GET has answered; the panel copy, the platform prompt, the ask_operator description and the user docs say an answer or a cancel wakes the agent and an expiry does not, so skills stop saying "write me again after you approve".
  • AC3 (attribution) and AC5 (idempotent on the ask id) are satisfied by the existing ent#329 machinery and pinned.

Merge-train follow-ups (pushed by the train)

  • test(ent695): golden fixture regenerated — twelve operator_resume_enabled: 0 → null rows plus _meta.regenerated_by.
  • test(ent1108): the start-hook test stubs the ent#752 marker spawn, so no task is left on a closed loop for test_ent752_marker_sync / test_2328_per_task_max_turns_wire to trip over.
  • fix(asks): NO_TURN_ERROR_CODES + queue_on_capacity=True (above).
  • fix(asks): carried answers marked at the terminal, not at compose (above); two module-binding leaks in the new tests fixed.
  • feat(asks): expiry no longer wakes (above), with copy and docs; test(3247): the replace-ask expiry pin follows.
  • fix(mcp): wake_state on the receipt type. fix(ui): unknown state until the GET answers. test(ent1108): _agent_ready's hand-off pinned (red under a return True mutation).

Test plan

  • tests/unit/test_ent1108_wake_default.py (14) + test_ent1108_deferred_wake.py (54) — red first on behaviour; mutations: getter coalesce, hook line, readiness gate and its hand-off, the no-turn set, compose-time marking each turn their tests red
  • Neighbouring suites (operator_queue, ent329, ent611, ent715, ent747, ent430, ent886, 3247, 2048, 2391, 4105, 3114, 3127, 1578, 2523, 2524, 1804, migrations): green; check_alembic_heads.py: 118 revisions, 1 head (0117_operator_queue_wake_state); check_alembic_parity.py (merge-base..HEAD): PASS, both tracks updated
  • reliabilityPanelWakeStatus.spec.js (4), operatorQueueEnding.spec.js, portalAskWakePending.mount.spec.js mounted; raw-color and loading-gate ratchets unchanged; src/mcp-server tsc --noEmit clean, npm test 1152/1154 (the 2 failures are the pre-existing real-transport tests, identical with types.ts at the base)

Closes abilityai/trinity-enterprise#1108 (cross-repo: close manually at release)

🤖 Generated with Claude Code

vybe and others added 7 commits November 4, 2026 20:11
…ake is delivered on the next start (Abilityai/trinity-enterprise#1108)

The ent#329 "wake on ask ending" switch was per agent and off unless an owner
found it; in the 2026-11-05 film an approval in the Inbox moved nothing until
the person wrote "go ahead" in the chat. The operator's ruling: on by default,
on every instance.

* `agent_ownership.operator_resume_enabled` is tri-state going forward: NULL
  is the platform default (on), 0 the owner's explicit off, 1 explicit on.
  The getter resolves NULL to on; `register_agent_owner` passes NULL
  explicitly because an upgraded SQLite column keeps its baked DEFAULT 0.
  Data migration (SQLite `operator_resume_default_on` + Alembic 0116): every
  0 moves to NULL except an agent whose latest audited `operator_resume_config`
  toggle said off, which keeps its explicit 0.
* AC4: `operator_queue.wake_state` (SQLite + Alembic 0117) — `pending`
  ("agent not yet woken") when the answer wake found the agent stopped or
  the turn never reached it (NETWORK class, idempotency claim released),
  `woken` once a turn ran. `start_agent_internal` spawns
  `redispatch_pending_wakes`, which waits for the agent's readiness and then
  re-dispatches each pending ask once through the ent#329 path (the
  idempotency key is the ask's). The Execution Context `ended_asks` line
  marks what it carries `woken`, so the status never lies. Capacity and
  rate-limit pressure is not `pending`: admission queues the turn on the
  backlog, which is already "delivered when next able".
* Receipt, Workspace ask payload and the Inbox card carry the state; the
  Reliability panel reads "Wakes when an ask ends: on/off"; the platform
  prompt and the MCP tool tell agents the answer wakes them, so skills stop
  saying "write me again after you approve".

Red first: the getter read NULL as off, the insert stamped an explicit off,
the stopped agent dispatched anyway, the hook line was absent from
`start_agent_internal`, readiness was not awaited before the first dispatch
(`test_ent1108_wake_default.py`, `test_ent1108_deferred_wake.py`).

Closes Abilityai/trinity-enterprise#1108

Co-Authored-By: Claude Fable 5.1 <[email protected]>
…the new copy (Abilityai/trinity-enterprise#1108)

A trailing SQL comment on the last column before a table-level FOREIGN KEY
hides the comma from the Postgres translator, so REFERENCES was stripped alone
and a bare FOREIGN KEY reached CREATE TABLE. The comment moves above the column.
operatorQueueEnding.spec pinned the wake setting's previous sentence.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
… NULL (Abilityai/trinity-enterprise#1108)

register_agent_owner writes NULL (platform default: on) where the ent#329
column default was 0, so the twelve pinned agent_ownership rows move 0 → null.
Regenerated with TRINITY_ENT695_REGENERATE_GOLDEN per the test's docstring;
the diff is those rows plus the _meta.regenerated_by entry, nothing else.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
start_agent_internal also spawns the ent#752 skill-gate marker sync, and the
#421 harness runs it on a loop it then closes; the dead task stayed in
skill_gate_service._inflight and every later gather() over that set in
test_ent752_marker_sync (and the pre-fix-gate-record case of
test_2328_per_task_max_turns_wire) raised "The future belongs to a different
loop". The marker spawn is stubbed in this test, so test order cannot matter.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
…acity it queues (Abilityai/trinity-enterprise#1108)

operator_resume_service treated only error_code=network as "no turn ran":
a capacity, circuit_open, ephemeral_exhausted, auth or billing failure wrote
wake_state=woken and completed the idempotency key, so the wake was never
retried. NO_TURN_ERROR_CODES is spelled from TaskExecutionErrorCode and
covers every class in which no turn started on the agent; a timeout means a
turn ran and keeps reading woken.

Both wakes now dispatch with queue_on_capacity=True: execute_task's new
producer opt-in makes build_pull_queue_payload return the overflow payload
for ANY agent, so capacity_manager.acquire hands a wake arriving at capacity
to BacklogService (queue_persistent) instead of rejecting it, the push drain
runs it when a slot frees, and dispatch_and_await_terminal waits out the
queue for the real terminal. The #2391 default is unchanged: without the
opt-in the pull predicate stays the sole widening (test_2048's structural pin
still holds). The ent#329 closed kwarg set admits the new keyword.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
…ot when its prompt is composed (Abilityai/trinity-enterprise#1108)

platform_prompt_service._resolve_ended_asks stamped every answered ask in
the Execution Context line `woken` while composing the system prompt — before
any turn reached the agent. A schedule firing at a stopped agent composes,
the HTTP call fails, and the pending wake was dropped silently (AC #4).

The compose step now hands the answers the line LISTS (carried_answer_wakes:
the first MAX_ENDED_ASKS rows, never the overflow row the resolver reads to
say "and more") to operator_resume_service.note_carried_wakes, keyed by the
execution id. mark_carried_wakes hangs off event_dispatch_service
.spawn_task_terminal_event — the fan-out every CAS-won terminal writer calls
(push, the #1083 callback, the pull sink, the sweeps) — and flips them
`woken` on SUCCESS; any other terminal drops the entry and leaves the rows
`pending` for the next start. Best-effort and process-local: a compose and a
terminal on different workers miss the entry and the next start re-dispatches
once, a duplicate turn rather than a dropped wake.

Tests fix two module-binding leaks of their own: the ending wake and the
resolver import services.operator_queue_service lazily, and a first import
under a fake `database` in sys.modules bound the fake for the whole session
(32 ent#715 failures when run after this file).

Co-Authored-By: Claude Fable 5.1 <[email protected]>
…'s answer or cancel (Abilityai/trinity-enterprise#1108)

Product ruling on the merge train: with the wake on by default, the expiry
sweep spending an owner's turn for a timeout nobody chose is out; the issue
names answers and cancellations. ask_service._wake_filer returns before the
ending spawn on `expired`; the expired row is still committed, announced and
read on the agent's next turn (readback, Execution Context line, get_my_ask),
where the rider stands verbatim. Cancel and dismiss still wake.

Copy follows: the Reliability panel names an answer or a cancel and says an
expiry wakes nobody (cost sentence kept accurate), the platform prompt and
the ask_operator description tell the agent the same, and the user docs
(FAQ, agent configuration, approvals, executions) plus the feature flow and
requirement sentences stop saying "off by default" / "or expires".
config/trinity-meta-prompt/prompt.md is a dead-but-present reference copy
(test_1402_prompt_contract) and is left alone.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
vybe added a commit that referenced this pull request Nov 5, 2026
…eue_wake_state (Abilityai/trinity-enterprise#1107)

`0116_terms_acceptances` shared `down_revision` 0115 with #4261's
`0116_operator_resume_default_on` → `0117_operator_queue_wake_state`, which
merges first. Two revisions off one parent are two heads, and `upgrade head`
then applies nothing (#2068). Renamed to `0118_terms_acceptances`, revises
0117; every reference follows (the SQLite docstring, database.md, the
enterprise companion's docstring in its own PR).

`check_alembic_heads.py` reports a missing parent until #4261 lands — expected.
A local PostgreSQL stamped with the old id needs
`alembic downgrade 0115_access_requests_requester_identity && alembic upgrade head`
once both are on dev.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
vybe and others added 4 commits November 4, 2026 21:24
…enterprise#1108)

The backend receipt gained wake_state (pending | woken | null); the MCP
OperatorAskReceipt type did not, so the third surface read it as unknown.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
…as answered (Abilityai/trinity-enterprise#1108)

ReliabilityPanel initialised resumeEnabled to false, so a failed GET showed
"Wakes when an ask ends: off" for a setting that is on by default. null
renders "unknown" and keeps the switch disabled until the read lands.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
… is pinned

_agent_ready could be replaced by `return True` and every test stayed green;
the probe now has to return lifecycle.wait_for_agent_ready's verdict, both
ways, for the named agent (verified red under that mutation).

Co-Authored-By: Claude Fable 5.1 <[email protected]>
…s nobody (Abilityai/trinity-enterprise#1108)

The replace-ask path's expiry pin still expected the ent#329 expiry wake;
with the ruling that an expiry spends no owner's turn, the sweep's event and
audit row stand and no wake is spawned.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
@vybe

vybe commented Nov 5, 2026

Copy link
Copy Markdown
Contributor Author

Pushed by the merge train — head 1c830e348, ten commits on top of d7b362f49, one per finding. Nothing merged, approved or labelled.

Commit Why
50ebde9fd merge-train: PG baseline parses again; ending spec reads the new copy The train's earlier fix, kept.
dc6264473 test(ent695): golden reads operator_resume_enabled as NULL Tier 1 red: db/agents.py now writes NULL where the golden pinned 0. Regenerated via TRINITY_ENT695_REGENERATE_GOLDEN; diff is exactly twelve 0 → null rows + _meta.regenerated_by. 14/14.
43002eddc test(ent1108): start-hook test leaves no task on a closed loop Tier 1 red: the test ran start_agent_internal on a throwaway loop and left the ent#752 marker-sync task in skill_gate_service._inflight; six test_ent752_marker_sync cases and test_2328…[pre-fix-gate-record] then raised "future belongs to a different loop". Marker spawn stubbed; reproduced and proved with the combined run (71 passed).
57e89adeb fix(asks): a wake that never reached the agent stays owed, and at capacity it queues Ruling (a)+(b): NO_TURN_ERROR_CODES = {network, capacity, circuit_open, billing, auth, ephemeral_exhausted} keep pending and release the idempotency claim (timeout = a turn ran). Both wakes dispatch queue_on_capacity=True — a new execute_task producer opt-in that makes build_pull_queue_payload return the overflow payload for any agent, so capacity.acquire hands a wake at capacity to BacklogService (queue_persistent), the push drain runs it, and dispatch_and_await_terminal waits it out. The #2391 default and test_2048's structural pin are unchanged. Parametrised tests per error class.
904a26ef6 fix(asks): a carried answer is marked woken at the turn's terminal Ruling on AC #4: _resolve_ended_asks no longer marks at compose. compose_system_prompt stashes the LISTED answers (carried_answer_wakes, first MAX_ENDED_ASKS, never the overflow row) via note_carried_wakes; mark_carried_wakes hangs off spawn_task_terminal_event and flips them on SUCCESS only. Tests: failed dispatch leaves pending, completed turn marks woken (real SQLite), fan-out reaches the marker. Also fixed two module-binding leaks in the new tests (a lazy from database import db under a fake database poisoned 32 ent#715 cases).
46f81e701 feat(asks): an expiry wakes nobody Product ruling: _wake_filer returns on expired; cancel/dismiss still wake. Panel copy ("answers it or cancels it", cost sentence accurate), platform prompt, ask_operator description, FAQ collaboration.md, agent-configuration.md, approvals.md, executions.md, operating-room flow and security requirement updated. config/trinity-meta-prompt/prompt.md is a dead-but-present reference copy (test_1402) — left as is.
a853602e0 fix(mcp): receipt type carries wake_state OperatorAskReceipt lacked the field. tsc --noEmit clean; npm test 1152/1154 — the 2 failures are pre-existing real-transport tests, identical with types.ts at the base.
3ca4e1c65 fix(ui): wake switch reads unknown, never off, until the GET answers resumeEnabled was ref(false); now null renders "unknown" with the switch disabled. Spec added (red first).
42f95266a test(ent1108): _agent_ready hand-off pinned Proved red under a return True mutation, both verdicts.
1c830e348 test(3247): expired predecessor wakes nobody The replace-ask path's expiry pin followed the ruling.

Verification: 47 backend suites (PR-touched + ent752, 2328, ent695, ent329, 2048/2391/4105/3114/3127, 1578/2523/2524/1804, migrations, alembic) — 1627 passed; frontend operatorQueueEnding, reliabilityPanelWakeStatus, portalAskWakePending.mount + both ratchets — 50 passed; check_alembic_heads.py: 118 revisions, 1 head (0117); check_alembic_parity.py (merge-base..HEAD): PASS. 0116/0117 left off 0115 as instructed.

Noted, not changed: the carried-wake stash is process-local — a compose and a terminal on different uvicorn workers (#1083 callback, pull claim result) miss it and the next start re-dispatches once (a duplicate turn, never a dropped wake); the queued wake needs no priority or caller-side idempotency key (BacklogService.enqueue takes neither; the service's own key completes after the awaited terminal, and a backend restart mid-queue leaves that claim in flight for 24h — the known #3298 residual).

🤖 Generated with Claude Code

@trinity-ability trinity-ability left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

merge-train: validated at 50ebde9 (lane B +schema, /validate-pr + /review); the findings were fixed on the branch per the operator's rulings (see the train comment), Tier 1 green on 1c830e3. Alembic: single head 0117, parity PASS.

vybe and others added 2 commits November 4, 2026 21:33
…n-ask-default

# Conflicts:
#	tests/unit/fixtures/ent695_create_mode_golden.json
…acity (Abilityai/trinity-enterprise#1108)

test_ent751_gate_guards pins that every execute_task keyword has a fate; the
new keyword is DROP — the wake producer's own admission choice, never replayed
into an approved run.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
@vybe

vybe commented Nov 5, 2026

Copy link
Copy Markdown
Contributor Author

merge-train: one more mechanical commit — queue_on_capacity classified DROP in the skill gate's DISPATCH_FIELDS (test_ent751_gate_guards went red on the dev-merged head because the new keyword had no fate). Also merged dev (the ent695 golden was regenerated over #4247's version; 12 rows 0→null as before).

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