Skip to content

fix(apps): stop an app's backend on uninstall and observe the port instead of trusting the stop - #13304

Merged
iamwhatever merged 1 commit into
mainfrom
fix/uninstall-stop-evidence-9396
Sep 25, 2026
Merged

iamwhatever merged 1 commit into
mainfrom
fix/uninstall-stop-evidence-9396

Conversation

@chenmingwei23

@chenmingwei23 chenmingwei23 commented Sep 24, 2026 •

Copy link
Copy Markdown
Contributor

What is the problem?

Removing an app does not stop the backend process that app runs, and the command still reports success.

Two entry points remove an app, and neither takes part in the teardown contract the rest of the lifecycle already holds:

  • kirocrew app uninstall runs the whole uninstall inside the CLI process. The CLI is a separate process from the gateway, so it holds no handle on the child the gateway spawned. It deletes the app's files and prints a success line while the backend keeps its port, its app secret, and its proxied routes.
  • The gateway's uninstall handler calls the stop only when the installed manifest's resources field reads gateway, and it discards the stop's return value. resources is written by the app itself, so an app that declares resources: "app" switches off its own teardown. Even on the branch that does stop, a False answer is thrown away.

The same resources gate sits on the handler's scheduler cleanup, one step earlier. An app:<name> cron job is persisted in the gateway's own cron store and fired by the gateway's own CronService, which applies no app-admission check at fire time. So for an app whose resources is not gateway, uninstall deleted the app directory and left its enabled jobs to keep running their command, script or agent payload until the next gateway boot reconciled the store. on_app_disable keys that cleanup on the app's cron permission and not on resources, so uninstall cleaned up less than the strictly less destructive disable.

One step further in, a cron cleanup that FAILED could not be told from one that found nothing. deregister_app_crons_from_service answers 0 for both: it is the honest answer for an app that owned no jobs, and it is also what an unexpected write failure looks like from outside, because the bridge logs and audits that case and then returns 0. The handler recorded removed=0 as completed and carried on through onUninstall and app deletion while the still-enabled rows were still on disk.

disable and trust-revoke already stop and then observe the port correctly.

One half of the issue's premise no longer holds. The issue names forgeable evidence in stop_recorded_app_backend, but that function is not on main: it was extracted from PR #7901 and never merged. app_backends.pids.json survives only as a cache the startup reap reads, and every row carries pid plus start_time and is matched positively before any signal is sent. No stop decision on main reads pidfile absence.

Why this issue matters to the user

After an uninstall the user has no app and no way to reach it, yet the process keeps running. It holds its TCP port, so reinstalling the app or installing a different one on that port fails. It still holds a valid app secret. The gateway's proxy routes for it are gone, so nothing inside the product can reach it to shut it down. The only remedy left is finding the pid by hand or restarting the gateway.

The scheduler half is worse than a held port, because it keeps executing. A removed app's jobs go on firing their payload against a directory that no longer exists, and nothing left in the store says they belonged to a removed app.

The success line the command prints is what makes any of this hard to notice at all.

How our fix solves it

Symptom: uninstall reports success while the app's backend is still executing and its scheduled jobs still fire.

