Skip to content

feat(slack): per-channel proactive-messaging consent (ent#223) - #1761

Closed
dolho wants to merge 3 commits into
devfrom
feat/223-slack-per-channel-proactive-consent
Closed

dolho wants to merge 3 commits into
devfrom
feat/223-slack-per-channel-proactive-consent

Conversation

@dolho

@dolho dolho commented Jul 24, 2026

Copy link
Copy Markdown
Contributor

Backend for ent#223 — the partner fast-follow from the 2026-07-23 call. Built OSS-core (confirmed with the owner): the flag lives on slack_channel_agents, an OSS table, and Invariant #3 forbids an enterprise migration from ALTERing an OSS table — so consent here is an edition-agnostic safety primitive (the users.suspended_at #995 pattern).

Problem

Proactive consent was per-recipient (agent_sharing.allow_proactive, keyed by verified email). In an open Slack workspace nobody authenticates, so there's no recipient record to opt in — and channel posts had no consent gate at all, only the owner check + #1609 rate caps.

What changed

  • slack_channel_agents.allow_proactive — dual-track migration (SQLite db/migrations.py + Alembic 0029), plus schema.py DDL and tables.py MetaData.
  • Default posture, deliberately split so nothing silently flips:
    • NEW bindings → 0 (deny). Binding an agent to a channel isn't itself consent to unprompted posts.
    • EXISTING bindings → backfilled to 1 (allow), because channel posts worked with no gate before this. The AC is explicit that existing behavior must not silently flip.
    • The backfill runs only when this caller added the column, so an operator's later explicit OFF survives re-runs (tested).
  • Enforcement in send_agent_slack_channel_message, placed between the 404 (not bound) and the 429 (rate capped) so all three refusal reasons stay distinguishable, returning a named actionable proactive_not_allowed. Rate caps still apply on top.
  • Toggle endpoint PUT /api/agents/{name}/slack/channels/{channel_id}/proactive (owner-gated) so it isn't API-only.

Tests

8 unit tests — default-deny for new bindings, flag on both read paths, toggle + scoping, unknown-binding miss, and the migration's no-silent-flip backfill, post-migration default, and idempotency. Green on SQLite (harness also runs PG when TEST_POSTGRES_URL is set).

⚠️ Alembic head collision to resolve at merge

This is 0029_... off 0028_agent_reminders. My open PR #1752 also adds a 0029_agent_evaluations off the same parent — two heads would break boot. Whichever merges second needs a one-line down_revision rebase.

Not in this PR (remaining ent#223 AC)

  • The channel-binding UI toggle (SlackChannelPanel.vue) — the endpoint is here, the switch isn't yet.
  • MCP send_group_message relaying the named reason to the agent.
  • Docs (Slack proactive = per-channel consent; DM stays per-recipient).

Unblocks ent#224 (completion report-back is gated on this consent).

🤖 Generated with Claude Code

dolho and others added 2 commits July 24, 2026 10:23
Proactive consent was modeled per RECIPIENT (agent_sharing.allow_proactive, keyed
by verified email). In an open Slack workspace users never authenticate, so no
recipient record exists to opt in and a Slack-facing agent had no sanctioned path
to post unprompted — channel posts had no consent gate at all, only the owner
check + #1609 rate caps. For Slack the consent unit is the CHANNEL BINDING.

- slack_channel_agents gains allow_proactive; dual-track migration (SQLite
  db/migrations.py + Alembic 0029) plus schema.py DDL and tables.py MetaData.
- Default posture, deliberately split so nothing silently flips:
    NEW bindings      -> 0 (deny). Binding an agent is not itself consent.
    EXISTING bindings -> backfilled to 1 (allow), because channel posts worked
                         with no gate before this change.
  The backfill runs only when this caller added the column (_safe_add_column
  returns True), so an operator's later explicit OFF survives re-runs.
- Enforcement in send_agent_slack_channel_message sits between the 404 (not
  bound) and the 429 (rate capped) so the three refusal reasons stay
  distinguishable, and returns a NAMED, actionable code (proactive_not_allowed)
  the agent can relay instead of a generic failure. Rate caps still apply on top.
- New owner-gated PUT /api/agents/{name}/slack/channels/{channel_id}/proactive
  so the flag is toggleable rather than API-only.

8 unit tests: default-deny for new bindings, flag present on both read paths,
toggle on/off + scoping, unknown-binding miss, and the migration's no-silent-flip
backfill + post-migration default + idempotency.

Related to ent#223

Co-Authored-By: Claude Opus 4.8 <[email protected]>
…ason, docs (ent#223)

Completes the remaining ent#223 acceptance criteria on top of the backend gate:

- GET /api/agents/{name}/slack/channel now returns allow_proactive so the panel
  can render the current state (it was write-only before).
- SlackChannelPanel.vue gains an "Allow proactive messages" switch that calls
  PUT .../slack/channels/{channel_id}/proactive and re-reads the binding, so the
  control always reflects what the backend stored. This is what makes the flag
  toggleable rather than API-only.
- MCP send_group_message now reports WHY a send was refused: consent_required
  (with an actionable hint), rate_limited, or not_bound — the three causes the
  backend already keeps distinguishable (403 / 429 / 404). Previously a consent
  refusal surfaced as a generic error the agent could not act on.
- docs/memory/feature-flows/proactive-messaging.md records the two consent units:
  DM = per-recipient verified email, Slack channel = per-channel binding, plus
  the split default posture and the refusal semantics.

Related to ent#223
…t#223)

0029_slack_channel_allow_proactive declared down_revision = 0028_agent_reminders,
but dev ALREADY carries 0029_product_events off that same parent. Two revisions
sharing a parent are two Alembic heads, and `upgrade head` then fails with
"Multiple head revisions are present" — which aborts init_database and
CRASH-LOOPS THE BACKEND on boot. Caught by deploying the branch to a real
PostgreSQL stack; no unit test would have seen it.

Renamed to 0030_slack_channel_allow_proactive chained off 0029_product_events,
so the line is linear again. Verified on a live stack: backend boots, alembic
head = 0030_slack_channel_allow_proactive, and the allow_proactive column is
present on slack_channel_agents.

Related to ent#223
dolho added a commit that referenced this pull request Jul 24, 2026
…t#206)

0029_agent_evaluations declared down_revision = 0028_agent_reminders, but dev
ALREADY carries 0029_product_events off that same parent — two heads, so
`alembic upgrade head` fails with "Multiple head revisions are present",
aborting init_database and crash-looping the backend on boot. Found by deploying
a sibling branch with the identical defect to a real PostgreSQL stack.

Renamed to 0031_agent_evaluations chained off 0030_slack_channel_allow_proactive
(trinity#1761), which is itself chained off 0029_product_events. That makes the
line linear and fixes the merge order deterministically: #1761 before this PR.

Related to ent#206
@dolho

dolho commented Jul 24, 2026

Copy link
Copy Markdown
Contributor Author

Superseded by #1763, which consolidates all three Slack partner follow-ups (ent#222 / ent#223 / ent#224) into a single OSS PR — they share a migration chain and ent#224 is gated by ent#223's consent flag, so reviewing them separately was artificial. Every commit from this branch is included there, plus the Alembic head fix. The enterprise half stays in trinity-enterprise#232 (repo boundary).

@dolho dolho closed this Jul 24, 2026
dolho added a commit that referenced this pull request Aug 3, 2026
…t#206)

0029_agent_evaluations declared down_revision = 0028_agent_reminders, but dev
ALREADY carries 0029_product_events off that same parent — two heads, so
`alembic upgrade head` fails with "Multiple head revisions are present",
aborting init_database and crash-looping the backend on boot. Found by deploying
a sibling branch with the identical defect to a real PostgreSQL stack.

Renamed to 0031_agent_evaluations chained off 0030_slack_channel_allow_proactive
(trinity#1761), which is itself chained off 0029_product_events. That makes the
line linear and fixes the merge order deterministically: #1761 before this PR.

Related to ent#206
dolho added a commit that referenced this pull request Aug 3, 2026
…t#206)

0029_agent_evaluations declared down_revision = 0028_agent_reminders, but dev
ALREADY carries 0029_product_events off that same parent — two heads, so
`alembic upgrade head` fails with "Multiple head revisions are present",
aborting init_database and crash-looping the backend on boot. Found by deploying
a sibling branch with the identical defect to a real PostgreSQL stack.

Renamed to 0031_agent_evaluations chained off 0030_slack_channel_allow_proactive
(trinity#1761), which is itself chained off 0029_product_events. That makes the
line linear and fixes the merge order deterministically: #1761 before this PR.

Related to ent#206
vybe pushed a commit that referenced this pull request Aug 3, 2026
… relabel (ent#206) (#1752)

* feat(eval): behavioral-eval foundation — referee surface + completion relabel (ent#206)

First implementation off the ent#206 strategy gate. The two lowest-dependency
children: the referee surface (child 2) and the completion relabel (child 1).

A run's QUALITY grade, kept apart from the clean-exit COMPLETION signal. The
load-bearing rule of the epic: the graded agent must never write its own grade.
agent_reports (#918) was rejected as the surface because its create is
self-gated (an agent writes its own report); this surface inverts that.

- New agent_evaluations table (id, agent_name, execution_id→schedule_executions,
  archetype, completion [exit mirror], quality [separate axis, nullable],
  checks_json, judge_json, evaluator, created_at). Dual-track (#1183): schema.py
  + migrations.py (SQLite) and Alembic 0029 (PostgreSQL); AGENT_REFS CASCADE.
- db/evaluations.py (three-layer, Invariant #1) — the ONLY writers are the
  platform and a future evaluator; no agent-scoped key reaches it.
- routers/evaluations.py: WRITE is human-admin-only (require_admin +
  reject_agent_principal, so an agent key — which inherits its owner's role —
  can't write, the trinity-ops-agent#232 trap the skill runner also closed).
  READ is access-scoped: an agent reads its OWN evaluations (feedback), an admin
  reads all. Read ≠ write.

Verified live: admin write → 200; the graded agent's own key → 403 on write,
200 on read.

schedule_executions.status='success' is a clean process exit, rendered as
"Success rate" on the Overview (#1107), schedules rollup (#1115) and fleet stats
(EXEC-022) as if it were correctness. Relabel those three surfaces to
"Completion" with a tooltip stating it is finish-without-error, not answer
quality. Additive — the success_rate API field is unchanged (back-compat); only
the user-facing labels move. The separate `quality` axis now lives on the
referee surface, populated by the Tier-0 runner (child 3, next).

Tests: 10 for the surface + fence (independent axes, agent-scoping, the fence
wiring, no agent-writable route, reports-not-reused guard, cascade parity). The
schema-parity guard caught a missing-index gap in schema.py, now fixed.

Related to Abilityai/trinity-enterprise#206

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

* fix(migrations): rebase the eval revision off the real head chain (ent#206)

0029_agent_evaluations declared down_revision = 0028_agent_reminders, but dev
ALREADY carries 0029_product_events off that same parent — two heads, so
`alembic upgrade head` fails with "Multiple head revisions are present",
aborting init_database and crash-looping the backend on boot. Found by deploying
a sibling branch with the identical defect to a real PostgreSQL stack.

Renamed to 0031_agent_evaluations chained off 0030_slack_channel_allow_proactive
(trinity#1761), which is itself chained off 0029_product_events. That makes the
line linear and fixes the merge order deterministically: #1761 before this PR.

Related to ent#206

* docs(eval): requirements, feature flow and architecture entries for the referee surface (ent#206)

Review catch (AndriiPasternak31): the PR added a table, a db module, a router and
new models while touching zero files under docs/memory/ — a new capability under
the tiered rule, and Rule 1 puts the requirements update BEFORE implementation, so
this was the write-path being skipped rather than a tail step dropped.

- requirements/lifecycle-observability.md §46 — the two axes (completion vs
  quality), FR-1..FR-5, and why agent_reports (§44) was rejected as the surface:
  its create is self-gated by design, which is the wrong boundary for a grade.
- feature-flows/agent-evaluations.md — the flow, the write fence and why it needs
  BOTH gates (an agent key inherits its owner's role, so require_admin alone lets
  a graded agent grade itself on a default install), the nullable-quality
  contract, and what this deliberately does not include.
- architecture.md — router catalog entry, a subsystem block, and the
  agent_evaluations DDL in Database Schema.
- feature-flows.md — changelog row + index row.

Records the open-core call rather than restating it as an assumption: OSS-core per
§10 of the merged strategy (trinity-enterprise#215), where the enforcement
primitive and the deterministic tier are edition-agnostic and the managed grading
experience is the paid layer — the #668 split exactly. Verified the
enterprise-docs guard pattern locally: clean.

Related to Abilityai/trinity-enterprise#267

* chore(eval): re-chain the eval revision onto the dev head after rebase (ent#206)

Rebasing onto dev (92 commits) left `0031_agent_evaluations` chained onto
`0030_slack_channel_allow_proactive`, but dev has since added
`0031_channel_report_back` and `0032_telegram_progress_indicator` — so the
branch carried a duplicate 0031 number and TWO Alembic heads, which
`alembic upgrade head` refuses (PostgreSQL boot break). Renamed to 0033_ and
re-pointed `down_revision` at `0032_telegram_progress_indicator`;
`ScriptDirectory.get_heads()` now returns one head over a 34-revision chain.

The five conflicts were all additive collisions between dev's `product_events`
(ent#184) and this branch's `agent_evaluations` — both sides kept in
database.py (import + ops wiring), db/migrations.py (MIGRATIONS list, eval
last), db/schema.py (DDL dict), db/tables.py (Core Table) and main.py (router
import + include). Verified by importing the metadata: both tables present,
65 total.

The four doc references to `0031_agent_evaluations` were updated with the file.

Related to #1752

---------

Co-authored-by: Claude Opus 4.8 (1M context) <[email protected]>
Co-authored-by: trinity-ability <[email protected]>
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.

1 participant