Skip to content

test(operator-queue): pin the readback's person-row 404 and census every door and read (abilityai/trinity-enterprise#780) - #3820

Merged
vybe merged 3 commits into
devfrom
feature/780-readback-person-rows
Oct 21, 2026
Merged

vybe merged 3 commits into
devfrom
feature/780-readback-person-rows

Conversation

@webmixgamer

Copy link
Copy Markdown
Contributor

Summary

  • The agent's own readback (GET /api/agents/{name}/operator-queue/{request_id}, MCP get_my_ask) already refuses an operator-queue row about a person. The check landed with trinity-enterprise#751 (feat(skills): gated skills — the approval comes before the agent sees the request (abilityai/trinity-enterprise#751) #3208), but nothing pinned it: narrowing it to gate- rows would have left every test green while the inbox-collision alert and the problem report leaked again. Tests only. No product code and no migrations.
  • Door sweep: every handler on both queue routers is driven with a real minted agent key and the real system key acting as trinity-system, over both heads-ups filed through their real emitters. The issue's own test becomes the get_my_ask cases.
  • Door census (§6): every handler is placed, and the bug(auth): agent-scoped keys can toggle their own agent's autonomy — PUT /api/agents/{name}/autonomy lacks reject_agent_principal #2996 route walker and the live routers must agree on the set. Every door that returns rows must consult is_about_a_person, checked by the shape of the code. A person-only door must refuse before it reads the row, and no other door may read rows itself.
  • Read census (§7): every read of a queue row in the backend is classified, along with every queue accessor, ending observer, table spelling and data module. It is the read-side twin of test_1677.
AC Where
1. get_my_ask 404s a row about a person (is_about_a_person kept) shipped in #3208; pinned by the sweep's get_my_ask cases and §6
2. The issue's test adopted, both emitters, real emitters test_no_door_hands_a_machine_a_row_about_a_person[*-get_my_ask-collision|report]
3. readback joins the routes TestPlatformRowsAboutAPerson drives DOORS in that class drives all 10 driven handlers
4. A census fails on a door that skips the rule §6, plus the wider §7
5. The system key acting as trinity-system the own_doors[system-key] fixture (a real minted key with system scope)

Changes

  • tests/unit/test_ent715_queue_person_fields.py: 56 new tests, 120 in the file.
  • tests/registry.json: this file's description.
  • docs/memory/feature-flows/operating-room.md: the readback's 404, the Testing entry and a revision row.
  • docs/memory/learnings/2026-10-19-a-read-census-must-follow-every-exit-of-the-row.md

Test Plan

  • cd tests && pytest unit/test_ent715_queue_person_fields.py: 120 passed under seeds 12345, 67890, 99999, 1, 4242 and 31337.
  • 202 neighbouring unit files (test_ent4* to test_ent9*, test_3242*, test_3246*, test_3247*, test_2996*, test_1677*, test_1854*), run with and without this file under seeds 12345 and 67890: no failure unique to it.
  • Mutation: 16 call-site mutants, each restored byte-identical afterwards. Each one turns the intended test red:
    • The readback check reverted, kept-but-dropped, narrowed inside the if, and shadowed by a local function: test_no_door_hands_a_machine_a_row_about_a_person[{agent,system}-key-…get_my_ask-{collision,report}] plus test_every_door_that_returns_rows_consults_the_one_predicate.
    • The raise replay lookup moved above validation: the four raise_my_ask sweep cases.
    • _for_principal dropped from its own machine filter: the four get_queue_item sweep cases.
    • A new unplaced handler, _for_principal dropped from a door, and the person check moved below the read: the §6 tests.
    • A new unclassified read, a new accessor, the table reached through a re-export, a new ending observer, and a new data module importing the table: the §7 tests.
  • Live check on localhost (dev), 2026-10-19: with an agent's own key, the readback answered 404 {"detail":"Ask not found"} for a real workspace-problem- row, a real portal-inbox-collision- row, a real gate-note- row and a made-up workspace-problem-nope. All four bodies were identical, and admin still sees those rows in GET /api/operator-queue.

Follow-ups

Fixes abilityai/trinity-enterprise#780

🤖 Generated with Claude Code

