feat(database): task followers
F1 of six PRs that build following on tasks: the data layer only, with no service, wire, MCP, or UI change.
What it adds
-
task_followertable (packages/database/src/schemas/task-follower.ts):task_id,user_id,machines(whether agents on the task may use this member's machines, default off), andcreated_at. The primary key is (task_id,user_id), there's an index onuser_id, and both ids cascade on delete, the same waytask_pindoes. It records no reason for following. -
Migration
20261112201451_task_follower, generated withdb:generateplus a hand-written backfill. For every existing task it inserts:- the assignee, with
machineson - the creator (
task.user_id), withmachinesoff unless they are also the assignee - every member who sent one of the task's agents a message (
messages.sender_user_idjoined throughagent.conversation_id), withmachinesoff
A member named more than once gets one row, with
bool_ordecidingmachines. Only current members of the task's workspace are inserted. The backfill only inserts into the new table and usesON CONFLICT DO NOTHING. - the assignee, with
-
Store
@repo/database/models/task-follower-store. Every function takes the acting account and checks that it can reach the task (taskReachableBy):listTaskFollowers(userId, taskId)answers none when the account can't reach the task. It lists only followers who are still members of the task's workspace.listFollowedTasks(userId, organizationId)lists the tasks in that workspace that the account follows and can reach.followTask(userId, { taskId, followerId, machines })lets any member who can reach the task add a member of its workspace as a follower. A follower who already exists keeps their row and their switch.unfollowTask(userId, taskId)removes the account's own row.setFollowerMachines(userId, taskId, machines)changes the account's own switch only, since the rules say only that person can flip it.
Decisions
- Former members are left out. Members who have left the workspace are skipped in the backfill and hidden from reads.
task_followeris not a Vespin Sync table yet. Its writes answer no txid. F2 can add the sync capture and txids if followers onTaskSummaryneed live updates.- The backfill scans
messagesonce. It filters onsender_user_id IS NOT NULLand joinsagent, which is a one-time cost in the deploy's migration transaction.
Tests
- I ran
pnpm exec vitest run packages/database/src/models/__tests__/task-follower-store.test.tsand both cases pass:- Following again keeps the follower's switch, and only the follower flips it.
- An account outside the task's workspace reads no followers and adds none, no outsider can be added, and a member who leaves stops reading as a follower.
- I checked the backfill with a scratch test that I didn't commit. It seeded tasks, an agent, and messages from a member, a former member, and a line with no sender, then reran the migration's statements over them. It produced exactly: the assignee with
machineson, the creator-and-assignee withmachineson, the creator withmachinesoff, and the deduplicated sender withmachinesoff. The former member and the line with no sender were skipped, and running it a second time wrote nothing. pnpm --filter @repo/database check:migrationsandtypecheckpass, and Biome passes on the changed files. I'm leaving the rest to CI.
🤖 Generated with Claude Code
Summary by CodeRabbit
- New Features
- Added support for following and unfollowing tasks, viewing task followers, and listing followed tasks within a workspace.
- Followers can manage whether their machine activity is shared on a task.
- Existing task assignees, task users, and relevant message senders are added as followers when they belong to the task’s workspace.
- Only workspace members can view or manage followers, and followed tasks are limited to the relevant workspace.