Repository navigation
test(operator-queue): pin the readback's person-row 404 and census every door and read (abilityai/trinity-enterprise#780) - #3820
Conversation
…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
left a comment
There was a problem hiding this comment.
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_routerGET; _for_principaltreating the system key as a person;get_queue_itemreturning 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
ifonis_about_a_person(<row from db.…>), with oneraise HTTPException(404)above the firstreturn); - 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, butmetadata.tables['operator_queue']andsa.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_doorsfixture sets it by hand instead of callingsystem_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 withtest_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.pyandtest_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]>
Summary
GET /api/agents/{name}/operator-queue/{request_id}, MCPget_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 togate-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.trinity-system, over both heads-ups filed through their real emitters. The issue's own test becomes theget_my_askcases.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.test_1677.get_my_ask404s a row about a person (is_about_a_personkept)get_my_askcases and §6test_no_door_hands_a_machine_a_row_about_a_person[*-get_my_ask-collision|report]readbackjoins the routesTestPlatformRowsAboutAPersondrivesDOORSin that class drives all 10 driven handlerstrinity-systemown_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.mdTest Plan
cd tests && pytest unit/test_ent715_queue_person_fields.py: 120 passed under seeds 12345, 67890, 99999, 1, 4242 and 31337.test_ent4*totest_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.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}]plustest_every_door_that_returns_rows_consults_the_one_predicate.raise_my_asksweep cases._for_principaldropped from its own machine filter: the fourget_queue_itemsweep cases._for_principaldropped from a door, and the person check moved below the read: the §6 tests.404 {"detail":"Ask not found"}for a realworkspace-problem-row, a realportal-inbox-collision-row, a realgate-note-row and a made-upworkspace-problem-nope. All four bodies were identical, and admin still sees those rows inGET /api/operator-queue.Follow-ups
withdraw_askanswers 403workspace_onlyfor an agent whose owner is Workspace-only, because the route is missing from_AGENT_SELF_ROUTES. Not fixed here.Fixes abilityai/trinity-enterprise#780
🤖 Generated with Claude Code