Repository navigation
fix(electron): reuse a composed edition's gateway instead of refusing it - #15355
Conversation
UX Review (Fable 5) — ✅ PASSUX-level review of UX-Verdict: PASS Nothing to check. [UX-REVIEWED] 06cbd2c Description read[DESCRIPTION-READ] 80651ba03793cafb89c8461473764fe4da7cad9d09fcfae83e617cf5324d5c91 That sha256 names everything this verdict read: the PR description, plus the 3 evidence file(s) the workflow collected from it and handed this review. It covers that evidence because the media strip replaces every attachment URL with the same placeholder, so an edit swapping one attachment for another would leave the description's captured text identical while what this review judged changed. Recompute it with |
Design Review (Fable 5) — ✅ PASSDesign-level review of Design-Verdict: PASS Verify on one real composed-edition install that reuse completes past the token handshake, since manual verification was skipped and CI only exercises the predicate. [DESIGN-REVIEWED] 06cbd2c Description read[DESCRIPTION-READ] 52393cfe8ab406b7207250102330767e573033475ec21b66d22d13937a99e185 That sha256 names everything this verdict read: the PR description, plus the 1 evidence file(s) the workflow collected from it and handed this review. It covers that evidence because the media strip replaces every attachment URL with the same placeholder, so an edit swapping one attachment for another would leave the description's captured text identical while what this review judged changed. Recompute it with |
GPT 5.6 Review — ✅ no blocking findingsGPT 5.6 completed its review of This comment is updated in place on each push. Review detailsNo findings. False positive or not applicable? A repository writer can comment: |
First Principles Review (Fable 5) — ✅ PASSPremise-level review of First-Principles-Verdict: PASS Confirm the affected edition install spawns What this change shipsInventory (5 items) — 5 justifiedIntent: FIX — the desktop app reuses a composed edition's already-running gateway instead of refusing to start on its own port. Provenance is checkable: the added
Notes from the counts run: item 2's narrowing matches the pre-existing Python gate ( [FIRST-PRINCIPLES-REVIEWED] 06cbd2c Description read[DESCRIPTION-READ] e6ba4ff87a9d72c63a21e0c903c467c607cb0ba733b1834fd58ba6c734a7e203 That sha256 names the PR description this verdict read. Recompute it with |
buluoray
left a comment
There was a problem hiding this comment.
LGTM. I checked this at head 8d78cd1.
isKirocrewCommand now accepts the first -m selector when it matches ^(?:kiro_crew|kirocrew_[a-z0-9][a-z0-9_]*)$ (gateway-stop.js), which is the same convention port_resolution._gateway_module_roots() relies on for kirocrew.plugins companions. classifyPortOwner and forceStopPort both default to this predicate, so a composed edition's gateway now classifies kirocrew and the supervisor reuses it instead of returning foreign-holder. The Windows path binding and the "first execution selector only" rule are unchanged. token-sources.js does not trust this predicate for the local secret.
Verified:
- A real edition launcher line,
/…/farm/bin/python3.12 -P -m <edition companion> gateway, returnstrue. node --test test/gateway-stop.test.jspasses 39/39. Reverting the regex to^kiro_crew$fails exactly the two new tests (38, 40).- No other identity check in
website/electron/hardcodeskiro_crew. The remaining hits are the spawn argv and comments.
Non-blocking: the new tests pin the matcher, but no test covers the supervisor end to end (foreign-holder refused before, reused after). A gateway-supervisor.test.js case with a faked ps line would lock in the user-visible outcome.
Opus 5 Review — ✅ no blocking findingsReviewed Verdict parsed from the review's SHA-scoped output markers for commit False positive or not applicable? A repository writer can comment: |
8d78cd1 to
c96c069
Compare
|
mechanism: server-subcommand gate on the
|
|
The desktop launcher decides who holds the gateway port from the holder's command line. `isKirocrewCommand` accepted a Python process only when its first `-m` operand was exactly `kiro_crew`. A composed edition boots the gateway from its companion's own top-level module (`-m kirocrew_<edition>`) so the composition root runs instead of the core CLI, so every such gateway classified as `foreign`, and the supervisor's reuse decision returned `foreign-holder` with no remote crew to name. The app then refused to start on a port its own edition was serving. The Python side already solved this in `port_resolution._gateway_module_roots()` by reading installed `kirocrew.plugins` entry points. The Electron process has no view of that Python environment, so it matches the naming convention the entry points follow instead: `kiro_crew`, or an exact top-level `kirocrew_<edition>` module. The core still learns no edition's name. The match stays on the first execution selector only, and a dotted submodule, a bare prefix, a hyphenated or mixed-case look-alike never authorize a kill.
c96c069 to
06cbd2c
Compare
|
mechanism: cross-runtime parity test reading gateway-stop.js from the Python suite
|
|
|
CI note: the one remaining red is inherited, not this diff.
|
buluoray
left a comment
There was a problem hiding this comment.
Approving at 06cbd2c.
What I checked myself in a worktree pinned to this head:
- The fix works for the internal edition. The Toolbox launcher ends in
exec "$PYTHON" -m kirocrew_amazon "$@", and the desktop app passesgateway --no-open --port N. Sotokens[index+1]iskirocrew_amazon, which matchesKIROCREW_MODULE_RE, andtokens[index+2]isgateway, which is inKIROCREW_SERVER_SUBCOMMANDS. The app reuses the gateway instead of refusing it as a foreign holder. - Tightening the core path costs nothing.
-m kiro_crewnow also has to be followed by a server subcommand, which is the same slot rule_args_look_like_kirocrewalready applies on the Python side. The one core spawn ingateway-supervisor.js(-s -P -m kiro_crew gateway …) still matches.-m kiro_crew run …is now refused, which is correct: the task runner is not a gateway, and this match is what authorizes a kill. - The tests fail when the guards are removed.
node --test electron/test/gateway-stop.test.jspasses 39/39 (1 skipped). Dropping the subcommand check turns 1 test red. Making the edition regex unmatchable turns 2 red.TestDesktopGatewayIdentityParityandTestComposedEditionGatewayModulepass 7/7. - The failing CI check is inherited.
Backend Tests (Windows) (2)fails intest/test_session_control_revive.py, the family behind #15364. This PR changes no Python source, only a test that reads the JS file.
Non-blocking: the legacy dotted -m kiro_crew.gateway is still recognised by stop but not by the desktop, as the cli.md note says. That matches what happened before this PR, so it is fine to leave.
… it (#15355) (#15580) The desktop launcher decides who holds the gateway port from the holder's command line. `isKirocrewCommand` accepted a Python process only when its first `-m` operand was exactly `kiro_crew`. A composed edition boots the gateway from its companion's own top-level module (`-m kirocrew_<edition>`) so the composition root runs instead of the core CLI, so every such gateway classified as `foreign`, and the supervisor's reuse decision returned `foreign-holder` with no remote crew to name. The app then refused to start on a port its own edition was serving. The Python side already solved this in `port_resolution._gateway_module_roots()` by reading installed `kirocrew.plugins` entry points. The Electron process has no view of that Python environment, so it matches the naming convention the entry points follow instead: `kiro_crew`, or an exact top-level `kirocrew_<edition>` module. The core still learns no edition's name. The match stays on the first execution selector only, and a dotted submodule, a bare prefix, a hyphenated or mixed-case look-alike never authorize a kill. (cherry picked from commit c50c246)
Problem / Motivation
Goal: The desktop app reuses a running gateway started by a composed edition instead of refusing to start.
A composed edition boots the gateway from its companion's own top-level module (
python -m kirocrew_<edition> gateway). The desktop launcher's port-owner matcher,isKirocrewCommandinwebsite/electron/gateway-stop.js, accepted a Python process only when its-moperand was exactlykiro_crew. The edition's own gateway therefore classified asforeign,gateway-supervisor.jsreturnedforeign-holder(a reuse decision on a foreign owner with no remote crew to name), and the app refused to start on a port its own edition was serving.Why it matters
Every desktop user of a composed edition whose gateway is already up (a service unit, a launcher, a prior app run) is blocked at launch with a "something else holds the port" state and no way through, because the holder is in fact their own gateway.
Not a goal
kirocrew_<edition>naming convention thekirocrew.pluginsentry points follow; no edition is named.port_resolution._gateway_module_roots()already reads installed entry points).token-sources.jsdeliberately never trusts this predicate for the secret).What changed (motivation → approach → change)
KIROCREW_MODULE_RE-moperand iskiro_crewor an exact top-levelkirocrew_<edition>KIROCREW_SERVER_SUBCOMMANDSgateway,dashboardorstartplatform-context.mdkirocrew_<edition>name is now a MUST for companionsTestDesktopGatewayIdentityParitySymptom: a composed edition's gateway is reported as a foreign holder and the app refuses to start. Root cause:
gateway-stop.jscompared the-moperand to the literalkiro_crew. Change: the operand is matched against the companion naming convention instead. The Electron process cannot read the Python environment's installed entry points, so it mirrors the convention those entry points follow rather than the entry points themselves.The module name alone does not authorize a kill.
forceStopPortSIGKILLs whatever this predicate says is ours, so the match also requires a server subcommand in the fixed argparse slot after the module, the same setport_resolution._KIROCREW_SERVER_SUBCOMMANDSgateskirocrew stopon. A process that merely imports akirocrew_*module on our port stays foreign. The match remains on the first execution selector only, exact top-level module only (no dotted submodule, no bare prefix, no hyphen, no mixed case).The two identity constants now live in two runtimes, so
test/test_cli.py::TestDesktopGatewayIdentityParityreadsgateway-stop.jsand pins the subcommand set equal to_KIROCREW_SERVER_SUBCOMMANDSand the module pattern to the root a conventionalkirocrew.pluginsentry point yields. Widening one side without the other fails a test instead of a user.docs/system-specs/modules/platform-context.mdmakes the naming convention normative in the Companion packaging section, so a companion named outside it is a spec violation rather than a desktop-only surprise;docs/system-specs/modules/cli.mdrecords the desktop-side rule beside the Python one, names the parity test, and states that the legacy dotted spawn-m kiro_crew.gatewayis matched bystoponly.Backwards compatibility
Compatible: every gateway spawn the repo ships (
gateway-supervisor.js,cli_server.py, the service units) carries-m kiro_crew gateway, which still matches. The one narrowing is-m kiro_crewfollowed by a non-server subcommand (run,setup), which never holds the gateway port, so no reuse or force-stop path that works today stops working.Tests
test/test_cli.py::TestDesktopGatewayIdentityParity(2 tests): the JSKIROCREW_SERVER_SUBCOMMANDSset equals Python's_KIROCREW_SERVER_SUBCOMMANDS; the JSKIROCREW_MODULE_REacceptskiro_crewand the root of a conventional companion entry point and rejects a dotted submodule, a bare or hyphenated name, and mixed case. Droppingstartfrom the JS set fails the first test.website/electron/test/gateway-stop.test.js:classifyPortOwner: a composed edition's gateway classifies as ours, not foreign— the end-to-end verdict for a-m kirocrew_enterprise gatewaylistener iskirocrew.isKirocrewCommand: a composed edition's -m kirocrew_<edition> gateway is ours— positive cases across POSIX, a path with a space,-s -Pinterpreter flags, and a trusted Windows python; negative cases for-mas a later argument, after-c, a dotted submodule, a barekirocrew_,kirocrew, a hyphen, mixed case,kiro_crew_enterprise, a prefixed look-alike, a bare-m, akirocrew_*module with no subcommand or a non-server subcommand (kirocrew_backup,kirocrew_backup serve), a server word in a later slot (run gateway,--port 5476 gateway), andkiro_crewalone or withrun.Mutation controls: loosening the pattern to
kirocrew_.*fails the new test; dropping the subcommand check fails the new test. The unmutated code passes the whole Electron suite (npm run test:electron: 2021 tests, 0 failures).Manual verification
N/A — unit coverage sufficient: the change is a pure predicate on a command-line string and the tests exercise the same
classifyPortOwnerpath the supervisor calls.Related Issues
no linked issue: observed directly on a composed-edition install where the desktop app reported a foreign port holder for the edition's own gateway; no tracker entry exists.
Pattern harvest
Rule candidate: lint
Pattern: "the same identity constant copied into a second runtime with no cross-runtime test pinning the copies equal" -- the added parity test is the instance; a generic check would grep for a named twin in each copy's comment and require a test naming both.
Checklist
feat|fix|docs|style|refactor|perf|test|chore|ci|build|revert: ...)Contribution License Agreement