feat: add manual feedback AI summaries and secure leaderboard scoring

Co-authored-by: Stephan Charles <[email protected]>
Co-authored-by: Amelia Hernandez <[email protected]>
Co-authored-by: Markus Franz <[email protected]>
Co-authored-by: Sabrina Hota <[email protected]>
Co-authored-by: Nilüfer Doğan <[email protected]>
This commit is contained in:
committed 2026-10-15 19:06:10 +02:00
1 parent 407b878e23
commit 821907b164
37 files changed
+1640 -77

No files matched your search

+4 -3
View File
@@ -1,8 +1,8 @@
# Backend — Supabase Core
Convivo has **no custom backend**. The entire server side is a **local Supabase
stack** (run with the Supabase CLI) plus the schema, RPCs, and RLS that live in
Postgres. This folder documents that core.
Convivo uses a **local Supabase stack** (run with the Supabase CLI) for its schema,
RPCs and RLS, plus a Node sidecar for imports, reports and manual feedback AI
summaries. This folder documents both the database core and those integrations.
| File | What it covers |
|---|---|
@@ -13,6 +13,7 @@ Postgres. This folder documents that core.
| [seed.md](./seed.md) | Seed data + the demo accounts |
| [docker.md](./docker.md) | Docker: the app image + root compose (how the core + app run together) |
| [sidecar.md](./sidecar.md) | The Sessionize sync sidecar (on-demand, service-role) |
| [feedback-ai.md](./feedback-ai.md) | Admin-configured LLM endpoint and manual event/session feedback summaries |
| [tests.md](./tests.md) | The RPC test suite (`npm run test:rpc`) |
## The big picture
+126
View File
@@ -0,0 +1,126 @@
# Feedback AI Summaries
Attendees submit ratings and comments through the existing event and session
feedback forms. Admin generates summaries manually in **Activity > Event feedback**
or **Activity > Session feedback**. Each session has an independent button.
There is no background generation and no provider call on feedback submission.
## Configuration
**Settings > Feedback AI** stores one global configuration for all events:
- **LLM endpoint:** the complete HTTPS URL of an OpenAI-compatible Chat
Completions API, for example `https://api.openai.com/v1/chat/completions`.
The server does not append a path. URLs with embedded credentials, query
parameters or fragments are rejected.
- **Model:** the provider's model identifier, maximum 200 characters.
- **API key:** optional; sent as `Authorization: Bearer <key>`. Leaving this
field blank preserves an existing key. The checkbox explicitly removes it.
Changing the endpoint requires entering or clearing the key to prevent
forwarding a previously stored credential to a different endpoint.
The endpoint must resolve to public IP addresses. HTTP, localhost, private
networks, link-local metadata endpoints and reserved IP ranges are not supported.
DNS lookups have a 10-second timeout. Results are validated and the HTTPS
connection is pinned to a validated
address, preserving TLS hostname verification. Redirects are not followed.
Private Ollama installations need a public, authenticated HTTPS gateway exposing
the compatible API. Azure-style `api-key` headers and native Responses/Ollama APIs
are not implemented by this adapter.
Stored keys are server-only: `llm_settings` has RLS enabled and no grants for
anonymous or authenticated clients. Authenticated admins use the sidecar routes,
which return only endpoint, model, update time and `has_api_key`. The key is stored
in the protected database table, not encrypted by this feature; privileged
database operators and database backups can access it.
## API and Generation
All routes below require the Admin user's bearer token, verified with Supabase
Auth `/auth/v1/user`, followed by the existing contact admin rule (`is_admin` or
an existing `@appe.at` contact). They return `Cache-Control: no-store`.
| Route | Purpose |
| --- | --- |
| `GET /sidecar/llm-settings` | Read redacted configuration. |
| `PUT /sidecar/llm-settings` | Save `{ endpoint, model, api_key? }`. |
| `POST /sidecar/feedback-summary` | Generate `{ scope: "event", event_id }` or `{ scope: "session", event_id, session_id }`. |
The sidecar checks that the event exists and that a selected session belongs to
it. It reads all feedback in ordered 500-row pages, selecting only `rating` and
`comment`. The LLM receives the scope, event/session title, response count, ratings
and comments; contact names, associated email columns, IDs and timestamps are
excluded. Free-text comments can still contain personal information supplied by
attendees: use an approved provider and appropriate privacy/retention terms.
Requests contain `model`, `stream: false` and system/user `messages`. The response
must contain a nonempty string at `choices[0].message.content`. The prompt asks
for sentiment, strengths, concerns and actionable improvements in the predominant
comment language (English for rating-only feedback), without inventing evidence.
Feedback content is explicitly treated as untrusted input. Output is displayed as
plain text, never HTML; AI output still requires human review.
No-feedback requests fail before calling the provider. Generation also requires
saved configuration. Input is capped at approximately 190 KB of feedback (the
adapter additionally caps its complete input at 200 KB). Provider calls time out
after 60 seconds; output is capped at 100 KB and summaries at 20,000 characters.
Provider failures return sanitized errors, without raw provider bodies or keys.
Concurrent generation of the same target is rejected in the single sidecar
process; this is not a distributed lock across replicas.
## Persistence and Permissions
Migration [20261011163332_feedback_ai_summaries.sql](../../supabase/migrations/20261011163332_feedback_ai_summaries.sql)
adds `llm_settings` and `feedback_summaries`. Only the service role writes them.
Summary reads are restricted to admins by RLS; attendees cannot read these
organizer summaries. A successful generation upserts the latest result for its
scope and target, storing response count, model, generation timestamp and a
SHA-256 fingerprint of the exact rating/comment snapshot. It does not overwrite
ratings or comments. Deleting its event or session cascades the summary.
The UI restores saved summaries and offers manual regeneration. A provider
failure leaves the previous summary untouched. A response-count change is shown;
same-count comment edits are not currently flagged by the UI even though the
saved fingerprint records the generation snapshot. There is no summary history.
Activity reads event-scoped feedback in ordered pages, so counts and available
session controls are not truncated by the database API's row limit. Mobile tabs
wrap into two columns and feedback tables scroll within their own containers.
The old `evaluate_session_feedback` RPC is a deprecated stub with client execution
revoked. Its Schedule button and legacy AI state display were removed. The
legacy `sessions.ai_generated_feedback` field is not used to store these summaries.
Attendee feedback submission, points and average-rating behavior are unchanged.
## Local Validation
The migration was applied alone to the local database and recorded in its ledger;
older pending migrations were not applied. No seed or reset was run. Production
deployment is not included in this change.
For an alternate local instance, leaving the existing servers intact:
```sh
PORT=3003 SUPABASE_URL=http://127.0.0.1:54321 SESSIONIZE_SYNC_INTERVAL_MS=0 PRETIX_SYNC_INTERVAL_MS=2147483647 node apps/sidecar/src/server.js
SIDECAR_TARGET=http://127.0.0.1:3003 npm run dev --prefix apps/admin -- --host 127.0.0.1 --port 3004 --strictPort
```
This preview sidecar has no immediate Sessionize poll, and its Pretix loop has a
long interval. These values are for isolated local validation only, not deployment.
The usual Admin proxy target remains port 3002 when `SIDECAR_TARGET` is unset.
See [tests](./tests.md#feedback-ai-summary-regression) for automated checks.
For this validation, the existing Admin on `http://127.0.0.1:3001` is connected to
the updated sidecar on port 3003 through the ignored local file
`apps/admin/.env.development.local` (`SIDECAR_TARGET=http://127.0.0.1:3003`).
This preserves the existing allowlisted magic-link callback. The isolated 3004
preview was used for mocked browser testing and then stopped; real magic-link
login on another port requires allowlisting its exact callback first. Auth
configuration and existing server processes were not changed or stopped.
Validation passed: 28 sidecar tests, eight rollback-only SQL assertions, the
54-test combined browser regression suite, Admin build, test TypeScript and
editor checks. Desktop/mobile screenshots were inspected, including explicit
grid and bounding-box checks for the mobile feedback tabs and summary panel.
A real local Auth smoke used a disposable confirmed account, verified redacted
settings and no-feedback rejection through the proxy, then deleted its account,
contact and inactive event. No mail or provider request was sent.
+20 -10
View File
@@ -33,22 +33,31 @@ Source of truth:
| Feedback — rating + comment | **+10** | the attendee |
| Admin adjustment | any | the target (audited as `admin`) |
Only eligible registered participants earn points. Staff registrations and Admin
contacts (`is_admin` or `@appe.at`) always have zero points and never rank,
including when checked in, leaving feedback, accepting connections or receiving
manual adjustments. Existing audit history is retained when a role changes.
## Internal helpers
### `_award_points(p_event_id, p_contact_email, p_delta, p_category)`
The single place points change. In one transaction it:
The shared award path first locks the registration and checks eligibility. Missing
registrations, staff and Admin contacts receive no award or new audit entry.
Clients cannot call this helper directly. In one transaction it:
1. `update registrations set points = greatest(0, points + p_delta)` (floored at
0) for the (event, contact),
2. `insert into points_log (event_id, contact_email, delta, category)`,
3. calls `_sync_leaderboard(p_event_id, p_contact_email)`.
3. synchronizes the leaderboard through the registration write trigger.
### `_sync_leaderboard(p_event_id, p_contact_email)`
Upserts the `leaderboard` row for that (event, contact) from `registrations` +
`contacts` (`on conflict (event_id, contact_email) do update ...`). This is what
makes the leaderboard a consistent, Realtime-friendly mirror. **Staff are
excluded:** if the contact's registration `type` is `staff` (or there is no
registration), the function **deletes** any existing leaderboard row instead of
inserting — so staff never appear on the board even if they hold points.
makes the leaderboard a consistent, Realtime-friendly mirror. **Staff, Admins and
missing registrations are excluded:** the function deletes existing excluded
rows. Registration writes force excluded balances to zero; role/point changes,
registration deletion, contact Admin promotion and name changes refresh rankings.
The zero-points guard runs after the existing role-normalization triggers.
`leaderboard` belongs to the `supabase_realtime` publication for live updates.
### `_recalc_event_aggregates(p_event_id)`
Recomputes the `events` aggregate columns (`num_sessions`, `num_speakers`,
@@ -59,7 +68,7 @@ triggers and the feedback RPC.
| Function | Returns | Used for |
|---|---|---|
| `get_leaderboard()` | `event_id, contact_email, full_name, points` (active event, **staff excluded**, ordered by points) | Leaderboard initial load + realtime re-fetch |
| `get_leaderboard()` | `event_id, contact_email, full_name, points` (active event, **staff/Admins excluded**, ordered by points descending, name and email ascending) | Leaderboard initial load + realtime re-fetch |
| `lanyard_lookup(p_qr_token)` | `email, full_name, linkedin_url` (null unless `show_linkedin`), `show_email`, `registration_type` | Resolve a scanned QR (pre-login + connect) |
| `get_public_contacts()` | `email, full_name, linkedin_url`, `show_email`, `registration_type` (active-event registrants) | Connections name/type lookups |
| `get_agenda()` | flat rows: slot fields + session fields + `speakers` (string_agg) | Agenda + Home |
@@ -238,9 +247,10 @@ immediately.
`p_type` is `text` and is cast to the `registration_type` enum on write.
### `evaluate_session_feedback(p_session_id)` → `sessions`
**Admin-only.** The **AI-feedback stub**: sets `ai_generated_feedback` to a
placeholder string ("AI evaluation stub: N comment(s) received. (LLM integration
pending.)"). Real LLM integration is a later phase.
**Deprecated stub.** Migration `20261011163332_feedback_ai_summaries` revokes
client execution. Admin now uses the authenticated sidecar for real manual event
and session summaries, stored separately from `sessions.ai_generated_feedback`.
See [Feedback AI summaries](./feedback-ai.md).
### `set_session_material(p_session_id, p_material_path)` → `sessions`
Sets only a session's `material_path`, with a row lock. Requires authentication
+4
View File
@@ -20,6 +20,10 @@ then every 15 minutes. Pretix retains its independent every-minute loop.
## What it does
The sidecar also provides authenticated, admin-only LLM configuration and manual
feedback summary routes. See [Feedback AI summaries](./feedback-ai.md) for the
provider contract, permissions, limits and privacy requirements.
There are **two import paths**; the source/API path also runs automatically:
**A. API sync** (`POST /run`) — fetches the event's `sessionize_endpoint` and
+42
View File
@@ -1,3 +1,45 @@
# Leaderboard Regression
After applying `20261015164546_leaderboard_staff_admin_exclusion`, run:
```sh
docker exec -i supabase_db_Convivo psql -X -U postgres -d postgres \
-v ON_ERROR_STOP=1 < supabase/tests/leaderboard_tests.sql
CONVIVO_BASE_URL=http://127.0.0.1:3000 npm test --prefix e2e -- leaderboard-live.spec.ts --project=chromium
```
The SQL fixture rolls back and checks scoring, idempotency, event isolation,
staff/Admin zero balances, role changes, deterministic ranking, API-role grants
and Realtime publication membership. The browser test is local-only and uses real
Auth, PostgREST and WebSockets, not mocked APIs. It creates disposable accounts,
verifies live score/rank changes and staff/Admin exclusions, then deletes its
fixtures. It requires the local attendee app, Supabase and an active event.
See [October 15 validation](../releases/2026-10-15.md) for results and scope.
# Feedback AI Summary Regression
After applying only `20261011163332_feedback_ai_summaries`, run:
```sh
npm test --prefix apps/sidecar
docker exec -i supabase_db_Convivo psql -X -U postgres -d postgres \
-v ON_ERROR_STOP=1 < supabase/tests/feedback_ai_summary_tests.sql
CONVIVO_ADMIN_URL=http://127.0.0.1:3001 npm test --prefix e2e -- feedback-ai-summary.spec.ts --project=chromium
```
The SQL fixture is rollback-only: eight assertions cover RLS, grants, deprecated
stub permissions, service-role persistence, admin/non-admin reads and cascades.
Unit tests cover provider payload privacy, settings-key redaction and retention,
scope isolation, empty feedback, errors, duplicate requests and private-address
rejection and multi-page snapshots. Eight API-mocked browser tests cover settings,
manual event/session generation, restored summaries, disabled states, pagination,
retry and desktop/mobile layouts.
These tests do not send real feedback to any LLM or send login emails.
See [Feedback AI summaries](./feedback-ai.md) for the request/response contract and
local-only activation status.
# Service Staff Regression
The attendee browser suite also covers demo clock dates for two different events