Skip to content

fix: pause Instructor callbacks when agent hooks are disabled - #327

Merged
Eigenwise merged 1 commit into
Eigenwise:mainfrom
LJK-ikun:fix/instructor-hook-lifecycle
Oct 24, 2026
Merged

Eigenwise merged 1 commit into
Eigenwise:mainfrom
LJK-ikun:fix/instructor-hook-lifecycle

Conversation

@LJK-ikun

Copy link
Copy Markdown
Contributor

AtomicAgent.disable_hooks() sets hooks_enabled to false, but callbacks registered on the Instructor client still run for subsequent completions. This also affects hooks registered while the agent is disabled. Detach this agent's callbacks while disabled and restore its remaining registrations on enable, with repeated enable/disable calls remaining idempotent.

The regression tests use the real Instructor hook dispatcher and cover pause/resume, registration while disabled, removal/clearing while disabled, and preservation of callbacks registered directly on the client. A separate offline reproduction also exercised AtomicAgent.run() through real Instructor/OpenAI clients and an HTTPX mock transport: two requests invoked the callback twice before the fix and once after it.

Validation on Windows, Python 3.13.9, upstream 2a26bbc039fe29f3cdcf79eabc087b12d3fb9399:

  • Unchanged runtime with the regression file: 2 failed, 5 passed.
  • python -m pytest atomic-agents/tests/agents -q: 103 passed, 3 skipped.
  • python -m pytest --cov=atomic_agents atomic-agents -q: 811 passed, 3 skipped, with 10 warnings (an unregistered integration marker and MCP transport deprecations).
  • python -m black --check atomic-agents atomic-assembler atomic-examples atomic-forge: 233 files unchanged.
  • python -m flake8 --extend-exclude=.venv atomic-agents atomic-assembler atomic-examples atomic-forge: passed.
  • CI-pinned Pyright 1.1.414 on atomic-agents/tests/agents/test_config_defaults_typing.py, with the task environment's Python selected explicitly: 0 errors, 0 warnings, 0 informations. It also printed that the checkout has no .venv directory; the test environment lives separately.
  • git diff --check: passed.

Dependencies were installed into an isolated environment using the declared runtime/test ranges; PYTHONPATH selected this checkout's source. Live provider calls, documentation builds, wheel-install tests, Linux/Python 3.12 checks and GitHub CI were not run locally. No manifest or lockfile changes.

AI assistance: Codex investigated, authored and locally validated this change under LJK-ikun's direction. Independent human review or testing is not asserted.

@Eigenwise Eigenwise left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Rechecked 26789a0. All seven native hook tests pass locally. Independent offline probes also checked real Instructor dispatch, shared-client callback ownership, and preservation of the observability hooks. Pause, resume, registration, removal, and clearing behave as intended. Exact-head CI is green.

@Eigenwise
Eigenwise merged commit 857e42b into Eigenwise:main Oct 24, 2026
3 checks passed
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.

2 participants