Skip to content

Mitigate orphan processes#1095

Merged
ebma merged 3 commits intostagingfrom
remove-orphan-processes
Mar 26, 2026
Merged

Mitigate orphan processes#1095
ebma merged 3 commits intostagingfrom
remove-orphan-processes

Conversation

@gianfra-t
Copy link
Contributor

No description provided.

@netlify
Copy link

netlify bot commented Mar 24, 2026

Deploy Preview for vortexfi ready!

Name Link
🔨 Latest commit ca7844b
🔍 Latest deploy log https://app.netlify.com/projects/vortexfi/deploys/69c4284e453f020008fca97a
😎 Deploy Preview https://deploy-preview-1095--vortexfi.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@netlify
Copy link

netlify bot commented Mar 24, 2026

Deploy Preview for vortex-sandbox ready!

Name Link
🔨 Latest commit ca7844b
🔍 Latest deploy log https://app.netlify.com/projects/vortex-sandbox/deploys/69c4284e1f2c5c0009566cd7
😎 Deploy Preview https://deploy-preview-1095--vortex-sandbox.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@ebma ebma requested a review from Copilot March 25, 2026 12:00
@gianfra-t gianfra-t marked this pull request as ready for review March 25, 2026 12:00
@ebma ebma self-requested a review March 25, 2026 12:00
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR aims to mitigate “orphan” phase-processing effects by centralizing persistence of phase transitions in the PhaseProcessor, rather than persisting during handler execution.

Changes:

  • PhaseProcessor now persists the handler result via .save() after the Promise.race(...) completes.
  • BasePhaseHandler.transitionToNextPhase was changed to return a new in-memory RampState instance instead of updating/reloading from the DB.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
apps/api/src/api/services/phases/phase-processor.ts Saves the handler-returned state after the timeout race to make persistence happen in one place.
apps/api/src/api/services/phases/base-phase-handler.ts Changes phase transition helper to return a newly built (in-memory) RampState instance.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines 98 to 112
@@ -105,12 +105,11 @@ export abstract class BasePhaseHandler implements PhaseHandler {
}
];

await state.update({
return RampState.build({
...state.get(),
currentPhase: nextPhase,
phaseHistory
});
Copy link

Copilot AI Mar 25, 2026

Choose a reason for hiding this comment

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

transitionToNextPhase now returns RampState.build({...state.get(), ...}). In Sequelize, Model.build() creates an unsaved instance with isNewRecord=true, so later calling .save() will attempt an INSERT (likely failing with a duplicate PK) rather than updating the existing ramp row. Additionally, copying ...state.get() risks persisting stale fields (e.g., processingLock) that were updated in the DB via RampState.update but not reflected on this in-memory instance.

Prefer mutating the existing state instance (e.g., state.set({ currentPhase: nextPhase, phaseHistory })) and returning that same instance so the processor can save only the intended changes without clobbering unrelated columns.

Copilot uses AI. Check for mistakes.
Copy link
Member

Choose a reason for hiding this comment

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

I think we can ignore this comment as your changes should work as intended.

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
// to avoid inserting new records or clobbering unrelated columns.
const updatedState = await state.update(
{ currentPhase: pendingState.currentPhase },
{ fields: ["currentPhase"] }
Copy link
Member

@ebma ebma Mar 25, 2026

Choose a reason for hiding this comment

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

I think we should also include the field phaseHistory here, as it's also returned from the 'transitionToNextPhase()' function.

Comment on lines 98 to 112
@@ -105,12 +105,11 @@ export abstract class BasePhaseHandler implements PhaseHandler {
}
];

await state.update({
return RampState.build({
...state.get(),
currentPhase: nextPhase,
phaseHistory
});
Copy link
Member

Choose a reason for hiding this comment

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

I think we can ignore this comment as your changes should work as intended.

@ebma ebma merged commit 0ef7d03 into staging Mar 26, 2026
6 checks passed
@ebma ebma deleted the remove-orphan-processes branch March 26, 2026 08:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants