Skip to content

[codex] address bugbash P1/P2 findings#65

Merged
lbliii merged 2 commits intomainfrom
codex/address-bugbash-p1-p2
May 3, 2026
Merged

[codex] address bugbash P1/P2 findings#65
lbliii merged 2 commits intomainfrom
codex/address-bugbash-p1-p2

Conversation

@lbliii
Copy link
Copy Markdown
Owner

@lbliii lbliii commented May 3, 2026

Summary

Addresses the project-wide bugbash P1/P2 findings across CLI dispatch, MCP/JSON-RPC transport, gateway child process handling, app/state concurrency, schema generation, forms/flows, llms.txt, and docs.

What changed

  • Inject Context consistently for CLI.call, CLI.call_raw, and MCP tools/call.
  • Harden JSON-RPC stdin loops for parse errors, non-object requests, notifications, and unknown methods.
  • Make gateway child calls skip interleaved progress notifications until the matching response id arrives.
  • Avoid resize re-entry into Store.dispatch, serialize listeners, and make shutdown cancel blocked root sagas.
  • Fix schema/CLI drift for required optional annotations, required bool flags, typed Literal schemas, and llms.txt hyphenated flags.
  • Fix flow propagation of cmds/view state and form select, Shift+Tab, and validator contract behavior.
  • Update affected docs, icons, snippets, and add a changelog fragment.

Root cause

Several shared contracts had drifted by surface: CLI invocation, programmatic calls, MCP dispatch, schema emission, and docs examples were each exercising slightly different assumptions. Runtime concurrency also had direct signal/listener paths that could re-enter or overlap terminal rendering under free-threading.

Validation

  • make lint passed
  • make ty passed with existing warnings in pipeline.py and callable __qualname__ handling in schema.py
  • make test-cov passed: 1492 passed, 1 skipped, coverage 81.82%, PYTHON_GIL=0
  • make docs-test passed
  • uv run bengal build --environment production --no-incremental --clean-output --strict --full-output --log-file /tmp/milo-bengal-build.log exits 0; Bengal still reports generated fragment-link health warnings for step anchors

Steward Notes

Consulted root constitution and affected steward domains: CLI dispatch, MCP/gateway/JSON-RPC, schema, app/state runtime, forms/flows, docs/scaffold verification.

Decisions:

  • Kept schema as the single source of truth and fixed inference rather than adding validation/model layers.
  • Kept protocol parsing sans-I/O except at JSON-RPC loop boundaries.
  • Used queue/thread handoff for resize dispatch instead of dispatching from signal/poll callbacks.
  • Preserved public docs card-link source-path invariants enforced by repo tests.

Risks:

  • Store shutdown now prioritizes non-hanging teardown by cancelling root saga contexts and waking Take waiters.
  • Child-process gateway still serializes calls per child; this fix handles interleaved notifications but does not introduce concurrent in-flight calls per child.

Follow-up:

  • Bengal health appears to validate generated fragment links for step anchors differently from the generated page anchors; repo docs gates pass, but the site generator warning may deserve a separate Bengal/config investigation.

@github-actions
Copy link
Copy Markdown

github-actions Bot commented May 3, 2026

Coverage Report

88.1% overall coverage

File Coverage
src/milo/\_\_init\_\_.py 100.0%
src/milo/\_cells.py 85.9%
src/milo/\_child.py 91.8%
src/milo/\_cli\_help.py 90.5%
src/milo/\_command\_defs.py 99.2%
src/milo/\_compat.py 63.3%
src/milo/\_errors.py 92.8%
src/milo/\_jsonrpc.py 81.4%
src/milo/\_mcp\_router.py 100.0%
src/milo/\_protocols.py 100.0%
src/milo/\_scaffold/\_\_init\_\_.py 100.0%
src/milo/\_types.py 100.0%
src/milo/app.py 58.9%
src/milo/cli.py 87.3%
src/milo/commands.py 89.3%
src/milo/completions.py 96.0%
src/milo/components\_cli.py 88.1%
src/milo/config.py 87.3%
src/milo/context.py 86.6%
src/milo/dev.py 91.9%
src/milo/doctor.py 89.9%
src/milo/flow.py 96.5%
src/milo/form.py 91.7%
src/milo/gateway.py 68.9%
src/milo/groups.py 93.5%
src/milo/help.py 100.0%
src/milo/input/\_\_init\_\_.py 100.0%
src/milo/input/\_platform.py 77.8%
src/milo/input/\_reader.py 96.2%
src/milo/input/\_sequences.py 100.0%
src/milo/live.py 0.0%
src/milo/llms.py 78.8%
src/milo/mcp.py 88.9%
src/milo/middleware.py 100.0%
src/milo/observability.py 100.0%
src/milo/output.py 90.5%
src/milo/pipeline.py 90.1%
src/milo/plugins.py 100.0%
src/milo/reducers.py 100.0%
src/milo/registry.py 89.1%
src/milo/schema.py 92.7%
src/milo/state.py 91.7%
src/milo/streaming.py 100.0%
src/milo/templates/\_\_init\_\_.py 100.0%
src/milo/testing/\_\_init\_\_.py 100.0%
src/milo/testing/\_mcp.py 100.0%
src/milo/testing/\_record.py 86.7%
src/milo/testing/\_replay.py 87.1%
src/milo/testing/\_snapshot.py 100.0%
src/milo/theme.py 100.0%
src/milo/verify.py 84.8%
src/milo/version\_check.py 60.6%

