Skip to content

feat(sdk): add shutdown() and ashutdown() lifecycle API#70

Merged
namrataghadi-galileo merged 3 commits intomainfrom
abhi/sdk-lifecycle-shutdown
Mar 9, 2026
Merged

feat(sdk): add shutdown() and ashutdown() lifecycle API#70
namrataghadi-galileo merged 3 commits intomainfrom
abhi/sdk-lifecycle-shutdown

Conversation

@abhinav-galileo
Copy link
Collaborator

@abhinav-galileo abhinav-galileo commented Mar 6, 2026

Summary

Adds agent_control.shutdown() (sync) and agent_control.ashutdown() (async) for deterministic SDK teardown.

  • Flushes all pending observability events
  • Stops the policy refresh background thread and prevents in-flight refreshes from publishing after shutdown
  • Resets global state
  • Idempotent and safe to call without prior init()

This gives users a single, documented shutdown path instead of relying on best-effort atexit behavior - which is fragile for short-lived scripts, CLI tools, and demos.

Implementation details

  • Extracted _fetch_controls_async() (fetch-only, no publish) so the refresh worker can check the stop event between fetch and publish, preventing zombie state writes after shutdown.
  • Added sync_shutdown_observability() as a public API in the observability module; shutdown() uses it instead of reaching into _batcher internals.
  • Extracted _reset_state() helper to deduplicate state clearing across both shutdown paths.

Shortcut: sc-57753

Test plan

  • make sdk-lint
  • make sdk-typecheck
  • make sdk-test (all passed, pre-existing integration failures only)
  • 10 new tests in test_shutdown.py covering sync/async paths, idempotency, no-init safety, and zombie refresh race regression
  • Updated test_policy_refresh_loop.py to match new _fetch_controls_async call path (14 tests pass)

@codecov
Copy link

codecov bot commented Mar 6, 2026

Codecov Report

❌ Patch coverage is 93.42105% with 5 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
sdks/python/src/agent_control/__init__.py 92.95% 5 Missing ⚠️

📢 Thoughts on this report? Let us know!

…internals

- Split _fetch_controls_async() from refresh_controls_async() so the
  background worker can check stop_event after fetch, before publishing.
  This prevents an in-flight refresh from writing controls back into
  global state after shutdown() has logically completed.
- Add sync_shutdown_observability() as a public API in the observability
  module; shutdown() now uses it instead of reaching into _batcher.
- Extract _reset_state() helper to deduplicate state clearing in both
  shutdown() and ashutdown().
- Fix unused import (F401) and import ordering (I001) in test_shutdown.py.
- Update test_policy_refresh_loop.py to patch _fetch_controls_async.
- Add race regression tests for both sync and async shutdown paths.
Copy link
Contributor

@lan17 lan17 left a comment

Choose a reason for hiding this comment

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

The shutdown API is close, but there are still two lifecycle regressions in the refresh path that should be fixed before merge.

Copy link
Contributor

@lan17 lan17 left a comment

Choose a reason for hiding this comment

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

Re-reviewed the updated lifecycle changes. The prior refresh/shutdown concerns appear addressed, and the current SDK tests pass locally.

@namrataghadi-galileo namrataghadi-galileo merged commit 9e29d86 into main Mar 9, 2026
7 checks passed
@namrataghadi-galileo namrataghadi-galileo deleted the abhi/sdk-lifecycle-shutdown branch March 9, 2026 23:55
galileo-automation pushed a commit that referenced this pull request Mar 11, 2026
## [1.1.0](ts-sdk-v1.0.1...ts-sdk-v1.1.0) (2026-03-11)

### Features

* **examples:** add Google ADK Agent Control examples ([#69](#69)) ([4b83542](4b83542))
* **infra:** publish UI image and add compose UI service ([#57](#57)) ([207c1af](207c1af))
* **sdk:** 57143 strands extra ([#59](#59)) ([97f2518](97f2518))
* **sdk:** add shutdown() and ashutdown() lifecycle API ([#70](#70)) ([9e29d86](9e29d86))
* **sdk:** migrate strands integration to be a plugin ([#74](#74)) ([897ece3](897ece3))
* **server:** enforce admin-only control-plane mutations ([#62](#62)) ([579407f](579407f)), closes [#61](#61)
* **ui:** serve exported Agent Control UI from the FastAPI server ([#71](#71)) ([c140198](c140198))

### Bug Fixes

* **docs:** add centered logo, header, and badges to README ([#92](#92)) ([39c3cbf](39c3cbf))
* **docs:** Test all examples ([#16](#16)) ([39e95c2](39e95c2))
* **evaluators:** migrate sqlglot rs extra to sqlglot c ([#86](#86)) ([5e3e48c](5e3e48c))
* **infra:** fix docker compose to make ui work ([#82](#82)) ([5edbb6b](5edbb6b))
* **infra:** Remove UI service from docker-compose.yml ([#91](#91)) ([330ef55](330ef55))
* **sdk): Revert "fix(sdk:** bundle evaluators in sdk wheel" ([#90](#90)) ([b516ea6](b516ea6)), closes [#89](#89)
* **sdk:** bundle evaluators in sdk wheel ([#89](#89)) ([ea5889a](ea5889a))
* **sdk:** fix observability events not reaching the server ([#63](#63)) ([70016db](70016db))
* **ui:** name update being saved now ([#87](#87)) ([919672d](919672d))
* **ui:** Step name not getting saved ([#68](#68)) ([13abef9](13abef9))
@galileo-automation
Copy link
Collaborator

🎉 This PR is included in version 1.1.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants