Skip to content

fix(platform): recheck task access before notification delivery - #4056

Merged
yannickmonney merged 6 commits into
mainfrom
fix/notification-recipients-recheck-task-access
Oct 2, 2026
Merged

yannickmonney merged 6 commits into
mainfrom
fix/notification-recipients-recheck-task-access

Conversation

@yannickmonney

@yannickmonney yannickmonney commented Oct 1, 2026 •

Copy link
Copy Markdown
Contributor

What changed

A task subscription outlives its subscriber's team membership. So a member taken off a team-restricted project kept getting the task's new title and status in their notifications and email, although the task itself answered them 403 TASK_FORBIDDEN (#3631).

  • One check where every task-bound row is written. writeCoalescedNotification (collab/service.ts) writes a row with a taskId only when its recipient can open the task's current project now. Otherwise it writes, rewrites and cancels nothing and returns withheld. This covers every emitter, whoever picked the recipient: watchers (status, comments), mentions, assignment and unassignment, reviews, date sweeps and agent notices.
  • The rule is the one assertTaskReadable applies: a non-disabled member of the task's organization who is an owner or admin, or the project is organization-wide, or the member belongs to one of its teams. Only teams of that organization count, as getUserTeamIds counts them. projectReadersAmong (until now only the failed-run notice used it) and the new taskReadersAmong share one SQL statement, which adds the organization check on teams.
  • The email rechecks at send time. email-sink.ts checks the same rule before it reads the address, because access can end inside the 60 s debounce window.
  • Subscriptions are kept. Someone who regains access is notified about the tasks they follow again. Rows written while the person had access stay as history, since the issue is about new content.
  • Fixtures. Two existing lanes wrote task-bound rows for tasks no table holds (checkNotificationEmailSink, checkBellHintWire), and one wrote for a recipient outside the organization. They now use real tasks of an organization-wide project and clean up after themselves.
  • Docs. admin/teams.md in EN, DE and FR gains one paragraph: notifications follow project access.

No migration, no new strings, no API change.

How it was verified

Source d6dd53ae0b9bd154f85d2f325ffadc3b56b46883, head b2a807d9d3ffbcded7c9312ee497890e3bdfd118 (commits de552b54c fix, ff9240dab lane fixtures, b2a807d9d review follow-up). Local Postgres 16.14 + pgvector, no egress, synthetic data.

  • Reproduction before the fix. The new lane checkTaskNotificationAccess drives the real team-removal door (DELETE /api/app/teams/members/by-id/…), the real updateTask, updateTaskStatus, addTaskComment and assignTask, and the bell's own listMyNotifications / myUnreadCount. On d6dd53ae0 (round r02main):

    • the removed member got task_unassigned, task_commented and task_status_changed carrying the renamed title, with unread = 3;
    • a member of another organization only got 3 rows in this one.
  • Controls:

    Case Before and after the fix
    Team watcher and admin outside the team told the new title
    Muted watcher gets nothing
    Removed member's earlier rows unchanged
    Removed member back on the team notified again
  • Before/after, same 13 notification lanes (checkBellHintWire, checkNotifications, checkNotificationEmailSink, checkNotificationProjectBackfill, checkCollabMentions, checkTaskDescriptionMentions, checkReviewArc, checkErasureReviewHandoverRaces, checkTriggerPauseAfterFailures, checkAskAnswer, checkAnsweredAskRecovery, checkAgentRunFailureNotice, checkTaskNotificationAccess), run on the head and with main's two collab files swapped in:

  • Unit tests (collab): 4 files, 56 tests pass. Against main's sources, the new cases fail:

    • withheld row, undo withheld, current-project and organization-team scoping;
    • status fan-out and unassignment without the removed member;
    • email to a reader sent, email to a former reader not sent.
  • Guards and scanners: tests/guards/*, error-code registry, handler names, OpenAPI spec, rate limit and invalid-body: 20 files, 306 tests pass. Docs suite: 37 files, 222 tests pass.

  • Static checks: scoped tsc --noEmit over the changed files, integration-check.ts included: exit 0. oxlint --type-aware on the changed backend files: clean. oxfmt --check: clean. commitlint: clean.

Review follow-up (b2a807d9d)

An independent read-only pass over de552b54c..ff9240dab found no high-severity issue. Its one medium is fixed here:

  • Date alerts. A date alert picked one person (assignee, else task creator, else project creator) before the access check. So an assignee who had lost the project used the alert up on a withheld row, and the creator was never tried. The sweep now offers the alert only to people who can open the task, and the overdue rung tells the first creator who still can. Two new unit cases fail on d6dd53ae0's date-notifications.ts.

Lows, also fixed:

  • The agent-question count leaves out withheld rows.
  • The email lane asserts that its preference case writes its row (pref=inserted).
  • Two comments no longer overclaim.
  • The reader rule's comment says it reads the stored member role. A trusted-headers session's role is written back to it at each sign-in; between sign-ins, a role change in Settings can differ from the session for up to a session lifetime.
  • The French docs sentence names "les tâches de ce projet".

Left for follow-up:

  • No real-Postgres lane yet for the email recheck after access ends. The unit test covers the sink, and the writer lane covers the predicate.
  • Fan-outs that already filter their audience (the failed-run notice, agent questions) now run the per-row check as well: one extra read per recipient.

Local round r09head on b2a807d9d, 13 notification lanes: 74/77. The 3 failures are environmental: BM25 and the box's email capture (emails=0, writes as on main).

Review notes

Closes #3631

A task's subscription outlives its subscriber's team membership, so a
member taken off a project's only team kept receiving the task's new title
and status through their bell and email, although the task itself refused
them (#3631).

Every task-bound notification row now passes one check where it is
written: its recipient must be able to open the task's current project
now. The rule is the one assertTaskReadable applies: a non-disabled member
of the organization who is an owner or admin, or the project is
organization-wide, or the member belongs to one of its teams of this
organization. Status changes, comments, mentions, assignments and
unassignments, reviews, dates and agent notices all pass it. A row for
anyone else is withheld: nothing is written, rewritten or cancelled. The
debounced email rechecks the same rule when it sends, since access can end
inside the debounce window. Subscriptions are kept, so a member who
regains access hears about the tasks they follow again. Rows written while
the person had access stay as history.

projectReadersAmong (the failed-run notice's filter) and the new
taskReadersAmong share one SQL statement. It also counts only teams of
the organization, as getUserTeamIds does.

The integration lane checkTaskNotificationAccess drives the real
team-removal door, the task writers and the bell read. On d6dd53a the
removed member received three rows carrying the renamed title, and a
member of another organization only received rows here. Controls: a team
watcher and an admin outside the team are told, a muted watcher is not,
and history and rejoining work.
checkNotificationEmailSink and checkBellHintWire wrote task-bound rows for
task ids no table holds, and the email lane's preference case wrote for a
user outside the organization. A task-bound row is now written only for
someone who can open its task, so both lanes file their rows under real
tasks of an organization-wide project, make the preference user a member,
and remove what they add, since later lanes count the organization's
members and projects.
…task

Review follow-up on #3631. A date alert picked one person (the assignee,
else the task creator, else the project creator) before the access check,
so an assignee who had lost the project used up the alert on a withheld row.
The sweep now offers the alert only to people who can open the task, and the
overdue rung tells the first creator who still can. The agent-question count
leaves withheld rows out. The email lane asserts that its preference case
writes its row. Two comments no longer overclaim, the reader rule says it
reads the stored member role, and the French docs sentence names the
project's tasks.
@yannickmonney

Copy link
Copy Markdown
Contributor Author

Independent review: accepted at tree dab58a7a80a3455349adfe41563210b6511e6024 (heads b2a807d9d and 6ffcd9e686faa548fb1e6e1dbee83d071cd4e178). Merge held: the final head has one red check.

  • Reviewer: Tale agent update dashboard ui (#508) #2 3f9fdcee-79e7-430b-a430-ba179d5b5132, run 976bf361-8ed2-4e8f-83cf-3c2d52a59c81 (TALE-359 review-merge occurrence, 2026-10-02 00:45 Europe/Zurich).
  • Implementation: agent optimize rag action #4 5f5307c9-4cbd-416a-a456-8bb667fc584d, run b70beb23-f96a-43d8-818f-db572522924f; the empty re-run commit came from run 3890e406. The reviewer is distinct.
  • 6ffcd9e68 is one empty commit on b2a807d9d, so the tree is the same. The merge base is d6dd53ae0.
  • main has since moved to 05543548e (fix(platform): keep a governance switch from reverting a newer save #4057), which shares no file with this PR. The combined tree merges cleanly.
  • A read-only review agent covered completeness, the reader rule and the lane in parallel. I re-checked what I relied on.

Verdict: the fix is right.

  • A task-bound row is written only for someone who can open the task's current project. The email rechecks at send time. Date alerts go to the next person in line who can open the task.
  • The reader rule matches assertTaskReadable: owners and admins; an organization-wide project; a team of this organization; disabled members excluded.
  • Every task-bound writer goes through writeCoalescedNotification, and email is the only outbound channel.

Local checks, on a private Postgres 16 + pgvector with synthetic data and no egress

  • Lanes at the head: checkNotifications, checkNotificationEmailSink, checkBellHintWire, checkPolicySweeps and checkTaskNotificationAccess pass 30/33. All 6 task notifications: checks pass:
    • a member taken off the team gets no new-title row and unread stays 0;
    • another organization's subscriber gets no row;
    • the team watcher and an admin outside the team are told, and the muted watcher isn't;
    • earlier rows stay, and the member hears again once back on the team.
  • The 3 failures are environmental: the BM25 boot check, and two email-capture checks with emails=0.
    • main with the same four lanes fails exactly those 3, at 24/27.
    • CI passes them: the email sink delivers 1.
  • Negative control: with main's collab/service.ts, collab/email-sink.ts and tasks/date-notifications.ts swapped under this lane, exactly two checks fail. The removed member gets the new-title rows, and the other organization's subscriber gets rows. So the lane proves Bug: Task notifications expose new task titles after project access is revoked #3631 and its fix.
  • Unit: collab plus date-notifications pass, 5 files and 64 tests.

CI

  • At 6ffcd9e68: Checks 36934181712 succeeded: Unit ran (no ytdlp_live timeout this time), and Backend integration passed 1270/1270 across 212/212 lanes. E2E, SAST and Commitlint succeeded.
  • Build 36934181654 failed: the Docs container test (job 110610581934) died in the docs image's bun install: GET https://cdn.sheetjs.com/xlsx-0.20.3/xlsx-0.20.3.tgz - 502, before any docs build or test.
  • At b2a807d9d, same tree: that Docs container test passed (job 110565152122), but Unit failed on the ytdlp_live toolchain timeout (CI: make ffmpeg prerequisite timeouts diagnosable #4010).
  • Hold: every check has passed on this tree, but not on one head. Per the manager's rule, I won't merge until every check is green on the final head.
  • Ask: one more empty chore: commit from the author or the manager; my token can't re-run jobs. The next TALE-359 occurrence merges once the new head is green and its tree still equals dab58a7a8.

Non-blocking (P3), for follow-up

  1. A withheld undo leaves a stale unread row. The gate returns before the cancel (collab/service.ts:311-326 vs :344).
    • Scenario: assigned, then loses access, then the task is reassigned. The member keeps the unread "You were assigned" row, and opening it answers 403. On main the undo deleted it.
    • This is by design and unit-tested. The dismiss* paths do still touch former readers' rows (harmless hints).
  2. One extra read per recipient.
    • The ask fan-out can add up to 500 round trips per ask or fold (:1453).
    • The failed-run notice now checks twice.
    • A batched check would remove both.
  3. Trusted-headers role drift, disclosed by the author. The rule reads the stored member.role. Between sign-ins, a promotion made in Settings differs from the session's role.
  4. Test gaps:
    • the email recheck's refusal is unit-tested on a fake SQL only;
    • no unit case for the overdue rung's "first creator who can still open it";
    • no lane for another organization's team, or for a disabled member.
  5. Lane cleanup: checkBellHintWire deletes p-bell-wire outside a finally (integration-check.ts:44420). A failing run leaves it behind for lanes that count projects.
  6. Docs wording.
    • The new EN paragraph says "tasks they follow", and DE "denen die Person folgt".
    • The UI says Watch / Verfolgen, and the existing EN docs say "watching the task". FR "suit" matches Suivre.
  7. Reviewer case, for the PR body. resolveReviewer (tasks/reviews.ts:134-165) already routes past a designee who lost edit access, so a withheld review request needs a race. The gap that predates this PR is a pending review whose reviewer later loses access: it is never retargeted. Worth its own issue.

Your three questions

  • Withholding rather than redirecting is fine, since the redirect happens upstream.
  • Keeping pre-revocation history is fine, apart from item 1.
  • The extra read is acceptable now; batch it later.

Not covered: no production contact. I didn't drive a real browser, because the change has no UI surface: the bell rows are verified at the API and database level in the lane.

@yannickmonney

Copy link
Copy Markdown
Contributor Author

Status from TALE-359 (agent #2, run 83ca77ca-f3c4-4a41-bb14-090024a62d3e): still accepted at tree dab58a7a8; merge still held.

  • The manager's re-run head ce22a0e4d has the same tree.
  • That head is red on Unit again (job 110658560318): ytdlp_live.test.ts:142's yt-dlp download from GitHub hit a 10 s connect timeout (CI: make ffmpeg prerequisite timeouts diagnosable #4010). The other 995 files passed. The Docs container test and Backend integration passed.
  • Every check has now passed on this tree, but each of its three heads had one red external-network fetch.
  • Whether to re-run again or accept the per-check evidence is now a Question to the manager on TALE-359 (key review-merge/4056/final-head-green).
  • Nothing was merged. This PR still merges cleanly with current main (e6132644f).

@yannickmonney

Copy link
Copy Markdown
Contributor Author

Exact-head check before merge (TALE-359, agent #2, run 9b7a4b83-9a97-4ce1-b60a-3983594b3250): every check is green on 68b80ba311863c50ac771c795ee9c39c8ae39a82. The acceptance at tree dab58a7a8 stands, so I'm merging.

  • The head: the manager's empty re-run commit, parent ce22a0e4d. Its tree is dab58a7a80a3455349adfe41563210b6511e6024, which is reviewed tree 9ea2b0ed exactly.
    • This follows the manager's Answer 2bd59619: one fully green head, on the merge onto e6132644f.
  • CI (merge ref 5e31897, 68b80ba31 into e6132644f): all five workflows succeeded. Checks 36963020802, Build 36963020714, E2E 36963020736, SAST 36963020770 and Commitlint 36963020751.
    • Unit passed 997 files, ytdlp_live included (job 110700649306).
    • Backend integration passed 1270/1270 checks across 212/212 lanes (job 110700674339).
    • The Docs container test passed (job 110700727230).
    • 51 checks succeeded.
    • Not counted as success: 1 neutral Trivy, and 10 skipped by design (the AI gateway, UI docs and Web container tests by path filter, 5× Candidate gate, 2 fork-PR jobs).
  • Since that run: main gained only feat(platform): filter a website's pages to the failed or skipped ones #4065 (30b2a6254). It shares one file with this PR, integration-check.ts, but only through one hunk in checkWebsitesCrawl, with no notification or task writes. It touches no collab or tasks code, and git merge-tree is clean.

@yannickmonney
yannickmonney merged commit df7fd99 into main Oct 2, 2026
@yannickmonney
yannickmonney deleted the fix/notification-recipients-recheck-task-access branch October 2, 2026 04:47
yannickmonney added a commit that referenced this pull request Oct 4, 2026
…#4165)

Follow-ups from the #4056 review, with no change to who receives
notifications. The EN and DE notification docs now use the UI's Watch
wording; FR already matched. New tests pin the existing behaviour: a former
reader's unread assignment row stays unchanged when the task is reassigned,
the overdue reminder falls back from the task creator to the project
creator only while that person can still open the task, disabled members
and members of another organization's team receive nothing in the
real-Postgres lane, and the bell-hint lane deletes its project when a step
or a tail close fails. A docs test checks the Watch wording in all three
languages.

Closes #4077
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.

Bug: Task notifications expose new task titles after project access is revoked

1 participant