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

@@ -0,0 +1,74 @@
package postgres
import (
"context"
"errors"
"fmt"
"time"
"github.com/google/uuid"
"github.com/jackc/pgx/v5"
"github.com/jackc/pgx/v5/pgtype"
"lincodex/backend/internal/adapter/secondary/postgres/sqlc"
"lincodex/backend/internal/port/outbound"
)
var (
_ outbound.AssessmentSignalNoticeRepositories = (*UnitOfWork)(nil)
_ outbound.AssessmentSignalNoticeRepository = assessmentSignalNoticeRepository{}
)
func (unit *UnitOfWork) AssessmentSignalNotices() outbound.AssessmentSignalNoticeRepository {
return assessmentSignalNoticeRepository{queries: unit.queries}
}
type assessmentSignalNoticeRepository struct {
queries *sqlc.Queries
}
func (repository assessmentSignalNoticeRepository) Get(
ctx context.Context,
userID uuid.UUID,
version int32,
) (time.Time, error) {
const location = "assessmentSignalNoticeRepository.Get"
if userID == uuid.Nil || version < 1 {
return time.Time{}, fmt.Errorf("%s - user and notice version are required", location)
}
stored, err := repository.queries.GetAssessmentSignalNoticeAcknowledgement(ctx, sqlc.GetAssessmentSignalNoticeAcknowledgementParams{
UserID: pgUUID(userID), NoticeVersion: version,
})
if errors.Is(err, pgx.ErrNoRows) {
return time.Time{}, fmt.Errorf("%s - read acknowledgement: %w", location, outbound.ErrAssessmentSignalNoticeNotAcknowledged)
}
if err != nil {
return time.Time{}, fmt.Errorf("%s - read acknowledgement: %w", location, mapAssessmentError(err))
}
return acknowledgementTime(location, stored)
}
func (repository assessmentSignalNoticeRepository) Acknowledge(
ctx context.Context,
userID uuid.UUID,
version int32,
at time.Time,
) (time.Time, error) {
const location = "assessmentSignalNoticeRepository.Acknowledge"
if userID == uuid.Nil || version < 1 || at.IsZero() {
return time.Time{}, fmt.Errorf("%s - user, notice version, and time are required", location)
}
if err := repository.queries.InsertAssessmentSignalNoticeAcknowledgement(ctx, sqlc.InsertAssessmentSignalNoticeAcknowledgementParams{
UserID: pgUUID(userID), NoticeVersion: version, AcknowledgedAt: pgTime(at),
}); err != nil {
return time.Time{}, fmt.Errorf("%s - insert acknowledgement: %w", location, mapAssessmentError(err))
}
return repository.Get(ctx, userID, version)
}
func acknowledgementTime(location string, stored pgtype.Timestamptz) (time.Time, error) {
if !stored.Valid || stored.Time.IsZero() {
return time.Time{}, fmt.Errorf("%s - stored acknowledgement time is missing", location)
}
return stored.Time.UTC(), nil
}
@@ -0,0 +1,299 @@
package postgres
import (
"context"
"errors"
"fmt"
"time"
"github.com/google/uuid"
"github.com/jackc/pgx/v5"
"lincodex/backend/internal/adapter/secondary/postgres/sqlc"
"lincodex/backend/internal/domain"
"lincodex/backend/internal/port/outbound"
)
func (repository assessmentSignalRepository) SaveAnswerObservation(
ctx context.Context,
observation domain.AssessmentAnswerObservation,
) error {
const location = "assessmentSignalRepository.SaveAnswerObservation"
if err := observation.Validate(); err != nil {
return fmt.Errorf("%s - observation is invalid: %w", location, err)
}
if err := repository.queries.InsertAssessmentAnswerObservation(ctx, sqlc.InsertAssessmentAnswerObservationParams{
AttemptID: pgUUID(observation.AttemptID.UUID()), ItemInstanceID: pgUUID(observation.ItemInstanceID),
UserID: pgUUID(observation.UserID), FamilyID: pgUUID(uuid.UUID(observation.FamilyID)),
// The seed is stored as the two's-complement image of the uint64, which
// keeps equality and inequality exact.
VariantSeed: int64(observation.Seed), //nolint:gosec // The two's-complement image of the seed keeps equality exact.
AnswerFormat: observation.AnswerFormat,
AnswerFingerprint: observation.Fingerprint[:], KeyVersion: observation.KeyVersion,
ElapsedMs: observation.ElapsedMS, MeasuredFromAnswer: observation.MeasuredFromAnswer,
ObservedAt: pgTime(observation.ObservedAt),
}); err != nil {
return fmt.Errorf("%s - insert observation: %w", location, mapAssessmentError(err))
}
return nil
}
func (repository assessmentSignalRepository) SaveOriginMark(ctx context.Context, mark domain.AssessmentOriginMark) error {
const location = "assessmentSignalRepository.SaveOriginMark"
if err := mark.Validate(); err != nil {
return fmt.Errorf("%s - mark is invalid: %w", location, err)
}
var network []byte
if !mark.NetworkDigest.IsZero() {
network = mark.NetworkDigest[:]
}
if err := repository.queries.InsertAssessmentOriginMark(ctx, sqlc.InsertAssessmentOriginMarkParams{
ID: pgUUID(mark.ID), AttemptID: pgUUID(mark.AttemptID.UUID()), Source: string(mark.Source),
ObservedAt: pgTime(mark.ObservedAt), SessionDigest: mark.SessionDigest[:], NetworkDigest: network,
KeyVersion: mark.KeyVersion,
}); err != nil {
return fmt.Errorf("%s - insert origin mark: %w", location, mapAssessmentError(err))
}
return nil
}
func (repository assessmentSignalRepository) LastOriginMark(
ctx context.Context,
attemptID domain.AssessmentAttemptID,
) (domain.AssessmentOriginMark, bool, error) {
const location = "assessmentSignalRepository.LastOriginMark"
if attemptID.IsZero() {
return domain.AssessmentOriginMark{}, false, fmt.Errorf("%s - attempt ID is required: %w", location, domain.ErrInvalidAssessmentReview)
}
row, err := repository.queries.GetLastAssessmentOriginMark(ctx, pgUUID(attemptID.UUID()))
if errors.Is(err, pgx.ErrNoRows) {
return domain.AssessmentOriginMark{}, false, nil
}
if err != nil {
return domain.AssessmentOriginMark{}, false, fmt.Errorf("%s - read last mark: %w", location, mapAssessmentError(err))
}
mark, err := restoreAssessmentOriginMark(row)
if err != nil {
return domain.AssessmentOriginMark{}, false, fmt.Errorf("%s - restore mark: %w", location, err)
}
return mark, true, nil
}
func (repository assessmentSignalRepository) ReviewInputs(
ctx context.Context,
attemptID domain.AssessmentAttemptID,
) (outbound.AssessmentReviewInputs, error) {
const location = "assessmentSignalRepository.ReviewInputs"
if attemptID.IsZero() {
return outbound.AssessmentReviewInputs{}, fmt.Errorf("%s - attempt ID is required: %w", location, domain.ErrInvalidAssessmentReview)
}
id := pgUUID(attemptID.UUID())
times, err := repository.queries.ListAssessmentAnswerTimes(ctx, id)
if err != nil {
return outbound.AssessmentReviewInputs{}, fmt.Errorf("%s - list answer times: %w", location, mapAssessmentError(err))
}
marks, err := repository.queries.ListAssessmentOriginMarks(ctx, id)
if err != nil {
return outbound.AssessmentReviewInputs{}, fmt.Errorf("%s - list origin marks: %w", location, mapAssessmentError(err))
}
totals, err := repository.queries.GetAssessmentClientSignalTotals(ctx, id)
if err != nil {
return outbound.AssessmentReviewInputs{}, fmt.Errorf("%s - total client signals: %w", location, mapAssessmentError(err))
}
inputs := outbound.AssessmentReviewInputs{
ClientFocusLossMS: totals.FocusLossMs, ClientClipboardCount: totals.ClipboardEvents,
ClientFullscreenExit: totals.FullscreenExits,
}
for _, row := range times {
inputs.Answers = append(inputs.Answers, domain.AssessmentResponseSample{
AnswerFormat: row.AnswerFormat, ElapsedMS: row.ElapsedMs, MeasuredFromAnswer: row.MeasuredFromAnswer,
})
}
for _, row := range marks {
mark, err := restoreAssessmentOriginMark(row)
if err != nil {
return outbound.AssessmentReviewInputs{}, fmt.Errorf("%s - restore origin mark: %w", location, err)
}
inputs.Marks = append(inputs.Marks, mark)
}
return inputs, nil
}
func restoreAssessmentOriginMark(row sqlc.AssessmentAttemptOriginMark) (domain.AssessmentOriginMark, error) {
if !row.ID.Valid || !row.AttemptID.Valid || !row.ObservedAt.Valid || len(row.SessionDigest) != len(domain.AssessmentDigest{}) ||
len(row.NetworkDigest) != 0 && len(row.NetworkDigest) != len(domain.AssessmentDigest{}) {
return domain.AssessmentOriginMark{}, domain.ErrInvalidAssessmentReview
}
mark := domain.AssessmentOriginMark{
ID: uuid.UUID(row.ID.Bytes), AttemptID: domain.AssessmentAttemptID(row.AttemptID.Bytes),
Source: domain.AssessmentOriginSource(row.Source), ObservedAt: row.ObservedAt.Time.UTC(),
KeyVersion: row.KeyVersion,
}
copy(mark.SessionDigest[:], row.SessionDigest)
copy(mark.NetworkDigest[:], row.NetworkDigest)
if err := mark.Validate(); err != nil {
return domain.AssessmentOriginMark{}, err
}
return mark, nil
}
func (repository assessmentSignalRepository) DuplicatePairs(
ctx context.Context,
attemptID domain.AssessmentAttemptID,
query outbound.AssessmentDuplicateQuery,
) ([]outbound.AssessmentDuplicatePair, error) {
const location = "assessmentSignalRepository.DuplicatePairs"
if attemptID.IsZero() || query.Limit < 1 || query.IntegerCapBits < 1 || query.SequenceCapBits < 1 || query.MinBits < 0 ||
query.EndedOnly && query.Now.IsZero() {
return nil, fmt.Errorf("%s - attempt, caps, and bounds are required: %w", location, domain.ErrInvalidAssessmentReview)
}
rows, err := repository.queries.ListAssessmentDuplicatePairs(ctx, sqlc.ListAssessmentDuplicatePairsParams{
AttemptID: pgUUID(attemptID.UUID()), IntegerCapBits: float64(query.IntegerCapBits),
SequenceCapBits: float64(query.SequenceCapBits), MinBits: float64(query.MinBits),
EndedOnly: query.EndedOnly, Now: pgTime(query.Now), RowLimit: query.Limit,
})
if err != nil {
return nil, fmt.Errorf("%s - list pairs: %w", location, mapAssessmentError(err))
}
pairs := make([]outbound.AssessmentDuplicatePair, 0, len(rows))
for _, row := range rows {
if !row.OtherAttemptID.Valid || !row.ProductPolicyVersionID.Valid || row.EvidenceBits < 0 {
return nil, fmt.Errorf("%s - stored pair is incomplete: %w", location, domain.ErrInvalidAssessmentReview)
}
pairs = append(pairs, outbound.AssessmentDuplicatePair{
AttemptID: domain.AssessmentAttemptID(row.OtherAttemptID.Bytes),
PolicyVersionID: domain.PolicyVersionID(row.ProductPolicyVersionID.Bytes),
EvidenceBits: row.EvidenceBits, IntegerItems: row.IntegerItems, SequenceItems: row.SequenceItems,
})
}
return pairs, nil
}
func (repository assessmentSignalRepository) ReviewSubject(
ctx context.Context,
attemptID domain.AssessmentAttemptID,
) (domain.PolicyVersionID, bool, error) {
const location = "assessmentSignalRepository.ReviewSubject"
if attemptID.IsZero() {
return domain.PolicyVersionID{}, false, fmt.Errorf("%s - attempt ID is required: %w", location, domain.ErrInvalidAssessmentReview)
}
policyID, err := repository.queries.GetAssessmentReviewSubject(ctx, pgUUID(attemptID.UUID()))
if errors.Is(err, pgx.ErrNoRows) {
return domain.PolicyVersionID{}, false, nil
}
if err != nil {
return domain.PolicyVersionID{}, false, fmt.Errorf("%s - read attempt: %w", location, mapAssessmentError(err))
}
if !policyID.Valid {
return domain.PolicyVersionID{}, false, fmt.Errorf("%s - stored policy is missing: %w", location, domain.ErrInvalidAssessmentReview)
}
return domain.PolicyVersionID(policyID.Bytes), true, nil
}
func (repository assessmentSignalRepository) LockReview(ctx context.Context, attemptID domain.AssessmentAttemptID) error {
const location = "assessmentSignalRepository.LockReview"
if attemptID.IsZero() {
return fmt.Errorf("%s - attempt ID is required: %w", location, domain.ErrInvalidAssessmentReview)
}
if err := repository.queries.LockAssessmentReview(ctx, attemptID.String()); err != nil {
return fmt.Errorf("%s - take advisory lock: %w", location, mapAssessmentError(err))
}
return nil
}
func (repository assessmentSignalRepository) SaveReview(ctx context.Context, review domain.AssessmentAttemptReview) error {
const location = "assessmentSignalRepository.SaveReview"
if err := review.Validate(); err != nil {
return fmt.Errorf("%s - review is invalid: %w", location, err)
}
measures := review.Measures
reasons := make([]string, 0, len(review.Outcome.Reasons))
for _, reason := range review.Outcome.Reasons {
reasons = append(reasons, string(reason))
}
if err := repository.queries.UpsertAssessmentAttemptReview(ctx, sqlc.UpsertAssessmentAttemptReviewParams{
AttemptID: pgUUID(review.AttemptID.UUID()), PolicyVersionID: pgUUID(uuid.UUID(review.PolicyVersionID)),
Band: string(review.Outcome.Band), Reasons: reasons, AnsweredItems: measures.AnsweredItems,
FastAnswers: measures.FastAnswers, DeviatingAnswers: measures.DeviatingAnswers,
ParallelAlternations: measures.ParallelAlternations, ExtraNetworks: measures.ExtraNetworks,
MatchedIntegerItems: measures.MatchedIntegerItems, MatchedSequenceItems: measures.MatchedSequenceItems,
DuplicateEvidenceBits: measures.DuplicateEvidenceBits, ClientFocusLossMs: measures.ClientFocusLossMS,
ClientClipboardEvents: measures.ClientClipboardEvents, ClientFullscreenExits: measures.ClientFullscreenExits,
}); err != nil {
return fmt.Errorf("%s - upsert review: %w", location, mapAssessmentError(err))
}
return nil
}
func (repository assessmentSignalRepository) GetReview(
ctx context.Context,
attemptID domain.AssessmentAttemptID,
) (domain.AssessmentAttemptReview, error) {
const location = "assessmentSignalRepository.GetReview"
if attemptID.IsZero() {
return domain.AssessmentAttemptReview{}, fmt.Errorf("%s - attempt ID is required: %w", location, domain.ErrInvalidAssessmentReview)
}
row, err := repository.queries.GetAssessmentAttemptReview(ctx, pgUUID(attemptID.UUID()))
if errors.Is(err, pgx.ErrNoRows) {
return domain.AssessmentAttemptReview{}, fmt.Errorf("%s - review does not exist: %w", location, outbound.ErrAssessmentReviewNotFound)
}
if err != nil {
return domain.AssessmentAttemptReview{}, fmt.Errorf("%s - read review: %w", location, mapAssessmentError(err))
}
review, err := restoreAssessmentAttemptReview(row)
if err != nil {
return domain.AssessmentAttemptReview{}, fmt.Errorf("%s - restore review: %w", location, err)
}
return review, nil
}
func restoreAssessmentAttemptReview(row sqlc.GetAssessmentAttemptReviewRow) (domain.AssessmentAttemptReview, error) {
if !row.AttemptID.Valid || !row.PolicyVersionID.Valid || !row.EvaluatedAt.Valid || !row.UpdatedAt.Valid {
return domain.AssessmentAttemptReview{}, domain.ErrInvalidAssessmentReview
}
reasons := make([]domain.AssessmentReviewReason, 0, len(row.Reasons))
for _, reason := range row.Reasons {
reasons = append(reasons, domain.AssessmentReviewReason(reason))
}
review := domain.AssessmentAttemptReview{
AttemptID: domain.AssessmentAttemptID(row.AttemptID.Bytes),
PolicyVersionID: domain.PolicyVersionID(row.PolicyVersionID.Bytes),
PolicyVersion: row.PolicyVersion,
Measures: domain.AssessmentReviewMeasures{
AnsweredItems: row.AnsweredItems, FastAnswers: row.FastAnswers, DeviatingAnswers: row.DeviatingAnswers,
ParallelAlternations: row.ParallelAlternations, ExtraNetworks: row.ExtraNetworks,
MatchedIntegerItems: row.MatchedIntegerItems, MatchedSequenceItems: row.MatchedSequenceItems,
DuplicateEvidenceBits: row.DuplicateEvidenceBits,
ClientFocusLossMS: row.ClientFocusLossMs, ClientClipboardEvents: row.ClientClipboardEvents,
ClientFullscreenExits: row.ClientFullscreenExits,
},
Outcome: domain.AssessmentReviewOutcome{
Band: domain.AssessmentReviewBand(row.Band), Reasons: reasons,
},
EvaluatedAt: row.EvaluatedAt.Time.UTC(), UpdatedAt: row.UpdatedAt.Time.UTC(),
}
if err := review.Validate(); err != nil {
return domain.AssessmentAttemptReview{}, err
}
return review, nil
}
func (repository assessmentSignalRepository) RecordReviewRead(
ctx context.Context,
id uuid.UUID,
attemptID domain.AssessmentAttemptID,
actor domain.AssessmentReviewActor,
found bool,
at time.Time,
) error {
const location = "assessmentSignalRepository.RecordReviewRead"
if id == uuid.Nil || attemptID.IsZero() || actor == "" || at.IsZero() {
return fmt.Errorf("%s - record identifiers, attempt, actor, and time are required: %w", location, domain.ErrInvalidAssessmentReview)
}
if err := repository.queries.InsertAssessmentReviewRead(ctx, sqlc.InsertAssessmentReviewReadParams{
ID: pgUUID(id), AttemptID: pgUUID(attemptID.UUID()), Actor: string(actor), Found: found, ReadAt: pgTime(at),
}); err != nil {
return fmt.Errorf("%s - insert read record: %w", location, mapAssessmentError(err))
}
return nil
}
@@ -0,0 +1,53 @@
// Code generated by sqlc. DO NOT EDIT.
// versions:
// sqlc v1.31.1
// source: assessment_signal_notice.sql
package sqlc
import (
"context"
"github.com/jackc/pgx/v5/pgtype"
)
const getAssessmentSignalNoticeAcknowledgement = `-- name: GetAssessmentSignalNoticeAcknowledgement :one
SELECT acknowledged_at
FROM assessment_signal_notice_acknowledgements
WHERE
user_id = $1
AND notice_version = $2
`
type GetAssessmentSignalNoticeAcknowledgementParams struct {
UserID pgtype.UUID
NoticeVersion int32
}
// The caller has already checked that the user is a candidate. A missing row
// means the notice version was not acknowledged.
func (q *Queries) GetAssessmentSignalNoticeAcknowledgement(ctx context.Context, arg GetAssessmentSignalNoticeAcknowledgementParams) (pgtype.Timestamptz, error) {
row := q.db.QueryRow(ctx, getAssessmentSignalNoticeAcknowledgement, arg.UserID, arg.NoticeVersion)
var acknowledged_at pgtype.Timestamptz
err := row.Scan(&acknowledged_at)
return acknowledged_at, err
}
const insertAssessmentSignalNoticeAcknowledgement = `-- name: InsertAssessmentSignalNoticeAcknowledgement :exec
INSERT INTO assessment_signal_notice_acknowledgements (user_id, notice_version, acknowledged_at)
VALUES ($1, $2, $3)
ON CONFLICT (user_id, notice_version) DO NOTHING
`
type InsertAssessmentSignalNoticeAcknowledgementParams struct {
UserID pgtype.UUID
NoticeVersion int32
AcknowledgedAt pgtype.Timestamptz
}
// The first acknowledgement wins; a repeat keeps the stored time and inserts
// nothing. The caller reads the stored row afterwards in the same transaction.
func (q *Queries) InsertAssessmentSignalNoticeAcknowledgement(ctx context.Context, arg InsertAssessmentSignalNoticeAcknowledgementParams) error {
_, err := q.db.Exec(ctx, insertAssessmentSignalNoticeAcknowledgement, arg.UserID, arg.NoticeVersion, arg.AcknowledgedAt)
return err
}
@@ -0,0 +1,577 @@
// Code generated by sqlc. DO NOT EDIT.
// versions:
// sqlc v1.31.1
// source: assessment_signal_review.sql
package sqlc
import (
"context"
"github.com/jackc/pgx/v5/pgtype"
)
const getAssessmentAttemptReview = `-- name: GetAssessmentAttemptReview :one
SELECT
review.attempt_id,
review.policy_version_id,
policy.version AS policy_version,
review.band,
review.reasons,
review.answered_items,
review.fast_answers,
review.deviating_answers,
review.parallel_alternations,
review.extra_networks,
review.matched_integer_items,
review.matched_sequence_items,
review.duplicate_evidence_bits,
review.client_focus_loss_ms,
review.client_clipboard_events,
review.client_fullscreen_exits,
review.evaluated_at,
review.updated_at
FROM assessment_attempt_reviews AS review
JOIN policy_versions AS policy ON policy.id = review.policy_version_id
WHERE review.attempt_id = $1
`
type GetAssessmentAttemptReviewRow struct {
AttemptID pgtype.UUID
PolicyVersionID pgtype.UUID
PolicyVersion int32
Band string
Reasons []string
AnsweredItems int32
FastAnswers int32
DeviatingAnswers int32
ParallelAlternations int32
ExtraNetworks int32
MatchedIntegerItems int32
MatchedSequenceItems int32
DuplicateEvidenceBits int32
ClientFocusLossMs int64
ClientClipboardEvents int32
ClientFullscreenExits int32
EvaluatedAt pgtype.Timestamptz
UpdatedAt pgtype.Timestamptz
}
func (q *Queries) GetAssessmentAttemptReview(ctx context.Context, attemptID pgtype.UUID) (GetAssessmentAttemptReviewRow, error) {
row := q.db.QueryRow(ctx, getAssessmentAttemptReview, attemptID)
var i GetAssessmentAttemptReviewRow
err := row.Scan(
&i.AttemptID,
&i.PolicyVersionID,
&i.PolicyVersion,
&i.Band,
&i.Reasons,
&i.AnsweredItems,
&i.FastAnswers,
&i.DeviatingAnswers,
&i.ParallelAlternations,
&i.ExtraNetworks,
&i.MatchedIntegerItems,
&i.MatchedSequenceItems,
&i.DuplicateEvidenceBits,
&i.ClientFocusLossMs,
&i.ClientClipboardEvents,
&i.ClientFullscreenExits,
&i.EvaluatedAt,
&i.UpdatedAt,
)
return i, err
}
const getAssessmentClientSignalTotals = `-- name: GetAssessmentClientSignalTotals :one
SELECT
COALESCE(sum(duration_ms) FILTER (WHERE kind = 'focus_loss'), 0)::bigint AS focus_loss_ms,
(count(*) FILTER (WHERE kind IN ('copy', 'paste', 'cut')))::integer AS clipboard_events,
(count(*) FILTER (WHERE kind = 'fullscreen_exit'))::integer AS fullscreen_exits
FROM assessment_signal_events
WHERE attempt_id = $1
`
type GetAssessmentClientSignalTotalsRow struct {
FocusLossMs int64
ClipboardEvents int32
FullscreenExits int32
}
func (q *Queries) GetAssessmentClientSignalTotals(ctx context.Context, attemptID pgtype.UUID) (GetAssessmentClientSignalTotalsRow, error) {
row := q.db.QueryRow(ctx, getAssessmentClientSignalTotals, attemptID)
var i GetAssessmentClientSignalTotalsRow
err := row.Scan(&i.FocusLossMs, &i.ClipboardEvents, &i.FullscreenExits)
return i, err
}
const getAssessmentReviewSubject = `-- name: GetAssessmentReviewSubject :one
SELECT product_policy_version_id
FROM assessment_attempts
WHERE id = $1 AND kind IN ('root', 'corrective')
`
// The attempt a review job works on: real attempts only.
func (q *Queries) GetAssessmentReviewSubject(ctx context.Context, attemptID pgtype.UUID) (pgtype.UUID, error) {
row := q.db.QueryRow(ctx, getAssessmentReviewSubject, attemptID)
var product_policy_version_id pgtype.UUID
err := row.Scan(&product_policy_version_id)
return product_policy_version_id, err
}
const getLastAssessmentOriginMark = `-- name: GetLastAssessmentOriginMark :one
SELECT id, attempt_id, source, observed_at, session_digest, network_digest, key_version
FROM assessment_attempt_origin_marks
WHERE attempt_id = $1
ORDER BY observed_at DESC, id DESC
LIMIT 1
`
// The caller holds the attempt row lock, so the last mark is stable.
func (q *Queries) GetLastAssessmentOriginMark(ctx context.Context, attemptID pgtype.UUID) (AssessmentAttemptOriginMark, error) {
row := q.db.QueryRow(ctx, getLastAssessmentOriginMark, attemptID)
var i AssessmentAttemptOriginMark
err := row.Scan(
&i.ID,
&i.AttemptID,
&i.Source,
&i.ObservedAt,
&i.SessionDigest,
&i.NetworkDigest,
&i.KeyVersion,
)
return i, err
}
const insertAssessmentAnswerObservation = `-- name: InsertAssessmentAnswerObservation :exec
INSERT INTO assessment_answer_observations (
attempt_id,
item_instance_id,
user_id,
family_id,
variant_seed,
answer_format,
answer_fingerprint,
key_version,
elapsed_ms,
measured_from_answer,
observed_at
) VALUES (
$1,
$2,
$3,
$4,
$5,
$6,
$7,
$8,
$9,
$10,
$11
)
`
type InsertAssessmentAnswerObservationParams struct {
AttemptID pgtype.UUID
ItemInstanceID pgtype.UUID
UserID pgtype.UUID
FamilyID pgtype.UUID
VariantSeed int64
AnswerFormat string
AnswerFingerprint []byte
KeyVersion int16
ElapsedMs int32
MeasuredFromAnswer bool
ObservedAt pgtype.Timestamptz
}
func (q *Queries) InsertAssessmentAnswerObservation(ctx context.Context, arg InsertAssessmentAnswerObservationParams) error {
_, err := q.db.Exec(ctx, insertAssessmentAnswerObservation,
arg.AttemptID,
arg.ItemInstanceID,
arg.UserID,
arg.FamilyID,
arg.VariantSeed,
arg.AnswerFormat,
arg.AnswerFingerprint,
arg.KeyVersion,
arg.ElapsedMs,
arg.MeasuredFromAnswer,
arg.ObservedAt,
)
return err
}
const insertAssessmentOriginMark = `-- name: InsertAssessmentOriginMark :exec
INSERT INTO assessment_attempt_origin_marks (
id,
attempt_id,
source,
observed_at,
session_digest,
network_digest,
key_version
) VALUES (
$1,
$2,
$3,
$4,
$5,
$6,
$7
)
`
type InsertAssessmentOriginMarkParams struct {
ID pgtype.UUID
AttemptID pgtype.UUID
Source string
ObservedAt pgtype.Timestamptz
SessionDigest []byte
NetworkDigest []byte
KeyVersion int16
}
func (q *Queries) InsertAssessmentOriginMark(ctx context.Context, arg InsertAssessmentOriginMarkParams) error {
_, err := q.db.Exec(ctx, insertAssessmentOriginMark,
arg.ID,
arg.AttemptID,
arg.Source,
arg.ObservedAt,
arg.SessionDigest,
arg.NetworkDigest,
arg.KeyVersion,
)
return err
}
const insertAssessmentReviewRead = `-- name: InsertAssessmentReviewRead :exec
INSERT INTO assessment_review_reads (id, attempt_id, actor, found, read_at)
VALUES ($1, $2, $3, $4, $5)
`
type InsertAssessmentReviewReadParams struct {
ID pgtype.UUID
AttemptID pgtype.UUID
Actor string
Found bool
ReadAt pgtype.Timestamptz
}
func (q *Queries) InsertAssessmentReviewRead(ctx context.Context, arg InsertAssessmentReviewReadParams) error {
_, err := q.db.Exec(ctx, insertAssessmentReviewRead,
arg.ID,
arg.AttemptID,
arg.Actor,
arg.Found,
arg.ReadAt,
)
return err
}
const listAssessmentAnswerTimes = `-- name: ListAssessmentAnswerTimes :many
SELECT answer_format, elapsed_ms, measured_from_answer
FROM assessment_answer_observations
WHERE attempt_id = $1
ORDER BY observed_at, item_instance_id
LIMIT 220
`
type ListAssessmentAnswerTimesRow struct {
AnswerFormat string
ElapsedMs int32
MeasuredFromAnswer bool
}
// An attempt holds at most 220 items, so the list is bounded by the attempt.
func (q *Queries) ListAssessmentAnswerTimes(ctx context.Context, attemptID pgtype.UUID) ([]ListAssessmentAnswerTimesRow, error) {
rows, err := q.db.Query(ctx, listAssessmentAnswerTimes, attemptID)
if err != nil {
return nil, err
}
defer rows.Close()
var items []ListAssessmentAnswerTimesRow
for rows.Next() {
var i ListAssessmentAnswerTimesRow
if err := rows.Scan(&i.AnswerFormat, &i.ElapsedMs, &i.MeasuredFromAnswer); err != nil {
return nil, err
}
items = append(items, i)
}
if err := rows.Err(); err != nil {
return nil, err
}
return items, nil
}
const listAssessmentDuplicatePairs = `-- name: ListAssessmentDuplicatePairs :many
WITH mine AS (
SELECT
own.family_id,
own.key_version,
own.answer_fingerprint,
own.answer_format,
own.variant_seed,
own.user_id
FROM assessment_answer_observations AS own
WHERE own.attempt_id = $5
),
pair_items AS (
SELECT
other.attempt_id AS other_attempt_id,
mine.answer_format,
least(
CASE
WHEN mine.answer_format = 'integer' THEN $6::float8
ELSE $7::float8
END,
greatest(0::float8, -ln(holders.holders::float8 / totals.answer_count::float8) / ln(2::float8))
) AS bits
FROM mine
INNER JOIN assessment_answer_observations AS other
ON mine.family_id = other.family_id
AND mine.key_version = other.key_version
AND mine.answer_fingerprint = other.answer_fingerprint
AND mine.user_id <> other.user_id
AND mine.variant_seed <> other.variant_seed
INNER JOIN assessment_answer_fingerprint_holders AS holders
ON mine.family_id = holders.family_id
AND mine.key_version = holders.key_version
AND mine.answer_fingerprint = holders.answer_fingerprint
INNER JOIN assessment_answer_family_totals AS totals
ON mine.family_id = totals.family_id
AND mine.key_version = totals.key_version
)
SELECT
pair_items.other_attempt_id,
other_attempt.product_policy_version_id,
floor(sum(pair_items.bits))::integer AS evidence_bits,
(count(*) FILTER (WHERE pair_items.answer_format = 'integer'))::integer AS integer_items,
(count(*) FILTER (WHERE pair_items.answer_format = 'integer_sequence'))::integer AS sequence_items
FROM pair_items
INNER JOIN assessment_attempts AS other_attempt ON pair_items.other_attempt_id = other_attempt.id
WHERE
NOT $1::boolean
OR other_attempt.state IN ('completed', 'expired', 'insufficient_bank')
OR other_attempt.expires_at <= $2::timestamptz
GROUP BY pair_items.other_attempt_id, other_attempt.product_policy_version_id
HAVING floor(sum(pair_items.bits)) >= $3::float8
ORDER BY evidence_bits DESC, pair_items.other_attempt_id
LIMIT $4
`
type ListAssessmentDuplicatePairsParams struct {
EndedOnly bool
Now pgtype.Timestamptz
MinBits float64
RowLimit int32
AttemptID pgtype.UUID
IntegerCapBits float64
SequenceCapBits float64
}
type ListAssessmentDuplicatePairsRow struct {
OtherAttemptID pgtype.UUID
ProductPolicyVersionID pgtype.UUID
EvidenceBits int32
IntegerItems int32
SequenceItems int32
}
// Compares this attempt with every other attempt separately. A matched answer
// is an equal fingerprint of the same family version under the same key
// generation, given by another candidate to a different seed variant. It
// carries -log2 of the share of answers that hold that fingerprint, read from
// the maintained counters, between
// zero and the cap of its format, and the bits of one pair add up. Pairs under
// min_bits are dropped, the strongest come first, and the list is bounded.
// An attempt has ended when its state is terminal or its deadline has passed.
func (q *Queries) ListAssessmentDuplicatePairs(ctx context.Context, arg ListAssessmentDuplicatePairsParams) ([]ListAssessmentDuplicatePairsRow, error) {
rows, err := q.db.Query(ctx, listAssessmentDuplicatePairs,
arg.EndedOnly,
arg.Now,
arg.MinBits,
arg.RowLimit,
arg.AttemptID,
arg.IntegerCapBits,
arg.SequenceCapBits,
)
if err != nil {
return nil, err
}
defer rows.Close()
var items []ListAssessmentDuplicatePairsRow
for rows.Next() {
var i ListAssessmentDuplicatePairsRow
if err := rows.Scan(
&i.OtherAttemptID,
&i.ProductPolicyVersionID,
&i.EvidenceBits,
&i.IntegerItems,
&i.SequenceItems,
); err != nil {
return nil, err
}
items = append(items, i)
}
if err := rows.Err(); err != nil {
return nil, err
}
return items, nil
}
const listAssessmentOriginMarks = `-- name: ListAssessmentOriginMarks :many
SELECT id, attempt_id, source, observed_at, session_digest, network_digest, key_version
FROM assessment_attempt_origin_marks
WHERE attempt_id = $1
ORDER BY observed_at, id
LIMIT 5000
`
// Marks exist only where the session or the network changed. The bound keeps a
// request that flaps between networks from growing the list without limit.
func (q *Queries) ListAssessmentOriginMarks(ctx context.Context, attemptID pgtype.UUID) ([]AssessmentAttemptOriginMark, error) {
rows, err := q.db.Query(ctx, listAssessmentOriginMarks, attemptID)
if err != nil {
return nil, err
}
defer rows.Close()
var items []AssessmentAttemptOriginMark
for rows.Next() {
var i AssessmentAttemptOriginMark
if err := rows.Scan(
&i.ID,
&i.AttemptID,
&i.Source,
&i.ObservedAt,
&i.SessionDigest,
&i.NetworkDigest,
&i.KeyVersion,
); err != nil {
return nil, err
}
items = append(items, i)
}
if err := rows.Err(); err != nil {
return nil, err
}
return items, nil
}
const lockAssessmentReview = `-- name: LockAssessmentReview :exec
SELECT pg_advisory_xact_lock(hashtextextended(
'lincodex.assessment.signal_review:' || $1::text,
0
))
`
// Serializes the evaluations of one review. A job takes these locks for every
// attempt it will write, in ascending attempt order, before it reads any fact,
// so what it reads is what the previous writer committed.
func (q *Queries) LockAssessmentReview(ctx context.Context, attemptID string) error {
_, err := q.db.Exec(ctx, lockAssessmentReview, attemptID)
return err
}
const upsertAssessmentAttemptReview = `-- name: UpsertAssessmentAttemptReview :exec
INSERT INTO assessment_attempt_reviews (
attempt_id,
policy_version_id,
band,
reasons,
answered_items,
fast_answers,
deviating_answers,
parallel_alternations,
extra_networks,
matched_integer_items,
matched_sequence_items,
duplicate_evidence_bits,
client_focus_loss_ms,
client_clipboard_events,
client_fullscreen_exits,
evaluated_at,
updated_at
) VALUES (
$1,
$2,
$3,
$4::text[],
$5,
$6,
$7,
$8,
$9,
$10,
$11,
$12,
$13,
$14,
$15,
clock_timestamp(),
clock_timestamp()
)
ON CONFLICT (attempt_id) DO UPDATE SET
policy_version_id = EXCLUDED.policy_version_id,
band = EXCLUDED.band,
reasons = EXCLUDED.reasons,
answered_items = EXCLUDED.answered_items,
fast_answers = EXCLUDED.fast_answers,
deviating_answers = EXCLUDED.deviating_answers,
parallel_alternations = EXCLUDED.parallel_alternations,
extra_networks = EXCLUDED.extra_networks,
matched_integer_items = EXCLUDED.matched_integer_items,
matched_sequence_items = EXCLUDED.matched_sequence_items,
duplicate_evidence_bits = EXCLUDED.duplicate_evidence_bits,
client_focus_loss_ms = EXCLUDED.client_focus_loss_ms,
client_clipboard_events = EXCLUDED.client_clipboard_events,
client_fullscreen_exits = EXCLUDED.client_fullscreen_exits,
updated_at = greatest(
clock_timestamp(), assessment_attempt_reviews.evaluated_at, assessment_attempt_reviews.updated_at
)
`
type UpsertAssessmentAttemptReviewParams struct {
AttemptID pgtype.UUID
PolicyVersionID pgtype.UUID
Band string
Reasons []string
AnsweredItems int32
FastAnswers int32
DeviatingAnswers int32
ParallelAlternations int32
ExtraNetworks int32
MatchedIntegerItems int32
MatchedSequenceItems int32
DuplicateEvidenceBits int32
ClientFocusLossMs int64
ClientClipboardEvents int32
ClientFullscreenExits int32
}
// The times come from the database clock, never from a caller, and the update
// time cannot fall behind the stored times, so two jobs writing one review in
// either order keep the order check. The first evaluation time and the policy
// version stay; the guard trigger refuses a change of either.
func (q *Queries) UpsertAssessmentAttemptReview(ctx context.Context, arg UpsertAssessmentAttemptReviewParams) error {
_, err := q.db.Exec(ctx, upsertAssessmentAttemptReview,
arg.AttemptID,
arg.PolicyVersionID,
arg.Band,
arg.Reasons,
arg.AnsweredItems,
arg.FastAnswers,
arg.DeviatingAnswers,
arg.ParallelAlternations,
arg.ExtraNetworks,
arg.MatchedIntegerItems,
arg.MatchedSequenceItems,
arg.DuplicateEvidenceBits,
arg.ClientFocusLossMs,
arg.ClientClipboardEvents,
arg.ClientFullscreenExits,
)
return err
}
@@ -16,6 +16,33 @@ type AccountDeletionRequest struct {
CompletedAt pgtype.Timestamptz
}
type AssessmentAnswerFamilyTotal struct {
FamilyID pgtype.UUID
KeyVersion int16
AnswerCount int32
}
type AssessmentAnswerFingerprintHolder struct {
FamilyID pgtype.UUID
KeyVersion int16
AnswerFingerprint []byte
Holders int32
}
type AssessmentAnswerObservation struct {
AttemptID pgtype.UUID
ItemInstanceID pgtype.UUID
UserID pgtype.UUID
FamilyID pgtype.UUID
VariantSeed int64
AnswerFormat string
AnswerFingerprint []byte
KeyVersion int16
ElapsedMs int32
MeasuredFromAnswer bool
ObservedAt pgtype.Timestamptz
}
type AssessmentAttempt struct {
ID pgtype.UUID
UserID pgtype.UUID
@@ -74,6 +101,16 @@ type AssessmentAttemptItem struct {
AnsweredAt pgtype.Timestamptz
}
type AssessmentAttemptOriginMark struct {
ID pgtype.UUID
AttemptID pgtype.UUID
Source string
ObservedAt pgtype.Timestamptz
SessionDigest []byte
NetworkDigest []byte
KeyVersion int16
}
type AssessmentAttemptResult struct {
AttemptID pgtype.UUID
UserID pgtype.UUID
@@ -99,6 +136,26 @@ type AssessmentAttemptResult struct {
DecidedAt pgtype.Timestamptz
}
type AssessmentAttemptReview struct {
AttemptID pgtype.UUID
PolicyVersionID pgtype.UUID
Band string
Reasons []string
AnsweredItems int32
FastAnswers int32
DeviatingAnswers int32
ParallelAlternations int32
ExtraNetworks int32
MatchedIntegerItems int32
MatchedSequenceItems int32
DuplicateEvidenceBits int32
ClientFocusLossMs int64
ClientClipboardEvents int32
ClientFullscreenExits int32
EvaluatedAt pgtype.Timestamptz
UpdatedAt pgtype.Timestamptz
}
type AssessmentCategoryCatalogBinding struct {
OpeningID pgtype.UUID
Specialization string
@@ -143,6 +200,14 @@ type AssessmentFamily struct {
RetiredBy pgtype.Text
}
type AssessmentReviewRead struct {
ID pgtype.UUID
AttemptID pgtype.UUID
Actor string
Found bool
ReadAt pgtype.Timestamptz
}
type AssessmentSignalBatch struct {
ID pgtype.UUID
AttemptID pgtype.UUID
@@ -169,6 +234,12 @@ type AssessmentSignalIdempotencyOutcome struct {
ReceivedAt pgtype.Timestamptz
}
type AssessmentSignalNoticeAcknowledgement struct {
UserID pgtype.UUID
NoticeVersion int32
AcknowledgedAt pgtype.Timestamptz
}
type AssessmentTrainingBankBinding struct {
ID pgtype.UUID
Category string
@@ -227,15 +227,22 @@ type Querier interface {
GetAssessmentAttemptKindForCandidate(ctx context.Context, arg GetAssessmentAttemptKindForCandidateParams) (string, error)
// Reads a result only for the owning candidate.
GetAssessmentAttemptResult(ctx context.Context, arg GetAssessmentAttemptResultParams) (string, error)
GetAssessmentAttemptReview(ctx context.Context, attemptID pgtype.UUID) (GetAssessmentAttemptReviewRow, error)
// Reads an active real attempt without taking the write lock used by create.
// The availability GET never expires or otherwise mutates this row.
GetAssessmentAvailabilityActiveAttempt(ctx context.Context, arg GetAssessmentAvailabilityActiveAttemptParams) (GetAssessmentAvailabilityActiveAttemptRow, error)
GetAssessmentClientSignalTotals(ctx context.Context, attemptID pgtype.UUID) (GetAssessmentClientSignalTotalsRow, error)
GetAssessmentFamilyByID(ctx context.Context, id pgtype.UUID) (AssessmentFamily, error)
GetAssessmentFamilyVersion(ctx context.Context, arg GetAssessmentFamilyVersionParams) (AssessmentFamily, error)
// The attempt a review job works on: real attempts only.
GetAssessmentReviewSubject(ctx context.Context, attemptID pgtype.UUID) (pgtype.UUID, error)
// Counts eligible root attempts in a policy window and computes the instant
// at which one additional root slot opens. The microsecond adjustment matches
// the creation predicate created_at >= since at PostgreSQL timestamp precision.
GetAssessmentRootQuotaAvailability(ctx context.Context, arg GetAssessmentRootQuotaAvailabilityParams) (GetAssessmentRootQuotaAvailabilityRow, error)
// The caller has already checked that the user is a candidate. A missing row
// means the notice version was not acknowledged.
GetAssessmentSignalNoticeAcknowledgement(ctx context.Context, arg GetAssessmentSignalNoticeAcknowledgementParams) (pgtype.Timestamptz, error)
// Read only the receipt associated with the reserved idempotency scope.
GetAssessmentSignalOutcome(ctx context.Context, scopeHash []byte) (GetAssessmentSignalOutcomeRow, error)
// Reads one hiding of the candidate with the current name of the
@@ -272,6 +279,8 @@ type Querier interface {
GetEmailTokenByHash(ctx context.Context, arg GetEmailTokenByHashParams) (EmailToken, error)
// Explains why ConsumeEmailToken matched no row.
GetEmailTokenState(ctx context.Context, arg GetEmailTokenStateParams) (GetEmailTokenStateRow, error)
// The caller holds the attempt row lock, so the last mark is stable.
GetLastAssessmentOriginMark(ctx context.Context, attemptID pgtype.UUID) (AssessmentAttemptOriginMark, error)
GetLatestAssessmentFamily(ctx context.Context, familyKey string) (AssessmentFamily, error)
// Reads the status of the newest delivery of a kind addressed to an account,
// for the account's own view of its mail. It selects no address and no
@@ -328,6 +337,7 @@ type Querier interface {
GetUnrevokedConsentRecordByVersion(ctx context.Context, arg GetUnrevokedConsentRecordByVersionParams) (GetUnrevokedConsentRecordByVersionRow, error)
GetUserByEmailNormalized(ctx context.Context, emailNormalized string) (User, error)
GetUserByID(ctx context.Context, id pgtype.UUID) (User, error)
InsertAssessmentAnswerObservation(ctx context.Context, arg InsertAssessmentAnswerObservationParams) error
// Inserts the attempt header. The database guard rechecks the current policy,
// opening or disjoint training binding, and immutable pins.
InsertAssessmentAttempt(ctx context.Context, arg InsertAssessmentAttemptParams) error
@@ -351,12 +361,17 @@ type Querier interface {
// returns no row instead of an error, so a conflict does not abort the
// surrounding transaction.
InsertAssessmentFamily(ctx context.Context, arg InsertAssessmentFamilyParams) (AssessmentFamily, error)
InsertAssessmentOriginMark(ctx context.Context, arg InsertAssessmentOriginMarkParams) error
InsertAssessmentReviewRead(ctx context.Context, arg InsertAssessmentReviewReadParams) error
// The attempt row is already locked by the caller. Store a parent before its
// bounded child events, in the same transaction as the immutable receipt.
InsertAssessmentSignalBatch(ctx context.Context, arg InsertAssessmentSignalBatchParams) error
// Each inserted event is checked by the database guard against attempt state
// and the aggregate capacity as a second line of defense.
InsertAssessmentSignalEvent(ctx context.Context, arg InsertAssessmentSignalEventParams) error
// The first acknowledgement wins; a repeat keeps the stored time and inserts
// nothing. The caller reads the stored row afterwards in the same transaction.
InsertAssessmentSignalNoticeAcknowledgement(ctx context.Context, arg InsertAssessmentSignalNoticeAcknowledgementParams) error
// Save exactly one immutable response receipt for each live idempotency scope.
InsertAssessmentSignalOutcome(ctx context.Context, arg InsertAssessmentSignalOutcomeParams) error
// Records a successfully authorized view after visibility and quota checks.
@@ -473,6 +488,8 @@ type Querier interface {
// Read the latest serialized event so a temporarily regressing application
// clock cannot make the next request fall before an event already counted.
LatestSupportCaseRequestEvent(ctx context.Context, ownerID pgtype.UUID) (pgtype.Timestamptz, error)
// An attempt holds at most 220 items, so the list is bounded by the attempt.
ListAssessmentAnswerTimes(ctx context.Context, attemptID pgtype.UUID) ([]ListAssessmentAnswerTimesRow, error)
// Reads chain headers in creation order. The use case verifies root eligibility
// and descending target grades in the domain before it creates a correction.
ListAssessmentAttemptChain(ctx context.Context, arg ListAssessmentAttemptChainParams) ([]AssessmentAttempt, error)
@@ -488,10 +505,22 @@ type Querier interface {
// Counting the first unanswered item after expiry is conservative when the
// final response was lost, while frozen future items remain excluded.
ListAssessmentDisclosedFamilyKeys(ctx context.Context, arg ListAssessmentDisclosedFamilyKeysParams) ([]string, error)
// Compares this attempt with every other attempt separately. A matched answer
// is an equal fingerprint of the same family version under the same key
// generation, given by another candidate to a different seed variant. It
// carries -log2 of the share of answers that hold that fingerprint, read from
// the maintained counters, between
// zero and the cap of its format, and the bits of one pair add up. Pairs under
// min_bits are dropped, the strongest come first, and the list is bounded.
// An attempt has ended when its state is terminal or its deadline has passed.
ListAssessmentDuplicatePairs(ctx context.Context, arg ListAssessmentDuplicatePairsParams) ([]ListAssessmentDuplicatePairsRow, error)
// One page of the versions of a category in key and version order, after the
// given position; an empty key and version 0 start at the beginning. The
// (family_key, version) unique index serves the scan.
ListAssessmentFamiliesByCategory(ctx context.Context, arg ListAssessmentFamiliesByCategoryParams) ([]AssessmentFamily, error)
// Marks exist only where the session or the network changed. The bound keeps a
// request that flaps between networks from growing the list without limit.
ListAssessmentOriginMarks(ctx context.Context, attemptID pgtype.UUID) ([]AssessmentAttemptOriginMark, error)
// Reads the exact family membership pinned by a training binding.
ListAssessmentTrainingBindingFamilies(ctx context.Context, bindingID pgtype.UUID) ([]ListAssessmentTrainingBindingFamiliesRow, error)
// Lists only the current candidate's own access history. It deliberately
@@ -566,6 +595,10 @@ type Querier interface {
// published or open the category, until the transaction ends. The key is
// namespaced, so it cannot collide with another use of advisory locks.
LockAssessmentCategory(ctx context.Context, category string) error
// Serializes the evaluations of one review. A job takes these locks for every
// attempt it will write, in ascending attempt order, before it reads any fact,
// so what it reads is what the previous writer committed.
LockAssessmentReview(ctx context.Context, attemptID string) error
// Lock the account before an organization checks candidate visibility. The
// hidden-organization insert trigger takes FOR NO KEY UPDATE on this row, so
// a hide either commits before the later visibility recheck or waits for the
@@ -895,6 +928,11 @@ type Querier interface {
// registrant never stands for the new one; the new registration records its
// own C1 in the same transaction. A version conflict deletes nothing.
UpdateUserRegistration(ctx context.Context, arg UpdateUserRegistrationParams) (UpdateUserRegistrationRow, error)
// The times come from the database clock, never from a caller, and the update
// time cannot fall behind the stored times, so two jobs writing one review in
// either order keep the order check. The first evaluation time and the policy
// version stay; the guard trigger refuses a change of either.
UpsertAssessmentAttemptReview(ctx context.Context, arg UpsertAssessmentAttemptReviewParams) error
}
var _ Querier = (*Queries)(nil)