feat(assessment): add the review band of attempt signals and the disclosed collector

This commit is contained in:
shira committed 2026-10-08 23:04:57 +03:00
1 parent 68286af8b7
commit b3c6dc870b
124 files changed
+13522 -633

No files matched your search

+18 -1
View File
@@ -187,7 +187,7 @@ To inspect an `invalid_record` while the topic retains it, read exactly that rec
### Scheduled jobs
The backend runs the scheduled job worker as a goroutine of the backend process next to the HTTP servers, the relay, and the consumers. It runs jobs that usecases scheduled in their transactions once they fall due; the design is in [ARCHITECTURE.md](ARCHITECTURE.md#scheduled-jobs). Current state: no product job kind is registered, so the backend logs `no scheduled job kind is registered` at startup and runs no worker; the settings below are still validated. With a registered kind, the worker runs when `JOBS_ENABLED` is true and `DATABASE_URL` is set. Compose passes none of the settings, so the stack uses the defaults; to change one, add it to the backend `environment` in `deploy/docker/docker-compose.yml`. A directly launched backend reads them from its environment. An invalid value stops startup, also with the worker disabled.
The backend runs the scheduled job worker as a goroutine of the backend process next to the HTTP servers, the relay, and the consumers. It runs jobs that usecases scheduled in their transactions once they fall due; the design is in [ARCHITECTURE.md](ARCHITECTURE.md#scheduled-jobs). Current state: one product kind is registered, `assessment.signal_review` (see [Assessment review band](#assessment-review-band)), so the worker runs when `JOBS_ENABLED` is true and `DATABASE_URL` is set; the settings below are validated in any case. Compose passes none of the settings, so the stack uses the defaults; to change one, add it to the backend `environment` in `deploy/docker/docker-compose.yml`. A directly launched backend reads them from its environment. An invalid value stops startup, also with the worker disabled.
| Variable | Default | Meaning |
| --- | --- | --- |
@@ -310,6 +310,23 @@ Implemented: the renderer in `backend/internal/usecase/notification/mailtemplate
- The renderer does not log. A rendering and notification data print only the kind, version, and content hash in `fmt` and `slog` output; tokens, links, and bodies are never printed.
- Golden files in `testdata/` make every copy change visible in review. After an intended change, run `go test ./internal/usecase/notification/mailtemplate -update` from `backend/` and review the diff.
## Assessment review band
The server computes a manual-review band (`normal`, `attention`, `review`) for real assessment attempts from the server signals and the policy version pinned to the attempt (see [ARCHITECTURE.md](ARCHITECTURE.md#assessment-signals-and-the-review-band)). The band is a hint for a person who checks an attempt by hand. It changes no result, category, or quota, and no HTTP endpoint serves it. Until staff roles exist, an operator reads it with a local command:
```sh
make -C backend assessment-review ARGS='inspect --attempt <uuid> --actor operator:<handle>'
```
- The band is computed by the scheduled job kind `assessment.signal_review`, never in a candidate's request. The jobs are inserted into `scheduled_jobs` with the first answer (due one minute after the deadline of the attempt) and with finalization (due at once). The worker must run (`JOBS_ENABLED=true`, [Scheduled jobs](#scheduled-jobs)); with the worker off the reviews wait with their jobs and no result is affected. A failed job is retried with the worker's backoff; a dead job (see [Dead jobs](#dead-jobs)) leaves the attempt without a refreshed review and does not touch its result.
- The command needs `DATABASE_URL` and reads nothing else from the environment or a dotenv file; the local database credential is its operator boundary. `make -C backend assessment-review-build` builds `backend/bin/assessment-review`.
- It prints the attempt ID, the band, the reason codes, the policy version, the evaluation and update times, and the counts behind the band. It prints no answer, address, session, candidate, or contact data, and it never names another candidate of a duplicate match.
- Every read is recorded in `assessment_review_reads` (attempt ID, actor handle, found or missing, database time) in the same transaction as the read, also when the attempt has no review. The table refuses UPDATE, DELETE, and TRUNCATE. The actor is an audit handle, not authentication: any holder of the database credential can type any handle. Rolling migration 33 back is refused while the audit holds a row; export or resolve it first.
- A band can be missing for a real reason: the policy version of the attempt has no `assessment.signals` section, the review job has not run yet, or the attempt has neither ended nor reached its deadline.
- A review is updated in place when a later attempt matches one of its answers; the policy version and the first evaluation time stay.
- To use thresholds other than the demo values, publish a policy version with an `assessment.signals` section through the policy publisher. `DemoProductPolicyV3` is the demo example and is published only explicitly (the isolated browser fixture does so); the startup seed publishes version 1 only. Attempts that already started keep the version they started with. The demo duplicate thresholds assume a population: a copied pair is flagged only from about 26 answers per family (attention) and 61 (review) at 13 items, or 9 and 14 at 23 items. To try the feature on a smaller stand, publish a policy version with lower `duplicate_bits_attention` and `duplicate_bits_review` (the integration tests use 4 and 6); do not edit the demo policy. A review is a point-in-time evaluation, run again by the job at the deadline. The job logs one line per run with the number of reviews and its duration (`assessment review job finished`).
- The rows hold counts, durations, and keyed digests (HMAC-SHA-256 under keys derived from `IDENTITY_KEY_SECRET`, each with a key version) and no answer text. Rotating the secret keeps the stored rows but makes new fingerprints incomparable with old ones. Deleting an account deletes its attempts and, by cascade, their facts and reviews; the audit rows keep only the attempt ID and the handle. The digests are kept for the lifetime of the attempt; no retention period is defined yet.
## Separate ML Compose project
ML uses a separate Compose file and project; it does not require or start Redis or SeaweedFS in the current scaffold. Its default host bind is 127.0.0.1:8000. Set ML_BIND_ADDRESS only after choosing a private address and preparing firewall rules. Prometheus does not scrape remote ML while ML_METRICS_TARGET is empty.