Root cause: the uninstall path is the only lifecycle path that gates teardown on app-written metadata, and the one signal that could have caught the remaining case is a count that means two different things.

  1. src/kiro_crew/cli_commands.py: app uninstall delegates to a running gateway through _run_app_action_through_gateway, the same way enable and disable already do, carrying --purge-data over the wire. The gateway owns the child, so the gateway is the process that can stop it. When no gateway answers, the file-only path no longer implies a clean stop: it states that the backend was not stopped, names the app, and names restarting the gateway as the action, carrying the caveat the neighbouring _print_file_only_app_result already states — on Windows and in sandboxed shells this path is taken even while a gateway is running, so "start the gateway" would not be actionable.
  2. src/kiro_crew/app_lifecycle_client.py: toggle_app carries the purge_data flag, so the delegated uninstall preserves the flag's meaning. A bodyless request would silently turn --purge-data into a data-preserving uninstall.
  3. src/kiro_crew/apps/routes.py: handle_uninstall_app stops the backend for every app rather than only when resources reads gateway, and captures the recorded port before the stop. After the stop it probes that port, and reports a port still accepting connections as unstopped_backend_port with the port number.
  4. src/kiro_crew/apps/routes.py: the scheduler cleanup loses the same gate, and runs for every app. Deregistration still honours resources: the process and the gateway's own scheduler entries are not the app's to keep, but the agents, skills and routes an app registered for itself are.
  5. src/kiro_crew/apps/bridges.py: deregister_app_crons_reporting_failures performs the same removal and reports every failure instead of answering 0. The uninstall handler consumes it and refuses with a retryable 409 before the non-idempotent onUninstall script runs, so a write that never landed no longer deletes the app while its rows keep firing.
  6. docs/system-specs/modules/app-kit-platform.md: the owning spec is corrected to match. Its teardown chain recorded cron cleanup as gateway-managed and backend stop plus deregistration as gateway-managed only, and its CLI-routing paragraph recorded that uninstall is deliberately not routed through a running gateway. This change reverses all three, and that paragraph now says so explicitly and supersedes the old statement. AGENTS.md requires reading this spec before touching this area, so a recorded decision left contradicting shipped behaviour is how the behaviour gets reverted by accident.

The exception is the only evidence available, which is why the fix propagates rather than re-checks. A post-hoc count cannot settle it: CronService's rollback keeps the removed rows filtered out of the in-memory job list after a failing _save() and only a reload restores them, so list_jobs reports a removal that did not persist. cron.py is untouched here — that rollback is load-bearing for the children whose ownership it restores.

deregister_app_crons_from_service keeps its own answer, deliberately. It is what the CLI's cron cleanup calls on disable as well as uninstall, and reporting a failed write is a decision only a caller about to do something irreversible needs to make. The gateway's disable path does not use it at all: on_app_disable drives CronSDK directly.

The port report is recorded in both warnings and uninstall_log, because their consumers are disjoint and neither shows it twice. print_result renders warnings and never uninstall_log; the dashboard's uninstall reads uninstall_log (website/src/pages/AppDetailPage.tsx:1168) and never warnings.

A probe that observed nothing is also reported, rather than read as a clean stop. unstopped_backend_port documents None as "nothing observed", not "definitely stopped", and the distinction is load-bearing here: with no gateway-recorded port the probe falls back to the port declared in app.json, which sits inside the app directory, and onUninstall has by then already run app-controlled code there. So an untracked fixed-port backend could relabel its port — or drop its entryPoint — and the fallback would probe the wrong port and answer None, leaving a live process and a valid app secret behind a success line, with the files gone and the pidfile record the next start would reap from already dropped. When no recorded port existed, the result now says the stop could not be verified. The warning is gated on a backend being declared in the installed record captured BEFORE the hook ran, so an app cannot suppress it by rewriting its manifest, and an app that never had a backend collects no warning about one.

The backend stop reports rather than aborts, while the scheduler steps abort. The difference is position: the scheduler steps run first, before anything destructive, so an abort there leaves nothing changed and the retry is safe. By the time the stop runs, the non-idempotent onUninstall has already executed, and an app that cannot be removed is worse than a port named in the result.

What tests we did

Every path that removes or stops an app backend was enumerated with a verdict, not just the ones that were edited.

