Repository navigation
Add the route and subcommand extension points behind serve.py and cli.py (split § 2.4, PR 1 of 4: scaffolding, zero behavior change) - #736
Conversation
….py (split § 2.4, PR 1 of 4: scaffolding, zero behavior change)
tasks.md § 2.4 says serve.py splits BY FUNCTION "behind an app-server route
extension point", and cli.py "behind a subcommand extension point", because
"without the extension point the integration layer forks the server, which is a
fork rather than a profile and breaks the same rule domain-descendant-boundary
applies one level down". This lands the two points and NOTHING ELSE: no route
and no subcommand is extracted here, so the risk surface is one clause in each
dispatch and one keyword-only argument on each builder.
Two neutral modules at the top of scripts/, on the precedent of
output_boundary.py (§ 2.1) and corpus_adapter.py (§ 2.2) and for the same three
reasons: both sides of the carve consume them, they travel with the carve to a
repository where the checker package does not exist, and they therefore import
neither package — stdlib and typing only, asserted by an AST scan over
tests/import_scan.py rather than left as a property of the current body.
* route_extension.RouteExtension — one member, routes() -> tuple of frozen
RouteBinding(method, pattern, is_prefix, handler). `handler` is the NAME of
a method, dispatched getattr(self, name) against the LIVE DashboardHandler.
That is the whole safety argument and the analogue of corpus-adapter-seam
requirement 4's "no privileged route": a contributed route reaches the
request through the same object every core route does, so it meets the same
central gating by construction. A test asks a contributed write route and a
core gate verb the same question off-loopback and compares the answers.
* subcommand_extension.SubcommandExtension — one member, register(subparsers),
handed the same argparse action every core subcommand is added through, so
main()'s args.func(args) dispatches a contributed verb by the identical line.
Wiring: build_server gains route_extensions=() (collected once at wiring,
bound to the handler subclass like every other injected attribute, and refused
at BUILD time if a binding names a handler the server does not have);
build_parser and main gain subcommand_extensions=(). Core arms are consulted
FIRST in both dispatches and the fallback LAST, so an empty tuple is today's
behaviour exactly and a contributed route can never shadow a core one.
Golden parity, both derived from origin/main before the wiring was written:
the help text of all 31 entry points at COLUMNS=100, and the ordered core
dispatch arms of _route/do_POST with the handlers each reaches. Both unchanged.
The intent routes land exactly as PR #718 left them — untouched.
Refs #656
Lane: openxfactory-4-opendox-extraction
Co-Authored-By: Claude Fable 5.1 <[email protected]>
Claude-Session: https://claude.ai/code/session_01MDVAo41VtZqJQpuawwJeYC
There was a problem hiding this comment.
Hi @brettheap! 👋
Your private repo does not have access to Sourcery.
Please upgrade to continue using Sourcery ✨
There was a problem hiding this comment.
🟡 Changes recommended
Route handler wiring currently validates only handler existence (not call shape), so some malformed bindings can let the server start and then fail at request time with a TypeError.
Once you've addressed the issues Copilot identified, you can request another Copilot review.
Pull request overview
Introduces neutral, stdlib-only extension-point modules to let downstream layers contribute HTTP routes and CLI subcommands without forking serve.py/cli.py, while aiming to preserve current behavior via parity tests and goldens.
Changes:
- Add
scripts/route_extension.pyand wire contributed route bindings intoDashboardHandlerdispatch (_route/do_POST) andbuild_server(...). - Add
scripts/subcommand_extension.pyand wire contributed subcommands intobuild_parser(...)/main(...). - Add tests + a CLI help-text golden to assert neutrality/closure and “zero behavior change” parity.
File summaries
| File | Description |
|---|---|
| tests/ideation-dashboard/test_subcommand_extension.py | New tests for subcommand extension neutrality/closure and parser/dispatch behavior. |
| tests/ideation-dashboard/test_route_extension.py | New integration tests exercising contributed routes over a real server instance. |
| tests/ideation-dashboard/test_extension_point_parity.py | New AST+golden tests pinning core dispatch-table order and CLI help output. |
| tests/ideation-dashboard/fixtures/cli-help-tree.golden.txt | Golden fixture for byte-identical CLI help-tree output. |
| scripts/subcommand_extension.py | New neutral SubcommandExtension Protocol + wiring helper. |
| scripts/route_extension.py | New neutral RouteExtension Protocol, RouteBinding, and binding collection/matching utilities. |
| scripts/ideation_dashboard/serve.py | Wires route extensions into server build and dispatch, with empty-default behavior. |
| scripts/ideation_dashboard/cli.py | Wires subcommand extensions into parser construction and main dispatch, with empty-default behavior. |
Review details
- Files reviewed: 8/8 changed files
- Comments generated: 1
- Review effort level: Lite
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
…string Three factual findings against scripts/route_extension.py, verified by V-a and (for F1) independently confirmed by the Copilot review thread and V-b: F1 (HIGH): resolve_handlers only checked hasattr(handler_holder, b.handler), not callability. A binding naming an existing non-callable attribute of DashboardHandler (e.g. "loopback", "capabilities", "route_bindings") passed build_server and only crashed the first live request that reached it with "TypeError: 'bool' object is not callable" — the exact failure the module's own "a route that cannot be served must not start" guarantee promises never happens. resolve_handlers now requires callable(getattr(handler_holder, b.handler, _UNRESOLVED)), with a distinct refusal clause naming the non-callable attribute separately from a genuinely missing one. Call-shape decision (the Copilot thread's second question, and V-b's one finding): resolve_handlers deliberately does NOT validate call shape (exact vs prefix, read vs write) via inspect.signature. Reliably telling a handler that is merely flexible about its arguments (*args, a defaulted parameter) from one that is genuinely the wrong shape needs signature introspection this module has no cheap way to perform correctly: the same handler name may resolve through the CLASS (self still explicit) or an INSTANCE (self already bound) — both accepted by design — and through a plain function, a staticmethod, a classmethod, or a decorated wrapper, each stripping a different set of leading parameters. A wrong-shape handler still fails loudly on its first request with an ordinary Python arity TypeError, rather than the silent-misroute or "starts but only crashes on this one path" defect the callability refusal exists to prevent, so the module's neutrality (stdlib only, no per-arm knowledge of the server it serves) is kept instead of growing a heavier validation framework for a narrower benefit. Documented in the docstring and explained on the review thread. F2 (LOW): collect_bindings's collision key was the literal (method, pattern, is_prefix), but a "GET" binding also answers a live HEAD request (RouteBinding.matches). A "GET" and a "HEAD" binding for the same (pattern, is_prefix) did not collide by key, yet both would answer the same HEAD request, leaving one silently unreachable. collect_bindings now also checks each binding against the collision key the OTHER method it overlaps with would claim, symmetric in either declaration order. F3 (LOW, wording): the module docstring claimed contributed routes meet central gating "by CONSTRUCTION". False: a contributed POST handler that skips its own self.loopback check executes off-loopback, exactly as a core write route that skipped it would (every core write route self-checks as its first statement). Softened to a reachability claim: the same primitives are reachable on the live handler, so a correctly written extension checks the same way a core route does — not an automatic-enforcement claim. Zero behaviour change for the default (empty) extension tuples: only scripts/route_extension.py and its own test file changed; the --help golden and pinned dispatch-arm tuples in test_extension_point_parity.py are untouched and still pass byte-identical. Tests: 58 -> 63 in the three targeted files (test_route_extension.py, test_subcommand_extension.py, test_extension_point_parity.py), all passing. Full tests/ideation-dashboard suite: 4956 passed, 31 skipped, 1 failed — the known environmental test_snapshot.py::test_find_validator_locates_pinned_checkout, unrelated to this change (it resolves a path against the pinned sibling checkout, which this detached worktree does not sit beside). Lane: openxfactory-4-opendox-extraction Co-Authored-By: Claude Fable 5.1 <[email protected]> Claude-Session: https://claude.ai/code/session_01CHAHvr9zFHRd4kWVnZLK9k
There was a problem hiding this comment.
🟢 Approval recommended
The extension-point wiring appears behavior-preserving and is backed by strong parity/behavioral tests; remaining feedback is limited to minor diagnostics clarity.
Review details
- Files reviewed: 8/8 changed files
- Comments generated: 1
- Review effort level: Lite
…ssage
Copilot review PRRT_kwDOTAvnrs6fwTVh, scripts/route_extension.py:296:
collect_bindings' collision refusal named the SLOT that matched
(claimed_key[0]) rather than each binding's own declared method, so a
GET/HEAD collision misreported itself as "two route bindings claim GET"
even where the second binding was actually declared HEAD, not GET.
Fix: `seen` now stores the full previous RouteBinding (not just its handler
name), and a new `_collision_message(previous, current)` builds the refusal
from each binding's own `.method`/`.pattern`: a same-method duplicate keeps
the original wording ("two route bindings claim GET '/x' ..."), and a
cross-method GET/HEAD collision now reads "GET '/x' and HEAD '/x' claim the
same GET/HEAD slot ...", naming both bindings correctly regardless of
declaration order.
Adjusted `test_a_get_and_a_head_binding_for_the_same_route_refuse_the_build`
(parametrized both orders) to assert the message names each binding beside
its own declared method, which fails on the old bug (a HEAD binding's own
method never appeared in the old message at all).
No other changes: only scripts/route_extension.py and its test file.
Tests: 63 in the three targeted files (test_route_extension.py,
test_subcommand_extension.py, test_extension_point_parity.py), all passing
(same count as before -- one existing test strengthened, none added). Full
tests/ideation-dashboard suite: 4956 passed, 31 skipped, 1 failed -- the
known environmental test_snapshot.py::test_find_validator_locates_pinned_checkout,
unrelated to this change.
Lane: openxfactory-4-opendox-extraction
Co-Authored-By: Claude Fable 5.1 <[email protected]>
Claude-Session: https://claude.ai/code/session_01CHAHvr9zFHRd4kWVnZLK9k
There was a problem hiding this comment.
🔵 Needs a closer look
The new extension-point helpers have a couple of wiring-time error-handling gaps (callability vs Protocol conformance and a misleading dispatch error message) that should be tightened before relying on these seams.
Review details
Suppressed comments (3)
Previously missed (2) — in code that hasn't changed since the last review.
scripts/route_extension.py:313
- In collect_bindings(), conformance is checked via isinstance(extension, RouteExtension), but the code then unconditionally calls extension.routes(). A runtime_checkable Protocol instance check only guarantees the attribute exists, not that it's callable (e.g., a
@propertynamed routes), so this can currently fail with a raw TypeError instead of a RouteBindingError (contradicting the “refused where it is wired” intent). Add an explicit callable() check and call via the resolved callable so wiring failures are consistently reported as RouteBindingError.
This issue also appears on line 383 of the same file.
scripts/subcommand_extension.py:101
- register_all() checks SubcommandExtension via isinstance(), then unconditionally calls extension.register(...). With runtime_checkable Protocols, isinstance() ensures the attribute exists but doesn’t necessarily guarantee it’s callable (e.g., a non-callable attribute or @Property), so this can currently raise a bare TypeError instead of SubcommandExtensionError. Consider resolving register via getattr + callable() and invoking that, so non-conforming extensions are refused with the intended wiring-time exception type.
scripts/route_extension.py:387
- The error text in resolve_handlers() says dispatch is
getattr(self, binding.handler)(), but contributed handlers are invoked in multiple call shapes (head_only / remainder / no-args). This can confuse debugging when a non-callable attribute is detected. Consider changing the message (and the unresolved list rendering) to avoid implying a zero-arg call, e.g. usegetattr(self, binding.handler)(...)or just refer to invoking the resolved attribute.
clauses.append(
"route bindings name attributes that exist but are not "
f"callable: {not_callable}. Dispatch is `getattr(self, "
"binding.handler)()` — a non-callable attribute would crash "
"the first live request that reaches it with `TypeError: "
- Files reviewed: 8/8 changed files
- Comments generated: 0 new
- Review effort level: Lite
Resolved a merge conflict in scripts/ideation_dashboard/cli.py: main's squash-merge of #736 independently reworded build_parser()'s docstring (diverging from this branch's own fix-round wording) while this branch had already split cmd_model_binding_* and _add_gate_subcommands (and its helpers) out of cli.py into cli_model_binding.py / cli_gate.py. Verified byte-for-byte that main brought zero functional change to either region (the model-binding functions and the gate helper functions matched the pre-split base exactly), so both conflict hunks resolved by keeping this branch's side, which already carries #736's docstring content as a strict superset (the shared "subcommand_extensions"/"registers LAST" paragraphs plus this branch's own IN-TREE PROFILE paragraph). Confirmed the resolved file is byte-identical to this branch's pre-merge cli.py. Lane: openxfactory-4-opendox-extraction Co-Authored-By: Claude Fable 5.1 <[email protected]> Claude-Session: https://claude.ai/code/session_019sa33gYhfLF1F1MkS7Xrd6
…742) split-opendox-two-layer-product § 2.4 PR-4 of 4: cli.py split by column behind the subcommand extension point — cli_gate.py (openXdox, 19 gate verbs + the gate subparser tree, registered through SubcommandExtension), cli_project.py and cli_model_binding.py (openDox, fixed core), profile_openxfactory.py naming the in-tree SUBCOMMAND_EXTENSIONS; the 31-entry --help golden byte-identical; the __main__ bootstrap re-dispatches to the package module and the columns resolve the core relative to their own package spelling, so script, -m and scripts.-prefixed imports all bind one module object (identity-tested); bypass-flag and HumanGate closed-world sweeps re-stated at landed strength over the whole CLI surface. Three ruling-(a) test repoints, disclosed. Three adversarial lenses over four fix rounds; final gating re-verify pass. The branch history carries #736 commits already landed as a83eb93; this squash is the authoritative diff. Landed on Brett Heap's word "merge 742 when green" (2026-09-07). Refs #656. Lane: openxfactory-4-opendox-extraction Co-Authored-By: Claude Fable 5.1 <[email protected]> Claude-Session: https://claude.ai/code/session_01UyynFBwGMQNeNU8D8qhQBW
…idence; record the § 2 carried items (#769) split-opendox-two-layer-product group-2 bookkeeping: tick § 2.1 (#724 e2b8f62), § 2.2/2.2a (#725 ea4e6ff), § 2.3 (#728 1a2ea82), § 2.4 (#736 a83eb93, #741 75467fe, #748 7f7ce75, #742 421b52d, #761 7992b87), § 2.6 (gate re-run on the branch: 6681 passed, the environmental snapshot test and the tolerated disposition artifact identical on main); § 2.5 stays open (Path A D-2). Records the twelve § 2 carried items for the § 3.1 carve manifest; repoints two doc_health sweep-record strings to doxbench_status_exemption. Landed under a Rule 6 window on Brett Heap's word "merge 769 when green" (2026-09-07). Refs #656. Lane: openxfactory-4-opendox-extraction Co-Authored-By: Claude Fable 5.1 <[email protected]> Claude-Session: https://claude.ai/code/session_01Q8CkMMAdcUZCqAUTgNjsPy
Lane: openxfactory-4-opendox-extraction (formerly openxfactory-opendox)
split-opendox-two-layer-product§ 2.4, PR 1 of 4: the extension points only, zero behaviour change. No route and no subcommand is extracted here.Why this shape
tasks.md§ 2.4 splitsserve.pyBY FUNCTION "behind an app-server route extension point", andcli.py"behind a subcommand extension point" — and says why in the same breath: "without the extension point the integration layer forks the server, which is a fork rather than a profile and breaks the same ruledomain-descendant-boundaryapplies one level down."Design § D2 states the target directly: openDox keeps the server, static and canvas routes, chat and model routes and
/capabilities; openXdox CONTRIBUTES snapshot,/sourceand projection routes "through an EXTENSION POINT openDox exposes", and "cli.pysplits the same way, with openXdox contributing subcommands." Design § D3's column table is what will travel through these points in PRs 2–4.The rule one level down is
domain-descendant-boundary's A descendant carries profile, never fork: a descendant "SHALL NOT carry a fork, an edited copy or a re-authoring of the neutral product's contracts, schemas, corpus or validator — pin and profile, NEVER fork", and "anything the profile cannot express SHALL be an UPSTREAM change in the product repository, released and re-pinned, rather than a local edit." A contributed route is the profile. A second copy of the dispatch is the fork. This PR is the machinery that makes the first possible.What landed
Two neutral modules at the top of
scripts/, on the precedentoutput_boundary.py(§ 2.1, #724) andcorpus_adapter.py(§ 2.2, #725) set, and for the identical three reasons: both sides of the carve consume them, they travel with the carve to a repository where the checker package does not exist, and they therefore import neither package — stdlib andtypingonly.Wiring, with empty-tuple defaults throughout:
serve.py:6494build_server(..., route_extensions: tuple = ())serve.py:6547route_bindings = route_extension.collect_bindings(route_extensions)— before a socket, a checkout read or a session bootstrapserve.py:6673"route_bindings": route_bindingson the bound handler subclass, beside every other injected attributeserve.py:6679route_extension.resolve_handlers(route_bindings, bound)— a route that cannot be served does not startserve.py:2056DashboardHandler.route_bindings: tuple = ()serve.py:5291-5310_route(), after the last core arm and before the static fallbackserve.py:5358-5374do_POST(), after the gate prefix and beforeERR_UNKNOWN_ACTIONcli.py:1917build_parser(*, subcommand_extensions: tuple = ())cli.py:1992subcommand_extension.register_all(subcommand_extensions, sub), after every core subparsercli.py:2452main(argv=None, *, subcommand_extensions: tuple = ())passes throughDesign decisions taken
handleris a NAME, dispatchedgetattr(self, name)against the LIVEDashboardHandler— never a callable the binding carries. This is the load-bearing constraint and the direct analogue ofcorpus-adapter-seamrequirement 4's no privileged route. A contributed route reaches the request through the same object every core route reaches it through, so it meetsself.loopback,self.capabilities,self.actor,_trusted_console_host()and_session_repository()by construction, not by each extension author remembering to.test_a_contributed_write_route_refuses_off_loopback_exactly_like_a_core_oneasks a contributed route and a core gate verb the same question off-loopback and asserts the answers are equal. The corollary is deliberate: a binding cannot introduce a handler the server does not already have./snapshot.json. A parity test also asserts no arm branching onpathsits after the clause.handler(head_only),handler(remainder, head_only),handler(),handler(remainder)— so an extracted route in PRs 2–4 needs no signature change.head_onlybody decision."HEAD"remains declarable for a HEAD-only binding.RouteBinding.__post_init__); a duplicate, a non-conformer or a handler name the server does not have refuses the build.RouteBindingErroris one exception for all of them, because the caller does nothing different for any: the server must not start./. Both core prefixes do, and it is not cosmetic — without it/sourcelessmatches the/sourceprefix and the remainder is a fragment of a sibling route's name.routes()is called once at wiring; an extension reachable from a request is an invitation to re-ask it per request, and a dispatch table that can change under traffic is not a dispatch table.--helpcomposes for free andargs.func(args)dispatches a contributed verb by the identical line as a core one. What is not defended (an extension reaching past its own subcommand) is recorded in the module as a decision: an extension is code the command line was assembled with, not input.Golden parity — the zero-behaviour-change evidence
Both goldens were derived from
origin/mainat0f9361e0before the wiring was written, and pinned.tests/ideation-dashboard/fixtures/cli-help-tree.golden.txtholds the help text of all 31 entry points (the root, six top-level subcommands, nineteengateverbs, fivemodel-bindingverbs) atCOLUMNS=100. Byte-identical before and after — and still identical after mergingorigin/mainwith Derive the dashboard's required header fields from the adapter's classify (split § 2.3) #728, which touchesauthoring.py's header fields. Text, not a hash, so a failure names the argument that moved; a companion test proves the width pin is doing something, and a floor proves the walk is not vacuous.test_the_core_dispatch_table_is_unchangedpins the ordered arms of_route(10) anddo_POST(11) with the handler methods each reaches, read out of the syntax tree. Identical toorigin/main, verified by running the same extractor overgit show origin/main:scripts/ideation_dashboard/serve.py. A negative control proves the reader is order-sensitive.COMMITTED_INTENTS_ROUTE/_serve_committed_intentsappear in the pinned table unchanged and are untouched by the diff.Validation
python3 -m pytest -q tests/ideation-dashboard tests/doc-health tests/corpus-adapter→ 6604 passed, 31 skipped, 1 failed. The one failure istest_snapshot.py::test_find_validator_locates_pinned_checkout, confirmed pre-existing and environmental by running it on an untouchedorigin/mainworktree, where it fails identically. The three new files add 58 passing tests, 0 skips (so the workflow's exactSKIPPEDpin is unmoved and itsPASSED/SELECTEDfloors only rise).OPENSPEC_TELEMETRY=0 openspec validate --all --strict→ 97 passed, 1 failed (change/disposition-codexfactory-declared-renames), byte-identical on the untouched baseline worktree — the known local artifact._route()extension clause reds 5 tests (4 behavioural + the parity clause assertion); makingroute_extension.pyimportideation_dashboardreds both neutrality scans. Both restored.What follows, and what this PR asks for
Offered for Brett Heap's word — nothing is merged, and no landing window is claimed.
PRs 2–4 of § 2.4, in the sequence the implementation memo sets out:
serve.pyopenDox-column extraction (serve_workbench.py,serve_project.py) as fixed core routes — a pure import rewrite, proved by the existing route tests re-run unmodified.serve.pyopenXdox + openxFactory-adapter-column extraction, registered through this point — the first PR where the seam carries live traffic. Must widenconftest.py'sNO_IMPLICIT_PUSH_MODULES.cli.pysplit, reusing this PR's subcommand point —cli_gate.pycontributed,cli_project.py/cli_model_binding.pyfixed core; proved by the golden above.Brett's § 2.4 rulings of 2026-09-06 (OQ-1 split
doxbench_packet.py; OQ-2 authority row deferred to D4.5; OQ-3 both seed routes to the adapter column) bear on PRs 2–4 and are deliberately not acted on here.Refs #656
🤖 Generated with Claude Code
https://claude.ai/code/session_01MDVAo41VtZqJQpuawwJeYC