Repository navigation
fix(apps): re-consent pre-feature installs that declare sessionApproval - #22067
Conversation
UX Review (Opus 5.5) — ⏭️ skippedRevision |
Design Review (Opus 5.5) — ✅ PASSDesign-level review of Design-Verdict: PASS Nothing blocks: consent is refused on read the moment the key is missing, and the post-readiness reconcile only persists that refusal under the per-app lifecycle lock. Notes
[DESIGN-REVIEWED] f2cf3c5 Description read[DESCRIPTION-READ] eb17140196abc6d89d4cea956e887db36cbcd3cd54faf3e1ca91d3084096e826 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 |
First Principles Review (Opus 5.5) — ✅ PASSPremise-level review of First-Principles-Verdict: PASS The fix is aimed at the cause: a missing consent key is now read as "pending". One rider duplicates protection the PR adds elsewhere. Notes
What this change shipsInventory (8 items) — 6 justifiedIntent: stop a pre-upgrade app from holding session control the user never consented to. FIX.
[FIRST-PRINCIPLES-REVIEWED] f2cf3c5 Description read[DESCRIPTION-READ] 64bee0ff07b595c34b63cdaec3e6ee39efc216360421ddee689c05d9cac2f9b8 That sha256 names the PR description this verdict read. Recompute it with |
GPT 6.1 Review — ✅ no blocking findingsGPT 6.1 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: |
Opus 5.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: |
cc3bc91 to
38783df
Compare
|
Answers to the review of cc3bc91, now superseded by 38783df:
Local GPT review of later heads also found two read-side races in app_can_manage_session_approvals (an unreadable record, and a second manifest read). Both are fixed: the check now decides from one manifest read and one record read and fails closed. |
|
|
38783df to
3f0cc52
Compare
|
self-added: yes
|
|
self-added: yes
|
3f0cc52 to
96bdb41
Compare
|
First Principles on 3f0cc52 (item 6, zero consumers): applied the subtraction in 96bdb41. reconcile_session_approval_consent and its manager.py re-export are deleted; its two tests now run the gateway coroutine session_consent.reconcile_after_ready. |
c08493a to
8dd0a0c
Compare
|
Rebased onto main (88914fd) to clear a merge conflict; conflict-only, no code or design change. The one conflict was the sorted import list in src/kiro_crew/apps/manager.py, where main added _scan_installed_app_config_keys beside this PR's _session_approval_consent_unrecorded; both are kept. Related tests pass (932). New head 8dd0a0c. The open design question stays with the maintainer. |
8dd0a0c to
56161f8
Compare
|
Rebased onto main (5f803ab) to pick up the red-main fix #22178; the Await Fast Gate, Harness Parity and Coverage Gate reds came from the old base. Rebase only: no conflict and no code or design change. Related tests pass (932) and the harness-parity gate passes locally. New head 56161f8. The open design question stays with the maintainer. |
56161f8 to
f5c447e
Compare
|
self-added: yes
|
f5c447e to
f2cf3c5
Compare
|
|
|
Review-ready at head f2cf3c5: PR Readiness passed, Coverage Gate passed, GPT and Opus raised no findings, and Design and First Principles both PASS. Every review item has its own disposition (19 records, no rule violations). Main has moved one commit since, in docs/system-specs/modules/side.md only, which this PR does not touch. The follow-up writer race is tracked in #22118. Waiting on a maintainer review; nothing is merged, approved or set to auto-merge. |
Problem / Motivation
Goal: An app installed before
permissions.sessionApprovalexisted, whose manifest already declares it, asks for consent after a host upgrade instead of silently gaining control of the user's sessions.The older host ignored
permissions.sessionApproval, so such an app was installed and enabled with no consent moment. Itsinstalled.jsonhas nosessionApprovalConsentPendingkey. After the upgrade the new parser reads the flag as granted, the record saysenabled: true, andapp_can_manage_session_approvalsreturns True. The two widen gates (update_app,register_external_app) never fire, because the manifest did not change; only the parser did.Why it matters
The session-control grant lets an app approve or deny tool calls in the user's own sessions. A grant nobody consented to is a trust-boundary hole for every user who upgrades with such an app installed.
Not a goal
api/eventsgrants on update (Re-consent when an app update widens any live-enforced permission (api, events, sessionApproval) #11212).kirocrew app enable(CLI: kirocrew app enable needs a consent path for permissions.sessionApproval #11423).What changed (motivation → approach → change)
Symptom: a pre-feature install that declares
sessionApprovalholds the grant with no consent. Cause: every record this host writes carriessessionApprovalConsentPending(to_dictkeeps every bool), but a record from the older host has no key, and the reader defaulted that to "not pending".The refusal lives on the read side, so the grant is never live, before or after start-up:
_read_installed(manager_records.py) marks a record pending when the key is absent AND the live manifest declaressessionApproval. Absence is only ever read toward "pending", never toward "consented".app_can_manage_session_approvals(permissions.py) decides from one manifest read and one record read: it passes the manifest that showed the grant into_read_installed(..., manifest=), so a second manifest read cannot clear "pending". It refuses a pending, disabled or unreadable record; the later enablement read can only refuse. Three route-test fixtures that fake an enabled app (test_app_route_trust_gate.py,test_dashboard_session_meta.py,test_dashboard_sessions_named.py) now also fake its record._write_installed(manager_records.py) judges the record on disk, not the caller's copy: it never turns one with no consent key, or one already pending, into "no consent needed" unless the write isenable_app's consent write (session_approval_consent=True), the live manifest is readable and does not declare the grant, and with no manifest at all it leaves a missing consent key missing rather than writing "no consent needed". So no save path (disable, an unreadable manifest, an early update, a race) records a consent that was not given.update_app(manager_install.py) reads the record against its one old-manifest read, since the replacement record lands in a new tree. A failedregister_external_app(manager_external.py) restores the record's prior bytes, so its rollback cannot add a consent key.docs/system-specs/modules/app-kit-platform.mddescribes the key-less rule, the writer rule and the post-readiness reconcile.The persisted reconcile runs after readiness, off the event loop, so boot does no new work (
no-new-work-on-gateway-boot-path):manager_activation.py:session_approval_consent_candidates()lists such records, plus any that read both enabled and pending (a key-less record another writer saved first), read-only.mark_session_approval_consent_pending(name)re-checks one record on disk, writesenabled=False, sessionApprovalConsentPending=Trueand auditssession_approval_widenedwith callerapp_boot. The write adds the key, so each record is handled once; a record uninstalled or consented since the listing is left alone.apps/session_consent.py:reconcile_after_ready()handles each candidate underapp_lifecycle_lock(name), so no install, update, uninstall, enable or disable of that app interleaves. Under the lock it re-checks the record and runs the disable route's bounded startup-hook preflight; a still-running hook defers the app to the next start. For an enabled app it then runsteardown_app_runtime, the same teardown the disable route runs, so boot-started backends, hooks and gateway-owned registrations stop. Then it marks the record, and rebuilds the agent spec once if anything changed. It never raises.run()(service_boot.py) starts it as a trackedasyncio.create_taskright after theKIROCREW_READYprint, beside the checkout warning, and skips it in test mode like that neighbour. File work runs inasyncio.to_thread.The user re-enables through the existing disclosure surface (
enable_app(..., session_approval_consent=True)), the same path a fresh install uses.Backwards compatibility
Compatible: records written by this host always carry the key and are read exactly as before; only a key-less record whose manifest declares
sessionApprovalchanges.The diff disables such an app just after start-up, so it takes away its enabled state. Readers of that state and of the pending flag:
Reader: src/kiro_crew/apps/permissions.py:app_can_manage_session_approvals -- app -- refuses while pending; test_boot_disables_and_marks_pending_until_consent
Reader: src/kiro_crew/apps/manager_activation.py:enable_app -- crew page -- requires session_approval_consent while pending; test_disabled_pre_feature_record_still_needs_consent
Reader: src/kiro_crew/apps/routes.py:_app_may_run_after_install -- crew page -- a pending app's resources do not start, the same as after a widening update
Reader: src/kiro_crew/apps/manager_lookup.py:is_app_enabled -- app -- reads the persisted
enabled: false; test_boot_disables_and_marks_pending_until_consentReader: src/kiro_crew/apps/manager_lookup.py:list_apps -- crew page -- shows
sessionApprovalConsentPending: true, so the app page offers the consent step; test_grant_is_refused_before_boot_reconcilesTests
test/test_app_session_approval_preconsent.pywrites a pre-featureinstalled.json(no key) beside a manifest that declaressessionApproval:test_grant_is_refused_before_boot_reconciles: grant refused and record reads pending before start-up runs.test_boot_disables_and_marks_pending_until_consent: the post-readiness step disables the app, persists pending, auditsapp_boot/session_approval_widened; plain enable is refused; enable with consent restores the grant; a second run leaves it alone.test_boot_rebuilds_the_agent_spec_only_when_it_disabled_an_app: the step rebuilds the spec once after disabling an app, and not when nothing changed.test_a_failed_spec_rebuild_keeps_the_app_disabled: a failing rebuild does not undo the disable.test_a_later_manifest_read_cannot_clear_pending: manifest reads of granted, missing, granted still refuse.test_first_run_setup_leaves_the_scan_to_after_readiness:run_first_run_setup(before readiness) does not touch the record; the grant is still refused.test_gateway_schedules_the_reconcile_after_readiness:run()schedules the step after theKIROCREW_READYprint, and_init_servicesdoes not.test_boot_stops_a_running_app_before_marking_it: teardown runs while the record still reads enabled.test_boot_skips_teardown_for_an_app_already_off: no teardown for a disabled record, which still needs consent.test_an_uninstall_holding_the_lock_is_not_undone: with the app's lifecycle lock held, the reconcile waits; an uninstall inside the lock is not undone and nothing is torn down.test_an_app_consented_while_waiting_is_not_torn_downandtest_a_stuck_startup_hook_defers_the_app: the under-lock re-check and the bounded preflight.test_consent_on_an_enabled_pre_feature_record_is_written:enable_app(..., session_approval_consent=True)on an enabled key-less record writes the consent instead of answering "already enabled" (manager_activation.py).test_a_pending_record_saved_before_boot_is_still_disabled: a key-less record that another writer saved (now enabled and pending) is still torn down and disabled; the candidate check selects that shape too.test_a_save_with_a_broken_manifest_keeps_consent_needed: a key-less app with a brokenapp.jsonis disabled; after the manifest is fixed, a plain enable still asks for consent and the grant stays refused until consent.test_a_save_of_a_no_grant_record_records_no_consent_step: an app without the grant is not made to ask.test_a_stale_copy_written_back_cannot_clear_pending_on_disk: a stale copy saved over a pending record keeps it pending until a consent write.test_an_update_after_a_failed_manifest_read_keeps_consent_neededandtest_a_failed_reregistration_restores_the_key_less_record: a manifest read that fails once cannot let an update or a rolled-back re-registration record "no consent needed".test_marking_an_uninstalled_app_recreates_nothingandtest_marking_a_consented_app_leaves_it_alone: the per-record re-check.test_app_permissions.py::test_unreadable_record_is_denied_even_when_enabled_reads_true: a record read that fails is a refusal, even if the enabled read says yes.test_pre_feature_app_without_the_grant_is_untouchedandtest_record_with_the_key_is_trusted_as_written: no change for apps without the grant or for records this host wrote.Each fix was proven by neutering it: the read-side check (grant tests fail), the manifest pass-through, the lifecycle lock (race test fails) and the teardown branch (teardown test fails). Determinism: the file passed 10/10 repeated runs and in reversed test order; the two race tests wait on the lock's waiter list through
async_wait_untiland on the task throughawait_until, both bounded by the runner's budget. The tests use no wall clock or network; waits use the repo's boundedkiro_crew.testing.waithelpers.Manual verification
N/A — the post-readiness step and the read check are covered on a real temp data home by the tests above; there is no UI change.
Related Issues
Closes #11447
Follow-up: #22118 — serialize
installed.jsonwriters so a stale save (for example a dev-mode toggle) cannot undo asessionApprovalconsent-pending mark. That race is already on main; this PR does not widen it.Pattern harvest
Not generalizable: the defect is specific to one record field added after installs existed; the fix reads its absence fail-closed at the one reader.
Checklist