Skip to content

CxODEV-2161: keep the engine polling after Conductor errors (3.10.1 backport) - #234

Merged
milansvitlica-codaxy merged 4 commits into
v3from
CxODEV-2161-engine-keeps-polling-v3
Nov 10, 2026
Merged

milansvitlica-codaxy merged 4 commits into
v3from
CxODEV-2161-engine-keeps-polling-v3

Conversation

@milansvitlica-codaxy

@milansvitlica-codaxy milansvitlica-codaxy commented Oct 19, 2026 •

Copy link
Copy Markdown
Collaborator

Backport of #233 to v3 (3.10.1). Fixes CxODEV-2161 and CxODEV-2000 (YouTrack) for the CxO engines, which pin ConductorSharp 3.10.x.

The three code commits from #233 cherry-picked cleanly: WorkflowEngineBackgroundService.cs and TaskQueuePollingService.cs were identical on master and v3. With them:

  • A ConductorSharp engine no longer stops polling for good after a Conductor error.
  • An HTTP timeout is no longer taken for a shutdown.
  • /health is Healthy only while the engine actually reads its queues.

See #233 for the root cause, design and before/after table.

Behaviour change to note: the old FTL Workflow Engine Background Service encountered an (API) error(s) is gone. Each failed attempt now logs at Error: ConductorSharp engine stopped polling (attempt N); retrying in …. Alerts that matched the old FTL text need updating.

Versions: Client, Engine, Patterns and KafkaCancellationNotifier go to 3.10.1. Toolkit stays 3.0.1-beta3.

Tests: v3 PRs get no CI, so this is the local run (LF checkout, net6.0 via DOTNET_ROLL_FORWARD=Major): 88/88 passed, including the 13 new unit tests and the 5 end-to-end recovery tests.

🤖 Generated with Claude Code

milansvitlica-codaxy and others added 4 commits October 19, 2026 13:44
…t is not a shutdown (CxODEV-2000)

WorkflowEngineBackgroundService ran the deployment and the execution manager
once. Any error, or an HTTP timeout mistaken for a shutdown, ended polling for
good while the host stayed up (and, for a timeout, stayed Healthy).

RunAsync is now a supervisor loop: deploy, mark running, run the execution
manager; on any error that is not our own shutdown, mark not running, log an
error, back off (1 s doubling to 30 s, 500 ms jitter) and start again. The
backoff resets after a successful deploy.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
A real engine (DI wiring, hosted service, beta execution manager, HTTP
client) against a fake Conductor that answers 503, hangs (request timeout)
or loses the task-def registration race, then recovers. Each test checks
that the engine backs off, reports not running, and completes a task queued
after recovery; one also checks that a task in flight during the outage
still completes. All four fail on the old loop.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
…shutdown cancel a hung deploy

Review findings on the supervisor loop:

- Health and the backoff reset followed a successful deploy, not a successful
  poll. With Conductor's metadata up and its task queues down (e.g. the queue
  backend), the engine reported Healthy most of the time while polling nothing,
  and redeployed about once a second on a 4xx. TaskQueuePollingService now marks
  the engine running after a successful read; the background service no longer
  marks it after deploy and restarts the backoff only after a run that polled.
  Unhealthy is still set only by the background service.
- Deploy takes no token, so a hung deploy blocked StopAsync. It now runs under
  WaitAsync(stoppingToken).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@milansvitlica-codaxy

milansvitlica-codaxy commented Nov 10, 2026 •

Copy link
Copy Markdown
Collaborator Author

Retracted: this run was green, not red. CxO Atlas misread its own test run on 02028e96. dotnet test ConductorSharp.sln reported "Test Run Successful", with 88 total and 88 passed (0 failed), including the 5 EngineRecoveryTests. Atlas's parser looked for a different summary line. Atlas runs the suite again once its parser is fixed, and posts that result in a new comment.

@milansvitlica-codaxy

Copy link
Copy Markdown
Collaborator Author

CxO Atlas ran the full test suite on this head (02028e96): green.

dotnet test ConductorSharp.sln --logger console;verbosity=normal in its worker (.NET 10 SDK, .NET 6 runtime): exit 0, 25 s.

  • Test Run Successful. Total tests: 88, Passed: 88, Failed: 0, Skipped: 0

Passed per test class: WorkflowBuilderTests 32, StructuredErrorTests 15, WorkflowEngineBackgroundServiceTests 11, FailedTaskStructuredErrorReaderTests 8, TaskQueuePollingServiceTests 5, ContainerBuilderTests 5, EngineRecoveryTests 5, TaskDefinitionBuilderTests 2, SerializationTests 2, WorkflowItemRegistryTests 2, UtilityTests 1.