Path Before After
CLI uninstall, gateway up no stop, prints success delegates, gateway stops
CLI uninstall, no gateway silent reports backend not stopped
CLI uninstall, manifest unreadable assumed clean reported, not assumed
API uninstall, resources: gateway stops, result discarded stops, port observed
API uninstall, resources: app no stop at all stops, port observed
API uninstall crons, resources: app jobs keep firing scheduler cleaned
API uninstall crons, write fails 0 read as "owned nothing", app deleted retryable 409 before onUninstall
API uninstall crons, store busy 409 abort unchanged
API uninstall crons, store unreadable 409 abort, non-retryable unchanged
API uninstall, port still answers silent success reported in both response fields
API disable crons, write fails answered 0 unchanged, answered 0
API disable correct unchanged
Trust revoke correct unchanged
Gateway shutdown sweep correct unchanged
Orphan reap after SIGKILL correct unchanged
Install after a leaked uninstall adopts the survivor unchanged, tracked in #13403

New file test/test_apps_uninstall_backend_stop.py, 20 tests across both entry points. Both directions of the widened scope are pinned: an uninstall whose cron write fails is refused with a retryable 409 and never reaches the teardown script, and the same failure through deregister_app_crons_from_service is still answered 0 so the disable path is unaffected. A third test holds 0 as the honest answer on both entry points when the app genuinely owned nothing.

Each decision was verified by mutation, one at a time, each reddening exactly one intended test with the rest green:

Mutation Reddened
stop re-gated on resources, port report dropped the handler stop tests
CLI reverted to the local-only uninstall the CLI tests
scheduler cleanup re-gated on resources test_the_scheduler_is_cleaned_even_for_a_self_managed_app
port report written to warnings only test_the_port_reaches_both_consumers
the wrapper re-raises instead of answering 0 test_an_unexpected_write_failure_is_still_answered_as_zero
the write-failure abort removed both write-failure tests

Local runs, all with -n0 and naming files rather than directories: the new file with test_app_routes.py and test_app_bridges.py, 251 passed; test_app_slot_ownership.py with test_apps_routes_coverage.py and test_trusted_apps_api.py, 341 passed; test_cli_commands_coverage.py with test_app_slot_ownership.py, 294 passed; test_cron_arbiter_items.py, test_cron_store_unreadable_boundaries.py and test_spawn_audit.py, 71 passed. flake8, isort, black and mypy are clean on the changed sources, and the comment-history gate passes.

Four existing test files change as a direct consequence, none of their assertions touched. test_app_routes.py's four cron-abort tests patch the bridge entry point the handler calls, by name, so they are retargeted. The other three drive handle_uninstall_app with a blanket MagicMock state, whose auto-created crons attribute makes the handler drive a fake removal that raises — harmless while that was swallowed, and now correctly an abort. Those tests supply no cron service so they stay scoped to the step each is about: test_app_slot_ownership.py's pointer-flush and teardown cases, test_apps_uninstall_keep_specific.py's keep-list parsing, and test_apps_uninstall_hook_registries.py's hook teardown. Every test that drives the handler was enumerated rather than found one CI round at a time; the fifth, test_trusted_apps_api.py, already supplies a cron service and needs no change.

Any other suggestions on the work

The invariant, swept

Every fix above is one instance of a single rule: app-controlled evidence, and the absence of evidence, must not stand in for proof. Four instances were found one per review round, so the remaining sites on the uninstall, disable and stop paths were enumerated deliberately rather than waiting for a fifth. Each place that reads app.json, reads a manifest, or could treat "cannot see it" as "it is not there":

Site Evidence it reads Same shape Verdict
CLI file-only warning gate app-written app.json, via _app_declares_backend yes fixed — warns on the declaration OR the gateway-owned recorded port
Handler unverifiable-stop gate app-written app.json, since get_app reads app_dir(name)/app.json yes residual, see below
Handler scheduler cleanup the gateway's own cron store, ungated no correct
Handler backend stop ungated; the port is observed afterwards no correct
Bridge cron removal the gateway's own store; every failure reported no correct
onUninstall lookup the app's manifest no intended: running the app's own script from its own manifest is the point
_app_declares_backend on an unreadable manifest answers True no already fail-safe
unstopped_backend_port manifest fallback app-written app.json yes pre-existing in backend.py, outside this change; the unverifiable report above is what makes it visible
on_app_disable scheduler cleanup app-written permissions.cron yes pre-existing on the disable path, which this change deliberately leaves byte-identical; recorded here, not fixed
_absence_is_genuine requires the nearest existing ancestor to be a directory no correct, and an existing instance of this same discipline

The one residual inside this change is the handler's unverifiable-stop gate, and it is stated rather than closed because the union that fixes the CLI cannot fix it: that branch is only reached when no recorded port exists, so the gateway-owned half of the union is empty there by construction. Warning anyway would fire on every uninstall of an app that never had a backend, and the only signal that distinguishes the two is the app's own manifest. Closing it properly needs a gateway-owned record that the app declared a backend, which does not exist today — installed.json carries the app's metadata but not its backend declaration. That belongs with the adoption-provenance work on #13403, which already needs gateway-owned provenance for the same reason.

The two pre-existing instances are recorded, not fixed. unstopped_backend_port's fallback is in a file this change does not touch, and on_app_disable's permission gate is on the disable path, whose behaviour this change holds byte-identical on purpose.

The swallowed-write hole this closes is pre-existing on main and is not created by this change: bridges.py's class-agnostic handler and cron.py's rollback are both untouched upstream. For an app whose resources is not gateway, main never cleaned crons on uninstall at all, so this change is a strict improvement for exactly the apps that were worst off, and the window it leaves is narrower than the one it removes — a failed write is now refused, where previously every such app's jobs were orphaned unconditionally.

A backend that outlives its uninstall meets a second gap that this PR deliberately does not close. The gateway's start path adopts an existing listener on an app's declared port when a health probe answers; it records which PIDs hold the socket, but nothing reads the code that listener executes, and an adopted instance is excluded from the startup stale-reap. So a listener that survived one removal can be adopted by the next install of the same name. That is pre-existing and wider on main, and reporting the surviving listener is what makes it visible. It is left to #13403, because the fix lands in src/kiro_crew/apps/backend.py and needs the record it consults to be a leaf covered by the sandbox security floor — the app's own backend receives KIROCREW_HOME in its spawn env and can otherwise delete the record that fences it, and a guard forgeable by the process it exists to fence is the same class as the defect being closed.

The stop-and-observe sequence is spelled twice: _stop_backend_and_observe here and the same triple inline in teardown_app_runtime at src/kiro_crew/apps/teardown.py:330-341. Sharing it needs a helper in that module, which also serves disable and trust withdrawal, so it is filed as #13462 rather than folded in.

The port probe establishes that something still listens on the recorded port. It cannot establish that the listener is the app's backend rather than an unrelated process that claimed the port after the stop, and it is a single instant, so a backend that rebinds after the probe reads as stopped. Both halves are carried by #13403. What the probe can no longer do is stay silent about not knowing: an absent recorded port is reported as unverifiable rather than as a clean stop.

app_backends.pids.json stays a cache. Nothing here makes a stop decision from it, and the startup reap's positive pid plus start_time match is untouched.

The CLI's no-gateway path still cannot stop a backend, and its cron cleanup still answers 0 on a failed write. It has no gateway-owned port to observe and no 409 to return; the row it leaves in the pidfile is what the next gateway start reaps. This change makes that limit visible instead of hiding it behind a success line.

That second half is a fair hit against this change's own stated criterion, so it is recorded rather than argued away: if reporting a failed write is a decision a caller about to do something irreversible needs to make, then _cleanup_app_crons_from_scheduler is such a caller too, since the CLI's local uninstall reaches deregister_app and uninstall_app after it. It is not fixed here because that helper is shared with CLI disable, whose disposition this change deliberately leaves byte-identical, so telling the two apart means splitting the helper. That belongs with the shared-helper work already filed as #13462.

Pattern harvest

Rule candidate: semgrep
Pattern: a stop or teardown helper invoked as a bare statement, its boolean return discarded

