Conversation
…board readiness flake _generate_pydantic_schemas(), _generate_pydantic_output_schemas(), and _apply_pydantic_schemas() previously ran at module import time, causing heavy Pydantic type imports to race with the storyboard readiness probe and producing "Agent unreachable" failures across PRs #391, #405, #406, #407. Generation is now deferred to the first get_tools_for_handler() call (which fires during create_mcp_tools() at server construction, not at import time). _PYDANTIC_SCHEMAS and _PYDANTIC_OUTPUT_SCHEMAS start as empty dicts and are populated via .update() so external references stay valid. The _schemas_applied sentinel makes subsequent calls no-ops (~0ms overhead on the hot path). Import-time delta: ~4.5s of schema generation is moved from `import adcp.server` to the first `create_mcp_tools()` call. Tests updated: conftest.py gains a session-scoped autouse fixture that triggers lazy init before any test reads ADCP_TOOL_DEFINITIONS schema fields; stale "at import time" references in docstrings and error messages are updated. Closes #412 https://claude.ai/code/session_01NnoQN3c6Wi5LY5DEUBp8W2
Addresses pre-PR review findings: test_spec_coverage.py assertion message still referenced 'at import time', and _ensure_pydantic_schemas_applied docstring understated the in-place mutation and misdirected to get_tools_for_handler instead of create_mcp_tools. https://claude.ai/code/session_01NnoQN3c6Wi5LY5DEUBp8W2
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.
Closes #412
Summary
_generate_pydantic_schemas(),_generate_pydantic_output_schemas(), and_apply_pydantic_schemas()previously ran at module import time, causing ~4.5s of Pydantic type-import and schema-generation work to race with the storyboard readiness probe. This produced "Agent unreachable" failures across PRs #391, #405, #406, #407.Schema generation is now deferred to the first
get_tools_for_handler()call, which fires duringcreate_mcp_tools()at server construction — after the process is ready but before any wire request arrives._PYDANTIC_SCHEMASand_PYDANTIC_OUTPUT_SCHEMASstart as empty{}dicts and are populated via.update()so any external references (test files importing those symbols) stay valid. A_schemas_appliedsentinel makes subsequent calls no-ops (~0ms on the hot path).What tested
pytest tests/test_mcp_schema_drift.py tests/test_tools_list_output_schema.py tests/test_spec_coverage.py tests/test_server_dx.py— 78 passedpytest tests/(excluding integration/conformance) — 2816 passed, 17 skipped, 1 xfailedmypy src/adcp/— no issues (749 source files)ruff check src/— all checks passedimport adcp.serveronto firstcreate_mcp_tools()callTest infrastructure change
tests/conftest.pygains ascope="session"autouse fixture that calls_ensure_pydantic_schemas_applied()before any test body runs. This ensures tests that import_PYDANTIC_SCHEMASor readADCP_TOOL_DEFINITIONS["inputSchema"]/["outputSchema"]directly continue to see the Pydantic-generated schemas rather than the hand-crafted stubs.Nits (not fixed — noted for awareness)
_schemas_appliedhas no type annotation (mypy infersboolcorrectly from the global rebinding)logger.warningif generation raises — exception propagates tocreate_mcp_tools()caller, same as old import-time crash behavior; per-tool failures still producelogger.debugas beforePre-PR review
get_tools_for_handleris correct; schemas are applied before_register_handler_toolsreadsoutputSchemafrom returned dicts;.update()mutation is safe; no blockerstest_spec_coverage.pyassertion message; fixed in follow-up commit); 3 nits noted aboveSession: https://claude.ai/code/session_01NnoQN3c6Wi5LY5DEUBp8W2
Generated by Claude Code