Skip to content

Process End()#665

Open
koden-km wants to merge 8 commits intoengine-testfrom
process-end
Open

Process End()#665
koden-km wants to merge 8 commits intoengine-testfrom
process-end

Conversation

@koden-km
Copy link
Member

What change does this introduce?

Ending a process is now permanent.

Why make this change?

This change is to match the new ADR-24 spec.

Is there anything you are unsure about?

  • I'm not sure if the process adaptor.go should be checking the instance HasEnded flag before creating the scope and panic from there rather than doing it in HandleMessage()?
  • Not adding ended: inst.HasEnded, to the process scope creation still passes tests. Another test case might be needed?

What issues does this relate to?

Fixes #660

@koden-km koden-km requested a review from jmalloc July 21, 2025 06:04
@jmalloc
Copy link
Member

jmalloc commented Jul 21, 2025

  • Not adding ended: inst.HasEnded, to the process scope creation still passes tests. Another test case might be needed?

I think this behavior makes sense as is. We never expect handling to get this far if the process has already ended. Therefore, the only purpose of scope.ended is to signal that we have ended the process within this scope, which aligns with its usage to cause the two new panics, and to pass true to the HasEnded flag when saving the instance.

All that said, I think we might have a race condition here when it comes to handling events. This line here

if !exists && !p.ScheduledFor.IsZero() {
handles the "ignoring" for timeouts, but as best I can tell there's nothing that handles it for events. I can't recall off the top of my head whether events are added to the queue for processes, or if they're fed directly from event streams, but I'm also not sure if that matters.

  • I'm not sure if the process adaptor.go should be checking the instance HasEnded flag before creating the scope and panic from there rather than doing it in HandleMessage()?

I think this relates to the last paragraph, but I'm not sure which panic you're referring to.

packer: a.Packer,
logger: a.Logger,
instanceID: inst.InstanceID,
ended: inst.HasEnded,
Copy link
Member

Choose a reason for hiding this comment

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

This may not be necessary, as you pointed out, adding it doesn't change any behavior. If we do need more test cases, it would be to guarantee that both events and timeouts are ignored for ended processes (these may already exist?)

Copy link
Member

Choose a reason for hiding this comment

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

Copy link
Member Author

Choose a reason for hiding this comment

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

Should I remove this ended initialisation?

@koden-km
Copy link
Member Author

I think this relates to the last paragraph, but I'm not sure which panic you're referring to.

The panic I ment was the one in the handler that is given the created scope. I guess i'm more referring to what happens on the next time the process gets sent an event after having ended from handling a previous event/timeout. Perhaps Dogma already knows not call it again?

@jmalloc
Copy link
Member

jmalloc commented Jul 22, 2025

Perhaps Dogma already knows not call it again?

No, something here needs to check the ended flag before routing the message (it's already doing it for timeouts).

@koden-km koden-km requested a review from jmalloc July 25, 2025 05:23
@koden-km
Copy link
Member Author

I've added a check for ended process before handling new messages. Not quite sure if that covers what you mentioned though?

return nil
}

if exists && inst.HasEnded {
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
if exists && inst.HasEnded {
if inst.HasEnded {

Pretty sure this can be simplified and the if above this one can then be removed.

Copy link
Member

Choose a reason for hiding this comment

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

Also, I don't think there's any existing test for this logic, and certainly not for events specifically.

Copy link
Member Author

Choose a reason for hiding this comment

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

Can't remove the if block above without breaking a timeout test for a not yet existing instance.

Copy link
Member Author

Choose a reason for hiding this comment

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

I've removed the exists check from that line and added another test to verify messages to an already ended process get ignored.

@koden-km koden-km requested a review from jmalloc July 25, 2025 23:07
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.

2 participants