Draft: Name the review decision on review_submitted to-do items
What does this MR do and why?
When a reviewer submits a review, the merge request author gets a review_submitted to-do. Today that to-do only says that a review happened, not whether the reviewer approved or asked for changes. After this MR, it gives the outcome already in the To-Do text.
Before: the To-Do List page and the push notification say "Jane Doe reviewed your merge request." The to-do has no field a client could use to say more.
After: both say "Jane Doe approved your merge request." or "Jane Doe requested changes to your merge request." A plain review keeps the old sentence. The decision is exposed in GraphQL as Todo.reviewState, which is where the To-Do List page reads it from.
How the decision is stored
The decision is recorded once, when the to-do items are created, in a new one-to-one table todo_review_decisions (todo_id, project_id, state). todos is over the table size limit, so the stamp cannot be a column on it; the narrow has_one table is the alternative the large tables guide recommends. The state uses the same values as merge_request_reviewers.state.
The state the reviewer picked in the submit form is applied first (approval or reviewer state update) and, only when that succeeded, travels with the publish request into MergeRequests::DraftNotePublishedEvent and on to TodoService#new_review, which writes the rows in the same transaction as the to-do items. When no state is submitted (API, Duo reviews), the author's reviewer state at that moment is recorded, if they are a reviewer. The to-do item keeps naming that review's decision after the reviewer approves, unapproves or is asked to review again.
Database
Three migrations: the table with its index, then one foreign key per migration.
Migration output
Up:
main: == 20261022222125 CreateTodoReviewDecisions: migrating ========================
main: -- create_table(:todo_review_decisions, {id: false})
main: -> 0.0202s
main: == 20261022222125 CreateTodoReviewDecisions: migrated (0.0254s) ===============
main: == 20261022222126 AddTodosFkToTodoReviewDecisions: migrating ==================
main: -- transaction_open?(nil)
main: -> 0.0000s
main: -- transaction_open?(nil)
main: -> 0.0000s
main: -- execute("LOCK TABLE todos, todo_review_decisions IN SHARE ROW EXCLUSIVE MODE")
main: -> 0.0004s
main: -- execute("ALTER TABLE todo_review_decisions ADD CONSTRAINT fk_87bd66f3b8 FOREIGN KEY (todo_id) REFERENCES todos (id) ON DELETE CASCADE NOT VALID;")
main: -> 0.0008s
main: -- execute("SET statement_timeout TO 0")
main: -> 0.0003s
main: -- execute("ALTER TABLE todo_review_decisions VALIDATE CONSTRAINT fk_87bd66f3b8;")
main: -> 0.0014s
main: -- execute("RESET statement_timeout")
main: -> 0.0003s
main: == 20261022222126 AddTodosFkToTodoReviewDecisions: migrated (0.0239s) =========
main: == 20261022222127 AddProjectsFkToTodoReviewDecisions: migrating ===============
main: -- transaction_open?(nil)
main: -> 0.0000s
main: -- transaction_open?(nil)
main: -> 0.0000s
main: -- execute("LOCK TABLE projects, todo_review_decisions IN SHARE ROW EXCLUSIVE MODE")
main: -> 0.0003s
main: -- execute("ALTER TABLE todo_review_decisions ADD CONSTRAINT fk_0a4070bc5b FOREIGN KEY (project_id) REFERENCES projects (id) ON DELETE CASCADE NOT VALID;")
main: -> 0.0009s
main: -- execute("ALTER TABLE todo_review_decisions VALIDATE CONSTRAINT fk_0a4070bc5b;")
main: -> 0.0032s
main: == 20261022222127 AddProjectsFkToTodoReviewDecisions: migrated (0.0182s) ======Down:
main: == 20261022222127 AddProjectsFkToTodoReviewDecisions: reverting ===============
main: -- transaction_open?(nil)
main: -> 0.0000s
main: -- remove_foreign_key(:todo_review_decisions, {column: :project_id})
main: -> 0.0026s
main: == 20261022222127 AddProjectsFkToTodoReviewDecisions: reverted (0.0396s) ======
main: == 20261022222126 AddTodosFkToTodoReviewDecisions: reverting ==================
main: -- transaction_open?(nil)
main: -> 0.0000s
main: -- remove_foreign_key(:todo_review_decisions, {column: :todo_id})
main: -> 0.0022s
main: == 20261022222126 AddTodosFkToTodoReviewDecisions: reverted (0.0372s) =========
main: == 20261022222125 CreateTodoReviewDecisions: reverting ========================
main: -- drop_table(:todo_review_decisions, {id: false})
main: -> 0.0164s
main: == 20261022222125 CreateTodoReviewDecisions: reverted (0.0246s) ===============Queries and plans
Plans from a postgres.ai thin clone of gitlab-production-main. The table does not exist there yet, so it was created with the migrations' DDL and seeded with copies of the 1,000 newest review_submitted to-do items before measuring. Literals are replaced with placeholders.
GraphQL batch load of a page of to-do items (`Todos::ReviewDecision.states_by_todo_id`) and the push worker preload (`Todo.with_preloaded_user_and_push_subscriptions`): same shape, bounded by the page size (100) or one `create_todos` batch
SELECT todo_id, state FROM todo_review_decisions WHERE todo_id IN (<todo_ids>) Index Scan using todo_review_decisions_pkey on public.todo_review_decisions (cost=0.28..7.19 rows=20 width=10) (actual time=0.041..0.044 rows=20 loops=1)
Index Cond: (todo_review_decisions.todo_id = ANY ('{<todo_ids>}'::bigint[]))
Buffers: shared hit=3
I/O Timings: read=0.000 write=0.000
Time: 0.641 ms
- planning: 0.569 ms
- execution: 0.072 ms
- I/O read: 0.000 ms
- I/O write: 0.000 ms
Shared buffers:
- hits: 3 (~24.00 KiB) from the buffer pool
- reads: 0 from the OS file cache, including disk I/O
- dirtied: 0
- writes: 0Single to-do item read (`Todo#review_decision`)
SELECT todo_review_decisions.* FROM todo_review_decisions WHERE todo_review_decisions.todo_id = <todo_id> LIMIT 1 Limit (cost=0.28..3.29 rows=1 width=18) (actual time=0.059..0.060 rows=1 loops=1)
Buffers: shared hit=6
I/O Timings: read=0.000 write=0.000
-> Index Scan using todo_review_decisions_pkey on public.todo_review_decisions (cost=0.28..3.29 rows=1 width=18) (actual time=0.058..0.058 rows=1 loops=1)
Index Cond: (todo_review_decisions.todo_id = <todo_id>)
Buffers: shared hit=6
I/O Timings: read=0.000 write=0.000
Time: 0.602 ms
- planning: 0.507 ms
- execution: 0.095 ms
- I/O read: 0.000 ms
- I/O write: 0.000 ms
Shared buffers:
- hits: 6 (~48.00 KiB) from the buffer pool
- reads: 0 from the OS file cache, including disk I/O
- dirtied: 0
- writes: 0Recording the decision with the to-do items (`TodoService#record_review_decisions`, one multi-row `insert_all` per review; shown for one row)
INSERT INTO todo_review_decisions (todo_id, project_id, state) VALUES (<todo_id>, <project_id>, 3) Insert on public.todo_review_decisions (cost=0.00..0.01 rows=0 width=0) (actual time=0.297..0.297 rows=0 loops=1)
Buffers: shared hit=60
WAL: records=3 fpi=0 bytes=201
I/O Timings: read=0.000 write=0.000
-> Result (cost=0.00..0.01 rows=1 width=18) (actual time=0.001..0.001 rows=1 loops=1)
I/O Timings: read=0.000 write=0.000
Trigger RI_ConstraintTrigger_c_334627004 for constraint fk_87bd66f3b8: time=2.430 calls=1
Trigger RI_ConstraintTrigger_c_334627009 for constraint fk_0a4070bc5b: time=7.091 calls=1
Time: 9.876 ms
- planning: 0.033 ms
- execution: 9.843 ms
- I/O read: 0.000 ms
- I/O write: 0.000 ms
Shared buffers:
- hits: 60 (~480.00 KiB) from the buffer pool
- reads: 0 from the OS file cache, including disk I/O
- dirtied: 0
- writes: 0Fallback when no state was submitted (`MergeRequest#find_reviewer`, existing query on an existing unique index)
SELECT merge_request_reviewers.* FROM merge_request_reviewers WHERE merge_request_reviewers.merge_request_id = <merge_request_id> AND merge_request_reviewers.user_id = <user_id> LIMIT 1 Limit (cost=0.57..3.59 rows=1 width=50) (actual time=8.002..8.003 rows=0 loops=1)
Buffers: shared hit=3 read=4
I/O Timings: read=7.935 write=0.000
-> Index Scan using index_merge_request_reviewers_on_merge_request_id_and_user_id on public.merge_request_reviewers (cost=0.57..3.59 rows=1 width=50) (actual time=8.001..8.002 rows=0 loops=1)
Index Cond: ((merge_request_reviewers.merge_request_id = <merge_request_id>) AND (merge_request_reviewers.user_id = <user_id>))
Buffers: shared hit=3 read=4
I/O Timings: read=7.935 write=0.000
Time: 9.032 ms
- planning: 0.980 ms
- execution: 8.052 ms
- I/O read: 7.935 ms
- I/O write: 0.000 ms
Shared buffers:
- hits: 3 (~24.00 KiB) from the buffer pool
- reads: 4 (~32.00 KiB) from the OS file cache, including disk I/O
- dirtied: 0
- writes: 0Growth: one row per recipient (author plus assignees) of each submitted review, so it tracks the review_submitted subset of todos. Rows are never updated and are removed with their to-do item through the ON DELETE CASCADE foreign key, so the table stays a small fraction of todos.
Screenshots or screen recordings
To-Do List page, filtered to Reason = Review submitted, with one approval, one change request and one plain review:
| Before | After |
|---|---|
![]() |
![]() |
How to set up and validate locally
-
As user A, open a merge request and add user B as a reviewer.
-
As user B, leave a draft comment and submit the review with Approve.
-
As user A, open Your work > To-Do List. The to-do reads "B approved your merge request."
-
As user A, run in GraphiQL:
{ currentUser { todos(action: [review_submitted]) { nodes { id reviewState } } } }The newest node reports
APPROVED. Submit another review as B with Request changes and a new node reportsREQUESTED_CHANGES. Click Approve as B afterwards: the node still reportsREQUESTED_CHANGES, because it names the review that raised it. -
Optional, in the Rails console:
todo = User.find_by(username: 'a').todos.pending.last Gitlab::MobilePush::Payload.new(todo).body # => "B requested changes to your merge request."

