Skip to content

fix(runtime): drain autoscaler example phases - #1036

Merged
Coldwings merged 1 commit into
mainfrom
fix/autoscaler-example-lifetime
Aug 13, 2026
Merged

fix(runtime): drain autoscaler example phases#1036
Coldwings merged 1 commit into
mainfrom
fix/autoscaler-example-lifetime

Conversation

@Coldwings

Copy link
Copy Markdown
Owner

Description

Make each autoscaler example load phase own and drain its submitted work before
the phase-local completion counter is released. This removes the queued-task
use-after-scope reported in #1022 and ensures the low-load phase starts only
after the high-load phases are empty.

The default workload now completes in a few seconds, while a dedicated
--smoke mode provides a short, timeout-bounded CI termination regression.

Type of Change

  • Bug fix (non-breaking change that fixes an issue)
  • New feature (non-breaking change that adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Performance improvement (optimization that improves speed/memory usage)
  • Documentation (changes to documentation, comments, or examples)
  • Refactoring (code changes that neither fix bugs nor add features)
  • Tests (adding or modifying tests)
  • Build/CI (changes to build system, CI configuration, or dependencies)

Related Issues

Closes #1022

Changes Made

Core Changes

  • Retain one join_handle per submitted task and wait for frame destruction
    before a phase returns; the exceptional submission path drains already
    accepted tasks as well.
  • Verify each phase reached its exact completion count and zero pending work
    before entering the next phase.
  • Reduce the default task duration/count to a roughly four-second demo and add
    a sub-second --smoke profile.
  • Run the smoke profile under a 15-second hard timeout in each Release CI
    matrix job.

API Changes

No library API or contract changes. The example adds the optional --smoke
command-line flag.

Testing

Unit Tests

  • Added a process-level smoke regression for successful example termination
  • Updated existing unit tests if needed
  • Relevant checks pass locally

Integration Tests

  • Built and ran the updated example out of source
  • Ran the default autoscaling demonstration end to end

Sanitizer Testing

  • Tested the example with ASAN and leak detection
  • Tested with TSAN
  • No ASAN or LeakSanitizer warnings or errors

Test Results

Release configure/build (TLS, HTTP, HTTP2, RDMA, TCP benchmarks disabled):
  cmake --build <release-build> --target autoscaler_example --parallel 2
  passed with developer warnings and warnings-as-errors

autoscaler_example --smoke:
  30/30 Release runs exited successfully within the 15-second CI timeout
  both phases reported Pending: 0 and their exact completion count before low load

autoscaler_example (default):
  exited 0 in 4.11 seconds
  demonstrated worker scaling from 2 to 8 and back to 2

ASAN_OPTIONS=detect_leaks=1:abort_on_error=1 autoscaler_example --smoke
ASAN_OPTIONS=detect_leaks=1:abort_on_error=1 autoscaler_example
  both exited successfully with no sanitizer diagnostics

CI workflow YAML parsed successfully.

Checklist

Code Quality

  • My code follows the project code style
  • I have added comments only where the lifetime constraint is non-obvious
  • I have removed debug code and temporary instrumentation
  • The changed example builds with warnings-as-errors

Documentation

  • I updated the examples wiki and changelog
  • The smoke invocation and phase-lifetime behavior are documented
  • No API reference update is required

Testing

  • The smoke regression proves successful process termination
  • Default and smoke modes pass locally
  • ASAN coverage passes locally; the repository CI will run its normal TSAN matrix

Compatibility

  • The change is backward compatible
  • No public library behavior changes
  • CHANGELOG.md is updated

Performance

  • The default example runtime remains practical and the CI profile is sub-second
  • No benchmark is required for this example-lifetime fix

Reviewer Guidance

Areas requiring special attention:

  • Verify that every exit after task admission waits for all retained task frames
    before the phase-local atomic is destroyed.
  • Verify that the low-load phase cannot begin until both load phases report an
    exact completion count and zero pending tasks.
  • Check that the smoke settings exercise queued work while remaining independent
    of exact timing or worker-count assertions on shared CI runners.

Copilot AI balanced review requested due to automatic review settings August 13, 2026 04:02

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Fixes the autoscaler example’s queued-task lifetime issue by draining each load phase before releasing captured state.

Changes:

  • Retains join handles and verifies each phase fully drains.
  • Adds shorter default and --smoke workloads.
  • Adds CI smoke coverage and updates documentation.

Reviewed changes

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

File Description
examples/autoscaler_example.cpp Implements safe phase draining and smoke mode.
.github/workflows/ci.yml Runs the smoke example with a timeout.
wiki/Examples.md Documents phase lifetime and smoke usage.
CHANGELOG.md Records the autoscaler example fix.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@Coldwings
Coldwings merged commit 1d77968 into main Aug 13, 2026
11 checks passed
@Coldwings
Coldwings deleted the fix/autoscaler-example-lifetime branch August 13, 2026 04:24
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.

[Bug] Autoscaler example lets queued tasks outlive phase counters

2 participants