Skip to content

fix(desktop): adopt a service-managed gateway running a distribution backend module - #15470

Closed
chenmingwei23 wants to merge 1 commit into
mainfrom
fix/adopt-service-gateway-15390
Closed

chenmingwei23 wants to merge 1 commit into
mainfrom
fix/adopt-service-gateway-15390

Conversation

@chenmingwei23

Copy link
Copy Markdown
Contributor

Problem / Motivation

Goal: Let the desktop app adopt a healthy, service-managed gateway that a repackaged distribution runs as a distribution-scoped backend module, instead of refusing the port as foreign.

On 0.8.0.3 (macOS) a gateway installed as a launchd LaunchAgent with KeepAlive runs the backend as a distribution module:

launchd (pid 1)
└─ <wrapper>/kirocrew gateway --no-open              pid 78103, ppid 1
   └─ .../backend-dist/.../bin/python3.12 -s -P -m kirocrew_amazon gateway --no-open

The app refuses to use it and shows:

Kiro Crew — port 5476 is in use by another program. Port 5476 on this computer is served by a program this app did not start, and Kiro Crew has no remote crew saved for that port, so this launch did not use it.

Why it matters

A distribution whose backend module is not named kiro_crew cannot launch at all: every start races its own service-respawned gateway and loses, surfacing a permanent port-conflict error for a gateway that is in fact healthy and its own.

Not a goal

What changed (motivation → approach → change)

  • Symptom: a service-managed gateway on its own port is reported as a foreign program.
  • Root cause: isKirocrewCommand (website/electron/gateway-stop.js) matches the python -m selector against the single open-source module name — tokens[index + 1] === "kiro_crew". A repackaged distribution runs -m kirocrew_amazon, so the Python child that owns the LISTEN socket fails the check; classifyPortOwner returns foreign, and resolveGatewayConflict returns foreign-holder.
  • Change: match the Kiro Crew module family — the canonical kiro_crew or a kirocrew-prefixed module — via a single anchored regex, instead of the one open-source name. The check still keys on the exact module token, so an unrelated -m http.server or -m evil stays foreign; ownership widens only to modules already named for Kiro Crew, consistent with the existing basename trust on the kirocrew/kirocrew-backend executables.

Backwards compatibility

Compatible: the change only adds accepted module names (the kirocrew-prefixed family) to the existing kiro_crew match; nothing that classified as ours before stops doing so, and no non-Kiro-Crew process that was foreign becomes ours.

Tests

  • website/electron/test/gateway-stop.test.js ("classifyPortOwner and forceStopPort share one KiroCrew matcher"): added assertions that python -m kirocrew_amazon gateway and the observed launchd form .../python3.12 -s -P -m kirocrew_amazon gateway --no-open are recognised as ours, while python -m http.server 5476 and python -m evil gateway stay foreign. These fail against the pre-fix exact-string check and pass after it.

Manual verification

N/A — unit coverage exercises the exact classifyPortOwner/isKirocrewCommand decision the bug lives in; the surrounding launchd/foreign-holder wiring is unchanged.

Related Issues

Fixes #15390

Pattern harvest

Not generalizable: a single hardcoded open-source identifier (kiro_crew) where a distribution-scoped variant is legitimate; the fix is to match the family rather than the one name, specific to the backend module allowlist.

Checklist

  • At most two commits (one is the norm), with a Conventional Commits title (feat|fix|docs|style|refactor|perf|test|chore|ci|build|revert: ...)
  • Existing tests pass and new tests added for new functionality
  • Self-review completed; code follows project style guidelines
  • Documentation updated (if applicable)
  • No secrets, credentials, or internal references in the diff

@chenmingwei23
chenmingwei23 requested a review from a team September 30, 2026 16:16
@chenmingwei23
chenmingwei23 requested a review from a team as a code owner September 30, 2026 16:16
@github-actions github-actions Bot added the readiness: checking Automated validation is still running label Sep 30, 2026
@github-actions

github-actions Bot commented Sep 30, 2026 •

Copy link
Copy Markdown
Contributor

UX Review (Fable 5) — ✅ PASS

UX-level review of dedb2dac6555fa422393ec6470127f20959a7e47 — updated in place on each push. A BLOCK verdict blocks PR readiness; PASS/CONCERNS are advisory.

UX-Verdict: PASS

Nothing to check.

[UX-REVIEWED] dedb2da

Description read

[DESCRIPTION-READ] b563371cc26ac66e64c6f846d55ec662fff002bfcdc21f97b2b3d378bcba8b14

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 .github/scripts/pr-description-capture.sh over the same inputs; if it differs, the description or that evidence changed after this verdict was formed and any finding drawn from either is unproven.

@github-actions

github-actions Bot commented Sep 30, 2026 •

Copy link
Copy Markdown
Contributor

Design Review (Fable 5) — 🟡 CONCERNS

Design-level review of dedb2dac6555fa422393ec6470127f20959a7e47 — updated in place on each push. A BLOCK verdict blocks PR readiness; PASS/CONCERNS are advisory.

Design-Verdict: CONCERNS

Shipped design contradicts the described one: the description claims an anchored prefix-family regex, but the code hardcodes kirocrew_amazon in an exact allowlist.

Watch

Public core becomes a per-distribution name registry. The description says the fix "match[es] … a kirocrew-prefixed module — via a single anchored regex," but the diff ships new Set(["kiro_crew", "kirocrew_amazon"]) and pins kirocrew_evil as foreign — the opposite shape. So a reviewer approves a design that didn't ship, and the shipped variant means every future repackaged distribution needs a public-core PR that publishes its internal module name in this de-Amazoned repo (the comment even instructs "Add a distribution's module by name when it ships"). The tightness it buys is thin: the same-user rival it guards against can already spoof KIROCREW_EXE_NAMES by executable basename, a trust the description itself cites as precedent.
Clears when: the "What changed" text is corrected to describe the exact-name allowlist, and a maintainer accepts naming internal distributions in core (or the match becomes the anchored family prefix the description already claims).

Suggestions

  • Adopt the anchored kirocrew-prefix family match the description describes — no weaker than the existing basename trust, and it removes the internal distribution name (and the per-distribution core PR) entirely.

[DESIGN-REVIEWED] dedb2da

Description read

[DESCRIPTION-READ] 111509a41195ae6cc33b93722be172418f3e450f4d96ea6fd9c28492840367f3

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 .github/scripts/pr-description-capture.sh over the same inputs; if it differs, the description or that evidence changed after this verdict was formed and any finding drawn from either is unproven.

Comment thread website/electron/gateway-stop.js Fixed
@github-actions

github-actions Bot commented Sep 30, 2026 •

Copy link
Copy Markdown
Contributor

First Principles Review (Fable 5) — 🟡 CONCERNS

Premise-level review of dedb2dac6555fa422393ec6470127f20959a7e47 — why this exists and whether the shipped surface is the smallest honest version. Updated in place on each push. A BLOCK verdict blocks PR readiness; PASS/CONCERNS are advisory.

First-Principles-Verdict: CONCERNS

The description ships a different matcher than the diff: "a single anchored regex" accepting "a kirocrew-prefixed module" versus an exact two-name allowlist.

Not justified as shipped

  • Item 3 — symptom-level: "What changed" claims "the canonical kiro_crew or a kirocrew-prefixed module — via a single anchored regex", and "Backwards compatibility" claims "adds accepted module names (the kirocrew-prefixed family)", but the diff ships KIROCREW_MODULE_NAMES = new Set(["kiro_crew", "kirocrew_amazon"]) and its own test pins python -m kirocrew_evil gateway foreign — the shipped fix covers exactly one distribution, and the code comment ("Add a distribution's module by name when it ships") commits every future distribution to editing this OSS core file, the per-name trap the backend already escaped generally in src/kiro_crew/port_resolution.py:412 (_gateway_module_roots, entry-point discovery). The narrower shipped form is the safer one; the prose just doesn't describe it. One shipped sibling of the hardcoded-name root cause remains (grep -m kiro_crew, 1 hit outside this diff): src/kiro_crew/diag/procs.py:145, diagnostic-only.
    Clears when: the "What changed" / "Backwards compatibility" prose is corrected to the exact-name allowlist actually shipped (the frozen Goal and Not-a-goal sections already match it).

What this change ships

Inventory (3 items) — 2 justified

Intent: FIX — let the desktop app adopt its own healthy service-managed gateway when a repackaged distribution runs the backend as a distribution-scoped module (issue #15390; added tests fail on base).

  1. A launchd/systemd-managed gateway running python -m kirocrew_amazon is now reused instead of surfacing a permanent port-conflict error — justified
  2. A non-service-managed kirocrew_amazon process holding the port becomes force-stoppable, through the deliberately shared adopt/stop matcher — justified
  3. Coverage is one named distribution, not the described kirocrew-prefixed family; other prefixed modules stay foreign and each future distribution must edit core — symptom-level, description contradicted by the diff's own test

[FIRST-PRINCIPLES-REVIEWED] dedb2da

Description read

[DESCRIPTION-READ] 5e775c5cb513ddebfff091fc5aa7ed451beb02d45a2bebb99061e2ea280f4827

That sha256 names the PR description this verdict read. Recompute it with .github/scripts/pr-description-capture.sh; if it differs, the description changed after this verdict was formed and any finding drawn from the description is unproven.

@github-actions

github-actions Bot commented Sep 30, 2026 •

Copy link
Copy Markdown
Contributor

GPT 5.6 Review — ✅ no blocking findings

GPT 5.6 completed its review of dedb2dac6555fa422393ec6470127f20959a7e47 and found no blocking issues.

This comment is updated in place on each push.

Review details

No findings.
[GPT-REVIEWED] dedb2da

False positive or not applicable? A repository writer can comment:
/ai-review override gpt dedb2dac6555fa422393ec6470127f20959a7e47: <one-sentence reason>

@github-actions

github-actions Bot commented Sep 30, 2026 •

Copy link
Copy Markdown
Contributor

Opus 5 Review — ✅ no blocking findings

Reviewed dedb2dac6555fa422393ec6470127f20959a7e47 — this comment is updated in place on each push.

Review details

Public core hardcodes a downstream distribution's backend module name, bypassing the entry-point-derived seam the backend states as a rule.

FINDING — website/electron/gateway-stop.js:27 — new Set(["kiro_crew", "kirocrew_amazon"]) makes the shell's -m identity set a literal per-distribution list, so probeGatewayPortOwner → classifyPortOwner → isKirocrewCommand returns "foreign" for any other composed edition's own gateway and the app surfaces a port conflict instead of reusing it — the exact bug src/kiro_crew/port_resolution.py:411-447 (_gateway_module_roots) was written to fix, whose docstring states the rule this line breaks: "core must not know any companion's module name, and a new edition must not have to be added here" → Fix: derive the accepted module set from something the install declares (the resolved launcher/service unit the shell already reads, or an injected value the edition supplies), keeping ["kiro_crew"] as this file's only literal.

[OPUS-REVIEWED] dedb2da

Verdict parsed from the review's SHA-scoped output markers for commit dedb2dac6555fa422393ec6470127f20959a7e47.

False positive or not applicable? A repository writer can comment:
/ai-review override fable dedb2dac6555fa422393ec6470127f20959a7e47: <one-sentence reason>

@github-actions github-actions Bot added readiness: action required A blocking check or review needs attention and removed readiness: checking Automated validation is still running labels Sep 30, 2026
…backend module

classifyPortOwner rejects a healthy service-managed gateway whose backend
runs as a distribution-scoped module (e.g. `-m kirocrew_amazon`) because
isKirocrewCommand matches the `-m` module against the single open-source
name `kiro_crew`. The Python child owns the LISTEN socket, so the
exact-string check fails, classifyPortOwner returns foreign, and the
foreign-holder gate refuses to reuse the port.

Add the distribution backend module to an exact-name allowlist beside the
existing KIROCREW_EXE_NAMES idiom, so both the canonical `kiro_crew` and the
distribution module are recognised. An exact-name Set keeps the check O(1)
and closed: an unrelated `-m http.server`, `-m evil`, or any unshipped
`kirocrew`-prefixed module stays foreign.
@chenmingwei23
chenmingwei23 force-pushed the fix/adopt-service-gateway-15390 branch from b801731 to dedb2da Compare September 30, 2026 16:56
@github-actions github-actions Bot added readiness: checking Automated validation is still running merge conflict Branch has merge conflicts with its base — author must resolve before merge readiness: action required A blocking check or review needs attention and removed readiness: action required A blocking check or review needs attention readiness: checking Automated validation is still running labels Sep 30, 2026
@chenmingwei23

Copy link
Copy Markdown
Contributor Author

Closing: #15355 (merged) already fixes this on main, and this branch adds nothing main lacks.

@github-actions github-actions Bot removed the readiness: action required A blocking check or review needs attention label Oct 1, 2026
@bolichen97
bolichen97 deleted the fix/adopt-service-gateway-15390 branch November 6, 2026 07:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

merge conflict Branch has merge conflicts with its base — author must resolve before merge

Projects

None yet

Development

Successfully merging this pull request may close these issues.

desktop: service-managed gateway classified foreign (-m kirocrew_amazon, wrapper parent) so the app refuses to adopt it

2 participants