You post /add_child #2 on a work item. The hierarchy widget's count ticks up. The child list does not change until you refresh the page. /remove_child does the same thing in reverse: the count is right, the list is not.
This is the story of gitlab-org/gitlab!272650, a short-term refetch that made the list catch up, and a cache detail that, in the first version, refetched every notes page after each successful command.
The issue: two queries, one of them stale
The issue was gitlab-org/gitlab#498118, opened by Amanda Rueda. The investigation in the issue is the important part. WorkItemUpdated, and the main work item query, include hierarchy counts (rolledUpCountsByType) but not the children connection. That connection lives only on workItemTreeQuery. The count in the widget can change while the list stays stale.
A fuller fix would be a hierarchy subscription. That had been tried and removed for performance and UX reasons. Kushal Pandya agreed on the issue that refetching workItemTreeQuery when the command succeeds is the right short-term approach.
There had been earlier attempts. One updated Apollo cache counts from the add/create/remove child form, which is a different path. This bug is specifically the comment-box quick action.
The fix: refetch after a successful command
The production change lives next to the existing time-tracking quick action refetch in work_item_add_note.vue. After a successful /add_child or /remove_child note, it refetches every active workItemTreeQuery:
// Children come from workItemTreeQuery, which is not part of the main work item // query, so /add_child and /remove_child leave the list stale. Refetch on success. // See https://gitlab.com/gitlab-org/gitlab/-/work_items/498118 refetchHierarchyIfChildQuickActionApplied(commentText, { errorMessages, messages }) { if ( !this.quickActionRanSuccessfully({ errorMessages, messages }) || !/\/(add_child|remove_child)(?!\S)/im.test(commentText) ) { return; } this.$apollo .getClient() .refetchQueries({ include: [getWorkItemTreeQuery] }) .catch((error) => Sentry.captureException(error)); }, The command is detected from the note text, not from the internationalized success message. A comment that only talks about adding a child, without the slash command, does not refetch.
Each active tree query is refetched, so a list that was expanded past the first 50 children with Load more reloads from its first page. That pagination reset is an accepted trade-off for this short-term fix. Cross-tab updates are out of scope: the refetch only runs in the tab that posts the comment.
An earlier commit also watched rolled-up counts and refetched whenever they changed, including after a child was created from the tree form, which already writes the child into the cached tree. The integration test forbids a tree refetch on that path, so the watcher was removed. The refetch stays only on the quick action.
The review: do not overwrite features.notes
Anas Shahid found the cache problem. workItemTreeQuery selects features { hierarchy } on the same WorkItem that the notes query uses for features.notes. Apollo's default refetch write policy is overwrite. Refetching the tree dropped features.notes from the cache, so every /add_child or /remove_child refetched the notes pages as well — three requests for 40 discussions, plus the main query. Notes still rendered. They just got fetched again, for no reason.
The fix is refetchWritePolicy: 'merge' on every mounted getWorkItemTreeQuery watcher, not only in work_item_tree.vue. move_work_item_modal.vue stays mounted with the same variables, and work_item_link_child.vue has its own watcher. All three need the merge policy.
Deepika Guliani then caught a test that did not actually prove the fix. The example that forbids a notes refetch passed even when refetchWritePolicy: 'merge' was removed, because waitForAssertion stopped as soon as workItemTreeQuery was sent. The notes refetch starts one turn later, after the tree response is written to the cache. Waiting one more turn made the example fail without the policy and pass with it. That is the kind of spec you want: it is coupled to the bug, not to the nearby request.
The description had to be updated too. After the count-watcher commit was dropped, it still talked about the list updating in another tab. At head, a second tab stays stale. The Screenshots table also needed a real recording of /add_child and /remove_child, not a prose stand-in.
What I took away
1. A count and a list can come from different queries. If you only watch the subscription that updates counts, the widget looks "updated" and the list is still wrong. Find the query that owns the connection you are staring at.
2. refetchQueries is not free. Overwriting a WorkItem in the cache can drop fields another query selected. refetchWritePolicy: 'merge' is the difference between refreshing the tree and accidentally refreshing notes.
3. Put the policy on every mounted watcher, not only the obvious component. A modal that stays mounted with the same variables is another writer.
4. A forbid assertion that returns too early will pass without the fix. If the side effect happens after the cache write, wait for that turn. Deepika's change is the reason that example is load-bearing.
5. Keep the description honest about what you dropped. Cross-tab updates sounded good. They were no longer in the MR.
The MR merged on 29 November 2026.
Links
- Issue: gitlab-org/gitlab#498118
- Merge request: gitlab-org/gitlab!272650
Thanks to Amanda Rueda for the issue, to Kushal Pandya for agreeing the refetch was the right short-term path, to Anas Shahid for the cache overwrite, and to Deepika Guliani for the extra turn in the notes-refetch example.
If you've been thinking about contributing to GitLab, the community issues are a great place to start: contributors.gitlab.com.
