Skip to content

feat(wake): caller is woken when its delegated run ends, default on (ent#1102, ent#790) - #4269

Merged
vybe merged 15 commits into
devfrom
feature/ent1102-wake-on-ending
Nov 6, 2026
Merged

vybe merged 15 commits into
devfrom
feature/ent1102-wake-on-ending

Conversation

@vybe

@vybe vybe commented Nov 5, 2026 •

Copy link
Copy Markdown
Contributor

What

Wake-on-ending (ent#1102, absorbing ent#790): when a delegated run reaches a terminal state, the caller agent is woken once so it can act without polling. Default on per D4 (hub retrospective 2026-11-04); storm bounded by a 15 s per-caller bucket.

Migration: additive nullable column wake_on_ending on agent_ownership; dual-track (SQLite + Alembic), OSS, single-head verified against live dev.

8 commits:

  • 7fdd195 feat(wake): one resolver decides who may be woken, and its default is on (ent#1102, ent#790)
  • ea8d775 feat(wake): the caller is told its delegated run ended, instead of polling for it (ent#1102)
  • cd0a3ff feat(wake): the contract teaches the wake, and the receipt says whether one is coming (ent#1102)
  • a7825cf feat(wake): an agent can read its own wake policy, and which layer set it (ent#1102)
  • cf2a144 feat(wake): the resume switch becomes tri-state, and every gate reads the one resolver (ent#1102, ent#790)
  • a15788a fix(wake): the receipt carries the policy it told agents to read (ent#1102)
  • 7338bec fix(wake): the resolver's db is reachable, and every read fails closed (ent#1102)
  • f8f97c5 docs(learnings): a receipt field fed by a key nobody sends (ent#1102)

Rulings carried

  • D4: wake-on-ending default ON (hub retrospective 2026-11-04)
  • P0: OSS-core placement confirmed — no enterprise gate
  • T2: storm bounded by 15 s per-caller bucket (per-caller, not global)
  • T3: possible double message on one ending accepted
  • T5: resolve_turn_model absent from MCP model readback — named gap, separate follow-up
  • P9/P10: chain-depth forwarding and event-loopback vouched-name arm — pinning tests added
  • Freeze rule honoured: channel_completion_report.py NOT touched (ent#1102/ent#1103 boundary)

Review + security

  • Reading review: MERGEABLE AFTER FIXES (Fable, kzu4zF1QdIVylpiU7o7GEw)
  • Evidence sweep: PASS (Opus, DFl11M9OEQ6pzry3HucRqQ — 7 branch-defect reds traced to function-local db import, now fixed)
  • CSO: /cso --diff clean (enterprise-guard + private-term greps pass)
  • Security: flooding bounded by 15 s per-caller bucket; recursion break tested; chain-depth both tested
  • Autonomy-off does not suppress wake (matches existing ask-answer wake behaviour, D4 intent)
  • Fail-closed: unreadable wake flag resolves to OFF on every exception path (C2 fix)
  • 2 critical fixes applied: C1 (chat router now emits wake_on_ending {effective, source} on task/chat receipts; MCP reads .effective not truthy-object); C2 (wake_policy.py module-level db import; both exception paths resolve OFF)

Tests

  • 7 sweep failures fixed (function-local from database import db bypassed test stubs; module-level import restores stubbing)
  • 3/3 mutations caught (default-ON flip, bucket removal, terminal hook removal)
  • Pinning tests added: chain-depth forwarding (P9) and event-loopback vouched-name arm (P10)
  • Targeted tests green on engineer; full unit island runs on CI

Before merge

  • Frontend (ReliabilityPanel.vue stale boolean for tri-state column): filed as separate issue trinity#4268
  • MCP resolve_turn_model readback absent (T5 named gap): separate follow-up
  • Duplicate-wake edge case (I4): informational, later issue
  • fan_out receipts missing wake field (I5): informational, later issue
  • Dev has advanced since branch was cut (1a5d90ba → 8df0445f); merge-tree clean, single Alembic head verified

Handoffs

  • After merge: ent#1103 (report-back-fence) may now touch channel_completion_report.py — freeze was branch-scoped
  • Deferred items: per-caller coalescing beyond bucket, fan_out batch wake, two hotspot paydowns — in project_files/chain-ent1102/run-log.md §T6
  • Closes abilityai/trinity-enterprise#1102. Closes abilityai/trinity-enterprise#790 (absorbed)

merge-train 2026-11-06: a126581 reconciles the resolver with ent#1108's tri-state operator_resume_enabled that landed on dev after this branch was cut (NULL → instance default, 0 → off, 1 → on; the PUT writes both columns in step). The body above predates that commit; the 'merge-tree clean / single head' line now refers to head a1265819d with the revision renamed to 0121_agent_ownership_wake_on_ending.

Trinity Agent (trinity) and others added 8 commits November 4, 2026 22:13
… on (ent#1102, ent#790)

Checkpoint A of ent#1102: the storage and the policy, before anything
dispatches a turn.

`agent_ownership.wake_on_ending` is deliberately NULLable with no server
default, unlike every boolean beside it. That is the whole point: an
`INTEGER DEFAULT 0` cannot tell "nobody ever touched this" from "the owner
said off", and ent#790 asks for the default to be flipped ON — so with a
two-state column the flip would either skip the owners who already said no
or silence the fleet that never answered. NULL means "no opinion".

`services/wake_policy.resolve` is the only reader, so an owner who silences
one wake path has silenced both (the delegated-run wake of this issue and
ent#329/ent#611's ask-answer wake). It reads, in order: the tri-state
column, then a pre-existing `operator_resume_enabled = 1` as an explicit
opt-in made before the tri-state existed, then the instance default
`wake_on_ending_default` (ON, ruling D4). A legacy `operator_resume_enabled
= 0` is NOT read as an opt-out, because that column shipped `DEFAULT 0` and
an owner who turned it off is byte-identical to one who never saw it;
reading it as "off" would silence the entire pre-upgrade fleet. No backfill
— ent#790's flip is one admin default, not a bulk rewrite of intent (#1945).

Fail-closed everywhere: an unreadable flag, an unreadable setting row or an
empty agent name all resolve OFF. A wake that does not happen is
recoverable — the ending stays readable through `get_execution_result`; a
turn billed on a flag nobody could read is not.

Dual-track migration (Invariant #9): SQLite `agent_ownership_wake_on_ending`
+ Alembic `0116`, single head verified.

Tests: `tests/unit/test_ent1102_wake_policy.py` — 14 tests over a real
SQLite file through the real mixin and the real resolver, red before this
commit on the missing `get_wake_on_ending` and the missing module. They pin
the three distinctions that carry the design: NULL ≠ 0, the legacy opt-in
survives an instance default of off, and the tri-state beats the legacy
flag when the same owner has spoken more recently.

Refs: abilityai/trinity-enterprise#1102, abilityai/trinity-enterprise#790

Co-Authored-By: Claude Opus 5 <[email protected]>
…lling for it (ent#1102)

Checkpoint B of ent#1102: the dispatch, hooked into the one terminal
fan-out every CAS-won writer already calls.

An async `chat_with_agent` hands back a receipt, not an answer, and before
this there was no way to learn the answer had arrived — so agents polled.
The retrospective behind ruling D4 priced that: $246 of polling, 13
re-dispatches and 10 operator nudges for runs that had already finished. One
push replaces all of it.

`_terminal_side_effects` is the hook, as a fourth guarded sibling. It covers
all 16 terminal writers without any of them changing, and it is deliberately
NOT nested inside `emit_task_terminal_event`, which returns early when no
event subscription matches — the common case — so anything inside it would
almost never run. Nor is it armed by the MCP client at receipt time: the
terminal knows the run ended; the client does not.

The wake spends a billed turn on an agent that did not schedule it, so the
stand-downs are the design, not the edge cases. No `source_agent_name` (a
human's run has nobody to tell); a self-task or a fan-out leg (the #2524
join is the batch's own reaction); any of the four reserved platform
triggers — `caller_wake` first, which is the recursion break, so no wake
chain can sustain itself, and which also closes Premise P10: an event-
loopback row is refused before its vouched `source_agent_name` is read, so
the vouching path has no reach here. Then the policy, then the caller's own
`agent.task.*` subscription (the emit is already dispatching that turn — one
ending, one turn, AC 6), then a stopped container, which is audited rather
than dispatched at because nothing auto-starts an agent.

Two bounds that make default-ON affordable. The idempotency key is
`caller_wake:{caller}:{15s bucket}` and NOT the callee's execution id: a
cleanup sweep can terminate hundreds of stale rows in one cycle, and keying
per callee would bill a turn for each — so the frame says plainly that other
runs may have ended in the same window and names `list_recent_executions`,
rather than telling a half-truth. And `chain_depth = callee + 1`, so the
wake is governed by the same `inter_agent_max_chain_depth` as the call chain
it answers (#2806/#2973) instead of being an unbounded side channel around
it. Premise P9 is now verified, not assumed: `dispatch_and_await_terminal`
forwards `**execute_kwargs` to `execute_task`, which threads `chain_depth`.

The frame carries ids, enums and the sanitized-then-capped summary through
the #1578 chokepoint, `request_text=""` and no `source_user_email` — the
platform wrote this prompt, not a person (ent#751/#886/#715). It also names
any asks the run parked and never got answered (new indexed read
`list_pending_ask_ids_for_execution`, ids only): a run can reach a normal
terminal with asks still pending, and a caller told only "ended
successfully" would read that as finished work.

Tests: `tests/unit/test_ent1102_caller_wake.py` — 26 tests through the real
`maybe_wake_caller`. Mutation battery, each reverted from a scratch copy and
restored byte-identical: deleting the hook call reddens
`TestWiring::test_each_sibling_is_guarded_separately`; dropping the reserved-
trigger break reddens the P10 loopback test; dropping the replay return
reddens `test_a_replayed_claim_produces_no_second_wake`; dropping
`chain_depth` reddens `test_a_missing_chain_depth_starts_the_count`; keying
the window on the callee reddens `test_one_wake_per_caller_per_bucket`.
Regression over the touched seams (#1578/#2523/#2524/#3520/ent#329/ent#611/
#2806/#2973): 509 passed, 1 skipped.

Refs: abilityai/trinity-enterprise#1102

Co-Authored-By: Claude Opus 5 <[email protected]>
…er one is coming (ent#1102)

Checkpoint C1 of ent#1102: the two surfaces a caller actually reads.

Checkpoint B made the backend dispatch a turn on the caller when a delegated
run ends. Nothing told the caller that, so the delegation contract still gave
the pre-ent#1102 instruction — "to finish later, set a reminder and end your
turn" — which for a run that WILL be reported is now the wrong move and
re-buys the polling the feature exists to remove.

The contract gains one bullet, in both copies, because at PromptTier.MINIMAL
the `chat_with_agent` description is the only copy an agent sees and an
external MCP client never reads the prompt at all. `on_ending` says a turn is
started on you, so ending yours is correct; `none` carries the reason and keeps
the reminder advice, which is why that sentence left the bullet above rather
than being duplicated — two bullets would have given one receipt two
contradictory instructions.

It is paid for, not simply added. The contract shares Claude Code's 2,048-char
description cap with each tool's own lead and had 15 chars of headroom: most of
the new bullet comes out of the text it replaces (the unconditional reminder
sentence), out of the subscription sentence's `execution_id` advice (which the
bullet above it already gives), and out of the lead's modes paragraph, whose
detail its own parameter descriptions carry in full and are not cut — the
same trade #3245 made. 12 chars of headroom are left, and the guard's new cap
says in words that raising it again without trimming something is how the end
of the contract stops being read.

`resolveWake` is the receipt half, and it is in this commit rather than the
next one on purpose: the ent#568 guard refuses a contract that teaches a field
no answer carries, which is exactly right — a caller told to end its turn on
`wake: on_ending` must be reading a real field. Four stand-downs are knowable
in the MCP server whatever the policy says (nobody to wake, nothing ran, the
reply is already in hand, or the ending has its own reaction — a self-task's
caller IS the callee, a `fan_out` leg ends into the #2524 join). The POLICY is
the backend's to report, so an answer that carries no `wake_on_ending` leaves
the receipt SILENT rather than defaulting to the promise: the instance default
being on is not evidence about the one agent whose owner turned it off, and a
receipt that says `on_ending` and then goes quiet costs precisely what the
retrospective priced.

Two layers, mirroring resolveReportBack/chatRouteFields: `resolveWake` is the
full verdict (every reason named, for the audit row and `get_agent_info`), and
`wakeReceiptFields` decides what a result prints. It keeps quiet on
`no_caller` / `answered_inline` / `self_task` — the three where the caller has
no wake expectation to correct — which is also what keeps today's results
byte-unchanged under delegation-contract.test.ts's "only `message` may change".

Tests: `tests/unit/test_ent1102_contract_wake.py` (10, red before this commit
on the missing bullet in both copies — including that the unconditional
reminder sentence does not survive beside it) and `src/mcp-server/src/wake.test.ts`
(18, pure). The ent#568 guard gains a `WAKE_VALUES` classification set with its
own producer check, so a future value the receipt cannot answer fails the build
instead of shipping as an instruction. Green: 43 passed, 1 skipped
(`-k delegation_contract`); 33 passed (MCP contract suite over a real
transport, which is where the 2,048-char cap is actually enforced).

Refs: abilityai/trinity-enterprise#1102, abilityai/trinity-enterprise#568

Co-Authored-By: Claude Opus 5 <[email protected]>
…t it (ent#1102)

Checkpoint C2 of ent#1102: `GET /api/agents/{name}/info` gains
`wake_on_ending: {effective, source}`, carried through to the MCP
`get_agent_info` third surface (Invariant #13).

The receipt answers one question — will THIS run be reported — and it is
deliberately terse. The standing policy is a different question, and an agent
just told `wake: none, wake_reason: opted_out` had nowhere to look. `source`
is the half that stops the answer being a dead end: `agent` (the owner's own
tri-state), `legacy_resume` (ent#329's pre-tri-state opt-in), `instance` (the
default) or `unreadable` (fail-closed). Without it, an owner who reads
`effective: false` cannot tell a decision they made from one the instance made
for them, and goes to change the wrong control.

The block is stamped on EVERY answer rather than inside the running-agent
branch, which is why the handler's body moved into `_agent_template_info` and
the route became four lines around it. The endpoint has five returns — a
stopped container, a non-200 from the agent server, a timeout, an exception,
and the real template read — and the policy depends on none of them: it is a
platform fact. The stopped branch is the one that matters most, because a
stopped agent is exactly the state an owner is in when they are wondering why
nothing woke up.

Tests: `tests/unit/test_ent1102_agent_info_wake.py` — 5 tests through the real
route handler and the real resolver over a real SQLite file (Docker and the
container reload stubbed, nothing else), red before this commit on
`KeyError: 'wake_on_ending'`. They drive the stopped branch specifically, so
stamping the block on the running path only would still fail. Green:
148 passed, 1 skipped (`-k wake`); 41 passed (MCP suites); `tsc --noEmit` clean.

Refs: abilityai/trinity-enterprise#1102

Co-Authored-By: Claude Opus 5 <[email protected]>
… the one resolver (ent#1102, ent#790)

Checkpoint C3 of ent#1102: `PUT /api/agents/{name}/operator-resume` accepts
`{"mode": "default" | "on" | "off"}`, and the four places that gated a wake on
ent#329's boolean column now ask `wake_policy.resolve`.

The second half is the one that would otherwise rot. Checkpoint A made the
resolver the only reader of the policy, but `operator_resume_service` (both
gates), `ask_service._opted_in` and the Workspace asks' `wakes_on_ending`
receipt were still reading `operator_resume_enabled` directly. A tri-state
"on" never writes that column, so a pre-filter in front of the dispatcher
would have declined to schedule the work and the resolver would never have
been consulted — the switch would read as wired and do nothing. The two
receipt readers matter for the same reason in reverse: a receipt that says
`wakes_on_ending: false` while the dispatcher says yes is the honesty bug this
feature exists to remove, one layer down.

`mode` is three states because the instance default is ON (ruling D4).
`DEFAULT 0` cannot tell "nobody has touched this" from "the owner said off",
so a two-state switch over a default-on policy either silences the fleet that
never answered or overrides the owners who already said no.

`enabled` stays accepted and is NOT aliased to `mode`: it writes the boolean
column as before (it still has readers) AND records the same answer in the
tri-state, because a person who moved the switch has expressed an opinion
either way — a legacy `enabled: false` that did not reach the tri-state would
leave the instance default overriding the owner who just turned the wake off.
Exactly one of the two must be present; both or neither is a named 422 rather
than a precedence rule invisible from the request, and an unknown mode is a
422 on the field (Literal), not a quiet fallback to the default. The GET and
the PUT answer with `mode` + `effective` + `source`, so a control can say
"On (instance default)" instead of inventing a reason.

The resolver import in `operator_resume_service` is deliberately function-local
beside its existing `from database import db`: both gates are reached in tests
by swapping the module in `sys.modules`, and a module-level binding would have
made the gate unreachable to exactly the suites that prove it.

Four existing suites moved with the mechanism rather than being worked around:
ent#329's and ent#611's fixtures now stub the verdict instead of the column
(`_get_flag` is still the switch; only the layer that reads it moved), and the
M3 human-only test asserts the widened answer and both writes. Mutation
battery, reverted from `cp` scratch copies and restored byte-identical:
replacing the tri-state write with the boolean one reddens 2 tests, and
putting the ent#329 column back in the gate reddens 2 more, including the
regression test written for exactly that.

Tests: `tests/unit/test_ent1102_operator_resume_modes.py` — 15 through the
real routes and the real resolver over a real SQLite file. Green: 549 passed,
1 skipped over the touched seams (operator_resume / ent329 / ent611 / ent1102 /
ask_service / models_centralized / wake / delegation_contract / auth_wiring).

Refs: abilityai/trinity-enterprise#1102, abilityai/trinity-enterprise#790, abilityai/trinity-enterprise#329

Co-Authored-By: Claude Opus 5 <[email protected]>
…#1102)

Reading review C1. `chat.ts::resolveWake` decided the receipt's `wake` field
from one input — "did the dispatch answer carry `wake_on_ending`" — and no
backend path emitted that key. So `wakeReceiptFields` returned `undefined` on
every live receipt while the contract shipped to every agent said *"The
receipt's `wake` field says who brings you the ending"* and the unconditional
`set_reminder` guidance had been removed. The backend wake fired anyway: the
behaviour was "surprise turn, unannounced", the opposite of what ent#1102 set
out to buy.

`chat_execution_service._wake_on_ending_receipt` resolves the caller's policy
and stamps `wake_on_ending: {effective, source}` on the three answers that are
a receipt rather than a reply: the `/task` async `accepted` and `queued`
payloads, and the pull-pilot `/chat` `queued_timeout`. The sync-path and
MCP-synthesised `queued_timeout` receipts keep no field — the MCP server builds
those itself when its own fetch aborts, so there is no backend answer to read,
and silence there is already the documented behaviour.

`{effective, source}` is the shape `GET /agent-info` already publishes, with
`wake_policy`'s own source vocabulary (`agent` / `legacy_resume` / `instance`),
so the receipt, the audit row and the agent's own read of its policy speak one
language. The ruling sketched `default|instance|operator-resume`; using the
resolver's existing names keeps one vocabulary rather than a second one that
would need translating at each surface.

No claim at all — the key absent — when there is nobody to wake, when the
caller IS the callee, or when the policy could not be read. The client stands
the first two down by itself, and a receipt that promises `on_ending` and then
goes quiet costs exactly what this feature removes.

On the client, `wakePolicyFromAnswer` reads `effective` rather than the field's
truthiness. That matters: `{effective: false}` is a truthy object, so the old
`Boolean(answer.wake_on_ending)` would have read an opt-out as a promised wake
— the one misreading that makes an agent end its turn waiting for a turn nobody
will dispatch. A flattened boolean is still accepted so the two sides cannot
drift silently.

Tests: `test_ent1102_receipt_wake.py` drives the real `_dispatch_async` receipt
branches (both states × wake-on / wake-off / no caller / self-task) and asserts
on the stored idempotency snapshot as well as the returned body; the four
behavioural tests go red with the emit reverted (verified). `wake.test.ts` gains
a suite that drives the client off a backend-shaped receipt — mutating the
reader back to truthiness turns the opt-out test red (verified).

Co-Authored-By: Claude Opus 5 <[email protected]>
…d (ent#1102)

Reading review C2, found by the branch sweep: 7 tests in 3 files went red on
this branch and were green at base, all on one cause.

`resolve` did its own function-local `from database import db`. The four gates
it replaced read the `db` their OWN module holds — which every one of those
tests substitutes — so the substitution stopped reaching the decision. In
production both are the same singleton, so this was never a behaviour change at
the call sites; what it was is the stale-fake class. The tests that pin the
opt-out and the fail-closed property stopped exercising them, and here they
failed loudly rather than passing vacuously, which is the only reason anyone
found out. One module-level `db` means one place to point at.

The same reads were also not fail-closed. `get_operator_resume_enabled` raising
fell through to `instance_default()` and `get_setting_value` raising returned
the built-in ON, so a broken read BOUGHT a billed turn — against this module's
own docstring and the ent#329 rule it cites. Both now resolve OFF with
`source=unreadable`, like the tri-state read above them. Ruling D4 (default ON)
is the policy for an absent or malformed VALUE, which still falls back to the
default; a read that failed is a different question, and a malformed-value test
now pins that line from both sides.

Tests. The three sweep-red files point their fakes at the resolver's seam:
`_PolicyDb` (ent430 workspace) gives the resolver a view of the same fake, and
the ent430-dispatch and ent886 fakes gain the tri-state and setting reads. Two
test premises are re-spelled rather than re-interpreted: with the instance
default ON, "the owner never opted in" no longer means off, so those tests say
"the owner switched it off" through the tri-state column — same property, one
per-agent switch read from the accessor the dispatch gates on, new spelling.
`test_resume_requested_is_false_when_the_agent_has_not_opted_in` also gains the
succeeding spawn stub: with the spawn left real it failed on its own and the
assertion held whatever the policy said.

Verified by mutation: with `resolve` forced to return ON, the opt-out and
fail-closed tests in all three files go red (they did not before this commit).
Two fixture DDLs gain `system_settings.updated_at` — the real table has it, and
without it the instance-default read raises, so the FIXTURE rather than the
policy would decide the verdict now that a failed read means OFF.

Co-Authored-By: Claude Opus 5 <[email protected]>
The fragment the reading review assigned to the fix author: C1's defect class,
the two greps that would have caught it before review, and the truthiness trap
on the object payload that commit 1 closes.

Co-Authored-By: Claude Opus 5 <[email protected]>
@github-actions

github-actions Bot commented Nov 5, 2026 •

Copy link
Copy Markdown

✅ Alembic head check clear — merging this PR into dev leaves one head (0120_public_user_memory_writes_section).

Previously flagged; resolved.

Advisory — this check does not block merge. · head_sha: a1265819d8dd8e11b907dab245056e6b68ae2888 · run

…to 0118)

dev's version line moved to 0118_mcp_external_access_backfill while this branch
sat at 0116 off 0115, forking the line into two heads. `alembic upgrade head` is
singular and resolves its target before applying anything, so that graph applies
ZERO revisions (#2068). Rechained onto the real head; no DDL change.

Co-Authored-By: Claude Opus 5 <[email protected]>
@github-actions

github-actions Bot commented Nov 5, 2026

Copy link
Copy Markdown

⚠️ Nightly unit-suite check skipped — merge conflict against dev.

Resolve by running git merge dev locally and pushing the result. The next nightly run will re-test once the conflict is gone.

@github-actions

github-actions Bot commented Nov 5, 2026

Copy link
Copy Markdown

⚠️ Live-instance suite skipped — merge conflict against dev.

Resolve by merging dev locally and pushing the result; the next nightly re-tests.

vybe and others added 2 commits November 5, 2026 22:44
) — mechanical, per the merge-train note on the PR

Conflicts resolved: client_portal/asks/service.py (import union),
db/migrations.py (dev's five entries first, then agent_ownership_wake_on_ending),
db/schema.py and db/tables.py (dev's tri-state operator_resume_enabled comment
+ the PR's wake_on_ending column). Alembic revision re-parented
0119_agent_ownership_wake_on_ending -> 0121_agent_ownership_wake_on_ending,
down_revision 0120_public_user_memory_writes_section (dev's head), one head.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
…aw (#4269) — mechanical, per the merge-train note on the PR

Semantic conflict with dev's ent#1108: `get_operator_resume_enabled` now
COALESCEs NULL to ON, so the resolver's second layer read every untouched
agent as a `legacy_resume` opt-in and the instance default
(`wake_on_ending_default`) became unreachable; and a 0 — the owner's explicit
OFF since the ent#1108 migration disambiguated the DEFAULT 0 rows — was read as
"no opinion" and overridden by the instance default ON.

- db mixin + database facade: `get_operator_resume_override` (raw NULL/0/1);
  `set_operator_resume_enabled` accepts None (NULL).
- wake_policy layer 2: NULL -> instance default; 0 -> OFF; 1 -> ON (source
  legacy_resume either way).
- PUT operator-resume writes both columns in step on every body (mode default
  clears the ent#329 column to NULL), so an older answer cannot outvote a
  newer one.
- tests: ent#1102 fakes/seeds say NULL where they meant "never said"; new
  resolver test for an explicit legacy OFF; ent#1108 tests meet the ent#1102
  gate (resolver stub, wake_on_ending column on the fixture row); ent#1066
  sink world states its "not opted in" on the tri-state (was red on the PR
  head too).

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

vybe commented Nov 6, 2026 •

Copy link
Copy Markdown
Contributor Author

merge-train (acting for the author): pushed two commits to feature/ent1102-wake-on-ending, head a1265819d.

c7e1f26 — merge origin/dev. Conflicts resolved: client_portal/asks/service.py (import union), db/migrations.py (dev's five entries first, then agent_ownership_wake_on_ending), db/schema.py + db/tables.py (dev's tri-state operator_resume_enabled comment plus the PR's wake_on_ending column). Alembic revision re-parented 0119_agent_ownership_wake_on_ending → 0121_agent_ownership_wake_on_ending, down_revision = 0120_public_user_memory_writes_section; check_alembic_heads.py → 1 head.

a126581 — semantic conflict with dev's ent#1108. On dev get_operator_resume_enabled now COALESCEs NULL → ON, so after the merge the resolver's second layer read every untouched agent as a legacy_resume opt-in (the instance default wake_on_ending_default was unreachable), and a 0 — the owner's explicit OFF since the ent#1108 migration disambiguated the DEFAULT 0 rows — was read as "no opinion" and overridden by the instance default. Fix: wake_policy reads the column raw through a new get_operator_resume_override (NULL → instance default, 0 → OFF, 1 → ON, source legacy_resume); PUT operator-resume writes both columns in step on every body (mode: default clears the ent#329 column to NULL). Tests: ent#1102 seeds/fakes say NULL where they meant "never said", a new resolver test for an explicit legacy OFF, the ent#1108 tests now meet the ent#1102 gate, and test_ent1066_credential_sink (red on the PR head itself) states its "not opted in" on the tri-state.

Local evidence: 37 unit files (the PR's 19 + migration/alembic guards + the ent#1108/ent#1066/ent#751/ask-sink suites) → 1910 passed; src/mcp-server/src/wake.test.ts → 22 passed; hand-off deletion mutation in _terminal_side_effects → 2 wiring tests red, reverted.

Note for the author: the body's "Closes ent#1102" is not a GitHub closing keyword — cross-repo needs Closes abilityai/trinity-enterprise#1102.


Follow-up push — head 1d739b651. CI regression diff on a1265819d found 8 failures outside my first run.

1d739b6 — pure registrations: test_ent715_queue_person_fields gets list_pending_ask_ids_for_execution in _NON_ROW_ACCESSORS (ids only); the ent#695 create-mode golden was regenerated for the PR's own additive column (TRINITY_ENT695_REGENERATE_GOLDEN=abilityai/trinity-enterprise#1102, serial) — the fixture diff is exactly 12 × "wake_on_ending": null on agent_ownership rows, their preceding trailing commas, and _meta.regenerated_by. Re-run: test_ent695_create_mode_golden 14/14, test_ent715_queue_person_fields all green; the PR's 19 suites + ent#1108 + ent#1066 sink: 625 passed.

Two remain red and need the author's intent — not registrations, so I did not guess:

  1. test_4105_pull_trigger_census — caller_wake (caller_wake_service.py:330) is in NO trigger enumeration. Its sibling operator_ending sits in seven: routers/executions.py:_VALID_TRIGGERS, task_execution_service._AUTONOMOUS_TRIGGERS, pull_pilot.PULL_REACHABLE_TRIGGERS, skill_gate_service._PERSONLESS_REPLAY_TRIGGERS, canvas_service.py:233, db/schedules/analytics.py:52 (label), caller_wake_service.RESERVED_TRIGGERS. Deciding pull reach / autonomous classification / personless-replay for the new trigger is topology, not a census line. Suggested: mirror operator_ending in all of them (the wake dispatches with request_text="" citing ent#751, which is what _PERSONLESS_REPLAY_TRIGGERS governs).
  2. test_3246_platform_alerts_db::test_clear_platform_mirrors_expire — clear_platform now spawns an ending wake (2 scheduled, test pins 1). Root cause: wake_policy.resolve resolves ON for an agent with no live agent_ownership row (get_wake_on_ending → None, get_operator_resume_override → None → instance default), whereas dev's ent#1108 getter deliberately reads a missing/soft-deleted row as False ("a wake for an agent nobody owns is spend on nothing"). The test agent has no ownership row. Options: (a) the resolver fails closed when no live row exists (needs the mixin to tell "no row" from NULL — the PR's docstring collapses them by design), or (b) the test seeds an explicit OFF. (a) matches both ent#1108 and the PR's own fail-closed stance; your call.

merge-train decisions, author to acknowledge — head d324e3bd0 (two commits, one per decision):

(1) 45637143b — caller_wake mirrors operator_ending in every trigger enumeration (test_4105 census): src/backend/routers/executions.py:43 _VALID_TRIGGERS, src/backend/services/task_execution_service.py:300 _AUTONOMOUS_TRIGGERS, src/backend/services/pull_pilot.py:154 PULL_REACHABLE_TRIGGERS, src/backend/services/skill_gate_service.py:1647 _PERSONLESS_REPLAY_TRIGGERS, src/backend/services/canvas_service.py:234 _OPERATOR_SIDE_TRIGGERS, src/backend/db/schedules/analytics.py:65 _TRIGGER_BUCKETS (bucketed Agent-to-agent, not Operator queue — the spend is delegation-driven), caller_wake_service.RESERVED_TRIGGERS (already there). Pinning tests updated: tests/unit/test_2048_pull_pilot_reach.py (_REACHABLE, adapter_served), tests/unit/test_ec_pull_coordination_properties.py (sampled triggers).

(2) d324e3bd0 — the resolver fails closed for an agent nobody owns (test_3246): src/backend/db/agent_settings/operator_resume.py get_wake_on_ending returns the falsy sentinel NO_LIVE_ROW for an unknown/soft-deleted agent (None stays "live row, NULL"); src/backend/services/wake_policy.py resolves NO_LIVE_ROW → OFF, source no_owner (NULL on a live row still follows the instance default); src/backend/routers/agents.py GET treats the sentinel as mode: default; src/mcp-server/src/types.ts source union gains "no_owner". Tests: new resolver cases (no row, soft-deleted) in test_ent1102_wake_policy.py; test_ent611_native_ask, test_ent747_748_ask_discuss_dismiss, test_ent901_withdraw_ask, test_3247_replace_ask state the owner's switch on the tri-state (their fixture agent has no ownership row).

Evidence: 41-file run (PR's 19 suites, ent#1108 ×2, ent#1066 sink, ent#695 golden, ent#715, 3246, 4105, the trigger-set pins, the ask-sink suites) → 1586 passed, 0 failed. Per file: test_4105 10/10, test_3246 14/14, test_ent695 14/14, test_ent715 120/120, test_ent1108_deferred_wake 54/54, test_ent1108_wake_default 14/14, test_ent1066_credential_sink 54/54. wake.test.ts 22/22. Hand-off deletion mutation (_terminal_side_effects → maybe_wake_caller) still red: 2 wiring tests, reverted.

@vybe
vybe marked this pull request as ready for review November 6, 2026 06:46

@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 2026-11-06: validated at a126581 (lane B+sch) — single Alembic head after re-parent to 0121, 1910 tests pass across 37 files, wiring mutation red, ent#1108 tri-state reconciled in a126581 (author to read).

vybe and others added 4 commits November 5, 2026 23:15
…lumn in the censuses (#4269) — mechanical, per the merge-train note on the PR

- test_ent715_queue_person_fields: `list_pending_ask_ids_for_execution` placed
  in `_NON_ROW_ACCESSORS` (request ids only).
- ent#695 create-mode golden regenerated for the PR's own additive column
  (`TRINITY_ENT695_REGENERATE_GOLDEN=Abilityai/trinity-enterprise#1102`); the
  fixture diff is 12 x `"wake_on_ending": null` on agent_ownership rows, the
  preceding trailing commas, and `_meta.regenerated_by` — nothing else.

Left for the author (needs intent, not a registration): `caller_wake` is in
no trigger enumeration (test_4105), and `wake_policy.resolve` resolves ON for
an agent with no live agent_ownership row (test_3246).

Co-Authored-By: Claude Fable 5.1 <[email protected]>
…rator_ending in every trigger enumeration (#4269)

The new trigger was in no enumeration (test_4105 census red). It now sits
beside `operator_ending` in routers/executions.py `_VALID_TRIGGERS`,
task_execution_service `_AUTONOMOUS_TRIGGERS`, pull_pilot
`PULL_REACHABLE_TRIGGERS`, skill_gate_service `_PERSONLESS_REPLAY_TRIGGERS`
and canvas_service `_OPERATOR_SIDE_TRIGGERS`; `RESERVED_TRIGGERS` already
carried it. The analytics bucket is `Agent-to-agent` rather than
`Operator queue`: the spend is driven by delegation, not by an operator.
Pinning tests updated: test_2048_pull_pilot_reach (`_REACHABLE`,
`adapter_served`), test_ec_pull_coordination_properties (sampled triggers).

Co-Authored-By: Claude Fable 5.1 <[email protected]>
…ed for an agent nobody owns (#4269)

`wake_policy.resolve` resolved ON for an agent with no live agent_ownership
row (both reads None -> instance default), where dev's ent#1108 getter reads a
missing or soft-deleted row as OFF — a wake for an agent nobody owns is spend
on nothing (test_3246 `clear_platform` spawned a wake for an unowned agent).

- db mixin: `get_wake_on_ending` returns the falsy sentinel `NO_LIVE_ROW` for
  an unknown or soft-deleted agent; `None` stays "live row, NULL column".
- wake_policy: `NO_LIVE_ROW` -> OFF with source `no_owner`; NULL on a live
  row still follows the instance default. MCP `types.ts` source union widened.
- routers/agents.py GET: a sentinel is not an owner's voice (`mode: default`).
- tests: resolver no-row + soft-deleted cases; four ask-sink suites whose
  fixture agent has no ownership row now state the owner's switch on the
  tri-state (ent611_native_ask, ent747_748, ent901, 3247).

Co-Authored-By: Claude Fable 5.1 <[email protected]>
One conflict, in `chat_execution_service.py`'s queued receipt: #4257
(#4267) spreads `_queue_wait_fields` into it and ent#1102 spreads
`_wake_on_ending_receipt`. Both kept, #4267's first. Alembic stays at one
head (`0121_agent_ownership_wake_on_ending`); the #4257 and ent#1102 unit
suites pass on the merged tree (198 passed).

Co-Authored-By: Claude Fable 5.1 <[email protected]>
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