Repository navigation
feat(asks): rows the platform addresses reach their addressee; a project attachment on asks - #4148
Merged
Merged
Conversation
…; one person off a shared row (abilityai/trinity-enterprise#981) C4a of the ent#981 plan (public half, checkpoint 1 of 2). The Workspace Inbox fenced every ask on the raising agent's roster. That is right for an agent's own asks and wrong for a row the platform raised about the person: the platform chose this row's addressee; the roster was never its fence, and such a row is raised under a platform agent nobody is shared with. - One narrow reserved sub-family, `gate-addressee-only-reach-` (`ADDRESSEE_REACH_ID_PREFIXES`, inside the ent#980 addressee-only family, under `gate-` so no agent can mint it), reaches its addressee by address alone when ALL of: the prefix, the row's own `raised_by = 'gate'`, and the viewer as its single addressee or one of its `resolved_to`. The condition is SQL, OR'd beside the access set in `_list_conditions`, for the page AND its count; the `if allowed:` short-circuit no longer hides a viewer on no roster. `_owned_ask` applies the same rule (`is_addressee_reach`), so a non-addressee gets the uniform 404. The wider `gate-addressee-only-` family keeps its roster fence. - `ask_service.drop_addressee(ask_id, email, *, reason)`: one person off a row's address — removed from `resolved_to`, the single addressee cleared when it named them — compare-and-set on both columns; the row stays for the others. Audit carries ids and the reason, never the address. - `_request_id_prefixed_ci`, the positive twin of the existing negative prefix match, sharing one normalisation expression. - Read-side census (test_ent715): the new accessor placed, the two Workspace readers' reasons name the new exit. Tests: tests/unit/test_ent981_addressee_reach.py (15). Mutations, each restored from a scratch copy: prefix condition dropped -> the wider-family fence test red; `raised_by` dropped (SQL) -> the not-raised-by-gate test red; `raised_by` dropped (door predicate) -> the same test plus the prefix test red; door ignores the reach -> the two open-it-off-roster tests red; drop_addressee writes nothing -> the three drop tests red. The addressee match is guarded twice (the branch's own match and the list's addressee filter): dropping either alone stays green, dropping both reds ten tests. Co-Authored-By: Claude Fable 5.1 <[email protected]>
…own context; the Inbox projects the project (abilityai/trinity-enterprise#981)
C4b of the ent#981 plan (public half, checkpoint 2 of 2).
- `raise_ask(attach_chat=True, platform_context=None)`, gate raises only
(ValueError for an agent's raise, like `addressee`). `attach_chat=False`
skips the Workspace attachment, so a row the platform raises about a person
under a platform agent opens no Main chat and carries no `chat_id`.
`platform_context` merges into `context` AFTER the agent-content strip and
only for keys in `_PLATFORM_CONTEXT_KEYS`, so the platform is the one
writer of those keys.
- `_PLATFORM_CONTEXT_KEYS` gains `workspace_project_id`,
`workspace_project_task`, `workspace_project_event`: stripped from agent
content at both ingestion boundaries (native and file) and ignored by the
replay comparison.
- `WorkspaceAsk.project` — `{id, task_id, event}` from the platform keys only;
None without a project id.
- MCP: `list_project_tasks` and `get_steward_digest` descriptions say each
task carries when its owner was last reached (text only; the payload passes
through).
Tests: tests/unit/test_ent981_addressee_reach.py (28, with C4a's 15).
Mutations, each restored from a scratch copy: the three keys dropped from
`_PLATFORM_CONTEXT_KEYS` -> six tests red (both strip boundaries, the merge,
the projection); merge for every key instead of platform keys only -> the
platform-keys-only test red; `attach_chat` ignored -> the no-chat test red.
Co-Authored-By: Claude Fable 5.1 <[email protected]>
…red row (abilityai/trinity-enterprise#981) C5 of the ent#981 plan (public docs). - workspace-inbox.md: new section — a reserved gate-raised family reaches its addressee by address (SQL for page and count, and `_owned_ask`), the wider addressee-only family keeps its roster fence; `drop_addressee`; `attach_chat` / `platform_context` on a gate raise; the `project` field and the platform-only keys it reads. - api-endpoints.md: one paragraph in the Operator Queue section pointing there. - requirements/core-agent.md §5.40: one bullet. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…e#981) Co-Authored-By: Claude Opus 5.5 <[email protected]>
trinity-ability
approved these changes
Nov 1, 2026
trinity-ability
left a comment
Contributor
There was a problem hiding this comment.
PR Validation Report — #4148
Branch: feature/ent981-task-reaches-owner → dev · 13 files (+807/−19) · tip 34c9d3add · Lane B (no auth/credential/CI/image paths; no schema)
Read together with its private counterpart, which merges first.
| Category | Status | Notes |
|---|---|---|
| Commit messages | ✅ | 4 conventional commits (feat/feat/docs/test) |
| Base branch / size | ✅ | dev; 13 files |
| Status auto-promotion | No closing keyword, on purpose: the counterpart PR closes abilityai/trinity-enterprise#981. That is cross-tracker, so set status-in-dev by hand after merge. The issue still reads status-ready, not status-in-progress. |
|
| Requirements / architecture / flow | ✅ | core-agent.md, api-endpoints.md, workspace-inbox.md |
| Security §4.1–4.10 | ✅ | No keys, emails, IPs, mode flips or host paths. The enterprise-docs-guard pattern finds nothing in the added lines. |
| Build / config packaging | ➖ | No new package dir, no new env var |
| Structural review | ✅ | The reading review found one issue (registry entry), fixed in 34c9d3add. /cso --diff found nothing. |
| Merge gate (Tier 1) | ✅ | All checks green: pytest (head), regression diff, pg-migrations, schema-parity, CodeQL. dev-ci reads success on dev, and no dev-ci red issue is open. |
| Test adequacy | ✅ | 28 new tests cover the non-addressee 404, the wider family keeping its fence, the non-gate row, a row addressed to nobody, and paging and count together |
| Product fit | ✅ | Matches the stated ruling: a narrow reserved prefix, nothing live until the private half raises one, UI explicitly out |
Execution coverage (§5.4)
| changed symbol | executed by | live consumer | verdict |
|---|---|---|---|
_list_conditions reach branch |
test_ent981_addressee_reach.py::TestReachByAddress (list + count) |
client_portal/asks/service.py::list_asks_page |
✅ |
_owned_ask reach OR |
same file (open / 404) | answer and context doors | ✅ |
drop_addressee (db + service) |
same file | private caller (counterpart PR) | ✅ |
raise_ask(attach_chat, platform_context) |
same file (gate-only ValueError, strip-then-merge) | private caller | ✅ |
_project_attachment / WorkspaceAsk.project |
same file | _project |
✅ |
test_ent715 census rows |
guard | the read-side census itself | ✅ (two description strings rewritten, nothing loosened) |
Run locally in the PR worktree: the new file plus the census give 148 passed. I also ran a mutation: replacing raised_by == "gate" in the SQL branch with true() turns test_a_row_not_raised_by_the_gate_keeps_its_roster_fence red. The prefix sits under the reserved gate- family, which an agent raise is refused, and the raised_by column is checked separately. So an agent can't mint a reach row.
Warnings (non-blocking)
- The reach doesn't check the ask type.
_owned_asknow opens a reach row off-roster, anddiscuss_askgoes through_owned_ask. So a reach row of typequestionorapprovalcould start a discussion chat with an agent the person isn't shared with. Today's only producer raisesalert, which is refused as not discussable, so nothing is reachable now. Consider either restricting the reach toalertor havingdiscuss_askrefuse a reach row, so a later producer can't open that path by accident. _discussed_inand_recent_answersstill use the roster and ignore the reach. That is consistent with the no-chat rule, and noted only for whoever extends this later.- Merge order and overlap are recorded in the PR body: the private half first, then this PR, then a submodule pin bump. A test-merge with another open PR conflicts in
src/mcp-server/src/tools/projects.ts(description text only).
Recommendation
APPROVE. Not marked ready and not merged; the operator owns the merge order.
vybe
marked this pull request as ready for review
November 1, 2026 07:35
This was referenced Nov 2, 2026
vybe
pushed a commit
that referenced
this pull request
Nov 4, 2026
…hole modules (#3785, PR 3 of 4) (#4038) * fix(operator-queue): the #1677 helper delegates to the platform-alert seam create_bounded_alert(_outcome) keep their signatures and outcome contract and become a thin delegate of platform_alerts.observe, which already composes the per-(agent, type) budget inside its one locked create. The registered type names its kind; the key is read back from the item's id and context by derive_legacy_subject and must resolve to that same kind, else ALERT_FAILED_CREATE. The two kinds whose ids carry no subject (gitignore, problem report) are keyed by the request id minus the kind's prefix. observe's "updated" and "snoozed" pass through; "failed" maps to ALERT_FAILED_CREATE; every refused or failed arm logs [#1677 budget]. ALERT_FAILED_COUNT stays importable and is no longer returned. The budget episode reports through observe as kind alert_budget keyed by the budgeted type: one alert_budget:<type> row per agent, re-read by a later refusal outside the cooldown, ended by its 14-day lifetime. The bucketed id and its own operator_queue_new broadcast are gone; observe sends the thin operator_queue_sync trigger. Ratchet: create_bounded_alert_outcome and _maybe_emit_alert_budget_episode leave EMITTERS_NOT_YET_ON_SEAM; alert_budget gets a NO_CLEAR_SITE reason. Census: both leave _ALLOWED_CALLERS (no direct create left in either). #3254 re-pins (asserted outcomes unchanged): - test_1677_operator_alert_budget: write-observation point. The harness stands in for the seam's create with the same budget arithmetic and runs what observe spawns. Id shape in test_deterministic_bucketed_id_with_reserved_prefix, test_cooldown_knob_zero_never_raises (the subject replaces the bucket) and test_under_cap_creates_item_and_notification (the seam's id). The episode raise now stays in its spawned task, so test_episode_helper_raise_swallowed_refusal_stands reads the delegate's WARNING marker; test_ws_broadcast_failure_swallowed checks the thin operator_queue_sync payload. - test_3130_flood_guard, test_1632_operator_queue_caps: write-observation point. The flood alert still rides the delegate, so its writes, the typed budget read and the I1 fault injection move to the seam's create. - test_3243_atomic_asks::test_a_cap_hold_never_fires_the_flood_alert: write-observation point. Watched at observe, since the oqs.db assertion alone would now pass whether or not the alert fired. Known until the problem report moves in its own commit: nine test_3521_problem_report_comment cases are red here. The delegate files an event-kind row under the seam's id, which the old _attach_comment (keyed on the pre-seam request id) cannot find. New: tests/unit/test_3254_budgeted_alerts.py (registry parity, reach-back imports, the delegate's outcome table over all five budgeted types, the episode's seam properties, R1 for alert_budget). Part of #3254 * fix(operator-queue): the flood alarm reports through the seam and ends with its episode OperatorQueueSyncService._maybe_emit_flood_alert reports through platform_alerts.observe as kind queue_flood keyed by the reason: one pending row per (agent, reason), rewritten in place, budgeted by the seam. #3130's outcome rule is kept on observe's strings: a failed write releases the episode and is retried after the cooldown (I1); created, updated, snoozed and refused consume it. While an episode lasts it is re-read at most every 6 hours, so the kind's 14-day lifetime ends only a row nobody re-read, never a condition that still holds. The refresh time per (agent, reason) is a dict the method creates on the instance for itself; __init__ is unchanged. The flood's own operator_queue_new broadcast (which carried the title) is gone; observe sends the thin operator_queue_sync trigger. The two _sync_agent statements where an episode ends (_flood_episodes.discard for oversize_file and ingestion_cap) become calls to the new _end_flood_episode, which ends the episode and, only when one was running, ends its alert as the platform through platform_alerts.clear. A cycle with no episode costs no read. Ratchet: _maybe_emit_flood_alert leaves EMITTERS_NOT_YET_ON_SEAM; queue_flood's clear site is _end_flood_episode. No re-pin in this commit: the #3130 and #1632 harnesses were moved to the seam's create in the previous commit and keep their results. Tests: the flood through the real _sync_agent poll for 30 simulated days with the real expiry sweep (one row, re-read every 6 hours, ended as the platform when nothing is held), no read without an episode, two reasons two subjects, I1 on the real seam, a person's ending standing through the re-read and the clear, the thin trigger, R1 for queue_flood. Part of #3254 * fix(execution): the effect guard and missing-skill alarms report through the seam _on_unguarded_effect reports a refused effect through platform_alerts.observe as kind effect_unguarded keyed "<effect_type>:<reason>": one row per agent, effect and reason, rewritten by each further refusal, ended by its lifetime (nothing observes an agent starting to send ids). The send is refused whatever the alarm's outcome. _alert_skill_not_found reports through observe as kind skill_not_found keyed by the truncated command: one row per agent and command, re-read by each scheduled run. The paired notification is sent only on "created": a repeat of a pending command is an "updated" reading and already had one; refused, failed and snoozed wrote no new row. The pre-create dedup read stays and now matches only a pending pre-#3246 row (no subject), which keeps standing for its command until the upgrade sweep stamps it; a seam row is re-read through observe, where a repeat is never refused at the cap. task_execution_service.py: only _alert_skill_not_found changes. Its module-level utc_now_iso import is now unused and is left in place. Ratchet: _on_unguarded_effect and _alert_skill_not_found leave EMITTERS_NOT_YET_ON_SEAM; skill_not_found gets a NO_CLEAR_SITE reason (only the dispatch path could see a command resolve, and there the detector cannot tell "resolved" from "not a slash command"). #3254 re-pins (asserted outcomes unchanged): - test_1677_operator_alert_emitters:: test_skill_not_found_emitter_is_routed_not_allowlisted: the module must call platform_alerts.observe naming "skill_not_found" (AST), the seam that composes the budget, instead of mentioning create_bounded_alert. - test_2392_effect_guard_fail_closed: write-observation point and id shape. The alarm is recorded at platform_alerts.observe instead of a sys.modules stub of operator_queue_service, which lacks the names the seam reaches back for. The id prefix is asserted on the kind; the at-budget case returns the seam's refused_at_budget. - test_ent879_aauth_resource_route (the refused-call case): the dead create_bounded_alert patch moves to platform_alerts.observe. Tests: the effect refusal's seam properties and lifetime; the missing skill's one row per command, no notification on a repeat, a pre-seam row still standing, no notification at the cap; R1 for both kinds; the other shape, the clock 30 days ahead: a full skill_not_found budget frees itself through the real expiry sweep and a new command files. Part of #3254 * fix(git-sync): the gitignore sweep's alert is one row per change set _emit_gitignore_untracked_alert reports through platform_alerts.observe as kind gitignore_untracked, which stops being an event kind (platform_alerts.py: event=True dropped). It is a must-act kind: no lifetime, never ended by the platform. It is keyed by the change itself: a 32-hex digest of the canonical, direction-tagged set of paths the Push untracked and newly un-ignored (sorted removed paths, the exact removed count, sorted un-ignored paths). A repeat of the same set collapses onto one row; a different set, a different total behind a capped list, or the same path in the other direction is a different row. Keying per agent would let a later Push overwrite an earlier Push's path list on a pending must-act alert, which #2529 calls the surface that outlives the session. The legacy prefix keeps its _no_subject parser, so pre-existing rows stay pending until a person acts. Ratchet: _emit_gitignore_untracked_alert leaves EMITTERS_NOT_YET_ON_SEAM. #3254 re-pins (asserted outcomes unchanged): - test_2529_gitignore_precedence: write-observation point and id shape. The alert is watched at platform_alerts.observe (the two create.await_count == 0 checks would otherwise have gone vacuous); the per-agent id prefix is asserted on the kind, with the 32-hex key. - test_3246_platform_alerts_leaf::test_event_kind_has_no_subject: gitignore_untracked is a condition now, so it is asserted keyed and the problem report stays the event example. Tests: a repeated set is one row that never expires; distinct sets and a capped list with another total stay distinct; the direction tag holds; a person's ending stands; the 30-day case now also shows the gitignore row still pending. Part of #3254 * fix(workspace): the problem report is one seam row per person, target and day raise_problem_report reports through platform_alerts.observe as kind workspace_problem_report, which stops being an event kind (event=True dropped). It is keyed by the 32-hex digest _problem_report_id already computes: one row per person per target per UTC day, the "never duplicates" rule its docstring states. A person must act on it, so it never expires and the platform never ends it. The workspace-problem- id prefix is kept, so ent#866's owner-only rule and the machine-key "about a person" exclusion still hold. It returns True when the row was created or updated, False when snoozed, refused or failed. #3521's words-only rule moves under the seam's lock. observe gains keep_text (passed through database.create_platform_operator_queue_item to create_platform_item and _touch): with keep_text and a pending row, the reading only counts (last_seen_at, seen_count, expires_at) and the title, question, priority and context stand. The bare click passes keep_text, a reading with words does not. The click and the comment are two background requests that meet on one row inside the per-agent lock, so either order ends with the words. With no pending row the reading files as usual. update_pending_problem_report (database.py, db/operator_queue.py) and the nested _attach_comment are removed: one write path. Ratchet: raise_problem_report leaves EMITTERS_NOT_YET_ON_SEAM, which fixes the nine test_3521 cases the delegate commit left red. #3254 re-pins (asserted outcomes unchanged): - test_3521_problem_report_comment: the acknowledgement fixture goes through ask_service.answer (fixture shape; a raw status UPDATE carries no person ending for the snooze to read); the accessor test asserts the same type guard at the seam (a foreign row under the report's old id is never written); the lost-race test injects the bare click's whole reading, in its own thread, before the comment's locked create. - test_ent499_problem_report: write-observation point. The fake moves from create_bounded_alert to platform_alerts.observe; the routing AST test asserts the call to observe. - test_ent715_queue_person_fields: update_pending_problem_report leaves _NON_ROW_ACCESSORS (the accessor census forbids a stale entry). - test_3246_platform_alerts_leaf::test_event_kind_has_no_subject: no built-in kind is an event any more, so the property is pinned on a kind registered for the test, and both former events are asserted keyed. test_ent866_problem_report_owner_only is unchanged. Tests: keep_text at the sink, both interleavings keeping the words, one must-act row per person, target and day, the owner-only prefix, the delegate and the emitter landing on one subject, a person's ending not rewritten or reopened; the 30-day case now also shows the report still pending; the five-type admission test asserts every kind keyed. Part of #3254 * fix(operator-queue): decide a platform alert's snooze under the create's lock observe checks the snooze before the create's lock. Two moments let a person's ending slip past that check: an acknowledgement after observe read the pending row but before the locked create (the locked find then misses), and one between the locked find and _touch's compare-and-set (the lock covers creates, not respond_to_item, so the CAS loses). Either way the create fell through to an insert, and the alert a person had just ended was back at once. Before this batch most of the moved writers had a deterministic id that could not re-file after an ending, so the moves would otherwise ship that regression. create_platform_item gains snooze_since and a snoozed predicate. On the insert path, after a missed find or a lost CAS and inside the same locked transaction, it reads the newest person-ended row for the subject through the transaction's own connection (the public lookup opens another one) and returns {"outcome": "snoozed"} without inserting when the predicate says so. observe passes the standard 7-day window, computed on its own rather than from the pre-lock check's conditionally assigned cutoff, and lambda ended: _snoozed_by(kind, ended, priority, context). The pre-lock check stays as the fast path. A caller that passes neither keeps the old behaviour. The statement behind the public find_person_ended_by_subject becomes _find_person_ended_by_subject(conn, ...), shared by both reads. Tests: a person's acknowledgement through ask_service.answer, landed (a) between observe's read and the locked create and (b) between the locked find and the CAS, yields "snoozed" and no new row, for the problem report, an inbox collision as registered on dev, and the flood alarm's 6-hourly re-read. All six cases were red before this commit (a fresh row was created) and pass with it. On SQLite, BEGIN IMMEDIATE holds every other writer, so moment (b) lands the ending first and hands both finds the row as it stood just before it; two real workers are not exercised. Review fixes carried here (the earlier commits are left as they are): - OperatorQueueSyncService._maybe_emit_flood_alert: the cooldown is stamped before every reading, the 6-hourly re-read included. A failed re-read released the episode with the cooldown stamp still 6 hours old, so it was retried on the next 5-second cycle. New test: a failed re-read is retried no sooner than the cooldown (red before the fix). - test_3521_problem_report_comment (the lost-race re-pin): asserts the bare click's own request returned True and left a pending, comment-free row before the comment's locked create ran, so the test cannot pass without the interleaving it claims. - gitignore_sweep: states that past the probe's 2,000-line cap the key is the capped list plus the exact total (a full-set digest needs the in-container probe, outside this change). - test_1677_operator_alert_emitters: the census's guidance for an agent-influenceable emitter now points at platform_alerts.observe, not the delegate the #3246 ratchet counts as off the seam. - test_3254_budgeted_alerts: the frozen clock also covers db.operator_queue's ent#815 commit-lag check, which logged spurious errors against the real clock. Part of #3254 * fix(operator-queue): a failed flood re-read keeps the episode, so its end still clears the alert Fresh review of the #3254 budgeted slice (two findings): - A failed 6-hourly re-read of a persisting flood released the episode. If the condition then cleared before the retry, `_end_flood_episode` found no episode and the pending alert waited out its 14-day lifetime, although the code had seen the condition clear (AC 2). A failed re-read now keeps the episode, whose alert an earlier reading filed, and the re-read is retried once the cooldown has passed. A failed first reading still releases the episode (#3130 I1). New test: test_a_failed_reread_keeps_the_episode_so_its_end_still_clears_the_alert (red with the old release branch put back). - AC 8 for two kinds had no "a person's ending is never overwritten" test: `skill_not_found` (the next run is snoozed and sends no notification) and `alert_budget` (a later refusal re-reads the episode and the acknowledgement stands). Both added. * test(operator-queue): the budgeted-alert suite freezes the clock its running methods read In the full serial unit tier, test_1595_sync_health_signals evicts `database` and every `db.*` module from sys.modules and restores only some of them. Afterwards `database.db` and `ask_service.db` run on an older `db.operator_queue` module than the one this suite's clock fixture imports and patches, so the seam's create, the expiry sweep and the answer's compare-and-set read the real clock: rows filed at the frozen T0 read as long expired (five cases red, `AskConflict: expired`, a second flood row). The fixture now also freezes `utc_now_iso` and `datetime` in the globals of the live operations class (R6: patch what the running method reads). Red before: test_1595 followed by this file, 7 failed; green after: 66 passed; the file alone: 55 passed. * refactor(operator-queue): operator_queue_service becomes a package, content unchanged (#3785) The 2,840-line module moves to services/operator_queue_service/__init__.py byte for byte (100% similarity), the first step of the Invariant #1 split. Every `from services.operator_queue_service import X` and `from services import operator_queue_service` resolves as before. Six path-keyed guards name the file by its path, so their key moves with it (the PR #2487 precedent): _NOT_EMITTERS (test_3246), _ALLOWED_CALLERS (test_1677), _ALLOWED (test_1920), _OQS (test_ent715), FLEET_LEVEL_ALLOWLIST (test_ent467), and the source read in test_ent499. Only the key changes; the rule, the reason text and every assertion are untouched. Part of #3785 * test(operator-queue): pin the package's one-binding rules before the split (#3785) tests/unit/test_3785_operator_queue_package.py pins what S2–S6 must keep while they move code out of __init__, each property derived from the tree so no later slice edits it: modules under 800 lines (__init__ exempt, with a staleness check); the import surface src/backend and tests/ read still resolves; no from-import between package modules; one top-level binding per name; import-time reads defined first and the _MARKER_UNCHANGED default the owner's object; a patch of a re-exported name lands where its readers read; one logger identity; owner-exact qualified reads; no submodule named like a package attribute; one rate_limiter; no method on two classes of the composed service; external imports before the first submodule import, and a failed first import, injected at that line, leaves no stale submodule. The AST scans live in _oqs_package_scan.py (pure stdlib, never imports src). The other shape, a fresh install: each consumer imported first in its own interpreter on an empty database raises a bounded alert (created; only main binds a WebSocket manager, and then exactly one thin operator_queue_sync trigger goes out). Outcomes equal on the base. Part of #3785 * refactor(operator-queue): bind the service's collaborators once, in deps.py (#3785) db, _queue_db, principal_reach, get_breaker_redis, ask_service, AgentClient and the audit sink _audit_sync move to services/operator_queue_service/deps.py, bound once and read as deps.X everywhere in the package. They are no longer attributes of the package, so a stale monkeypatch.setattr(oqs, "db", ...) raises AttributeError instead of patching a copy nothing reads (Invariant #1(a), the PR #2487 rule). rate_limiter stays on the package: ask_service reads oqs.rate_limiter.check. Tests that patched a collaborator on the package now patch oqs.deps.X; no assertion, expected value, fixture or control flow changes. The package guard gains G4 (deps binds exactly the collaborators, no other module imports one from its source under any alias or holds one by identity, the package has none) and refuses any reach of a package function's __globals__. Part of #3785 * refactor(operator-queue): the agent-file channel leaves __init__ as whole modules (#3785) The file-channel code moves out of __init__ in four modules, so that the channel's removal (#3438) becomes a file deletion rather than surgery: * filechannel.py: the module helpers (clamping, comparison, the ingestion marker and its _MARKER_UNCHANGED sentinel, delivery matching); * rows.py: what a row says about itself, read on both sides of the package (the audience predicates, the receipt vocabulary, aging); * ingest.py: IngestMixin (_apply_sync_state, _notice_file_channel, _sync_agent); * write_back.py: WriteBackMixin (_apply_delivery_state, _write_responses_to_agent). OperatorQueueSyncService composes the two mixins; the flood methods stay on it and _sync_agent reaches them through self. The moved code is unchanged apart from owner-exact qualifications (_oq.X, filechannel.X, rows.X). Four path-keyed censuses re-key _sync_agent to ingest.py and the write-back source read to write_back.py; two tests move their _validated_addressee patch to oqs.filechannel, its owner. No assertion changes. Part of #3785 * fix(operator-queue): a new flood, budget or untracking episode files after an acknowledgement (#3254) A person's ending of a `queue_flood`, `alert_budget` or `gitignore_untracked` row snoozed every later reading of the subject for 7 days, because none of the three kinds had a material key, so `_snoozed_by` was vacuously true. A runaway agent's second flood, a second budget-full episode and a second untracking Push of the same paths were all silent (review C1; dolho on operator_queue_service.py:2800 and gitignore_sweep.py:335). Each reading now carries an episode marker that the kind lists in its `material_keys`: - queue_flood: `episode_started_at`, stamped when the in-memory episode starts. Re-reads of one episode share it; an episode that starts after the condition cleared does not. - alert_budget: `filled_by`, a digest of the ids of the pending rows filling the budget. Re-reads of the same full budget share it; once a slot frees and a new row fills it, it differs. - gitignore_untracked: `push_id`, one per call. The emitter runs once per Push, so every untracking Push after an acknowledgement files; repeats still collapse onto a pending row. So the snooze silences re-reads of the acknowledged episode for the snooze window and a new episode files at once, which makes the `_maybe_emit_flood_alert` docstring's #3130 edge-trigger claim true again. The budget episode's read of the filling rows is classified in the ent#780 row-reader census as internal. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01HWna79vVmnezQdhpaGRKbw * fix(operator-queue): a flood re-read no longer stamps the per-agent cooldown; the oversize end is pinned (#3254) Review follow-ups on the flood alarm: - dolho on operator_queue_service.py:2778 (webmixgamer agreed): the 6-hourly re-read of one reason's episode stamped the per-agent `_flood_alert_cooldown`, so the other reason's first alert could wait up to one cooldown. The cooldown spaces episodes and a re-read is not one, so it is now stamped only before an episode's first reading. A failed re-read's retry spacing already comes from its refresh time. - webmixgamer I3: the 6-hour re-read spacing is one constant, `OPERATOR_QUEUE_FLOOD_REREAD_SECONDS`, read by the gate and by the failed re-read's retry arithmetic, so the two cannot drift. - webmixgamer I1: a `_sync_loop` case serves an oversized file and then a sane one and asserts the row ends as the platform. It goes red when `_sync_agent`'s `_end_flood_episode(agent_name, "oversize_file")` is replaced by a bare episode discard. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01HWna79vVmnezQdhpaGRKbw * docs(operator-queue): state the fail-open double-leader bound on the flood episode marker (#3254) The episode marker is worker-local. With Redis down the leader lease fails open, so each worker stamps its own episode_started_at and another worker's re-read can file past a person's ending, at most one extra row per extra worker per re-read window. Docstring only; no behaviour change (review L1). Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01HWna79vVmnezQdhpaGRKbw * lint(operator-queue): __init__ drops its file-level F401 waiver (#3785) Review I1 (dolho): the file-level `# ruff: noqa: F401` switched off unused-import detection for all of `__init__`, so a dead import left behind by a later slice or feature would go unflagged. At this PR's head `__init__` still reads every name in its import block, so the waiver hid nothing: `ruff check --select F401` gives 0 findings with it removed. It is dropped, and the block's comment now says that a name `__init__` stops reading keeps its line with a per-line waiver naming why (G13, or read as `oqs.X` from outside). PR2, PR3 and PR4 add those per-line waivers where their moves leave a name unread. `deps.py` keeps its file-level waiver: it is a binding module whose imports are its bindings, so there is no import there F401 could rightly flag. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01HWna79vVmnezQdhpaGRKbw * lint(operator-queue): per-line F401 waivers for what __init__ stops reading (#3785) Review I1 on #4036: PR1 dropped `__init__`'s file-level F401 waiver. This slice's moves leave these names unread in `__init__`; each now carries its own `noqa: F401` with the reason, so F401 keeps checking every other name: - `datetime`, `timedelta`, `timezone`, `Sequence`, `options_cap_violation`, `title_cap_violation`: kept for G13, because `rows`, `filechannel` and `ingest` import them at module level. - `rate_limiter`: O1(d), read as `oqs.rate_limiter` from outside (`ask_service`, tests) and as `_oq.rate_limiter` in `ingest`. - `to_utc_iso`: read as `oqs.to_utc_iso` from outside (`test_ec_operator_queue_properties.py`) and kept for G13. - `from . import filechannel` / `rows`: load the submodules at their G6 point; the names callers read come from the re-export block. The `typing` and `utils.helpers` imports become parenthesised so the waiver sits on the one unread name, not the whole line. They stay single statements: splitting one into two breaks the guard's failed-first-import leg, which injects the failure at the module's first statement. `ruff check --select F services/operator_queue_service/` is clean. With every waiver stripped in a scratch copy, the F401 findings are exactly the waived names, and an injected dead import is still reported. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01HWna79vVmnezQdhpaGRKbw * test(operator-queue): ent#981's file-path case patches `_validated_addressee` on `filechannel` (#3785) test_ent981_addressee_reach arrived from dev (#4148) patching the name on the package. This slice moves `_validated_addressee` to `filechannel.py`, where `_clamp_ingested_item` reads it, so the package no longer binds it: the patch raised AttributeError, and the #3785 G7 guard refused it. Same target as test_ent734's two patches of the same name. --------- Co-authored-by: Claude Opus 5.5 <[email protected]>
AndriiPasternak31
added a commit
that referenced
this pull request
Nov 4, 2026
…d the split is complete (#3785, PR 4 of 4) (#4039) * fix(operator-queue): the #1677 helper delegates to the platform-alert seam create_bounded_alert(_outcome) keep their signatures and outcome contract and become a thin delegate of platform_alerts.observe, which already composes the per-(agent, type) budget inside its one locked create. The registered type names its kind; the key is read back from the item's id and context by derive_legacy_subject and must resolve to that same kind, else ALERT_FAILED_CREATE. The two kinds whose ids carry no subject (gitignore, problem report) are keyed by the request id minus the kind's prefix. observe's "updated" and "snoozed" pass through; "failed" maps to ALERT_FAILED_CREATE; every refused or failed arm logs [#1677 budget]. ALERT_FAILED_COUNT stays importable and is no longer returned. The budget episode reports through observe as kind alert_budget keyed by the budgeted type: one alert_budget:<type> row per agent, re-read by a later refusal outside the cooldown, ended by its 14-day lifetime. The bucketed id and its own operator_queue_new broadcast are gone; observe sends the thin operator_queue_sync trigger. Ratchet: create_bounded_alert_outcome and _maybe_emit_alert_budget_episode leave EMITTERS_NOT_YET_ON_SEAM; alert_budget gets a NO_CLEAR_SITE reason. Census: both leave _ALLOWED_CALLERS (no direct create left in either). #3254 re-pins (asserted outcomes unchanged): - test_1677_operator_alert_budget: write-observation point. The harness stands in for the seam's create with the same budget arithmetic and runs what observe spawns. Id shape in test_deterministic_bucketed_id_with_reserved_prefix, test_cooldown_knob_zero_never_raises (the subject replaces the bucket) and test_under_cap_creates_item_and_notification (the seam's id). The episode raise now stays in its spawned task, so test_episode_helper_raise_swallowed_refusal_stands reads the delegate's WARNING marker; test_ws_broadcast_failure_swallowed checks the thin operator_queue_sync payload. - test_3130_flood_guard, test_1632_operator_queue_caps: write-observation point. The flood alert still rides the delegate, so its writes, the typed budget read and the I1 fault injection move to the seam's create. - test_3243_atomic_asks::test_a_cap_hold_never_fires_the_flood_alert: write-observation point. Watched at observe, since the oqs.db assertion alone would now pass whether or not the alert fired. Known until the problem report moves in its own commit: nine test_3521_problem_report_comment cases are red here. The delegate files an event-kind row under the seam's id, which the old _attach_comment (keyed on the pre-seam request id) cannot find. New: tests/unit/test_3254_budgeted_alerts.py (registry parity, reach-back imports, the delegate's outcome table over all five budgeted types, the episode's seam properties, R1 for alert_budget). Part of #3254 * fix(operator-queue): the flood alarm reports through the seam and ends with its episode OperatorQueueSyncService._maybe_emit_flood_alert reports through platform_alerts.observe as kind queue_flood keyed by the reason: one pending row per (agent, reason), rewritten in place, budgeted by the seam. #3130's outcome rule is kept on observe's strings: a failed write releases the episode and is retried after the cooldown (I1); created, updated, snoozed and refused consume it. While an episode lasts it is re-read at most every 6 hours, so the kind's 14-day lifetime ends only a row nobody re-read, never a condition that still holds. The refresh time per (agent, reason) is a dict the method creates on the instance for itself; __init__ is unchanged. The flood's own operator_queue_new broadcast (which carried the title) is gone; observe sends the thin operator_queue_sync trigger. The two _sync_agent statements where an episode ends (_flood_episodes.discard for oversize_file and ingestion_cap) become calls to the new _end_flood_episode, which ends the episode and, only when one was running, ends its alert as the platform through platform_alerts.clear. A cycle with no episode costs no read. Ratchet: _maybe_emit_flood_alert leaves EMITTERS_NOT_YET_ON_SEAM; queue_flood's clear site is _end_flood_episode. No re-pin in this commit: the #3130 and #1632 harnesses were moved to the seam's create in the previous commit and keep their results. Tests: the flood through the real _sync_agent poll for 30 simulated days with the real expiry sweep (one row, re-read every 6 hours, ended as the platform when nothing is held), no read without an episode, two reasons two subjects, I1 on the real seam, a person's ending standing through the re-read and the clear, the thin trigger, R1 for queue_flood. Part of #3254 * fix(execution): the effect guard and missing-skill alarms report through the seam _on_unguarded_effect reports a refused effect through platform_alerts.observe as kind effect_unguarded keyed "<effect_type>:<reason>": one row per agent, effect and reason, rewritten by each further refusal, ended by its lifetime (nothing observes an agent starting to send ids). The send is refused whatever the alarm's outcome. _alert_skill_not_found reports through observe as kind skill_not_found keyed by the truncated command: one row per agent and command, re-read by each scheduled run. The paired notification is sent only on "created": a repeat of a pending command is an "updated" reading and already had one; refused, failed and snoozed wrote no new row. The pre-create dedup read stays and now matches only a pending pre-#3246 row (no subject), which keeps standing for its command until the upgrade sweep stamps it; a seam row is re-read through observe, where a repeat is never refused at the cap. task_execution_service.py: only _alert_skill_not_found changes. Its module-level utc_now_iso import is now unused and is left in place. Ratchet: _on_unguarded_effect and _alert_skill_not_found leave EMITTERS_NOT_YET_ON_SEAM; skill_not_found gets a NO_CLEAR_SITE reason (only the dispatch path could see a command resolve, and there the detector cannot tell "resolved" from "not a slash command"). #3254 re-pins (asserted outcomes unchanged): - test_1677_operator_alert_emitters:: test_skill_not_found_emitter_is_routed_not_allowlisted: the module must call platform_alerts.observe naming "skill_not_found" (AST), the seam that composes the budget, instead of mentioning create_bounded_alert. - test_2392_effect_guard_fail_closed: write-observation point and id shape. The alarm is recorded at platform_alerts.observe instead of a sys.modules stub of operator_queue_service, which lacks the names the seam reaches back for. The id prefix is asserted on the kind; the at-budget case returns the seam's refused_at_budget. - test_ent879_aauth_resource_route (the refused-call case): the dead create_bounded_alert patch moves to platform_alerts.observe. Tests: the effect refusal's seam properties and lifetime; the missing skill's one row per command, no notification on a repeat, a pre-seam row still standing, no notification at the cap; R1 for both kinds; the other shape, the clock 30 days ahead: a full skill_not_found budget frees itself through the real expiry sweep and a new command files. Part of #3254 * fix(git-sync): the gitignore sweep's alert is one row per change set _emit_gitignore_untracked_alert reports through platform_alerts.observe as kind gitignore_untracked, which stops being an event kind (platform_alerts.py: event=True dropped). It is a must-act kind: no lifetime, never ended by the platform. It is keyed by the change itself: a 32-hex digest of the canonical, direction-tagged set of paths the Push untracked and newly un-ignored (sorted removed paths, the exact removed count, sorted un-ignored paths). A repeat of the same set collapses onto one row; a different set, a different total behind a capped list, or the same path in the other direction is a different row. Keying per agent would let a later Push overwrite an earlier Push's path list on a pending must-act alert, which #2529 calls the surface that outlives the session. The legacy prefix keeps its _no_subject parser, so pre-existing rows stay pending until a person acts. Ratchet: _emit_gitignore_untracked_alert leaves EMITTERS_NOT_YET_ON_SEAM. #3254 re-pins (asserted outcomes unchanged): - test_2529_gitignore_precedence: write-observation point and id shape. The alert is watched at platform_alerts.observe (the two create.await_count == 0 checks would otherwise have gone vacuous); the per-agent id prefix is asserted on the kind, with the 32-hex key. - test_3246_platform_alerts_leaf::test_event_kind_has_no_subject: gitignore_untracked is a condition now, so it is asserted keyed and the problem report stays the event example. Tests: a repeated set is one row that never expires; distinct sets and a capped list with another total stay distinct; the direction tag holds; a person's ending stands; the 30-day case now also shows the gitignore row still pending. Part of #3254 * fix(workspace): the problem report is one seam row per person, target and day raise_problem_report reports through platform_alerts.observe as kind workspace_problem_report, which stops being an event kind (event=True dropped). It is keyed by the 32-hex digest _problem_report_id already computes: one row per person per target per UTC day, the "never duplicates" rule its docstring states. A person must act on it, so it never expires and the platform never ends it. The workspace-problem- id prefix is kept, so ent#866's owner-only rule and the machine-key "about a person" exclusion still hold. It returns True when the row was created or updated, False when snoozed, refused or failed. #3521's words-only rule moves under the seam's lock. observe gains keep_text (passed through database.create_platform_operator_queue_item to create_platform_item and _touch): with keep_text and a pending row, the reading only counts (last_seen_at, seen_count, expires_at) and the title, question, priority and context stand. The bare click passes keep_text, a reading with words does not. The click and the comment are two background requests that meet on one row inside the per-agent lock, so either order ends with the words. With no pending row the reading files as usual. update_pending_problem_report (database.py, db/operator_queue.py) and the nested _attach_comment are removed: one write path. Ratchet: raise_problem_report leaves EMITTERS_NOT_YET_ON_SEAM, which fixes the nine test_3521 cases the delegate commit left red. #3254 re-pins (asserted outcomes unchanged): - test_3521_problem_report_comment: the acknowledgement fixture goes through ask_service.answer (fixture shape; a raw status UPDATE carries no person ending for the snooze to read); the accessor test asserts the same type guard at the seam (a foreign row under the report's old id is never written); the lost-race test injects the bare click's whole reading, in its own thread, before the comment's locked create. - test_ent499_problem_report: write-observation point. The fake moves from create_bounded_alert to platform_alerts.observe; the routing AST test asserts the call to observe. - test_ent715_queue_person_fields: update_pending_problem_report leaves _NON_ROW_ACCESSORS (the accessor census forbids a stale entry). - test_3246_platform_alerts_leaf::test_event_kind_has_no_subject: no built-in kind is an event any more, so the property is pinned on a kind registered for the test, and both former events are asserted keyed. test_ent866_problem_report_owner_only is unchanged. Tests: keep_text at the sink, both interleavings keeping the words, one must-act row per person, target and day, the owner-only prefix, the delegate and the emitter landing on one subject, a person's ending not rewritten or reopened; the 30-day case now also shows the report still pending; the five-type admission test asserts every kind keyed. Part of #3254 * fix(operator-queue): decide a platform alert's snooze under the create's lock observe checks the snooze before the create's lock. Two moments let a person's ending slip past that check: an acknowledgement after observe read the pending row but before the locked create (the locked find then misses), and one between the locked find and _touch's compare-and-set (the lock covers creates, not respond_to_item, so the CAS loses). Either way the create fell through to an insert, and the alert a person had just ended was back at once. Before this batch most of the moved writers had a deterministic id that could not re-file after an ending, so the moves would otherwise ship that regression. create_platform_item gains snooze_since and a snoozed predicate. On the insert path, after a missed find or a lost CAS and inside the same locked transaction, it reads the newest person-ended row for the subject through the transaction's own connection (the public lookup opens another one) and returns {"outcome": "snoozed"} without inserting when the predicate says so. observe passes the standard 7-day window, computed on its own rather than from the pre-lock check's conditionally assigned cutoff, and lambda ended: _snoozed_by(kind, ended, priority, context). The pre-lock check stays as the fast path. A caller that passes neither keeps the old behaviour. The statement behind the public find_person_ended_by_subject becomes _find_person_ended_by_subject(conn, ...), shared by both reads. Tests: a person's acknowledgement through ask_service.answer, landed (a) between observe's read and the locked create and (b) between the locked find and the CAS, yields "snoozed" and no new row, for the problem report, an inbox collision as registered on dev, and the flood alarm's 6-hourly re-read. All six cases were red before this commit (a fresh row was created) and pass with it. On SQLite, BEGIN IMMEDIATE holds every other writer, so moment (b) lands the ending first and hands both finds the row as it stood just before it; two real workers are not exercised. Review fixes carried here (the earlier commits are left as they are): - OperatorQueueSyncService._maybe_emit_flood_alert: the cooldown is stamped before every reading, the 6-hourly re-read included. A failed re-read released the episode with the cooldown stamp still 6 hours old, so it was retried on the next 5-second cycle. New test: a failed re-read is retried no sooner than the cooldown (red before the fix). - test_3521_problem_report_comment (the lost-race re-pin): asserts the bare click's own request returned True and left a pending, comment-free row before the comment's locked create ran, so the test cannot pass without the interleaving it claims. - gitignore_sweep: states that past the probe's 2,000-line cap the key is the capped list plus the exact total (a full-set digest needs the in-container probe, outside this change). - test_1677_operator_alert_emitters: the census's guidance for an agent-influenceable emitter now points at platform_alerts.observe, not the delegate the #3246 ratchet counts as off the seam. - test_3254_budgeted_alerts: the frozen clock also covers db.operator_queue's ent#815 commit-lag check, which logged spurious errors against the real clock. Part of #3254 * fix(operator-queue): a failed flood re-read keeps the episode, so its end still clears the alert Fresh review of the #3254 budgeted slice (two findings): - A failed 6-hourly re-read of a persisting flood released the episode. If the condition then cleared before the retry, `_end_flood_episode` found no episode and the pending alert waited out its 14-day lifetime, although the code had seen the condition clear (AC 2). A failed re-read now keeps the episode, whose alert an earlier reading filed, and the re-read is retried once the cooldown has passed. A failed first reading still releases the episode (#3130 I1). New test: test_a_failed_reread_keeps_the_episode_so_its_end_still_clears_the_alert (red with the old release branch put back). - AC 8 for two kinds had no "a person's ending is never overwritten" test: `skill_not_found` (the next run is snoozed and sends no notification) and `alert_budget` (a later refusal re-reads the episode and the acknowledgement stands). Both added. * test(operator-queue): the budgeted-alert suite freezes the clock its running methods read In the full serial unit tier, test_1595_sync_health_signals evicts `database` and every `db.*` module from sys.modules and restores only some of them. Afterwards `database.db` and `ask_service.db` run on an older `db.operator_queue` module than the one this suite's clock fixture imports and patches, so the seam's create, the expiry sweep and the answer's compare-and-set read the real clock: rows filed at the frozen T0 read as long expired (five cases red, `AskConflict: expired`, a second flood row). The fixture now also freezes `utc_now_iso` and `datetime` in the globals of the live operations class (R6: patch what the running method reads). Red before: test_1595 followed by this file, 7 failed; green after: 66 passed; the file alone: 55 passed. * refactor(operator-queue): operator_queue_service becomes a package, content unchanged (#3785) The 2,840-line module moves to services/operator_queue_service/__init__.py byte for byte (100% similarity), the first step of the Invariant #1 split. Every `from services.operator_queue_service import X` and `from services import operator_queue_service` resolves as before. Six path-keyed guards name the file by its path, so their key moves with it (the PR #2487 precedent): _NOT_EMITTERS (test_3246), _ALLOWED_CALLERS (test_1677), _ALLOWED (test_1920), _OQS (test_ent715), FLEET_LEVEL_ALLOWLIST (test_ent467), and the source read in test_ent499. Only the key changes; the rule, the reason text and every assertion are untouched. Part of #3785 * test(operator-queue): pin the package's one-binding rules before the split (#3785) tests/unit/test_3785_operator_queue_package.py pins what S2–S6 must keep while they move code out of __init__, each property derived from the tree so no later slice edits it: modules under 800 lines (__init__ exempt, with a staleness check); the import surface src/backend and tests/ read still resolves; no from-import between package modules; one top-level binding per name; import-time reads defined first and the _MARKER_UNCHANGED default the owner's object; a patch of a re-exported name lands where its readers read; one logger identity; owner-exact qualified reads; no submodule named like a package attribute; one rate_limiter; no method on two classes of the composed service; external imports before the first submodule import, and a failed first import, injected at that line, leaves no stale submodule. The AST scans live in _oqs_package_scan.py (pure stdlib, never imports src). The other shape, a fresh install: each consumer imported first in its own interpreter on an empty database raises a bounded alert (created; only main binds a WebSocket manager, and then exactly one thin operator_queue_sync trigger goes out). Outcomes equal on the base. Part of #3785 * refactor(operator-queue): bind the service's collaborators once, in deps.py (#3785) db, _queue_db, principal_reach, get_breaker_redis, ask_service, AgentClient and the audit sink _audit_sync move to services/operator_queue_service/deps.py, bound once and read as deps.X everywhere in the package. They are no longer attributes of the package, so a stale monkeypatch.setattr(oqs, "db", ...) raises AttributeError instead of patching a copy nothing reads (Invariant #1(a), the PR #2487 rule). rate_limiter stays on the package: ask_service reads oqs.rate_limiter.check. Tests that patched a collaborator on the package now patch oqs.deps.X; no assertion, expected value, fixture or control flow changes. The package guard gains G4 (deps binds exactly the collaborators, no other module imports one from its source under any alias or holds one by identity, the package has none) and refuses any reach of a package function's __globals__. Part of #3785 * refactor(operator-queue): the queue listing engine moves to listing.py (#3785) QueueListError, narrow_to_agent_key, the cursor and walk-snapshot helpers and list_for_principal (trinity-enterprise#815) move whole from __init__ to services/operator_queue_service/listing.py. The two package-owned prefix tuples are read as _oq.X, collaborators as deps.X. The package re-exports exactly the six names read from outside (the router's list_for_principal and QueueListError; narrow_to_agent_key, encode_cursor, decode_cursor and CURSOR_MAX_BYTES, which tests call or compare). test_ent715's row-reader census re-keys list_for_principal to listing.py; no assertion changes. Part of #3785 * refactor(operator-queue): the poller core moves into PollerCoreMixin (#3785) The instance state, start/stop, the Redis leader lease, _poll_loop, _poll_cycle and _broadcast_sync move into PollerCoreMixin in services/operator_queue_service/poller.py. OperatorQueueSyncService is now composed in __init__ from the mixin and keeps its singleton there (the db/schedules shape). Package-owned names (DEFAULT_POLL_INTERVAL, _LEADER_KEY, _RESERVED_ID_PREFIXES, _websocket_manager) are read as _oq.X; the default poll_interval still binds 5 at import. Three path-keyed censuses re-key their poller entries to poller.py (test_1920's lease, test_ent467's operator_queue_sync trigger, test_ent715's _poll_cycle); no assertion changes. Part of #3785 * refactor(operator-queue): the agent-file channel leaves __init__ as whole modules (#3785) The file-channel code moves out of __init__ in four modules, so that the channel's removal (#3438) becomes a file deletion rather than surgery: * filechannel.py: the module helpers (clamping, comparison, the ingestion marker and its _MARKER_UNCHANGED sentinel, delivery matching); * rows.py: what a row says about itself, read on both sides of the package (the audience predicates, the receipt vocabulary, aging); * ingest.py: IngestMixin (_apply_sync_state, _notice_file_channel, _sync_agent); * write_back.py: WriteBackMixin (_apply_delivery_state, _write_responses_to_agent). OperatorQueueSyncService composes the two mixins; the flood methods stay on it and _sync_agent reaches them through self. The moved code is unchanged apart from owner-exact qualifications (_oq.X, filechannel.X, rows.X). Four path-keyed censuses re-key _sync_agent to ingest.py and the write-back source read to write_back.py; two tests move their _validated_addressee patch to oqs.filechannel, its owner. No assertion changes. Part of #3785 * refactor(operator-queue): the alert emitters move out; the split is complete (#3785) The bounded-alert delegates and outcome constants (create_bounded_alert, create_bounded_alert_outcome, ALERT_*) move to alerts.py, and the flood alert (_maybe_emit_flood_alert, its lazily created refresh-time dict and _end_flood_episode) moves into FloodAlertMixin in flood.py, composed into OperatorQueueSyncService. The #1677 budget episode and its cooldown state stay in __init__ with their only mutators; platform_alerts still reaches every name it reads back through the package. __init__ is now 670 lines (2,848 when this started; radon CC 0, the largest module 159), so the guard's size exemption is dropped. The package docstring records who owns what and where new code goes. The live docs that named the old single-file path, or a symbol that has since moved, are re-pointed to the owning module (path and symbol tokens only). test_3246's census re-keys create_bounded_alert to alerts.py; no assertion changes. Fixes #3785 * fix(operator-queue): a new flood, budget or untracking episode files after an acknowledgement (#3254) A person's ending of a `queue_flood`, `alert_budget` or `gitignore_untracked` row snoozed every later reading of the subject for 7 days, because none of the three kinds had a material key, so `_snoozed_by` was vacuously true. A runaway agent's second flood, a second budget-full episode and a second untracking Push of the same paths were all silent (review C1; dolho on operator_queue_service.py:2800 and gitignore_sweep.py:335). Each reading now carries an episode marker that the kind lists in its `material_keys`: - queue_flood: `episode_started_at`, stamped when the in-memory episode starts. Re-reads of one episode share it; an episode that starts after the condition cleared does not. - alert_budget: `filled_by`, a digest of the ids of the pending rows filling the budget. Re-reads of the same full budget share it; once a slot frees and a new row fills it, it differs. - gitignore_untracked: `push_id`, one per call. The emitter runs once per Push, so every untracking Push after an acknowledgement files; repeats still collapse onto a pending row. So the snooze silences re-reads of the acknowledged episode for the snooze window and a new episode files at once, which makes the `_maybe_emit_flood_alert` docstring's #3130 edge-trigger claim true again. The budget episode's read of the filling rows is classified in the ent#780 row-reader census as internal. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01HWna79vVmnezQdhpaGRKbw * fix(operator-queue): a flood re-read no longer stamps the per-agent cooldown; the oversize end is pinned (#3254) Review follow-ups on the flood alarm: - dolho on operator_queue_service.py:2778 (webmixgamer agreed): the 6-hourly re-read of one reason's episode stamped the per-agent `_flood_alert_cooldown`, so the other reason's first alert could wait up to one cooldown. The cooldown spaces episodes and a re-read is not one, so it is now stamped only before an episode's first reading. A failed re-read's retry spacing already comes from its refresh time. - webmixgamer I3: the 6-hour re-read spacing is one constant, `OPERATOR_QUEUE_FLOOD_REREAD_SECONDS`, read by the gate and by the failed re-read's retry arithmetic, so the two cannot drift. - webmixgamer I1: a `_sync_loop` case serves an oversized file and then a sane one and asserts the row ends as the platform. It goes red when `_sync_agent`'s `_end_flood_episode(agent_name, "oversize_file")` is replaced by a bare episode discard. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01HWna79vVmnezQdhpaGRKbw * docs(operator-queue): state the fail-open double-leader bound on the flood episode marker (#3254) The episode marker is worker-local. With Redis down the leader lease fails open, so each worker stamps its own episode_started_at and another worker's re-read can file past a person's ending, at most one extra row per extra worker per re-read window. Docstring only; no behaviour change (review L1). Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01HWna79vVmnezQdhpaGRKbw * lint(operator-queue): __init__ drops its file-level F401 waiver (#3785) Review I1 (dolho): the file-level `# ruff: noqa: F401` switched off unused-import detection for all of `__init__`, so a dead import left behind by a later slice or feature would go unflagged. At this PR's head `__init__` still reads every name in its import block, so the waiver hid nothing: `ruff check --select F401` gives 0 findings with it removed. It is dropped, and the block's comment now says that a name `__init__` stops reading keeps its line with a per-line waiver naming why (G13, or read as `oqs.X` from outside). PR2, PR3 and PR4 add those per-line waivers where their moves leave a name unread. `deps.py` keeps its file-level waiver: it is a binding module whose imports are its bindings, so there is no import there F401 could rightly flag. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01HWna79vVmnezQdhpaGRKbw * lint(operator-queue): per-line F401 waivers for what __init__ stops reading (#3785) Review I1 on #4036: PR1 dropped `__init__`'s file-level F401 waiver. This slice's moves leave four of its imports unread in `__init__`; each now carries its own `noqa: F401` with the reason, so F401 keeps checking every other line: - `asyncio`, `base64`, `uuid`: kept for G13, because `listing` and `poller` import them at module level. - `from . import listing`: loads the submodule at its G6 point; the names callers read come from the re-export block. `ruff check --select F services/operator_queue_service/` is clean. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01HWna79vVmnezQdhpaGRKbw * lint(operator-queue): per-line F401 waivers for what __init__ stops reading (#3785) Review I1 on #4036: PR1 dropped `__init__`'s file-level F401 waiver. This slice's moves leave these names unread in `__init__`; each now carries its own `noqa: F401` with the reason, so F401 keeps checking every other name: - `datetime`, `timedelta`, `timezone`, `Sequence`, `options_cap_violation`, `title_cap_violation`: kept for G13, because `rows`, `filechannel` and `ingest` import them at module level. - `rate_limiter`: O1(d), read as `oqs.rate_limiter` from outside (`ask_service`, tests) and as `_oq.rate_limiter` in `ingest`. - `to_utc_iso`: read as `oqs.to_utc_iso` from outside (`test_ec_operator_queue_properties.py`) and kept for G13. - `from . import filechannel` / `rows`: load the submodules at their G6 point; the names callers read come from the re-export block. The `typing` and `utils.helpers` imports become parenthesised so the waiver sits on the one unread name, not the whole line. They stay single statements: splitting one into two breaks the guard's failed-first-import leg, which injects the failure at the module's first statement. `ruff check --select F services/operator_queue_service/` is clean. With every waiver stripped in a scratch copy, the F401 findings are exactly the waived names, and an injected dead import is still reported. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01HWna79vVmnezQdhpaGRKbw * lint(operator-queue): per-line F401 waivers for what the integrated __init__ stops reading (#3785) With both PR2's and PR3's moves in `__init__`, two more names go unread there: `iso_cutoff` and `parse_iso_timestamp`. Each gets its own `noqa: F401` (kept for G13: `listing`, `rows`, `filechannel` and `ingest` import them at module level). With every waiver stripped in a scratch copy, the F401 findings are exactly the waived names. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01HWna79vVmnezQdhpaGRKbw * lint(operator-queue): per-line F401 waivers for what __init__ stops reading (#3785) Review I1 on #4036, at the slice where the import block is final. PR1 dropped `__init__`'s file-level F401 waiver; PR2, PR3 and the integration added per-line waivers for the names their moves left unread. This slice leaves two more: - `utc_now_iso`: kept for G13 (`poller`, `filechannel`, `ingest`, `write_back` and now `flood` import it at module level); - `from . import alerts`: loads the submodule at its G6 point; the names callers read come from the re-export block. `hashlib` and `deps` are read in `__init__` again since #4021's budget episode digest (`deps.db.list_operator_queue_items`, `hashlib.sha256`), so they carry no waiver. With every waiver stripped in a scratch copy, the F401 findings are exactly the waived names (16 per-line, plus the four re-export blocks), and an injected dead import is still reported. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01HWna79vVmnezQdhpaGRKbw * docs(operator-queue): re-point the last live pointers to the deleted single-file path (#3785) Review I1 on #4039 (dolho): the sweep covered `docs/memory/**` and `db/operator_queue.py`, but a few live pointers to `services/operator_queue_service.py` survived. Each now names the package, or the module that owns the cited code: - `tests/registry.json`, the two `/edge-cases` entries' descriptions: `services/operator_queue_service/`. - `docs/requirements/OPERATOR_QUEUE_OPERATING_ROOM.md`: the §2.2 `**Location**` line and the §4 implementation-map row: `src/backend/services/operator_queue_service/`. This spec is still edited by features (#3242, ent#715), so it is a live map, not a frozen record. - `tests/unit/test_ec_operator_queue_edges.py:9,121,235`: the package directory, and `operator_queue_service/ingest.py` for the two `_sync_agent` citations (the `_ID_RE` guard and the #3243 block). - `tests/unit/test_3274_gate_wiring.py:111`: `operator_queue_service/poller.py` (`_poll_cycle` runs the sweep). The two test files change only in comments and docstrings: their ASTs with docstrings stripped are identical to before, so no assertion, value or control flow moves (not an E1–E3 test edit). Left as they are, because they are point-in-time records: the dated `docs/memory/learnings.md` entries (`:1075`, `:1323`), migration `0039_operator_queue_addressed_to.py:10`, and `docs/{archive,releases, security-reports,metrics}/`. `test_ent499_problem_report.py:247` cites the service's `_write_responses_to_agent` by symbol, not by path, and the composed service still has it. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01HWna79vVmnezQdhpaGRKbw * test(operator-queue): ent#981's file-path case patches `_validated_addressee` on `filechannel` (#3785) test_ent981_addressee_reach arrived from dev (#4148) patching the name on the package. This slice moves `_validated_addressee` to `filechannel.py`, where `_clamp_ingested_item` reads it, so the package no longer binds it: the patch raised AttributeError, and the #3785 G7 guard refused it. Same target as test_ent734's two patches of the same name. --------- Co-authored-by: Claude Opus 5.5 <[email protected]> Co-authored-by: trinity-ability <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The public half of abilityai/trinity-enterprise#981. It adds three generic mechanisms to asks; the feature that uses them lives in the enterprise module. With this PR alone nothing changes for anyone: no row uses the new prefix until the enterprise side raises one.
What
db/operator_queue.py,client_portal/asks/service.py):gate-addressee-only-reach-, is listed, counted and opened for the person it is addressed to (addressed_to_emailorresolved_to), without the agent roster. The platform chose the addressee, so the roster was never this row's fence.ask_service.drop_addressee(ask_id, email, *, reason): takes one person off a shared row, using compare-and-set. It is audited with ids only.raise_ask(..., attach_chat=True, platform_context=None), gate raises only:attach_chat=Falsecreates no chat.platform_contextmerges after the agent-content strip, and only for platform keys._PLATFORM_CONTEXT_KEYS, so they are stripped from agent content at both boundaries.WorkspaceAsk.project:{id, task_id, event}, read from platform keys only.list_project_tasksandget_steward_digest.workspace-inbox.md,api-endpoints.mdandcore-agent.md§5.40.Review + security
/cso --diff: nothing found.raised_by,drop_addressee, the context strip, self-assignment). MCP: 1113 passed.Tests
tests/unit/test_ent981_addressee_reach.py(28).test_ent715_queue_person_fields.pypins the new exit.Before merge
src/backend/enterprise. The bump makes the feature live and also carries an earlier enterprise commit that is not pinned yet.dev: two commits, with no shared files; GitHub reports it mergeable.Handoffs
projectfield and link it. That is UI work, not in this PR.🤖 Generated with Claude Code