Skip to content

fix(wake): an agent's key keeps its execution reads while a wake turn runs (abilityai/trinity-enterprise#1216) - #4472

Merged
vybe merged 3 commits into
devfrom
feature/1216-wake-turn-reads
Nov 12, 2026
Merged

vybe merged 3 commits into
devfrom
feature/1216-wake-turn-reads

Conversation

@webmixgamer

Copy link
Copy Markdown
Contributor

Summary

  • The bug: an agent's key lost every execution read while a wake turn ran on that agent. get_execution_result answered 404 and list_recent_executions, get_schedule_executions and get_agent_activity_summary came back empty, inside the wake turn too. The wake turn was woken to read a result it could not read.
  • The cause: the wake (caller_wake) was dispatched with nobody on its row. turn_actor rates such a row a visitor's turn, and the ledger rule (acting_turn_user_id) gives the agent's key no rows while a share turn with no platform user is running.
  • The fix: the wake carries the callee row's person when that person rates owner on the delegating agent, and nobody otherwise. An owner's own work wakes as an owner turn and reads at the full view. Every other wake is exactly what it was.
  • Also: the wake notice marks a cut of the callee's words with both lengths, and the wake audit row records the standing (owner / none).

What is not changed

A wake for a person the delegating agent is only shared with, for a visitor, and for a person who cannot open the delegating agent still carries nobody and still reads no rows. The callee row's person, rated afresh on the delegator, is not always where the delegating turn stood, and no column records the delegating execution, so that standing cannot be rebuilt without a migration. The same holds for the turns that resume an agent after an answered or ended ask and for the gated-request notice. That work is tracked in the private tracker.

Changes

  • src/backend/services/caller_wake_service.py — _standing_person (rated with the real turn_actor over a row with no source agent; anything unreadable carries nobody), the hand-off to the dispatch, standing on the audit row, the cut marker.
  • tests/unit/test_ent1216_wake_turn_reads.py — new, 13 tests.
  • tests/unit/test_ent1102_caller_wake.py — 3 cut-marker tests.
  • tests/registry.json, docs/memory/architecture/security.md §5d, docs/memory/feature-flows/agent-to-agent-collaboration.md, docs/security-reports/cso-diff-2026-11-11-ent1216-wake-standing.{md,json}.

No migration, no schema change, no new endpoint, no MCP or frontend change.

Behaviour change to know about

Auto-memory follows the existing owner rule, so it is on for an owner-standing wake. It was off for every wake.

Evidence

Unit, on a real database. The new test drives the real /task admission (which writes the callee row), the real maybe_wake_caller, the real ledger (get_running_turn_attribution) and the real acting_turn_user_id / viewer_row_scope. Only the wake's dispatch is replaced, by a writer that records the row from the kwargs it was handed.

  • Before the fix: 6 of 13 fail, on ('share', 'visitor', None) == ('owner', None, None) and -1 is None.
  • Mutation 1, the hand-off of the person removed: 5 red.
  • Mutation 2, every person carried: 4 red (shared person, cannot-open person, deleted user, audit).

Live, v1.0.5-rc2 (af465288a) plus this change, PostgreSQL. With the delegating agent's own key:

Without the fix With the fix
Wake row nobody on it, rated share/visitor carries the owner, no email, rated owner
get_execution_result while the wake runs 404 success with the response
list_recent_executions while the wake runs receipt missing receipt listed
Audit row — standing: owner

Regression. 60 related unit files: 2,727 passed; the only failures are 39 in test_ent926_turn_tier_hook.py, which fail the same way on the untouched base on this machine. Pinned guards (301 files, CI flags, seed 12345): no test fails at head that does not also fail at the merge-base.

Security. /cso --diff: no findings at the gate. The one grant is owner standing for a wake whose delegation already ran with the owner's identity. A shared person's turn cannot dispatch as the owner, because the turn header comes from the process environment and wins over a model-typed id.

Test plan

  • cd tests && pytest -p no:randomly unit/test_ent1216_wake_turn_reads.py unit/test_ent1102_caller_wake.py -q
  • Existing wake, tier and read-scope suites unaffected
  • Live repro on a local stack
  • Re-test of the matrix row by someone other than the author, on the next release candidate

Fixes abilityai/trinity-enterprise#1216

🤖 Generated with Claude Code

webmixgamer and others added 2 commits November 11, 2026 13:16
…o the agent's key keeps its execution reads (Abilityai/trinity-enterprise#1216)

When a run an agent delegated ends, the platform wakes the delegator with a
`caller_wake` turn. That turn had nobody on its row, so `turn_actor` rated it
a visitor's turn, and the ledger rule (`acting_turn_user_id`) then hid every
execution row from the agent's own key for as long as the wake ran:
`get_execution_result` answered 404 and the list reads came back empty, inside
the wake turn too, which was woken to read that result.

