Skip to content

fix(operator-queue): an expired approval the platform did not hold is marked outcome_unknown (abilityai/trinity-enterprise#844) - #3515

Merged
vybe merged 5 commits into
devfrom
feature/ent844-approval-sweep-audit
Oct 11, 2026
Merged

vybe merged 5 commits into
devfrom
feature/ent844-approval-sweep-audit

Conversation

@trinity-ability

@trinity-ability trinity-ability commented Oct 10, 2026 •

Copy link
Copy Markdown
Contributor

Summary

An approval the clock ends no longer reads the same whether or not anything held its action. When the expiry sweep ends a pending approval whose action the platform does not hold, the ending is now recorded as disposition_reason = 'outcome_unknown'. That covers every approval except a gated-skill one, for example an agent asking before it merges a PR. The marker shows up on the API rows, in the agent readback, in the expired audit row and on the Operations resolved card. This is option (b) from the issue's acceptance criteria.

Root cause

OperatorQueueOperations.mark_expired (run on every operator-queue poll cycle) and the #3247 replace path's in-transaction expiry end any pending ask past expires_at. Both wrote the same ledger values every time: expired / disposed_by='timeout' / no reason. Only a gated-skill approval (raised_by='gate') names an action the platform holds, and when that one expires nothing runs. Every other approval names an action the agent holds, and the agent can go ahead without an answer. So afterwards, "went stale, nothing happened" and "skipped, the action happened anyway" left identical traces.

The fix

  • db/operator_queue.py: a single SQL CASE (_TIMEOUT_REASON) runs inside the same compare-and-set UPDATE in both timeout writers. It writes outcome_unknown when type='approval' and the row is not a gate row (the existing _NOT_A_GATE_ROW predicate, so legacy NULL-raiser rows count too). Questions, alerts and gate approvals stay NULL. Only the writer that wins the CAS records the marker. Rows that already ended are never rewritten.
  • services/ask_service.expire: the expired audit row gets outcome_unknown: true in its details. It is a boolean, because the reason text never goes into an audit row.
  • Frontend: queueEndingText is the one rule shared by ResolvedCard, the queue detail and /m. It now reads "Expired — nobody answered in time; whether the action went ahead is unknown" (TIMEOUT_ENDING_REASONS). ResolvedCard no longer prints a timeout's token as a note.
  • No schema change. The existing disposition_reason column already reaches the API (person and machine views) and the agent readback. The Workspace projection still does not expose it, as before.
  • Docs: the operating-room feature flow, the database.md column comment, the MCP type comment, and tests/registry.json.

Why (b) and not (a): for an agent-held approval the platform cannot see whether the action happened, so a sweep that "checks the action's outcome" has nothing to check. Never expiring these items would change the agreed "denied by timeout" contract and leave asks pending forever. (b) is the smallest change that records the truth.

Tests

  • tests/unit/test_ent844_expired_approval_outcome.py, 9 tests on real SQLite:
    • Marked: agent-raised approvals (native and file) and legacy rows.
    • Not marked: gate approvals, questions, alerts, and approvals answered in time.
    • The replace-path expiry writes the same marker.
    • The audit flag is set on exactly the marked rows.
  • Mutation check: I reverted both writers to disposition_reason=None. Five tests went red: test_an_approval_the_platform_did_not_hold_expires_as_outcome_unknown[agent-mcp|agent-file|None-None], test_the_replace_path_expires_the_same_way_as_the_sweep and test_the_expiry_audit_row_names_an_unknown_outcome_and_only_that. With the fix restored, all 9 pass.
  • src/frontend/tests/unit/operatorQueueOutcomeUnknown.spec.js: 3 tests failed before the frontend change; all 7 pass after it.
  • Every unit file under tests/unit that touches operator_queue, cleanup_service or ask_service (143 files): 4122 passed, 6 skipped, 7 xfailed.
  • npm run test:unit in src/frontend: 5457 passed.

Product decisions taken (please confirm)

  • New user-facing wording: "Expired — nobody answered in time; whether the action went ahead is unknown". It extends the existing "Expired — nobody answered in time" text, with no new badge or primitive.
  • New closed token outcome_unknown on disposition_reason. The agent's own readback also sees it.
  • A gate approval's expiry carries no marker, because "held, did not run" is already implied by raised_by='gate' and recorded on the skill-gate request.
  • Not in scope: the retention sweep still hard-deletes terminal rows (including these) after the configured retention window. The marker lasts as long as the row does.

Fixes abilityai/trinity-enterprise#844

🤖 Generated with Claude Code

trinity-ability and others added 5 commits October 10, 2026 15:21
… marked outcome_unknown (Abilityai/trinity-enterprise#844)

The expiry sweep (mark_expired, every poll cycle) ends a pending ask on its
deadline alone and wrote every timeout identically (expired / timeout, no
reason). Only a gated-skill approval names an action the platform holds;
for every other approval the agent holds the action, so "the approval went
stale and nothing happened" and "the approval was skipped and the action
went ahead" left the same trace.

Both timeout writers (mark_expired and the #3247 replace path's
in-transaction expiry) now write disposition_reason = 'outcome_unknown' for
an approval that is not a gate's, from one SQL CASE inside the same
compare-and-set, so only the winning writer records it. Questions, alerts
and gate approvals stay NULL; rows that ended earlier are never rewritten.
The expired audit row carries outcome_unknown: true for those rows. No
schema change: the existing disposition_reason column carries the fact.

Test: tests/unit/test_ent844_expired_approval_outcome.py. Mutation check
(disposition_reason=_TIMEOUT_REASON reverted to None in both writers): 5
red - test_an_approval_the_platform_did_not_hold_expires_as_outcome_unknown
[agent-mcp, agent-file, None-None], test_the_replace_path_expires_the_same_way_as_the_sweep,
test_the_expiry_audit_row_names_an_unknown_outcome_and_only_that; restored, 9 green.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…s outcome is unknown (Abilityai/trinity-enterprise#844)

queueEndingText - the one rule ResolvedCard, the queue detail and /m share -
words disposition_reason 'outcome_unknown' on a timeout as "Expired - nobody
answered in time; whether the action went ahead is unknown"
(TIMEOUT_ENDING_REASONS; an unknown token falls back to the plain wording).
ResolvedCard no longer prints a timeout's reason token as a note.

Test: src/frontend/tests/unit/operatorQueueOutcomeUnknown.spec.js (3 red
before the change, 7 green after; full npm run test:unit green).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ilityai/trinity-enterprise#844)

Operating-room feature flow (ledger + new paragraph), database.md column
comment, MCP type comment, and test registry entries for the two new suites.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…wn outcome too (Abilityai/trinity-enterprise#844)

Review finding: both timeout writers stamp disposition_reason='outcome_unknown',
but only the sweep's `expired` audit row carried `outcome_unknown: true`. The
#3247 replace path in raise_ask built its own inline audit row without it, so
the same bypass read differently in the audit trail depending on which writer
the clock used. One builder (`_expired_audit`) now serves both. The new test
drives the replace path through ask_service.raise_ask and goes red without the fix.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…n included (Abilityai/trinity-enterprise#844)

Review finding: QueueItemDetail rendered queueEndingText only for a platform
ending, so an expired approval fell through to the person-answer branch
("by  · …") and the outcome_unknown marker never reached the detail panel,
which is one of the surfaces the PR and AC3 rely on. A clock ending now renders
through the shared ending rule. The mounted spec goes red without the fix.

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

Copy link
Copy Markdown
Contributor Author

/review Report

Branch: feature/ent844-approval-sweep-audit → dev (merge-base diff)
Files Changed: 11 in the PR (+287/-10), plus 2 review-fix commits
Scope: CLEAN. The issue asks for (a) or (b). The PR delivers (b): a distinct marker, written in the same CAS.
Plan Completion (issue ACs): 1 not chosen (alternative (a)), 1 done, 1 done after the review fixes

AC Status Evidence
(a) don't cancel while the action is pending NOT CHOSEN The platform cannot observe an agent-held action. The PR body explains why (b) is the honest option.
(b) mark distinctly DONE db/operator_queue.py _TIMEOUT_REASON CASE in both timeout writers
Reflected on the history/audit surface DONE (after fixes) Before the fixes, two surfaces missed the marker: the replace-path audit row (C1) and the queue detail panel (C2). Both are fixed.

Execution coverage (Step 2.5)

changed symbol / test file executed by live consumer verdict
_TIMEOUT_REASON in mark_expired / _replace_predecessor test_ent844_expired_approval_outcome.py on real SQLite operator_queue_service poll cycle → ask_service.expire; ask_service.raise_ask replace path ✅ executed
ask_service._expired_audit (review fix) TestTheAuditTrailSaysSo, TestTheReplacePathAuditSaysSoToo (through raise_ask) expire(), raise_ask ✅ executed
queueEnding / queueEndingText / TIMEOUT_ENDING_REASONS operatorQueueOutcomeUnknown.spec.js ResolvedCard, QueueItemDetail, MobileAdmin ✅ executed
ResolvedCard note mounted in operatorQueueOutcomeUnknown.spec.js Operations resolved list ✅ executed
QueueItemDetail endedByTimeout (review fix) mounted in queueItemDetailExpired.mount.spec.js Operations detail panel ✅ executed

Neither new test file contains a source-text assertion.

Fix mutation: I reverted both writers to disposition_reason=None. 6 of 10 backend tests went red. I reverted ask_service.py to the PR head: the new replace-path audit test went red. I reverted QueueItemDetail.vue: both mounted specs went red.

Critical Findings (both fixed)

[C1] Incomplete fix (4.14): the second timeout writer's audit row had no marker (Confidence: 9/10). Fixed in d64b598.
File: src/backend/services/ask_service.py (raise_ask, replaces_ended / expired_now branch)
Evidence (PR head): "details": {"agent_name": pred["agent_name"]},. The sweep's copy in expire() had the outcome_unknown spread; this inline copy did not.
Issue: the PR stamps the DB marker in both timeout writers, but only the sweep's expired audit row carried outcome_unknown: true. When the clock's ending happened through #3247's in-transaction expiry, the audit trail read like an ordinary stale expiry. That is the indistinguishability the issue asks to remove.
Fix: one builder, _expired_audit(row), used by both writers. New test TestTheReplacePathAuditSaysSoToo drives the replace through ask_service.raise_ask. It fails without the fix.

[C2] AC3: the queue detail panel never showed the marker (Confidence: 9/10). Fixed in 1282349.
File: src/frontend/src/components/operator/QueueItemDetail.vue:105
Evidence (PR head): <p v-if="endedByPlatform" ...>{{ endingText }}, with v-else showing decisionLabel(item.response) and by {{ item.responded_by_email }}.
Issue: the PR says "the queue detail" words the ending through queueEndingText, but the detail only used it for platform endings. An expired approval fell through to the person-answer branch ("by · …"), so a reviewer opening the item never saw the outcome-unknown wording.
Fix: added endedByTimeout = ending.kind === 'expired'. A clock ending now renders through the shared rule. New mounted spec queueItemDetailExpired.mount.spec.js fails without the fix.

Informational Findings

[I1] All writers that end an ask were checked (Confidence: 9/10). I grepped every update(operator_queue) / delete(operator_queue) and every raw-SQL writer:

The only by-age endings of a pending ask are the two timeout writers, and both are covered.

[I2] Marker lifetime equals row lifetime (Confidence: 8/10). The retention sweep still hard-deletes terminal rows after operator_queue_retention_days. After that, the expired audit row (with outcome_unknown: true, now from both writers) is the surviving trace. The PR body already states this. It is a product choice.

[I3] The Workspace and file write-back do not carry the marker (Confidence: 7/10). The Workspace projection withholds disposition_reason, so a Workspace reviewer sees a plain "Expired". The agent's queue file sees expired only. Operations, /m, the API and the audit log are the reviewer surfaces, so this is a scope choice, not a defect.

[I4] Replace-path expiry CAS does not re-check expires_at (Confidence: 5/10, appendix-grade). It runs on status='pending' inside the same transaction that read expires_at <= now. A respond cannot win, because its CAS requires expires_at > now, so this is safe. The code predates this PR.

Clean Categories

  • SQL safety: SQLAlchemy case() expression with bound literals. No interpolation.
  • Race/CAS: the marker is evaluated inside the same UPDATE that flips status. Only the winner records it, and earlier-ended rows are never rewritten.
  • Auth: no new endpoints or principals.
  • Credentials: none touched.
  • Enterprise disclosure: the docs diff carries no private-module tokens.
  • Schema: no DDL change, so neither migration track is needed.
  • Enum completeness: outcome_unknown is handled in TIMEOUT_ENDING_REASONS, the ResolvedCard note suppression, the MCP type comment and the database.md column comment. Unknown tokens fall back to the plain wording.

Tests run

  • pytest unit/test_ent844_expired_approval_outcome.py: 10 passed.
  • Every tests/unit/test_*.py touching ask_service / mark_expired / operator_queue: 3193 passed, 6 skipped, 7 xfailed.
  • npm run test:unit (src/frontend): 334 files, 5459 passed, raw-color and loading-gate ratchets included.

Summary

  • Critical: 2. Both fixed (d64b598, 1282349).
  • Informational: 4. No action needed; I2 and I3 are product/scope choices already disclosed in the PR body.
  • Scope: clean.
  • Learning fragment: docs/memory/learnings/2026-10-10-ending-side-effects-per-writer.md

🤖 Generated with Claude Code

@trinity-ability
trinity-ability marked this pull request as ready for review October 10, 2026 20:38

@vybe vybe left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

merge-train: batch validated on train/20261011-0752 (#3528)

@vybe
vybe merged commit adbbe34 into dev Oct 11, 2026
29 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.

2 participants