Three further patterns here are not mechanical enough for semgrep, so they belong in a review prompt instead. First, a teardown step gated on a field that the managed component itself authors, which lets that component switch off its own cleanup — worth checking against every sibling step in the same handler, not only the one a report names, since this change found two under one gate. Second, a reuse decision made from a liveness probe alone, where the probe answers "something is here" and the code reads it as "the thing I expect is here". Third, a count used as a success signal where zero is also the honest answer for an empty set: the caller cannot tell those apart, and if what it does next is irreversible, the failure has to arrive as something other than a number.

Closes #9396

@chenmingwei23
chenmingwei23 requested review from a team and CrysisDeu September 24, 2026 08:39
@github-actions github-actions Bot added readiness: checking Automated validation is still running readiness: action required A blocking check or review needs attention and removed readiness: checking Automated validation is still running labels Sep 24, 2026
@github-actions

github-actions Bot commented Sep 24, 2026 •

Copy link
Copy Markdown
Contributor

Design Review (Fable 5) — ✅ PASS

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

Design-Verdict: PASS

Verify one live end-to-end kirocrew app uninstall --purge-data against a running gateway — the body-carrying delegation is only exercised through mocked sockets in the tests.

[DESIGN-REVIEWED] e31164d

@github-actions

github-actions Bot commented Sep 24, 2026 •

Copy link
Copy Markdown
Contributor

GPT 5.6 Review — ✅ no blocking findings

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

This comment is updated in place on each push.

Review details

No findings.
[GPT-REVIEWED] e31164d

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

@github-actions

github-actions Bot commented Sep 24, 2026 •

Copy link
Copy Markdown
Contributor

First Principles Review (Fable 5) — 🟡 CONCERNS

Premise-level review of e31164d0410907e83c05c88b3c3276fa8e137a02 — 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 uninstall handler re-copies the stop-and-observe sequence that teardown.py was created to hold exactly once — and the two copies' texts have already diverged.