The wake now carries the callee row's person when that person rates `owner`
on the delegator (`_standing_person`, rated with the real `turn_actor` over a
row with no source agent), and nobody otherwise. The owner's own work wakes
as an owner turn and reads at the full view. A wake for a shared person, a
visitor, a deleted user or a person who cannot open the delegator is the
no-person turn it was. No email goes on the row. The wake audit records the
standing (`owner` / `none`).

Known behaviour change: auto-memory follows the existing owner rule, so it
is on for an owner-standing wake (it was off for every wake).

Tests: `tests/unit/test_ent1216_wake_turn_reads.py` drives the real `/task`
admission, the real `maybe_wake_caller`, the real ledger and
`viewer_row_scope` on a real database. Before the fix it fails with
`('share', 'visitor', None)` and read scope -1. Mutations: removing the
hand-off of the person turns 5 tests red; carrying every person turns 4 red.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
…tyai/trinity-enterprise#1216)

The notice quotes the callee's own words capped at 2,000 characters. The cut
was silent, so a longer answer read as if the run itself had stopped
mid-sentence. When the cap cut the text, the frame now ends the quote with
`[cut here: the first N of M characters]`. The cut is measured after
redaction, so a text that fits once its credentials are redacted carries no
marker.

Tests: three cases in `tests/unit/test_ent1102_caller_wake.py` (cut, fits,
measured after redaction).

Co-Authored-By: Claude Fable 5.2 <[email protected]>
@webmixgamer
webmixgamer requested a review from dolho November 11, 2026 13:17
@webmixgamer

Copy link
Copy Markdown
Contributor Author

@vybe this is the fix for the wake-turn read blindness you reported. Two things need your call: whether the shape is right (owner-standing wakes only; every other wake unchanged), and whether it goes into the next release candidate. The open questions are on the issue.

@dolho dolho 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.

/review — approve

Scope: clean. The diff does what abilityai/trinity-enterprise#1216 asks: an owner-tier wake carries the callee row's person, and every other wake carries nobody as before. The cut marker and the standing audit field are small and the PR body names them. Docs are updated (security.md §5d, the agent-to-agent flow).

Test coverage

changed symbol executed by live consumer verdict
_standing_person test_ent1216_wake_turn_reads.py: owner, admin, shared, cannot-open, deleted, nobody, and turn_actor raising maybe_wake_caller → dispatch_and_await_terminal(source_user_id=…) ✅ executed. Real /task admission, real ledger, real acting_turn_user_id / viewer_row_scope, on a real DB
standing on the audit row test_the_audit_names_the_standing_and_never_the_person _audit → platform_audit_service.log ✅
_summary_of / cut marker 3 new tests in test_ent1102_caller_wake.py, including the after-redaction case _framed_wake ✅

Fix mutation: the PR reports 6 of 13 red with the fix reverted, 5 red with the hand-off removed and 4 red with every person carried. I read the tests and they are behavioural, not source-text. I did not re-run them locally because this machine has no pytest env; CI pytest (head) was still pending when I approved.

Critical

None.

Informational

  • I1 (confidence 5/10, pre-existing class): turn_origin_user_id returns the key owner's id whenever acting_turn is None, meaning no X-Trinity-Execution-Id header or manual. Say a share-person or visitor turn on A delegates without the header, for example a shell curl with the agent key. The callee row then records the owner, and after this PR the wake is also rated owner and reads at the full view. Two things limit the impact: the wake's output goes back to A's own turn, not to the visitor, and while the visitor's own turn is still RUNNING the ledger still narrows. The root cause is in turn_origin_user_id, not here, so this is not a blocker. It may be worth noting as a residual in §5d.
  • I2 (nit): the cut marker [cut here: the first N of M characters] mixes two measures. N is the length after redaction and M is the raw length, so when redaction shrinks the text, N + (M − N) does not describe the same text. Labelling M as "raw" would remove the ambiguity.

Clean categories

SQL (no new SQL), concurrency (pure read, then dispatch kwargs), auth (fails closed to nobody on any error; tier is computed with the real turn_actor, so the delegation rule cannot lift it), credentials (summary is still sanitized before the cap; no email on the row, per ent#886), enterprise disclosure (no paid-module detail in the docs), no new enum values.

LGTM. Approving.

Conflict in tests/registry.json only (both sides appended an entry);
rebuilt from the merge stages: dev's entries plus this branch's new one.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
@vybe
vybe merged commit d5196ba into dev Nov 12, 2026
26 checks passed
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.

4 participants