webmixgamer and others added 2 commits October 19, 2026 17:45
…ery door and read (trinity-enterprise#780)

The agent's own readback (`get_my_ask`) already refuses a row about a person
on dev: the check landed with trinity-enterprise#751. Nothing pinned it. A
narrowing to `gate-` rows would have left every test green while the inbox
collision alert and the problem report leaked again. Tests only; no product
code changes.

- Door sweep (`TestPlatformRowsAboutAPerson`): every handler on both queue
  routers is driven with a real minted agent key and the real system key
  acting as trinity-system, over both heads-ups filed through their real
  emitters.
  - The readback and the item route answer a heads-up exactly like an
    unknown id.
  - Both lists leave the heads-ups out and still list the key's own ask.
  - respond, cancel and bulk-cancel refuse a machine by name.
  - A raise with a heads-up's id is refused 422 before the replay lookup.
  - A withdraw is a 404 that leaves the row pending.
  - /stats returns numbers only.
  The issue's test is the `get_my_ask` cases (AC2, AC3, AC5).
- §6 door census (AC4): every handler is placed, and the #2996 walker and
  the live routers must agree on the set. Every door that returns rows must
  consult `is_about_a_person` (checked by the shape of the code), and a
  person-only door must refuse before it reads.
- §7 read census: every read of a queue row in the backend is classified,
  along with every queue accessor, ending observer, table spelling and
  data module (the read-side twin of test_1677).

Mutation: 16 call-site mutants, each red for the intended test.
- Readback check: reverted, name kept with the branch dropped, narrowed and
  shadowed. Each turns the four get_my_ask sweep cases red, plus the
  predicate census.
- A new unplaced handler.
- `_for_principal` dropped from a door and from its own filter.
- The person check moved below the read.
- The raise replay lookup moved above validation (four raise sweep cases).
- A new unclassified read, a new accessor, the table reached through a re-export,
  a new ending observer and a new data module importing the table.
Seeds 12345, 67890, 99999, 1, 4242 and 31337 all pass. 201 neighbouring unit
files run with and without this file show no failure unique to it.

Fixes Abilityai/trinity-enterprise#780

Co-Authored-By: Claude Opus 5.5 <[email protected]>

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

Approving. I confirmed the product fix is the one from #3208 (c508a63c7), still on dev in get_my_ask.

At eb3efeae7 the file passes 120/120 with -p no:randomly and under seeds 1, 12345, 98765 and 7. It also passes 120/120 against current origin/dev source. tests/lint_sys_modules.py is OK.

I broke the product code in these ways, and each one turned the suite red:

  • the predicate dropped from get_my_ask;
  • a 403 instead of the 404 (the enumeration differential);
  • a new raw-row agent_router GET;
  • _for_principal treating the system key as a person;
  • get_queue_item returning the raw row;
  • a new service reader;
  • a raw-row handler in routers/agents.py.

Dropping the gate- prefix stays green here but goes red in test_ent751_gate_dispatch.py, which is expected.

The real-key arms really do run the auth dependencies: no overrides, both routers, agent key and system key.

One small fix. Please do it here or in a quick follow-up:

The §6 shape check fails on harmless refactors and prints only the handler name. The assert is assert _refuses_a_person_row_first(fn, idx), key (tests/unit/test_ent715_queue_person_fields.py:781), and _raises_404 (:707) accepts only keyword status_code=404. I made three behaviour-preserving edits to get_my_ask, and each one turns test_every_door_that_returns_rows_consults_the_one_predicate red:

  • moving the lookup into a helper;
  • wrapping the predicate in a helper;
  • writing HTTPException(404, "Ask not found") positionally.

Each time the output is just the handler key, so the next author has to reverse-engineer the AST rule from a docstring. Two changes would fix it:

  • put the expected shape in the assert message (an if on is_about_a_person(<row from db.…>), with one raise HTTPException(404) above the first return);
  • accept a positional 404.

Non-blocking notes:

  • The table-read detector misses one spelling. It misses a function-local alias (def f(): from db import tables as t; return t.operator_queue). Module-level aliases are caught, but metadata.tables['operator_queue'] and sa.table('operator_queue') are also missed. Nothing uses these spellings today. One more meta-test spelling would close it.
  • The system scope is set by a copied UPDATE. The own_doors fixture sets it by hand instead of calling system_agent_service._set_system_scope. It matches today but can drift.
  • §7 goes wider than AC4. It covers the whole backend, not only routers/operator_queue.py, and pins its list both ways. Any future PR that adds, renames or moves a queue-row reader has to edit this file. That's in line with test_1677, so it's fine. Worth knowing that the labels are self-asserted: it catches an unclassified read, not a mislabelled one.
  • Count nit in the learnings fragment. It says "45 sites". The scan finds 55 call sites, which is 45 qualnames.
  • My wider run had failures that aren't from this PR. 137 related unit files under seed 4242 gave 3 failures and 50 errors, in test_ent443_rooms_oss_core.py and test_ent79_portal_exposure.py. Replaying the same order with dev's version of this file gives the identical result, so it's existing order-dependence.

…and accepts a positional 404 (review)

Review follow-up on trinity-enterprise#780.

- The §6 shape check now states the expected shape when it fails, instead
  of printing only the handler key: an `if` on the module's own
  `is_about_a_person(row)`, with `row` from a `db.` lookup in the handler, and
  one `raise HTTPException(404, ...)` above the first `return`. It also says
  that moving the lookup or the predicate into a helper changes the rule.
- `HTTPException(404, ...)` written positionally is accepted, like the
  `status_code=404` keyword.
- The table-read detector also sees a function-local alias
  (`from db import tables as t`), `metadata.tables['operator_queue']` and
  `table('operator_queue')`, each with a meta-test case. An audit
  `target_type='operator_queue'` literal is the negative control.
- Learnings fragment: 55 call sites in 45 functions, not "45 sites".

Checked with the reviewer's three refactors as mutants. The positional 404
passes. The lookup moved into a helper and the predicate wrapped in one both
fail, with the new message. A function-local alias in a real service now fails
the bypass check. The readback mutants (reverted, kept-but-dropped, narrowed,
shadowed) are still red.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@vybe
vybe merged commit 04962a2 into dev Oct 21, 2026
24 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.

3 participants