v3 has no CI, so this run is the gate: Atlas merges this PR only while its head is the one tested here, then publishes its packages.

@milansvitlica-codaxy
milansvitlica-codaxy marked this pull request as ready for review November 10, 2026 07:37
@milansvitlica-codaxy

Copy link
Copy Markdown
Collaborator Author

Independent review of head 02028e96: no blocking defects for CxO. There is one low finding. It can't hit CxO engines, which all use InMemoryHealthService. #233 (master) has the same code, so all of this applies there too.

Evidence

  • Full suite on 02028e96 (dotnet test ConductorSharp.sln, net6.0 via DOTNET_ROLL_FORWARD=Major): 88/88 passed.
  • EngineRecoveryTests, WorkflowEngineBackgroundServiceTests and TaskQueuePollingServiceTests were run 10 times in a row: 21/21 every run, with no flakes.
  • Not checked: whether the new tests fail on the old code. They use the new internal constructors, so they don't compile against plain v3.

Findings

1. Low (no CxO impact): the retry loop can still end for good.
The health calls in the catch block have no guard (WorkflowEngineBackgroundService.cs#L117-L124). If GetHealthData or UnsetExecutionManagerRunning throws, the exception escapes the while loop. RunAsync then faults, and nothing awaits _executingTask. So the engine stops polling for good, which is the same failure class this PR fixes. InMemoryHealthService can't throw. FileHealthService can (an IOException), and so can a custom store.
Suggested fix: wrap those two calls in a try/catch that logs a warning and carries on with the backoff.

2. Low: the description overstates /health.
"Healthy only while the engine actually reads its queues" isn't true during a Conductor hang. AddConductorSharp sets no HttpClient.Timeout, so each of the 5 ListQueuesAsync attempts waits the 100 s default. Add the 1 + 2 + 4 + 8 s retry delays, and /health stays Healthy for about 8.5 min before it turns Unhealthy. This is still much better than before, when a timeout left it Healthy forever.
Suggested fix: reword the sentence.

3. Low: the health store is now on the poll path.
TaskQueuePollingService now reads the health data on every poll (TaskQueuePollingService.cs#L77-L79). With FileHealthService, that is one file read and one JSON parse per poll.
FileHealthService also has an older bug. Its finally calls _semaphore.Release() even when WaitAsync was cancelled and the semaphore was never taken (FileHealthService.cs#L35-L53). After that, reads and writes can overlap.
Before this PR, a health read error could not touch polling. Now it restarts the engine. No CxO impact, and not for this backport.

4. Design note, not a defect: every restart redeploys all definitions.
Each recovery re-POSTs all task definitions and re-PUTs all workflow definitions. After a Conductor outage, every replica does this at almost the same moment: the jitter is only 0–500 ms. The RegistrationRace test shows the Postgres duplicate-key race this can cause, and the retry handles it. The upside is that definitions come back if Conductor lost them. I'd keep it, and state the trade-off in the description.

What's good

  • Shutdown vs. timeout: catch (OperationCanceledException) when (cancellationToken.IsCancellationRequested) exits only on a real stop. An HttpClient timeout now counts as an error.
  • Hung deploy: Deploy(...).WaitAsync(cancellationToken) lets a stop return even while the deploy hangs.
  • Backoff reset: it resets only after a run reached a successful queue read, so a deploy-only success keeps backing off.
  • Recovery tests: they drive real DI, the hosted service and the HTTP client against a fake Conductor. They cover 503, hang, queue-only outage, the registration race and a task in flight across a restart.
  • Release: release.yml pushes with --skip-duplicate, so the unchanged Toolkit 3.0.1-beta3 won't fail the release.

Recommendation

Merge this head as it is. CxO is not exposed to finding 1. Put the finding 1 guard into #233 before 4.4.2 ships. Fixing it here would change the head that was tested.

Independent review by Claude Code for Milan Svitlica. It was not written by the session that wrote this PR, and it is not an approval.

milansvitlica-codaxy added a commit that referenced this pull request Nov 10, 2026
The catch block read and cleared the health flag without a guard. If the
health store threw (e.g. an IOException from FileHealthService), the
exception left RunAsync and the engine stopped polling for good. Both
calls are now guarded: the error is logged as a warning and the backoff
continues.

Found in the independent review of #234.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@milansvitlica-codaxy
milansvitlica-codaxy merged commit e99b5d2 into v3 Nov 10, 2026
@milansvitlica-codaxy
milansvitlica-codaxy deleted the CxODEV-2161-engine-keeps-polling-v3 branch November 10, 2026 08:42
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