Skip to content

persist more Temporal flags workflow state in Postgres - #8537

Open
aecsocket wants to merge 6 commits into
mainfrom
boris/temporal-persist
Open

aecsocket wants to merge 6 commits into
mainfrom
boris/temporal-persist

Conversation

@aecsocket

Copy link
Copy Markdown
Contributor

No description provided.

@github-actions

github-actions Bot commented Dec 2, 2026

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

@mergify

mergify Bot commented Dec 2, 2026

Copy link
Copy Markdown

Tick the box to add this pull request to the merge queue (same as @mergifyio queue). If it does not match the queue conditions yet, it enters the queue once it does.

  • Queue this pull request once it meets the queue conditions

@greptile-apps

greptile-apps Bot commented Dec 2, 2026 •

Copy link
Copy Markdown
Contributor

Confidence Score: 1/5RetriggerView in Greptile

[Medium impact] The changes affect project-flag scan history and results in the moderation workflow.

Fix the workflow recovery and compatibility failures before merging.

Summary

Moves project-flag run metadata, status, selected projects, and frozen summaries from Temporal into Postgres.

  • Moderators can find project-flag runs in PostgreSQL after Temporal history expires.
  • Project scan results use the new run IDs and only save while a run is active.

Reviews (1) · Last reviewed commit: "use base62 id for workflow names" · Reviewed by Greptile

Comment on lines 327 to 331
let status = lock_run(&mut transaction, id).await?;
if ctx.is_cancelled() || status != Some(RunStatus::Running) {
return Err(ActivityError::from(anyhow!(
"project flag run is no longer running"
)));

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 Finished runs fail on retry

If Postgres commits but the worker stops before Temporal records success, the next finalize attempt reads Completed and returns an error. The activity can no longer succeed even though its work finished. Return success for an already-completed run without changing its frozen summary.

Knowledge Base Used: Backend data storage

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

Comment:
**Finished runs fail on retry**

If Postgres commits but the worker stops before Temporal records success, the next `finalize` attempt reads `Completed` and returns an error. The activity can no longer succeed even though its work finished. Return success for an already-completed run without changing its frozen summary.

**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 +183 to +188
let _ = sqlx::query!(
r#"DELETE FROM project_flag_runs WHERE id = $1"#,
id.0 as i64
)
.execute(pool)
.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 Accepted scans can disappear

If Temporal accepts the workflow but the response times out or the connection drops, start still deletes the saved run. That also deletes any saved results, and the running workflow skips further writes because its run row is missing. Keep the row when the outcome is unknown, and confirm that the workflow did not start before deleting it.

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

Comment:
**Accepted scans can disappear**

If Temporal accepts the workflow but the response times out or the connection drops, `start` still deletes the saved run. That also deletes any saved results, and the running workflow skips further writes because its run row is missing. Keep the row when the outcome is unknown, and confirm that the workflow did not start before deleting it.

---

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

Comment on lines +209 to +212
if matches!(
&termination,
temporalio_sdk::WorkflowTermination::Failed(_)
) {

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 Stopped scans stay active

If a run is canceled, terminated, or timed out through Temporal, its Postgres row can remain Running forever. This branch only saves a failure for WorkflowTermination::Failed, while describe and list now read Postgres alone. Cancellation skips the update, and termination cannot run workflow cleanup at all. Copy these final states into Postgres so stopped runs no longer appear active or add queued projects to num_scanning.

Knowledge Base Used: Backend data storage

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

Comment:
**Stopped scans stay active**

If a run is canceled, terminated, or timed out through Temporal, its Postgres row can remain `Running` forever. This branch only saves a failure for `WorkflowTermination::Failed`, while `describe` and `list` now read Postgres alone. Cancellation skips the update, and termination cannot run workflow cleanup at all. Copy these final states into Postgres so stopped runs no longer appear active or add queued projects to `num_scanning`.

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

base62_id!(PasskeyId);

base62_id!(ProjectFlagRuleId);
base62_id!(ProjectFlagRunId);

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 Existing scans cannot resume

If any scans are queued or running during deployment, their saved RunInput and BatchInput still contain UUID strings. Changing ProjectFlagRunId to base62 makes those inputs unreadable by the new worker. The workflow name and task queue stay the same, so the worker still receives those executions but cannot resume them. Keep the old input type available until existing runs drain, or put the new workflow on a separate version.

Knowledge Base Used: Labrinth backend platform

Prompt To Fix With AI
This is a comment left during a code review.
Path: apps/labrinth/src/models/v3/ids.rs
Line: 49

Comment:
**Existing scans cannot resume**

If any scans are queued or running during deployment, their saved `RunInput` and `BatchInput` still contain UUID strings. Changing `ProjectFlagRunId` to base62 makes those inputs unreadable by the new worker. The workflow name and task queue stay the same, so the worker still receives those executions but cannot resume them. Keep the old input type available until existing runs drain, or put the new workflow on a separate version.

**Knowledge Base Used:** [Labrinth backend platform](https://app.greptile.com/-/switch-tenant?tenant=modrinth&next=%2Fcustom-context%2Fknowledge-base%2Fmodrinth%2Fcode%2F-%2Fdocs%2Flabrinth-backend.md)

---

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

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