Not justified as shipped

  • Item 6 — duplicate of src/kiro_crew/apps/teardown.py:334-349: _stop_backend_and_observe (routes.py:659) repeats the same capture-port → stop → probe → report sequence, near-verbatim comments included. Grep unstopped_backend_port( counts exactly 2 call sites: teardown.py:339 (shared by disable and both trust-withdrawal callers) and routes.py:691 (this PR). teardown.py's own docstring names the risk this recreates — "a copy is a defect with a delay on it: any step added … later would silently not run" — and the warning texts already differ ("still running on port …" vs "still listening on port … after uninstall stop"), so the divergence has begun in the same diff that introduced the copy. routes.py already imports teardown_app_runtime (routes.py:121), so no new dependency is needed.
    Subtraction: delete _stop_backend_and_observe from routes.py; host the one capture→stop→probe sequence in teardown.py and have the uninstall step call it, leaving a single copy.
    Clears when: routes.py's copy is deleted and both callers run the one sequence in teardown.py.

What this change ships

Inventory (10 items) — 9 justified

Intent: make removing an app actually stop its backend and its scheduled jobs, and stop reporting success when it did not — a FIX.

  1. kirocrew app uninstall now hands the work to a running gateway, as enable/disable do — justified
  2. With no gateway reachable, the CLI prints that the backend was not stopped instead of bare success — justified
  3. --purge-data travels in the delegated request body (toggle_app gains payload) — justified
  4. The gateway uninstall stops the backend for every app, no longer gated on app-written resources — justified
  5. Uninstall's cron cleanup likewise runs for every app — justified
  6. After the stop the port is probed and a still-live port reported — duplicate of src/kiro_crew/apps/teardown.py (the same sequence, second copy)
  7. An unverifiable stop (backend declared, no recorded port) is reported rather than read as clean — justified
  8. An unexpected cron write failure now aborts uninstall with a retryable 409 before onUninstall runs (deregister_app_crons_reporting_failures) — justified
  9. The owning spec records all three reversals, including the superseded "uninstall is deliberately not routed" contract — justified
  10. Four existing tests pin state.crons = None so the new abort path doesn't fire on their mocks — rides along

[FIRST-PRINCIPLES-REVIEWED] e31164d

@github-actions

github-actions Bot commented Sep 24, 2026 •

Copy link
Copy Markdown
Contributor

Opus 5 Review — ✅ no blocking findings

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

Review details

Nothing blocks — but the messages this change adds reach no surface that displays them.

FINDING — src/kiro_crew/apps/routes.py:1524 — the new still-listening-port message is invisible to both dashboard uninstalls, contradicting the comment that uninstall_log "is the field the dashboard's uninstall reads": AppDetailPage.confirmUninstall does setInstallLog(res.uninstall_log) but never setShowInstallLog(true) and then navigate('/apps') unmounts the <pre> (AppDetailPage.tsx:1167-1171, 1488), and LibraryPage.confirmUninstall discards the response entirely (LibraryPage.tsx:204) → an operator uninstalling from the dashboard is told a clean removal happened while the backend still holds its port → Fix: surface warnings in both handlers before navigating — an edit to frontend files this PR does not touch, so it cannot land inside this change.

FINDING — src/kiro_crew/cli_commands.py:1228 — the new delegation routes the CLI through the handler that runs onUninstall, but print_result renders only message, warnings and registration.errors (app_lifecycle_client.py:183-201), so uninstall_log lines such as "onUninstall script failed (exit code non-zero)" and "Cleaned N dependency(ies)" are dropped and the CLI prints ✅ Uninstalled <app> alone → Fix: render uninstall_log in print_result, or append the script-failure line to backend_warnings beside the port messages.

FINDING — src/kiro_crew/apps/routes.py:1526 — elif not had_port_evidence and bool((manifest.get("backend") or {}).get("entryPoint")) gates the "could not verify" report on app-written metadata, the same field the change refuses to let gate teardown: get_app swallows a parse failure and returns manifest_data = {} (manager.py:2157-2175), and an app trusted to run code can drop entryPoint from its own app.json, so the one case with no gateway-owned evidence is reported as a clean uninstall → Fix: mirror _app_declares_backend and treat an absent, unparseable or backend-less manifest as declaring one, warning unless the record positively shows no backend.

FINDING — src/kiro_crew/cli_commands.py:856 — "To stop it now, restart the gateway, or uninstall from the dashboard instead." prints inside if result.ok: after uninstall_app has already removed the app, so the dashboard remedy is unavailable, and in the branch that fires on declares_backend alone (recorded_port is None) the promised next-start reap cannot run either, because _reap_stale_app_backends acts only on pidfile rows (backend.py:4879-4886) → Fix: print the warning before uninstall_app, and drop the reap/dashboard remedies when recorded_port is None.

[OPUS-REVIEWED] e31164d

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

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

@github-actions github-actions Bot added readiness: checking Automated validation is still running 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 24, 2026
@chenmingwei23
chenmingwei23 force-pushed the fix/uninstall-stop-evidence-9396 branch from 980b32c to 0c0ebab Compare September 24, 2026 13:59
@github-actions github-actions Bot added readiness: checking Automated validation is still running and removed readiness: action required A blocking check or review needs attention labels Sep 24, 2026
@chenmingwei23
chenmingwei23 force-pushed the fix/uninstall-stop-evidence-9396 branch from 0c0ebab to e867365 Compare September 24, 2026 14:24
@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 24, 2026
@chenmingwei23
chenmingwei23 force-pushed the fix/uninstall-stop-evidence-9396 branch from e867365 to a58693d Compare September 24, 2026 16:04
@github-actions github-actions Bot added readiness: checking Automated validation is still running and removed readiness: action required A blocking check or review needs attention labels Sep 24, 2026
@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 24, 2026
@chenmingwei23
chenmingwei23 force-pushed the fix/uninstall-stop-evidence-9396 branch from a58693d to 51f47e4 Compare September 24, 2026 17:37
@github-actions github-actions Bot added readiness: checking Automated validation is still running readiness: passed Eligible automated validation passed for the current revision and removed readiness: action required A blocking check or review needs attention readiness: checking Automated validation is still running labels Sep 24, 2026
@github-actions github-actions Bot added readiness: checking Automated validation is still running readiness: action required A blocking check or review needs attention and removed readiness: passed Eligible automated validation passed for the current revision readiness: checking Automated validation is still running labels Sep 24, 2026
@chenmingwei23
chenmingwei23 force-pushed the fix/uninstall-stop-evidence-9396 branch 2 times, most recently from 7384f10 to f14ebc0 Compare September 24, 2026 20:06
@github-actions github-actions Bot added readiness: checking Automated validation is still running and removed readiness: action required A blocking check or review needs attention labels Sep 24, 2026
@github-actions github-actions Bot added readiness: passed Eligible automated validation passed for the current revision and removed readiness: checking Automated validation is still running labels Sep 24, 2026
@chenmingwei23
chenmingwei23 force-pushed the fix/uninstall-stop-evidence-9396 branch from f14ebc0 to 498d71c Compare September 24, 2026 21:54
@github-actions github-actions Bot added readiness: checking Automated validation is still running and removed readiness: passed Eligible automated validation passed for the current revision labels Sep 24, 2026
@chenmingwei23
chenmingwei23 force-pushed the fix/uninstall-stop-evidence-9396 branch from 498d71c to 7bcd1ae Compare September 24, 2026 22:26
@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 24, 2026
…ares

Both uninstall entry points take part in the positive-evidence stop contract that disable and trust-revoke already hold.

The CLI hands uninstall to a running gateway the way enable and disable do, carrying --purge-data. When no gateway answers it reports that the backend was not stopped instead of printing success, and names restarting the gateway as the action, since on Windows and in sandboxed shells this path is taken even while a gateway runs.

The gateway handler stops the backend for every app rather than only when the app-written resources field reads gateway, and observes the recorded port afterwards, reporting unstopped_backend_port when something still accepts connections. An app-written field cannot switch off the app's own teardown, and a discarded stop result cannot stand in for a stop that happened.

Scheduler cleanup loses the same gate, for the same reason and one more: an app:<name> job is persisted in the gateway's own cron store and fired by the gateway's own service, which applies no app-admission check at fire time. Gated, such a job outlived the uninstall and kept running its payload against a deleted app directory until the next boot reconciled the store, which also left uninstall cleaning up less than the strictly less destructive disable. Deregistration still honors the field: the process and the gateway's own scheduler entries are not the app's to keep, but the agents, skills and routes it registered for itself are.

A cleanup that RAISED is now told apart from one that found nothing. deregister_app_crons_from_service answers 0 for both, and the rows cannot be re-counted to settle it because a failing save leaves them filtered out of the in-memory job list until a reload, so the exception is the only evidence there is. deregister_app_crons_reporting_failures is that evidence: the same removal, reporting every failure. The uninstall handler consumes it and refuses with a retryable 409 before the non-idempotent onUninstall script runs, so a write that never landed no longer deletes the app while its still-enabled rows keep firing from disk.

The wrapper's own answer is unchanged, deliberately. It is what the CLI's cron cleanup calls on disable as well as uninstall, and reporting a failed write is a decision only a caller about to do something irreversible needs to make. The gateway disable path does not use it at all, driving CronSDK directly.

The uninstall completes rather than aborting on a still-listening port. An app the operator asked to remove has already run its own onUninstall script, which is not idempotent, so an unremovable app is worse than a reported port. The scheduler steps abort instead, which is sound because they run first, before anything destructive.

A reported port means the listener survived, and adoption reads health and owner PIDs rather than the code the listener executes, so a later install of the same name can adopt that survivor. Closing that requires provenance on the adoption path itself, which is a separate change on a file this one does not touch, and is left to its own issue.

Adds test/test_apps_uninstall_backend_stop.py covering both entry points, the delegation, the ungated scheduler cleanup, the write-failure abort, the disable path's unchanged disposition, and the port report.
@chenmingwei23
chenmingwei23 force-pushed the fix/uninstall-stop-evidence-9396 branch from 7bcd1ae to e31164d Compare September 24, 2026 23:21
@github-actions github-actions Bot added readiness: checking Automated validation is still running readiness: passed Eligible automated validation passed for the current revision and removed readiness: action required A blocking check or review needs attention readiness: checking Automated validation is still running labels Sep 24, 2026
@iamwhatever
iamwhatever enabled auto-merge (squash) September 25, 2026 01:21
@iamwhatever
iamwhatever merged commit 4948a6f into main Sep 25, 2026
138 of 147 checks passed
@iamwhatever
iamwhatever deleted the fix/uninstall-stop-evidence-9396 branch September 25, 2026 01:21
@github-actions github-actions Bot removed the readiness: passed Eligible automated validation passed for the current revision label Sep 25, 2026
wknight1 pushed a commit to wknight1/KiroCrew that referenced this pull request Oct 5, 2026
…ares (kirodotdev#13304)

Both uninstall entry points take part in the positive-evidence stop contract that disable and trust-revoke already hold.

The CLI hands uninstall to a running gateway the way enable and disable do, carrying --purge-data. When no gateway answers it reports that the backend was not stopped instead of printing success, and names restarting the gateway as the action, since on Windows and in sandboxed shells this path is taken even while a gateway runs.

The gateway handler stops the backend for every app rather than only when the app-written resources field reads gateway, and observes the recorded port afterwards, reporting unstopped_backend_port when something still accepts connections. An app-written field cannot switch off the app's own teardown, and a discarded stop result cannot stand in for a stop that happened.

Scheduler cleanup loses the same gate, for the same reason and one more: an app:<name> job is persisted in the gateway's own cron store and fired by the gateway's own service, which applies no app-admission check at fire time. Gated, such a job outlived the uninstall and kept running its payload against a deleted app directory until the next boot reconciled the store, which also left uninstall cleaning up less than the strictly less destructive disable. Deregistration still honors the field: the process and the gateway's own scheduler entries are not the app's to keep, but the agents, skills and routes it registered for itself are.

A cleanup that RAISED is now told apart from one that found nothing. deregister_app_crons_from_service answers 0 for both, and the rows cannot be re-counted to settle it because a failing save leaves them filtered out of the in-memory job list until a reload, so the exception is the only evidence there is. deregister_app_crons_reporting_failures is that evidence: the same removal, reporting every failure. The uninstall handler consumes it and refuses with a retryable 409 before the non-idempotent onUninstall script runs, so a write that never landed no longer deletes the app while its still-enabled rows keep firing from disk.

The wrapper's own answer is unchanged, deliberately. It is what the CLI's cron cleanup calls on disable as well as uninstall, and reporting a failed write is a decision only a caller about to do something irreversible needs to make. The gateway disable path does not use it at all, driving CronSDK directly.

The uninstall completes rather than aborting on a still-listening port. An app the operator asked to remove has already run its own onUninstall script, which is not idempotent, so an unremovable app is worse than a reported port. The scheduler steps abort instead, which is sound because they run first, before anything destructive.

A reported port means the listener survived, and adoption reads health and owner PIDs rather than the code the listener executes, so a later install of the same name can adopt that survivor. Closing that requires provenance on the adoption path itself, which is a separate change on a file this one does not touch, and is left to its own issue.

Adds test/test_apps_uninstall_backend_stop.py covering both entry points, the delegation, the ungated scheduler cleanup, the write-failure abort, the disable path's unchanged disposition, and the port report.
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.

App backend stop detection treats pidfile absence as proof of termination

2 participants