Skip to content

Fail Suspend/Postpone when function is currently interrupted#149

Closed
stidsborg wants to merge 3 commits into
mainfrom
suspend-postpone-fail-on-interrupt
Closed

Fail Suspend/Postpone when function is currently interrupted#149
stidsborg wants to merge 3 commits into
mainfrom
suspend-postpone-fail-on-interrupt

Conversation

@stidsborg
Copy link
Copy Markdown
Owner

Summary

Previously, SuspendFunction and PostponeFunction silently absorbed the interrupted flag at the storage layer — they converted the requested state into Postponed(expires=0) and cleared the flag, returning true. The runtime never saw that an interrupt had been observed, so an interrupt arriving mid-execution was effectively invisible to the caller.

Now both methods return false when the row is currently interrupted, letting the caller treat the interrupt as a real signal.

Changes

  • SuspendFunction: SQL/WHERE now gated on interrupted = FALSE; returns false if the row is interrupted. Status stays Executing, flag stays set.
  • PostponeFunction: same guard, but gated on a new failIfInterrupted: bool = true parameter so the runtime's internal Reschedule path can opt out (failIfInterrupted: false) and queue the function for immediate re-pickup while consuming the interrupt.
  • InvocationHelper.PersistResult Postpone case now returns Reschedule on false (was: Success on both branches, which swallowed the failure).
  • InvocationHelper.Reschedule passes failIfInterrupted: false since it's the consumer of the interrupt signal.

Applied uniformly across InMemory, PostgreSQL, MariaDB, and SqlServer stores.

Tests

Replaced 4 obsolete tests that pinned the old silent-convert behaviour with 3 new contract tests, wired into all 4 stores:

  • SuspendingInterruptedFunctionReturnsFalse
  • PostponingInterruptedFunctionReturnsFalse
  • PostponingInterruptedFunctionWithFailIfInterruptedFalseSucceedsAndClearsFlag

Test plan

  • Build solution
  • InMemory tests: 520 passed
  • PostgreSQL tests: 376 passed
  • MariaDB tests: 376 passed
  • SqlServer tests: 376 passed

stidsborg added 3 commits May 17, 2026 10:08
Previously, SuspendFunction and PostponeFunction silently absorbed the
interrupted flag at the storage layer: they converted the requested
state into Postponed(expires=0) and cleared the flag, returning true.
The runtime never saw that an interrupt had been observed.

Now both methods return false when the row has interrupted=true,
letting the caller treat the interrupt as a real signal:

- SuspendFunction: gains AND interrupted = FALSE in its WHERE clause
- PostponeFunction: same, but gated on a new failIfInterrupted=true
  default param so InvocationHelper.Reschedule can still pass false to
  consume the interrupt and queue the function for immediate re-pickup
- InvocationHelper.PersistResult Postpone case now returns Reschedule
  on false (was: Success on both branches, swallowing failure)

Replaces 4 obsolete tests that pinned the old silent-convert behaviour
with 3 new tests covering the new contract across all 4 stores.
Parameter is no longer optional with a default; every caller picks the
behaviour explicitly. Updated all 4 store implementations, both
CrashableFunctionStore wrappers, InvocationHelper's two call sites
(true for user-yield, false for Reschedule), and the remaining test
call sites which now pass failIfInterrupted: true to match the prior
default semantics.
Replace the if/failIfInterrupted/else branching with a single cached
SQL per shape (with/without effects), gated by a runtime parameter:

  WHERE ... AND (@FailIfInterrupted = 0 OR Interrupted = 0)

The SET clause unconditionally clears interrupted, which is a no-op
when WHERE already requires it false and the intended consumption
otherwise. Halves the SQL caches in PG, MariaDB, and SqlServer.
@stidsborg stidsborg closed this May 17, 2026
@stidsborg stidsborg deleted the suspend-postpone-fail-on-interrupt branch May 17, 2026 08:35
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.

1 participant