Repository navigation
refactor(AIC-3568): clear Agent Skills state through a core shutdown hook - #173
Merged
Merged
Conversation
…hook Core lifecycle.py imported the skills module and called skills._clear_state() from shutdown(), which is core hooking into experimental code (TESTING.md §0.3). skills_core now registers clear_state with a new generic shutdown_hooks module when it loads, and shutdown() runs the registered hooks, as the TypeScript SDK does. Importing the package root and calling shutdown() no longer loads any skills or evaluations module; a subprocess test pins that. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
XieX
approved these changes
Oct 14, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Why
TESTING.md §0.3 (launchdarkly/ai-sdks-monorepo#55, merged) says hooks go one way: experimental code may hook into core, but core never imports, names or calls experimental code. Python broke that in one place. Core
lifecycle.pyimported the skills module and calledskills._clear_state()fromshutdown()and_reset_for_testing(). The spec marks this as [shutdown hook: Python pending].What
Same shape as the TypeScript SDK (
shutdown-hooks.ts, registered fromskills-core.ts):shutdown_hooks.py.register_shutdown_hook(name, hook)andrun_shutdown_hooks(). It names no feature. A hook that raises is logged and the rest still run. The test reset passesraise_errors=True, so a failed reset still fails the test, as before.skills_core.pyregistersclear_statewhen it loads, under the name "Agent Skills". The warning text is unchanged:Could not clear the Agent Skills state, still on thelaunchdarkly_ai_server.lifecyclelogger.lifecycle.pyno longer importsskills.shutdown()and_reset_for_testing()run the hooks. Theshutdown()docstring no longer names the feature.agents.mdsays where the hook is registered.No behaviour change:
test_shutdown_clears_the_storestill passes unchanged.Tests
test_core_does_not_import_experimental_code: a subprocess imports the package root, callsshutdown(), and asserts nolaunchdarkly_ai_server.skills*,.evaluations*or.experimental*module was loaded. Withfrom . import skillsput back inlifecycle.py, it fails ('launchdarkly_ai_server.skills_core' == '').uv run pytest: 2462 passed, 12 skipped.ruff check,ruff format --checkandmypy packages/*/srcare clean.Follow-up
Once this merges, remove the [shutdown hook: Python pending] note from TESTING.md §0.3 in the monorepo.
🤖 Generated with Claude Code
Note
Overview
Refactors how experimental state is cleared on shutdown so core lifecycle no longer imports Agent Skills. Previously
lifecycle.pyimportedskillsand calledskills._clear_state()directly, which violated TESTING.md §0.3 (core must not import experimental code).New
shutdown_hooksmodule exposesregister_shutdown_hookandrun_shutdown_hooks. Experimental modules register cleanup at import time;shutdown()and_reset_for_testing()invoke all hooks. Hook failures are logged (with the hook’s registered name) and do not abort shutdown; test reset usesraise_errors=Trueto preserve strict cleanup behavior.skills_coreregistersclear_stateas the"Agent Skills"hook on load, so store/emitter teardown still happens when skills code has been imported, without lifecycle naming skills.Tests add a subprocess check that
shutdown()alone does not loadskills*,evaluations*, orexperimental*modules, and broaden the failure-isolation test to assert remaining hooks still run after one hook raises.Reviewed by Cursor Bugbot for commit 700a089. Bugbot is set up for automated code reviews on this repo. Configure here.