Skip to content

feat: project flag run execution with durable Temporal workflows - #8355

Draft
aecsocket wants to merge 23 commits into
mainfrom
boris/temporal
Draft

aecsocket wants to merge 23 commits into
mainfrom
boris/temporal

Conversation

@aecsocket

Copy link
Copy Markdown
Contributor

No description provided.

@aecsocket
aecsocket marked this pull request as draft November 17, 2026 12:59
@github-actions

Copy link
Copy Markdown
Contributor

Pull request changelog

App

Added

Changed

Deprecated

Removed

Fixed

Security

Website

Added

Changed

Deprecated

Removed

Fixed

Security

Hosting

Added

Changed

Deprecated

Removed

Fixed

Security

@greptile-apps

greptile-apps Bot commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 1/5

[High impact] Project changes across the API can now trigger model-backed moderation scans.

Fix the interrupted upload work, unused model answers, changing run modules, and supported-image failures before merging.

Summary

This PR adds Temporal workflows for project image and text scans, a saved-answer cache, shared Rhai modules, and moderation tools.

  • Project changes now start or signal scans of their images and text.
  • Moderators can save shared Rhai modules and decision questions for project-flag rules.
  • Moderators can test one rule against a batch of projects.
  • Moderators can inspect the rule inputs for one project.
  • Labrinth can run Temporal workers alongside its API.

Reviews (1) · Last reviewed commit: "add route to get project context" · Reviewed by Greptile

Comment on lines +524 to +531
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")?;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 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:

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.

Comment on lines +90 to +96
futures::try_join!(
image_scan::scan_project_images(ctx, project_id),
text_scan::scan_project_text(ctx, project_id),
)?;

if !ctx.state(|state| state.needs_reconcile) {
return Ok(());

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Model answers never affect flags

ReconcileProjectFlagsWorkflow::run finishes after caching model answers, without evaluating rules or updating project flags. Only the image and text scan functions read project_flag_scans; ProjectFlagEngine never reads these answers. With inference enabled, project edits therefore send paid model requests whose answers cannot affect moderation flags.

Connect the cached answers to rule evaluation and flag updates before treating reconciliation as complete.

Prompt To Fix With AI
This is a comment left during a code review.
Path: apps/labrinth/src/workflow/project_flag/mod.rs
Line: 90-96

Comment:
**Model answers never affect flags**

`ReconcileProjectFlagsWorkflow::run` finishes after caching model answers, without evaluating rules or updating project flags. Only the image and text scan functions read `project_flag_scans`; `ProjectFlagEngine` never reads these answers. With inference enabled, project edits therefore send paid model requests whose answers cannot affect moderation flags.

Connect the cached answers to rule evaluation and flag updates before treating reconciliation as complete.

---

For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.

Comment on lines +187 to +190
let engine = engine
.with_module_snapshot()
.await
.wrap_err("loading project flag module snapshot")?;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Run results use changing code

Each batch loads the current modules rather than the modules used when the run started. If a moderator edits or deletes an imported module while a run is queued, later batches use different code or fail to import it. One run can then contain results from different rule implementations despite its fixed rule snapshot.

Save module scripts with the run snapshot and load that saved copy for every batch.

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/queue/moderation/project_flag_run.rs
Line: 187-190

Comment:
**Run results use changing code**

Each batch loads the current modules rather than the modules used when the run started. If a moderator edits or deletes an imported module while a run is queued, later batches use different code or fail to import it. One run can then contain results from different rule implementations despite its fixed rule snapshot.

Save module scripts with the run snapshot and load that saved copy for every batch.

**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.

Comment on lines +184 to +187
matches!(content_type, "image/png" | "image/jpeg" | "image/webp"),
"decisions image must be PNG, JPEG, or WebP"
);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 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.

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.

Comment on lines +44 to +45
public async createModule(body: SaveProjectFlagModuleRequest): Promise<void> {
return this.client.request<void>('/moderation/project-flag/modules', {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 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://github.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!

@github-actions

github-actions Bot commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor

Frontend previews

Last deployed commit is 2b65c8d0928d7eea68a16551e504afd163cc9f04

Persistent

Environment URL
staging https://pr-8355.frontend-staging.rinth.dev
production https://pr-8355.frontend.rinth.dev
storybook https://pr-8355-storybook.modrinth.workers.dev

Latest commit

Environment URL
staging https://06b0098b.frontend-staging.rinth.dev
production https://249054c4.frontend.rinth.dev

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

1 participant