@lbliii lbliii marked this pull request as ready for review May 3, 2026 18:42
Copilot AI review requested due to automatic review settings May 3, 2026 18:42
@lbliii lbliii merged commit 5f942a9 into main May 3, 2026
7 checks passed
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Addresses project-wide bugbash P1/P2 contract and runtime issues across Milo’s CLI/MCP/JSON-RPC surfaces, gateway child transport handling, state/saga concurrency behavior, schema generation parity, forms/flows behavior, llms.txt output, and docs/snippet validation.

Changes:

  • Unify and harden dispatch/transport behavior (Context injection parity; stricter JSON-RPC request parsing; correct method-not-found handling; gateway child progress interleaving handling).
  • Improve state/runtime concurrency and teardown (serialized listeners, safer shutdown/cancellation semantics, unblock Take, All behavior under constrained workers).
  • Align schema + docs outputs (Literal schemas with types, required-ness rules, hyphenated llms.txt flags, docs snippet scanning improvements, and docs updates).

Reviewed changes

Copilot reviewed 62 out of 62 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
tests/test_state.py Adds concurrency/shutdown/all-effect tests for Store/sagas.
tests/test_schema_v2.py Updates Literal schema expectations to include type.
tests/test_mcp_transport.py New transport-level JSON-RPC behavior tests (invalid request, unknown method, notification).
tests/test_mcp_handler.py Ensures MCP handler tool-cache invalidation when groups/commands change.
tests/test_form.py Updates select default semantics + adds Shift+Tab and validator contract tests.
tests/test_flow.py Tests propagation of cmds/view from screen reducers in flows.
tests/test_docs_snippets.py Adds coverage for missing-path reporting and indented tagged fences.
tests/test_commands_core.py Adds powershell completion mode test coverage.
tests/test_command_contract.py Expands contract tests for Context injection, required bools, Literal CLI/MCP parity, llms.txt flag naming.
tests/test_child.py Verifies child transport skips interleaved progress notifications until matching response id.
tests/test_app.py Adds renderer truncation test around ANSI + terminal width handling.
tests/test_ai_native.py Updates required-ness expectation and llms.txt flag formatting assertions.
src/milo/state.py Serializes listeners, tracks/cancels root saga contexts on shutdown, unblocks Take waiters, adjusts Race/All execution strategy.
src/milo/schema.py Adjusts required-ness rules and improves Literal schema emission with JSON types.
src/milo/mcp.py Uses shared JSON-RPC parsing and maps method-not-found to -32601; suppresses notification responses.
src/milo/llms.py Formats llms.txt parameters/examples using hyphenated CLI flag names.
src/milo/groups.py Adds change propagation hook to invalidate CLI discovery caches on group mutations.
src/milo/gateway.py Uses shared JSON-RPC parsing; correct notification behavior; maps method-not-found to -32601.
src/milo/form.py Select field initialization uses choice values; Shift+Tab navigation; validator contract normalization helper.
src/milo/flow.py Propagates cmds and view through flow reducers alongside sagas/Quit.
src/milo/commands.py Centralizes command version bumping; invalidates caches on group changes; adds powershell completions; injects Context in call/call_raw.
src/milo/app.py Moves resize dispatch to a queue/thread; ensures store shutdown on non-TTY; truncates lines to terminal width via cell-width helper.
src/milo/_mcp_router.py Introduces MethodNotFoundError for clearer routing error classification.
src/milo/_jsonrpc.py Adds _parse_request helper for robust JSON-RPC line validation and error reporting.
src/milo/_child.py Reads until matching response id, skipping interleaved notifications; improves initialization consumption.
site/content/docs/reference/types.md Updates page icon metadata.
site/content/docs/reference/schema.md Updates schema docs for required/optional unions and typed Literal enums; icon tweak.
site/content/docs/reference/dispatch.md Updates page icon metadata.
site/content/docs/reference/_index.md Updates page icon metadata.
site/content/docs/quality/testing.md Updates page icon metadata.
site/content/docs/quality/_index.md Updates icons and card links (trailing slashes).
site/content/docs/get-started/quickstart.md Updates cards’ icons and links (trailing slashes).
site/content/docs/get-started/migrate-existing-cli/from-typer.md Updates page icon metadata.
site/content/docs/get-started/migrate-existing-cli/from-fire.md Updates page icon metadata.
site/content/docs/get-started/migrate-existing-cli/from-click.md Updates page icon metadata.
site/content/docs/get-started/migrate-existing-cli/_index.md Updates page icon metadata.
site/content/docs/get-started/_index.md Updates icons and card links (trailing slashes).
site/content/docs/examples/_index.md Updates icons for examples section.
site/content/docs/build-clis/output.md Updates page icon metadata.
site/content/docs/build-clis/mcp.md Updates page icon metadata.
site/content/docs/build-clis/groups.md Updates page icon metadata.
site/content/docs/build-clis/context.md Updates example to use ctx.dry_run and correct flag placement; icon tweak.
site/content/docs/build-clis/_index.md Updates icons and card links (trailing slashes).
site/content/docs/build-apps/templates.md Updates page icon metadata.
site/content/docs/build-apps/sagas.md Updates page icon metadata and tab icon.
site/content/docs/build-apps/plugins.md Updates page icon metadata.
site/content/docs/build-apps/live.md Updates page icon metadata.
site/content/docs/build-apps/input.md Updates page icon metadata.
site/content/docs/build-apps/forms.md Updates page icon and recommends make_form_reducer() usage in docs.
site/content/docs/build-apps/flows.md Updates page icon metadata.
site/content/docs/build-apps/_index.md Updates icons and card links (trailing slashes).
site/content/docs/applied-tutorials/build-a-wizard.md Updates example to use make_form_reducer() instead of manual form_reducer wrapping.
site/content/docs/applied-tutorials/build-a-counter.md Fixes category typo and updates icons/links.
site/content/docs/applied-tutorials/_index.md Updates icons and card links (trailing slashes).
site/content/docs/about/when-to-use.md Updates page icon metadata.
site/content/docs/about/concepts/return-values.md Updates page icon metadata.
site/content/docs/about/concepts/app-lifecycle.md Updates page icon metadata.
site/content/docs/about/concepts/_index.md Updates page icon metadata.
site/content/docs/_index.md Updates icons across top-level docs cards.
scripts/check_docs_snippets.py Allows indented fences and reports missing paths as errors.
docs/agent-quickstart.md Clarifies structured vs text MCP content behavior in quickstart rules.
changelog.d/bugbash-contracts.fixed.md Adds changelog fragment for bugbash fixes.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/milo/app.py
Comment on lines 91 to 95
# Write each line, clearing to end of line
for line in lines:
# Truncate to terminal width to avoid wrapping artifacts
sys.stdout.write(line[:cols])
sys.stdout.write(cell_truncate(line, cols, marker=""))
sys.stdout.write("\033[K\n") # Clear to end of line
Comment thread src/milo/state.py
Comment on lines 771 to 777
self._run_saga_capturing(saga, ctx, rb, eb, done)
with condition:
condition.notify_all()

self._executor.submit(_notify_wrapper)
threading.Thread(target=_notify_wrapper, daemon=True).start()

# Wait for first completion or parent cancellation
Comment thread src/milo/state.py
Comment on lines 831 to 837
self._run_saga_capturing(saga, ctx, rb, eb, done)
with condition:
condition.notify_all()

self._executor.submit(_notify_wrapper)
threading.Thread(target=_notify_wrapper, daemon=True).start()

# Wait for all to complete or first failure
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