Skip to content

Conversation

@zzstoatzz
Copy link
Collaborator

@zzstoatzz zzstoatzz commented Oct 13, 2025

Closes #19143

Summary

Add submission_count field to track the number of times a flow run was submitted (entered Pending state), separate from run_count which tracks executions (Running state).

This enables automations to retry flow runs that crash before reaching the Running state, addressing a pain point for users who need to retry flows that fail during submission.

Key Changes

  • Add submission_count field to FlowRun, ORMFlowRun, and FlowRunResponse models
  • Add IncrementFlowRunSubmissionCount orchestration transform that increments the count when entering Pending state
  • Expose prefect.submission-count in flow run state change events
  • Add database migrations for both SQLite and PostgreSQL
  • Add comprehensive tests including the motivating case (submission without running)

Test Coverage

Added test test_submission_count_increments_without_running that verifies the key use case: a flow run that is submitted (enters Pending) but crashes before reaching Running, resulting in submission_count=1 and run_count=0.

Also smoke tested manually against a running server with all scenarios passing.

Future Work

While this PR adds tracking capability, automatic retry logic for crashed submissions could be added via orchestration rules or empirical policy as a follow-up enhancement.

Migration Notes

Migrations add a new submission_count column to both flow_run and task_run tables with server_default='0' and nullable=False.

🤖 Generated with Claude Code

Co-Authored-By: Claude [email protected]

@github-actions github-actions bot added enhancement An improvement of an existing feature migration labels Oct 13, 2025
@codspeed-hq
Copy link

codspeed-hq bot commented Oct 13, 2025

CodSpeed Performance Report

Merging #19162 will not alter performance

Comparing add-submission-count-19143 (7d525f5) with main (9bae64b)

Summary

✅ 2 untouched

@github-actions github-actions bot added the docs label Oct 13, 2025
zzstoatzz and others added 8 commits October 20, 2025 14:08
Closes #19143

Add submission_count field to track the number of times a flow run
was submitted (entered Pending state), separate from run_count which
tracks executions (Running state).

This enables automations to retry flow runs that crash before reaching
the Running state, addressing a pain point for users like Humana who
need to retry flows that fail during submission.

<details>
<summary>Changes</summary>

- Add `submission_count` field to FlowRun and ORMFlowRun models
- Add `IncrementFlowRunSubmissionCount` orchestration policy that increments
  the count when entering Pending state
- Expose `prefect.submission-count` in flow run state change events
- Add database migrations for SQLite and PostgreSQL
- Add tests including specific case for submission without running

</details>

**Future work**: While this PR adds tracking, automatic retry logic for
crashed submissions could be added via orchestration rules or empirical
policy (see Slack discussion with @alex).

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>
- Add submission_count to FlowRun in server/schemas/core.py (was missing)
- Add comprehensive documentation on using submission_count with automations
- Document the retry pattern for submission failures
- Include examples and best practices
- Fix FlowRunSort.ID_DESC instead of non-existent CREATED_DESC
- Fix timedelta import and usage in exponential backoff example
- Add new doc to Automations section in docs.json navigation
The Automation class from prefect.automations has an optional id field that defaults to None, allowing .create() to work properly. The prefect.events.schemas.automations.Automation requires an id.
.serve() is a method on flow objects, not imported from prefect.deployments
Fixes TypeScript compilation errors where submission_count was missing from mock FlowRun objects
Remove incorrect example that would actually run the flow (run_count > 0).
Submission failures happen during infrastructure setup, not flow execution.
@zzstoatzz zzstoatzz force-pushed the add-submission-count-19143 branch from f3d25a8 to 7d525f5 Compare October 20, 2025 19:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

docs enhancement An improvement of an existing feature migration

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add submission-count field to flow run and expose in state change events

2 participants