Skip to content

feat(workspace): the seat-level decision record — why a thing was approved, deferred or killed (abilityai/trinity-enterprise#638) - #2949

Merged
vybe merged 3 commits into
devfrom
feature/ent638-seat-decision-record
Sep 22, 2026
Merged

vybe merged 3 commits into
devfrom
feature/ent638-seat-decision-record

Conversation

@dolho

@dolho dolho commented Sep 22, 2026

Copy link
Copy Markdown
Contributor

Refs abilityai/trinity-enterprise#638

Cross-repo, so nothing auto-closes. The enterprise issue is closed by hand at the release cut and needs a manual status-in-dev bump on merge to dev.

Stacked on #2927 (base feature/ent527-role-card) — Alembic 0068_seat_decisions ← 0067_agent_role_readiness, so the four 2026-09 schema PRs stay one head. Retarget to dev after #2927 lands.

What this is

Operator ruling R25: the approve / defer / kill judgments a role companion and its human make every week live nowhere — they evaporate with the chat that held them. This gives a seat (agent × person, the ent#637 memory scope) a small, lintable decision record, recorded by the companion over MCP or the person in Agent details, expiring unless reconfirmed, corrected by supersession, and read back into every turn so the criterion is reused. It is the evidence base for the autonomy dial (tandem-06 §2.2, #641). Paradigm's COO asked for it first.

The record (tandem-07 §7a): outcome (approved | deferred | killed) · what was decided · the alternatives that were live · the criterion that discriminated (the reusable part) · who decided (role + person) · decided_at + review_by · what would reverse it · notes (the only prose) · ask_class · cites · request_id (#611's gate).

Acceptance criteria → where

AC Where
Companion records over MCP; person reads / corrects / closes in the Workspace; readable per assignment kind tools/decisions.ts (record_decision, list_seat_decisions) → routers/seat_decisions.py; client_portal/seat_decisions.py + PortalAgentDecisions.vue; readers via the optional seam method assignment_provider.kinds_for (own seat always, owner every seat writable, a recognised stakeholder every seat read-only, no provider → own seat only)
The fields; prose only in notes seat_decision_service.validate_record — one line ≤ 280 per field, alternatives ≥ 1
Prose-only refused with a receipt; no alternatives is a note 422 decision_prose_only {receipt.fields} naming every failing field; 422 decision_is_a_note; nothing stored
Expires at review_by unless reconfirmed; superseded stays as history expired computed on read (equal is not expired), reconfirm moves the date; supersede = new row + CAS flip of the old, nothing deleted
"how many decisions were reused" / "same criterion, no reversals" stats(): reused = cited by a LATER record (superseding does not cite); per ask_class criteria / reversals / expired / stable (≥3, one criterion, 0 reversals) — #641's input
Direction routed as a canon proposal, not stored as a seat decision scope: direction → kept as routed (visible, expiring, outside the evidence) + the canon hint. Reviewed choice: refuse-and-drop would be the evaporation R25 closes, and no canon-proposal route exists in Trinity

Decisions worth your attention

  • The seat is never named by the caller, and no email ever comes back to the agent. MCP writes resolve the seat from execution_id exactly as write_user_memory (seat run stamp → verified channel email → 422 no_seat); to_agent labels the decider seat / owner. An execution can be an anonymous public turn — the audience the assignment provider must never expose identities to.
  • Read into context. Without a read path "reused" measures a loop that does not exist. The seat's active decisions ride the SAME composer every caller already uses (format_user_memory_block), keyed off the record's own seat, bounded, fail-open.
  • Owner via role_card._is_owner, admin dropped — PortalPrincipal carries no role; ownership is what the sibling routes gate on. A shared platform user is not an owner (tested).
  • No container read on the write path — decided_by_role from assignment_provider.resolve_assignment (sync, in-memory) or the caller; x-role is agent-writable anyway.
  • Idempotency + CAS: Idempotency-Key through idempotency_service (the tool derives one over the arguments; a retry records once); supersede cannot fork under a double submit; any action on a non-active row is a named 409.
  • Both access.ts rows are enforce:{param:"agent_name"} (the server refuses to boot on a missing row).

Tests

  • tests/unit/test_ent638_seat_decisions.py — 45: grammar table (every refusal code + receipt), lifecycle over a real SQLite file, evidence (later-citation rule, stability incl. paraphrase fold / different criterion / reversal / expired), the bounded email-free prompt block + the composer hook, readers (own / owner / provider kinds incl. absent method, raise, bad kind), the agent router (seat resolution per trigger, foreign execution 403, receipt + idempotency release, replay snapshot, email-free list), the portal service (own vs owner vs shared platform user, named seat, direction hint, uniform 404), both tracks + registry + single head, facade signature parity, # mcp: header + registration.
  • src/frontend/tests/unit/portalAgentDecisions.spec.js — 8, mounted (@vitest-environment jsdom): render criterion-first + evidence line, empty state, expired / routed / history / other seat read-only, record (chips, posted body, re-read), refusal on the named field, direction hint, close via ConfirmDialog + reverse with inline reason, correct → supersede.
  • src/mcp-server/src/tools/decisions.test.ts — 5: body without agent_name, deterministic key (retry same / different decision differs), user-key refusal, backend receipt as success:false, policy rows.
  • Mutation checks: flipping the expiry boundary (< → <=) and returning the email in the agent shape each turn tests red.
  • Full frontend unit suite (144 files / 3268, ratchets included), MCP suite (447), the affected backend subset (1198) and the lints are green; check_alembic_heads → 1 head (0068_seat_decisions).

Docs

requirements/core-agent.md §5.37 · feature-flows/workspace-seat-decisions.md (+ index) · architecture/workspace.md, database.md, api-endpoints.md, backend.md, mcp-server.md.

Deferred (trinity-dev DEBT_INBOX.md, 2026-09-22)

Readers per role rather than per agent · auto-record from an answered decision request (#611) · the canon-folder export (the role pack's record-decision, #510 — field names already match; the plan's canon-placement tension with tandem-03 §3 is recorded there).

🤖 Generated with Claude Code

@dolho dolho added priority-p2 Important type-feature New functionality ui PR touches the frontend UI — triggers Playwright e2e tests labels Sep 22, 2026
@dolho
dolho requested a review from vybe September 22, 2026 10:48
dolho added a commit that referenced this pull request Sep 22, 2026
…tus vocabulary is checked at the sink; the portal routes are executed by a test (Abilityai/trinity-enterprise#638)

Review findings on PR #2949: `effective_status` returned `routed` verbatim,
so a direction record kept to avoid evaporation accreted forever — it now
expires at `review_by` like an active one (the doc already said so).
`DECISION_STATUSES` was declared and never read; `insert_seat_decision`
now refuses a status outside it. Three tests execute the portal route layer
(roster gate first, receipt → HTTP detail, action body forwarded).

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
@dolho

dolho commented Sep 22, 2026

Copy link
Copy Markdown
Contributor Author

/review Report

Branch: feature/ent638-seat-decision-record → feature/ent527-role-card (merge-base diff = the feature commit + the fix commit below)
Files Changed: 35 (+3081 / −3) at review time
Scope: CLEAN — intent: R25 seat-level decision record (record over MCP / read-correct-close in Workspace, lintable fields with receipts, expiry + supersession, reuse/stability evidence, direction routed). Delivered: exactly that; the one addition beyond the issue text — active decisions injected into the seat's turn — is the read path the "reused" metric needs and was a plan decision, not drift.
Plan Completion: 6/6 AC done (seat_decision_service.py:validate_record / record / act / stats; routers/seat_decisions.py; client_portal/seat_decisions.py; PortalAgentDecisions.vue) · 3 deferred by plan and registered in DEBT_INBOX (readers per role, #611 auto-record, canon export) · 0 unverifiable.

Execution coverage (Step 2.5)

changed symbol / test file executed by live consumer verdict
seat_decision_service.validate_record / record / act / stats / prompt_block / readable_seats / to_agent / to_human test_ent638_seat_decisions.py (real SQLite file for the store, stubs for the boundaries) routers/seat_decisions.py, client_portal/seat_decisions.py, platform_prompt_service._seat_decisions_block ✅
db/seat_decisions.py mixin + database.py facade lifecycle tests over the real engine; test_the_facade_forwards_every_parameter… (signature parity) service ✅
routers/seat_decisions.py::record_seat_decision / list_seat_decisions TestAgentRouter (seat per trigger, 403/404, receipt + idempotency release, replay, email-free list) MCP decisions.ts ✅
client_portal/seat_decisions.py::page / record / act TestPortalRouter portal routes ✅
client_portal/router.py new routes TestPortalRoutes (added in the fix commit — roster gate first, receipt → HTTP, action body forwarded) clientPortal.js ✅
platform_prompt_service._seat_decisions_block test_the_memory_block_carries_the_decisions_on_every_caller the 4 format_user_memory_block callers (public link, channels, seat runs, Workspace) ✅
PortalAgentDecisions.vue + store slice portalAgentDecisions.spec.js — mounted (record, refusal on the named field, direction hint, close via ConfirmDialog, reverse inline, correct → supersede, agent-switch race) Agent details ✅
decisions.ts + client.ts + access.ts rows decisions.test.ts (body shape, deterministic key, user-key refusal, receipt envelope, policy rows) MCP server boot (policyFor throws on a missing row) ✅
DDL / revision / registry / # mcp: header pins text pins migration runner, check_alembic_heads, /validate-architecture 🛡 guard

Mutations (feature PR, run anyway): flipping the expiry boundary (< → <=) → 1 red; returning the person email in to_agent → 3 red.

Critical Findings

None.

Informational Findings (fixed in 431c28f1b unless noted)

[I1] Enum completeness: a routed record never expired (Confidence 9/10)
seat_decision_service.py::effective_status — if status != "active": return status. A direction record is kept so it does not evaporate, not so it accretes; the docs already said "visible, expiring". Fixed: routed expires at review_by like active; test added.

[I2] Dead constant: DECISION_STATUSES declared, never read (Confidence 10/10)
db/seat_decisions.py:26. Fixed: insert_seat_decision refuses a status outside it — the one check that belongs at the sink.

[I3] Test gap: the portal route layer was not executed (Confidence 8/10)
client_portal/router.py — the service was, the routes (roster gate, rate limit, DecisionRefused → HTTPException(detail=as_detail())) were not. Fixed: TestPortalRoutes (3).

[I4] Performance: the owner's page is one query per seat (Confidence 7/10) — not changed
client_portal/seat_decisions.py::page loops readable_seats × db.list_seat_decisions. Bounded by MAX_SEATS = 50 and MAX_ROWS_PER_SEAT = 500, per-agent, on an indexed (agent_name, seat_email, status) read. Acceptable for seat volumes; a single agent-wide select + Python group-by is the paydown if a fleet ever hits it.

[I5] Conditional side effect: one extra indexed read on every turn (Confidence 7/10) — not changed
platform_prompt_service.format_user_memory_block now calls prompt_block on the four memory callers. Fail-open (except Exception → None), bounded to 500 rows / 12 lines / ~1.5 KB, keyed off the record's own seat. Named here so the cost is visible; it is the price of the reuse loop.

[I6] Human surface shows other seats' emails to entitled readers (Confidence 8/10) — by design
to_human carries decided_by.person / closed_by for every seat the reader may see (owner, or a provider-declared kind). The agent shape (to_agent) never does. The reader filter runs before serialization (readable_seats → per-seat query), so an unentitled reader never receives another seat's rows. Stated, not a finding.

Clean Categories

  • SQL & data safety: SQLAlchemy Core throughout (db/seat_decisions.py); emails lower-cased at the sink; JSON lists in TEXT via json.dumps; no raw SQL. Migration is additive (new table, has_table guard, IF NOT EXISTS indexes); one head (0068).
  • Concurrency: supersede_seat_decision flips the old row WHERE status='active' and inserts the child in one transaction; close/reverse/reconfirm are CAS updates; a lost CAS is a named 409 (decision_not_active). MCP record: Idempotency-Key through idempotency_service (begin/complete/fail), the tool derives a deterministic key.
  • Auth boundaries: agent route Depends(get_current_user) + assert_agent_access + execution.agent_name != agent_name → 403; the seat is never caller-supplied. Portal routes _require_roster first (uniform 404), writes own-seat or role_card._is_owner; another seat's id → uniform 404 (test_another_seats_id_is_the_uniform_not_found). MCP tools carry enforce:{param:"agent_name"}. test_1310_auth_wiring / test_2094 green.
  • Credential exposure: no secrets logged; the agent-facing shape carries no email (mutation-verified); receipts echo field rules, never values.
  • Enterprise disclosure in public docs: guard pattern run over the added doc lines — no hit; the seam addition documents the mechanism (kinds_for), never a module.
  • Product quality bar: named 422/409/403/404 reasons with receipts; empty state teaches the next action; loading skeleton reserves space; direction degrades to routed + hint rather than dead-ending; new columns are nullable or defaulted, additive-safe.

Summary

  • Critical: 0
  • Informational: 6 — 3 fixed in 431c28f1b, 3 stated (bounded / by design)
  • Scope: clean

Suites after the fix: test_ent638_seat_decisions.py 48 ✅ · frontend 3268 ✅ (ratchets included) · MCP 447 ✅ · check_alembic_heads 1 head ✅.

@dolho

dolho commented Sep 22, 2026 •

Copy link
Copy Markdown
Contributor Author

Screenshots — Workspace › sidekick › Agent details › Decisions

Local dev, PostgreSQL migrated to 0068_seat_decisions, stack mounted on this branch (431c28f1b). Data seeded through the real APIs — the first record written by the companion's route (POST /api/agents/sidekick/decisions with an execution_id), the rest through the Workspace.

image image
# Shot What it proves
1 The record, light Criterion-first rendering; routed to canon on the direction decision; expired on the deferral whose review_by passed; another seat labelled and read-only; evidence line 6 recorded · 1 reused, vendor-renewal stable (3 records, one criterion, no reversals)
2 Dark Both themes first-class — every colour resolves from tokens defined on bare :root
3 Record form Alternatives as chips (Enter); review_by defaults +90d; Scope → Direction is the one judgment the platform cannot make from text
4 Refusal receipt 422 decision_prose_only with receipt.fields; each message lands on the field it names (criterion is required); nothing stored

Not in the shots, verified on the box: decided_by.person comes back as "seat" on the agent route (no email ever reaches the companion), and format_user_memory_block now carries the seat's standing decisions into the turn — the read path that makes cites non-zero.

To touch it directly: http://localhost:8001/workspace/a/sidekick → rail Info → scroll to Decisions. Reverse asks for the reason inline, Correct pre-fills the form and supersedes, Close goes through the confirm dialog, Reconfirm moves an expired record forward.

@dolho

dolho commented Sep 22, 2026

Copy link
Copy Markdown
Contributor Author

dolho and others added 2 commits September 22, 2026 17:52
…roved, deferred or killed, as a platform primitive (Abilityai/trinity-enterprise#638)

Operator ruling R25: the approve / defer / kill judgments a role companion
and its human make every week live nowhere — they evaporate with the chat.
This gives a seat (agent × person, the ent#637 memory scope) a lintable
record of its judgment, recorded by the companion over MCP or the person
in Agent details, expiring unless reconfirmed, corrected by supersession,
and read back into every turn so the criterion is reused. It is the
evidence base for the autonomy dial (tandem-06 §2.2, #641).

The record (tandem-07 §7a): outcome (approved | deferred | killed) · what was
decided · the alternatives that were live · the criterion that discriminated ·
who decided (role + person) · decided_at + review_by · what would reverse it ·
notes (the only prose) · ask_class · cites · request_id (the #611 gate).

- Grammar with receipts (services/seat_decision_service.py): prose where a
  field belongs → 422 decision_prose_only naming every failing field; no
  alternatives → 422 decision_is_a_note; a citation outside the seat's own
  records → 422 unknown_citation; a request_id that is not this agent's
  queue item → 422 unknown_request. Nothing is stored on refusal.
- Direction is not a seat decision (R C3): the caller declares scope; a
  direction record is kept as `routed` — visible, expiring, outside the
  evidence — with the canon-proposal hint, so it neither evaporates nor
  pollutes the record.
- Expiry is computed on read (review_by before today; equal is not expired),
  never written; correction inserts a new row chained by supersedes_id and
  flips the old one in one CAS transaction; close / reverse are status flips
  (reverse needs a reason — the evidence); reconfirm moves review_by. A
  non-active target is a named 409. Nothing is deleted.
- Evidence: reused = records cited by a LATER record (a superseding record
  does not implicitly cite); per ask_class the distinct criteria, reversals,
  expired and `stable` (≥3, one criterion, no reversal) — #641's input.
- Two surfaces, one seat rule. MCP `record_decision` / `list_seat_decisions`
  (src/mcp-server/src/tools/decisions.ts → POST/GET /api/agents/{name}/
  decisions, routers/seat_decisions.py): the seat is resolved from
  execution_id exactly as write_user_memory does, never supplied;
  Idempotency-Key honoured (the tool derives one over the arguments);
  decided_by_role from assignment_provider.resolve_assignment or the caller,
  never a container read; NO email in the answer (decider = seat | owner);
  enforce:{param:"agent_name"} policy rows. The person records, corrects,
  reconfirms, closes and reverses in Agent details (client_portal/
  seat_decisions.py, PortalAgentDecisions.vue, clientPortal store slice).
- Readers: own seat always; the agent OWNER (role_card._is_owner) every seat
  writable; a stakeholder the assignment provider recognises through the
  optional seam method kinds_for(agent, reader) every seat read-only; no
  provider → own seat only. Writes: own seat, or the owner on a named seat.
- Read into context: the seat's active decisions ride the shared memory
  block (platform_prompt_service.format_user_memory_block) on every caller,
  bounded and email-free — what makes a criterion reusable.
- Storage: seat_decisions on both tracks (SQLite seat_decisions_table +
  Alembic 0068 ← 0067, has_table guard + IF NOT EXISTS indexes), cleanup
  CASCADE, JSON lists in TEXT, stats in Python, bounded reads.

Tests: tests/unit/test_ent638_seat_decisions.py (45 — grammar table,
lifecycle over a real SQLite file, evidence, readers, both routers, both
tracks, facade parity), src/frontend/tests/unit/portalAgentDecisions.spec.js
(8, mounted), src/mcp-server/src/tools/decisions.test.ts (5). Mutation
checks: the expiry boundary and the email-free agent shape each turn tests red.

Deferred (trinity-dev DEBT_INBOX 2026-09-22): readers per role rather than
per agent; auto-record from an answered decision request (#611); the
canon-folder export (the role pack's record-decision, #510 — field names
already match).

Refs Abilityai/trinity-enterprise#638

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
…tus vocabulary is checked at the sink; the portal routes are executed by a test (Abilityai/trinity-enterprise#638)

Review findings on PR #2949: `effective_status` returned `routed` verbatim,
so a direction record kept to avoid evaporation accreted forever — it now
expires at `review_by` like an active one (the doc already said so).
`DECISION_STATUSES` was declared and never read; `insert_seat_decision`
now refuses a status outside it. Three tests execute the portal route layer
(roster gate first, receipt → HTTP detail, action body forwarded).

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
@vybe
vybe changed the base branch from feature/ent527-role-card to dev September 22, 2026 16:53
@vybe
vybe force-pushed the feature/ent638-seat-decision-record branch from 431c28f to 17d4a15 Compare September 22, 2026 16:53
@vybe

vybe commented Sep 22, 2026

Copy link
Copy Markdown
Contributor

merge-train: rebased onto dev and retargeted — mechanical. Pushed to this branch:

  1. git rebase --onto origin/dev <merge-base with feature/ent527-role-card> — the parent (feat(workspace): the role card in Agent details — role, objectives with metric freshness, readiness (abilityai/trinity-enterprise#527) #2927) had squash-merged, so the branch was carrying its pre-squash commits and read as 10 conflicts against dev. Only the two ent#638 commits remain, plus one commit below.
  2. Conflicts on the first commit, both append-tail, resolved keep-both (dev first): src/backend/db/migrations.py (the ent#549 / ent#477 / ent#478 entries landed after the fork) and tests/registry.json.
  3. Alembic re-parent (the bug: enterprise submodule pin advance lands two Alembic heads — entitled instances silently degrade to OSS-only #2068 class): 0068_seat_decisions revised 0067_agent_role_readiness, but dev already has 0068–0070, so on the merged tree it was a second head and upgrade head would have applied zero revisions. Renamed to 0071_seat_decisions, down_revision = "0070_metric_points"; references in migrations.py, database.md, the feature flow and test_ent638_seat_decisions.py updated. scripts/ci/check_alembic_heads.py → 1 head.

Base is now dev. Nothing in the feature's own code was changed.

@vybe
vybe force-pushed the feature/ent638-seat-decision-record branch from 17d4a15 to ec77ba8 Compare September 22, 2026 16:53
@vybe

vybe commented Sep 22, 2026

Copy link
Copy Markdown
Contributor

Addendum: test_the_table_is_on_both_tracks_and_in_the_cleanup_registry pinned down_revision = "0067_agent_role_readiness" by string; updated to 0070_metric_points in the same re-parent commit (amended and re-pushed). The file's 45 tests pass locally.

…metric_points as 0071 (abilityai/trinity-enterprise#638) — mechanical, per the merge-train note on the PR

dev gained 0068–0070 after this branch forked, so 0068_seat_decisions off 0067 was a second head (#2068 class): upgrade head would have applied zero revisions.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
@vybe
vybe force-pushed the feature/ent638-seat-decision-record branch from ec77ba8 to 93c8c34 Compare September 22, 2026 16:58

@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: validated (lane B+schema), rebased onto dev, all checks green on the retargeted run.

@vybe
vybe merged commit d91d564 into dev Sep 22, 2026
29 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

priority-p2 Important type-feature New functionality ui PR touches the frontend UI — triggers Playwright e2e tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants