Skip to content

fix(platform): close the reviewer edge cases after re-targeting - #3554

Merged
yannickmonney merged 33 commits into
mainfrom
fix/reviewer-edge-cases-after-retarget
Sep 28, 2026
Merged

yannickmonney merged 33 commits into
mainfrom
fix/reviewer-edge-cases-after-retarget

Conversation

@yannickmonney

@yannickmonney yannickmonney commented Sep 27, 2026 •

Copy link
Copy Markdown
Contributor

Problem

Follow-ups left open by #3517 (changing the reviewer re-targets the pending review):

  1. Erasure stamped a waiting review with the pseudonym. The reviewDecisions erasure pass rewrote a pending review's requestedFor to erased-user, so the review waited on nobody: no board chip, no Needs my review, no bell.
  2. A reviewer changed before In review kept ringing. With no review open there was nothing to re-target, and the previous designee's unread You're the reviewer heads-up stayed unread.
  3. The server accepted a designee who cannot edit the project. Only org membership was checked. The designee was stored, subscribed and sent the heads-up, and then the gate skipped them at mint, so the review went to a creator without anyone being told.

Change

  • backend/domains/tasks/reviews.ts
    • New reviewerEligibility(tx, {organizationId, projectTeamIds, userId}) → eligible | not_member | cannot_edit. It is the single rule: resolveReviewer uses it, and designation is checked against it.
    • resolveReviewer can now exclude one person from every slot of the chain.
    • In retargetPendingTaskReview, actorUserId is optional. When it is absent, the request is sent as the system submitter. It also takes a new excludeUserId.
  • backend/domains/erasure/service.ts (reviewDecisions pass):
    1. Discover tasks whose designation or pending review still names the subject.
    2. In one serializable transaction per task, conditionally clear the subject’s designation, re-read the pending review, and hand it to the next eligible reviewer with the subject excluded. The designation, review handover and task realtime hint commit together. The chain remains task creator, then project creator.
    3. Preserve a review or designation that another task edit reassigned after discovery; serialization retries concurrent edits instead of overwriting their choice. Emit a task hint only when the designation or review moves, so the board refreshes along with the bells.
    4. On an archived task the review still moves (archiving closes no gate, and a restore must not bring back a review waiting on nobody), but silently: retargetPendingTaskReview takes silent, which keeps the follow and skips the request bell and email for a card hidden from the board.
    5. A hand-over that throws no longer fails the pass. It is logged with console.error, the designation is still cleared and hinted in a transaction of its own, and the waiting row falls to the pseudonym, as it did before hand-overs existed. Routing can no longer keep the subject's id on later tasks or on past decisions.
    6. Only after that, pseudonymize whatever still names the subject: decisions, workflow-era rows, and a row whose task is gone (TASK_NOT_FOUND is caught, not swallowed), that was decided in the meantime, or whose hand-over failed.
  • backend/domains/collab/service.ts
    • New dismissReviewerAssignedNotifications: marks the former designee's unread heads-up on that task read and sends them a bell hint.
    • New {kind: 'system'} review submitter. It uses the existing taskReviewRequestedBodyHuman copy and actor_type = 'system'.
  • backend/domains/tasks/service.ts (updateTask)
    • A new designee is refused with 400 TASK_REVIEWER_NO_EDIT_ACCESS (or the existing TASK_REVIEWER_INVALID for a non-member) before anything is written.
    • Re-selecting the current designee is not re-checked.
    • When the designation moves or is cleared, the previous designee's heads-up is dismissed.
  • App:
    • The picker lists only eligible members: project audience ∩ editor roles. useAssignableActors now exposes scopeReady. Until the project's audience has loaded, the Reviewer picker lists nobody and reads common.actions.loading, where it used to fall back to every org editor. The assignee picker and mentions keep that fallback. reviewer-picker.test.tsx covers the role filter and the loading state, and use-actor-directory.test.ts covers the team-restricted narrowing.
    • A refusal from a stale picker now shows the picker's own hint (tasks.reviewer.editorsOnly) as a toast instead of the generic error, via app/features/tasks/lib/reviewer-refusal.ts.
    • No new strings.
  • Docs (EN/DE/FR): the erasure paragraph now says the review of an archived task moves without a notification.
  • TASK_REVIEWER_NO_EDIT_ACCESS is added to the app-only list in rest/error-codes.test.ts; REST carries no reviewer.
  • Docs (EN/DE/FR, admin/governance/data-subject-requests.md): one paragraph on what erasure does to reviewer designations, waiting reviews and past decisions. projects/tasks.md already says only project editors can be reviewers.
  • Manual layer:
    • New boxes PROJ-F33 (heads-up dismissed before review), PROJ-F34 (an erased reviewer's waiting review moves on) and PROJ-B9 (only an editor can be the reviewer), plus their reference/automation.md rows.
    • New reference/error-codes.md row for the refusal.
    • readme.md counts the three new boxes (projects 49 → 52); aa95295bb then recounts the whole inventory from the suites (876), which also corrects six rows main had let drift.

No schema change, no migration, no contract change.

Verification

  • Scope (review round 2). Merge 066d510ab had pulled the head of fix(platform): name the refused field at the app doors and in forms #3538 (fix/app-door-refusals-name-field, then still open) into this branch, which grew the diff to about 100 files. 203742c9a reverts that merge against its first parent, so the tree is exactly 4d2cf36fb again. 58986ce95 and 658b4f8cd then merge main up to 9662e8a5c, which by then carried fix(platform): name the refused field at the app doors and in forms #3538 as its own squash (df5bc9264). The PR now changes 27 files, all of them the reviewer work listed above, and depends on no other open PR. On 658b4f8cd: platform tsc --noEmit clean; server tests over backend/domains/{tasks,collab,erasure,approvals,projects}/, backend/jobs/, backend/rest/{error-codes,v1-tasks,v1-tasks.review}.test.ts: 65 files, 549 tests pass; --project client app/features/tasks: 44 files, 268 tests pass; scoped oxlint --type-aware --type-check: clean; bun run lint:manual: ok.

  • Committed concurrent-write regressions: backend/domains/erasure/review-handover.integration.ts, registered as checkErasureReviewHandoverRaces, runs full production processErasure while a SQL barrier allows production updateTask or updateTaskStatus to commit against its earlier snapshot. It asserts that a newer reviewer remains the recipient and that an already completed review receives no stale request. Fresh real Postgres: 19/19 including harness checks, with one serialization retry in each race. With exact original daeb4304 erasure service and the same tests: 17/19, failing both races (approval overwritten to creator; stale request sent after completion). Full platform typecheck, scoped type-aware lint and manual guard pass.

  • Review round 1. Server: 61 files, 514 tests. Client app/features/tasks/: 44 files, 262 tests. tsc --noEmit and scoped type-aware oxlint are clean. The new cases (silent retarget, archived hand-over, failed hand-over, picker loading state, hook narrowing) fail against the previous source. Real Postgres and MinIO, fresh, four lanes: 42/42. The erasure check now also asserts a task outbox hint for the handed-over task; with the pre-round-1 erasure service it reads task hints=0.

  • Final review validation. Fresh server regression run: 36 files, 260 tests; task picker/refusal UI: 2 files, 7 tests. After merging the latest main, the erasure, reviewer, retarget, activity, collaboration and error-code suites passed again: 6 files, 68 tests. Platform typecheck, scoped type-aware lint and manual-layer checks pass.

  • Erasure race regression. The lifecycle test verifies serializable isolation, clearing before handover, and the task realtime hint in the transaction; it fails against the original nonserializable implementation. A second test verifies that a review reassigned after discovery is left with its new reviewer and emits no spurious task hint.

  • Unit tests. bunx vitest run --project server over backend/domains/{tasks,collab,erasure,approvals,projects}/, backend/jobs/, backend/rest/{error-codes,v1-tasks,v1-tasks.review}.test.ts: 57 files, 471 tests pass. --project client app/features/tasks/: 44 files, 258 tests pass.

  • The new tests fail without the source change. With the four source files stashed, 16 of them fail:

    • collab/service.test.ts: dismissal ×2, system submitter.
    • erasure/service.lifecycle.test.ts: review pass hand-over.
    • tasks/reviews.retarget.test.ts: exclusion ×2, reviewerEligibility ×4.
    • tasks/service.reviewer.test.ts: refusal, heads-up dismissal ×3, and the two re-mocked designation cases.
    • reviewer-refusal.test.ts cannot resolve its module.
  • Real Postgres (my own tale-db + MinIO containers), ITEST_LANES=checkFiles,checkTasksCollabIntegrity,checkReviewArc,checkErasure. The integration check gains three assertions: a read-only member is refused with nothing written or rung, the heads-up is dismissed on move and on clear, and after erasure the waiting review belongs to the creator with an unread system bell.

    • With the fix, on a fresh DB: 42/42 pass. This was independently rerun on fresh Postgres and MinIO after the serialization and task-hint correction: 42/42 pass across all four lanes.
    • With the fix stashed, on a fresh DB: 39/42. The three new checks fail as described in the Problem section: the read-only member is accepted (200) and belled, A's heads-up stays unread, and the review ends up pending/erased-user with no creator bell.
    • backend:integration is not a CI job, so this local run is the real-Postgres proof.
  • Lint and other checks. bunx oxlint --type-aware --type-check on every changed file: clean. The pre-commit hook applied oxfmt and opengrep. bun run lint:manual: ok. check-guide.ts on suites/projects.md: OK. Docs suite (services/docs, bunx vitest run): 34 files, 166 tests pass, with no report-mode findings on the edited pages.

Left open

  • PROJ-F33, PROJ-F34 and PROJ-B9 have not been run by hand in a browser yet. The two live bells and the post-erasure board chip are manual per their automation rows.
  • Pending, workflow-free reviews that an erasure before this change stamped requestedFor: 'erased-user' are not repaired, and they still wait on nobody. No backfill ships: the reviewer chain checks membership and project access in code, so a SQL repair would be a second copy of it. This is recorded as BL-3 in tests/manual/reference/not-a-finding.md, with the recovery: set a Reviewer on the task, which moves the open review to that person, and clear it again to hand it to the creator.
  • The task dialog's refusal toast has no render test. PROJ-B9 now reaches it by hand through a stale picker: a team removal hints team, not the project audience.

yannickmonney and others added 17 commits September 27, 2026 19:39
About 190 app doors answered a body their schema refused with a bare
`{ error: 'invalid body' }`: the dialog could only say "invalid body",
and the error report carried the same opaque code, so nobody could tell
which field the form had let through.

Every door now answers through `backend/lib/invalid-body-response.ts`:
the same `invalid body` code, a `field: reason` message and the issues
under `data.issues`. `invalidBodyIssuesResponse` covers a refusal no
schema raised (a body that is not JSON, the automation save's missing
`document`). An email with neither body nor files is refused at
`content`. A guard test fails any bare literal left under `backend/`.

The caps a form has to mirror now live where the app can read them:
the contact caps beside the contact patterns in `lib/shared`, the
object-storage connection caps in its shared schema, and the Postgres
host rule and password cap in `@tale/shared/schemas/knowledge`.
The UI evaluations kept hitting `invalid body` on Products, Contacts and
Data residency (TALE-84, TALE-162, TALE-103): each form let through a
value the door refuses.

- Contacts: the form trims and caps Name (300), Email (320, at most 64
  characters before the `@`), Phone (50) and Locale (20) with the
  shared caps, and both dialogs put a refused body's reason on the toast.
- Products: a pasted image address must be an absolute http(s) URL (or
  the app path an upload returned); the error sits under Image URL.
- Data residency: Test connection checks the fields the way Save does
  and names what it would refuse instead of sending it; required fields
  are judged trimmed, as they are sent, and every field has the door's
  length cap.
- The default mutation and action toasts (and the task toasts) show an
  `invalid body` refusal's field-naming sentence instead of "Try again".

New `products.edit.validation.imageUrl` in en, de and fr; the product
and self-hosted data-residency docs say what the forms check, in all
three languages. Manual boxes KNOW-B13 and DATA-B8, with the owning
specs in the automation register.
The workspace-tool bridge kept only the code of a domain refusal. An
agent's task_create with a description over 20,000 code units or a label
over 50 came back as "TASK_DESCRIPTION_INVALID: the domain refused these
arguments.", so the model could not tell which limit it broke. The domain
threw one "Invalid title" for an empty and an over-long title on the human
create and edit paths, and the tasks app door dropped the domain's message
altogether.

- core/tasks/helpers.ts now holds the refusal sentences beside the limits.
  Each names the cap, the unit every cap is measured in (UTF-16 code
  units, where most emoji count as 2) and the length measured, never the
  value. validateTitle tells an empty title from an over-long one, and the
  description, label count, label name and comment caps are named.
- toolResultFromError relays the domain's sentence beside the code, and
  nothing else from the refusal's payload.
- The agent-comment writer moves into the coded write shim, so an
  over-long comment answers invalid_args instead of error.
- workspace_status states every cap of task_create, task_comment and
  task_upsert_by_external_ref from the shared constants, in code units.
- The tasks app door answers a domain refusal with its message, and an
  empty title on create reaches the domain instead of a bare invalid body.

Closes #3155
Three gaps left open by the reviewer re-target (#3517):

- Erasure stamped a review still waiting on the subject with the
  pseudonym, so it waited on nobody. The review pass now clears the
  designation first, hands each waiting review on through the chain a
  cleared designation takes (task creator, then project creator, the
  subject skipped in every slot) and rings the new reviewer as the
  system; only what still names the subject is pseudonymized after.
- Changing or clearing the reviewer before In review left the previous
  designee's unread "You're the reviewer" heads-up ringing; it is now
  marked read when the designation moves.
- A designee who cannot edit the project was stored and then routed
  past at mint. The designation is held to the same rule the gate
  resolves by (reviewerEligibility) and refused with 400
  TASK_REVIEWER_NO_EDIT_ACCESS; the task dialog names the refusal with
  the picker's own hint.

Manual boxes PROJ-F33, PROJ-F34 and PROJ-B9, their automation rows,
the error-code row, and the data subject request docs (EN/DE/FR).
asAppError translated every error carrying a string code and a numeric
status, so a MentionDirectoryError (503) on an agent comment reached the
model as invalid_args and was audited so. Only a 4xx refusal is
translated now; a coded 5xx stays a plain error and answers `error`.
…ence

A blank or whitespace-only title at the tool door still answered the
generic 'needs a non-empty "title" string', naming neither the range nor
its unit. It now answers taskTitleRefusal's empty sentence, the one the
domain's validateTitle throws; a missing or non-string title keeps the
generic text.
The tasks door's schema carried caps of its own above the domain's (a
title up to 500, a description up to 50,000, up to 100 labels, a comment
min(1)), and anything it refused answered a bare `invalid body` that
could not tell an empty title or comment from an over-long one. The
title, description, label count and comment body are now checked with
the domain's own refusal helpers and answer `{error: <code>, message}`,
before a rate-limit slot is spent.
A task refusal's sentence now reaches the app door and an agent's tool
result, yet SETUP_FOLDER_MISSING echoed the setup folder name it was
sent. The sentence names the rule instead, and a guard reads every
TaskError, TaskReviewError and task-domain ProjectError message so a new
interpolated value fails until it is made static or reviewed.
The REST reference and the house schema messages said "characters" for
the task title, description, label, comment and translation caps, which
count UTF-16 code units like the domain's refusals. The schema messages
and the en/de/fr reference now name the unit.
The row for named task limits now covers the app door's schema, the
empty task_create title, a coded outage staying `error`, the value-free
setup-folder refusal with its guard, and REST's unit wording.

@yannickmonney yannickmonney left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Needs correction before acceptance at daeb430451833d56ce1d085198b3cbb16c0cb8bd.

P2: serialize erasure handover with reviewer changes and review decisions. backend/domains/erasure/service.ts:1189 calls the retarget helper inside plain READ COMMITTED sql.begin. The task and approval reads take no locks. I reproduced two overlaps in isolated real Postgres using this exact helper and a rival SERIALIZABLE transaction:

  • A newer reviewer assignment commits first; erasure then overwrites the pending approval back to the creator. The final task reviewer is new-reviewer, while approval.metadata.requestedFor is creator.
  • A review completes first; the guarded update at tasks/reviews.ts:301 updates zero rows, but the helper still calls notifyTaskReviewRequested for the completed approval.

Use the existing serializable retry wrapper (or equivalent locking/re-read), and only publish routing side effects for pending rows actually updated. Add deterministic barrier tests for both overlaps. The local harness uses real SQL with mocked membership/notification seams; it is not a full HTTP erasure test.

P2: publish a task invalidation when erasure changes review routing. The handover at erasure/service.ts:1201 bypasses recordActivity and emits only notification hints. Board and review reads are under the task query prefix, so an already-open board can keep stale designation/review chips and Needs my review results while its bell updates. Emit a task hint for handed-over tasks and cleared designations without pending reviews. This second finding is traced through producer/consumer code, not browser-verified; include a local two-session check.

Independent verification: 66 server and 7 client tests passed in fresh direct Vitest runs. The two real-Postgres probes confirmed the faulty outcomes. The CI platform unit job was a cache miss and actually executed; green status alone was not treated as proof. No production testing or writes were performed for this review.

An erasure moved an archived task's waiting review to the creator with an
actionable bell and email, for a card hidden from the board. Archiving
closes no gate, so the routing still moves (a restore must not bring back
a review waiting on nobody), but `retargetPendingTaskReview` now takes
`silent`, and the erasure passes it for an archived task.

A hand-over that threw failed the whole reviewDecisions pass. The subject's
id then stayed on every later designation and on past decisions, and each
retry failed the same way. Now the failure is logged. The designation is
still cleared and hinted in a transaction of its own, and the waiting row
falls to the pseudonym, as it did before hand-overs existed.

The integration check now also asserts that the erasure hints the task.
While `listAccessibleUserIds` was in flight, `useAssignableActors` fell
back to every member of the organization, so the Reviewer picker offered
editors outside a team-restricted project whom the server refuses. The
hook now says when its narrowing has happened (`scopeReady`), and the
Reviewer picker lists nobody and reads "Loading..." until it has. The
assignee picker and mentions keep the fallback.
PROJ-B9 now provokes the refusal toast through a stale picker (a team
removal hints `team`, not the project audience). The console request uses
the organization ID rather than the slug and says where to copy both IDs.
The automation row now claims only the helper, and the task dialog's toast
stays manual. PROJ-F34's row covers the archived-task hand-over and the
failure fall-through. BL-3 records the pending reviews an older erasure
left waiting on the pseudonym, and how to recover them.

@yannickmonney yannickmonney left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rechecked the correction at 9c0ded96d7ebe5759305268b8cfc1b593cac85a0. The two findings in my earlier review are addressed in the reviewed code paths:

  • The designation clear, current task read, pending-recipient recheck, handover, and task hint now share transactSerializable. Discovery no longer clears designations before that transaction. A review already moved away from the erased subject is skipped on the fresh attempt.
  • A task hint is emitted for a cleared designation or a pending handover, including a cleared task with no pending review.

Fresh direct tests at this head: 5 relevant server files, 67 passed. I also reran the two deterministic real-Postgres interleavings using the exact-head retry wrapper and retarget helper, with the caller's new clear/read/recheck sequence against minimal real tables. Both passed: the newer reviewer remains the recipient, and a concurrently completed review gets no new request; each conflicting handover retried once.

Evidence limit: those two scratch probes test the transaction sequence, not the entire processErasure HTTP/background workflow, and the task hint has not been checked across two live browser sessions here. The committed lifecycle tests cover the wrapper/hint and a reassignment before the transaction, but please retain equivalent barrier-driven concurrency regressions in the repository so these particular overlaps stay covered. This follow-up clears my reported code defects; it is not a full release/merge approval.

@yannickmonney yannickmonney left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bounded follow-up on the four commits after the previously reviewed 9c0ded9, at 4097fa0.

The assigned reviewer inspected archived-task notification suppression, failed-handover fall-through, project-specific eligibility readiness and the added real-Postgres race test source. No substantive new source finding in this delta. Fresh direct runs passed 47/47 affected lifecycle, retarget, picker and actor-directory tests. The failed-handover fallback condition preserves a newer reviewer designation, while silent archived routing keeps subscription/dismissal effects without sending a new notification.

The new full-service Postgres probes were source-reviewed but not executed in this follow-up; the earlier two real-Postgres overlap results belong to 9c0ded9. No full root gate, SAST or browser loading/error-state run was repeated. GitHub currently reports merge conflicts, so the conflict-resolution head needs its own review and validation. This is not a whole-PR approval or merge.

Merge 066d510 pulled the head of the still-open #3538
(fix/app-door-refusals-name-field) into this branch, so the squash of
#3554 would have landed that PR's field-naming work under the reviewer
title. This reverts the merge against its first parent, leaving the
tree exactly as the reviewer fixes had it at 4d2cf36. #3538 lands on
its own.
Takes main up to 207883c and recounts the manual suites main grew.
Takes main up to 9662e8a, which now carries #3538 on its own.
@yannickmonney
yannickmonney merged commit 0f887a4 into main Sep 28, 2026
50 checks passed
@yannickmonney
yannickmonney deleted the fix/reviewer-edge-cases-after-retarget branch September 28, 2026 07:49
yannickmonney added a commit that referenced this pull request Sep 28, 2026
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