Repository navigation
fix(dashboard): restore the file manager under the installed Linux service - #30083
Conversation
bolichen97
left a comment
There was a problem hiding this comment.
Requesting changes on 5cda130 for one blocking point. CI is still starting on this head, and I read the whole change.
platform_compat_trust.py, _DESKTOP_SESSION_VALUES
The PR adds import re and four compiled patterns (DISPLAY, WAYLAND_DISPLAY, XAUTHORITY, XDG_CURRENT_DESKTOP). _desktop_session_from runs fullmatch on each value read from systemctl --user show-environment, and _x11_display_is_live runs it again and reads match.group(1) to build the socket path. These values come from outside the process and end up in the environment of a launched program, so a regex is the wrong tool for the check. The repo asks for exact structural checks here.
The four shapes are small enough to check directly:
DISPLAY: require a leading:, thennum, dot, screen = value[1:].partition("."). Requirenumto be ASCII digits, 1 to 4 long. Ifdotis present, requirescreento be ASCII digits, 1 to 4 long. Return the number as an int so_x11_display_is_livedoes not have to parse it again.WAYLAND_DISPLAY: length 1 to 64, the first character is a letter, digit or underscore, and every character is in a fixed set of letters, digits,_,.and-.XAUTHORITY: starts with/, length 2 to 1024, every character in the set of letters, digits,_,.,+,/and-, and no..part (you already check that).XDG_CURRENT_DESKTOP:value.split(":")gives 1 to 8 parts, each 1 to 64 characters from letters, digits,_and-.
Use str.isascii() with isdigit() for the numbers, since isdigit() alone accepts non-ASCII digits. The existing tests for good and bad values should pass unchanged, and a case with a non-ASCII digit, a trailing newline and a ninth desktop part would pin the edges.
I have not done the full trust review of the part that reads the user's systemd manager and copies session variables into the launcher environment. I will do it on the next head once the parsing no longer uses a regex.
UX Review (Opus 5.5, fork) — ⏭️ skippedRevision |
First Principles Review (Opus 5.5, fork) — ✅ PASSPremise-level review of First-Principles-Verdict: PASS Restores the reveal/open actions that #23019 hid from the installed service (tracked in #30026). The one premise nobody has checked is KDE support. Notes
What this change shipsInventory (9 items) — 7 justifiedIntent: Linux desktop users running the installed service get "Show in file manager" and "Open with default app" back while they are logged in. This is a FIX.
[FIRST-PRINCIPLES-REVIEWED] ebfce65 Description read[DESCRIPTION-READ] 908eccae981170ab79402e329c9f80039ea74f475854681c2947c167519e0762 That sha256 names the PR description this verdict read. Recompute it with |
Design Review (Opus 5.5, fork) — ✅ PASSDesign-level review of Design-Verdict: PASS No design-level concerns: the fix asks the user's systemd manager only when the gateway's own environment has no display, reusing the existing Notes
[DESIGN-REVIEWED] ebfce65 Description read[DESCRIPTION-READ] 6f2dcf7b48b220f087095e084dd729d73ec04e477f34ee4bbb979087beb27eb1 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 |
Opus 5.5 Review (fork) — ✅ no blocking findingsReviewed Review detailsNo findings. None of the four candidates holds up against the diff and the repository code. [OPUS-REVIEWED] ebfce65 |
GPT 6.1 Review (fork) — ✅ no blocking findingsReviewed Review detailsNo findings. |
5cda130 to
39d5482
Compare
|
self-added: yes
|
|
On the review of 5cda130: the session parsing in 39d5482 uses no regular expression. Each value has a plain check with the rules you gave, in Two other changes on this head:
This host is headless, so no real GNOME login was captured: no |
…rvice The installed Linux service is a system unit, so the gateway's own environment never names a display server. Since kirodotdev#23019 that hid "Show in file manager" and "Open with default app" on every Linux desktop running the service, including GNOME, where xdg-open used to reach Nautilus over the session bus. When the gateway's own environment names no display, ask the user's systemd manager (`systemctl --user show-environment`, 2 s timeout, answer kept for 30 s), run with the environment `systemctl_user_env` gives every `systemctl --user` spawn. Copy only DISPLAY, WAYLAND_DISPLAY, XAUTHORITY, XDG_CURRENT_DESKTOP and KDE_SESSION_VERSION, each passing a plain character check, and count a display only while its socket exists, checked again on every use of a kept answer. The launcher gets them on top of the same session-bus pointers. A reachable session bus alone is not a desktop, so a headless host stays hidden and refused. The open action asks before its stat-and-launch transaction, so no spawn lands inside it. Closes kirodotdev#30026
bolichen97
left a comment
There was a problem hiding this comment.
Thanks, the regexes are gone and the checks are explicit now. One blocking point is left at 39d5482, and the First Principles Review check is red on it. I checked it against main, and it is more than a duplicate: it likely breaks the case this PR is for.
platform_compat_trust.py, _user_manager_environment
The new spawn runs systemctl --user show-environment with env = dict(os.environ) and only PATH pinned. Main already has systemctl_user_env() in service/common.py, which every other systemctl --user spawn in the codebase uses (the pod runtime, the service verbs, the gateway restart). Its docstring explains why: a process started from a systemd system unit, which is how the installed Linux service runs the gateway, inherits neither XDG_RUNTIME_DIR nor DBUS_SESSION_BUS_ADDRESS, so a bare systemctl --user fails with "Failed to connect to bus: No medium found" even though the user manager is running. That is exactly the situation this PR targets (the installed service, no login environment). With the PR's environment the call is likely to return a non-zero exit, the answer becomes "no session", and the actions stay hidden. The tests mock the spawn, so they would not show it.
Suggested fix: build the child environment with systemctl_user_env() and then pin PATH as you do now. That removes the second copy, and the bus pointers are filled in only when the bus socket exists. Add a test that the spawned environment carries those pointers when the gateway's own environment has none (for example by patching session_runtime_dir).
The rest reads fine to me after the trust review: fixed argv, trusted binary path, timeout, checked values for five keys only, and every failure ends as "no session". GPT 6.1 reports no blocking findings on this head. I will approve once the spawn uses the shared environment helper.
39d5482 to
ebfce65
Compare
|
self-added: yes
|
|
Changes since 39d5482, now in ebfce65 (rebased onto main 3736af2, still one commit). They answer the First Principles lane's finding that the
|
bolichen97
left a comment
There was a problem hiding this comment.
Approving ebfce65. Both blocking points from my earlier reviews are fixed on this head.
[Security: this change reads the user's systemd manager environment to find a live desktop session and copies five checked variables into the environment of a file manager launch. It refuses nothing that works today and adds no new restriction. The input is parsed with exact checks and every failure ends as "no session", as below.]
What I checked on this head:
- Every check passes except PR Readiness, which is still running. The checks that showed as cancelled have newer passing runs. The fork review lanes (Design, First Principles, Opus 5.5, GPT 6.1, Security Scope, Internal Content Scan) all pass or report no blocking findings on this exact head.
- The four regexes are gone. The session values are checked with explicit rules: a local display number of 1 to 4 ASCII digits with an optional screen, a Wayland socket name (never a path), an X cookie path with no
..part, one to eight desktop names, and a one or two digit Plasma version. No pattern is added. - The
systemctl --user show-environmentspawn now builds its environment withsystemctl_user_env()fromservice/common.py, the helper every othersystemctl --usercall uses, so the session bus pointers are present under the installed system service. The tests check that environment. - Trust review: the argv is fixed, the binary comes from the trusted directories, no shell is involved, the call has a 2 second timeout and a short cache, and only five named keys are read. A display counts only while its socket exists, so a finished login names no session, and a headless host stays at "no actions offered". Values from the manager are only used when the gateway's own environment names no display, so a gateway started inside the desktop login behaves as before. The values only reach the launcher environment, never a shell or the request.
…rvice (#30083) The installed Linux service is a system unit, so the gateway's own environment never names a display server. Since #23019 that hid "Show in file manager" and "Open with default app" on every Linux desktop running the service, including GNOME, where xdg-open used to reach Nautilus over the session bus. When the gateway's own environment names no display, ask the user's systemd manager (`systemctl --user show-environment`, 2 s timeout, answer kept for 30 s), run with the environment `systemctl_user_env` gives every `systemctl --user` spawn. Copy only DISPLAY, WAYLAND_DISPLAY, XAUTHORITY, XDG_CURRENT_DESKTOP and KDE_SESSION_VERSION, each passing a plain character check, and count a display only while its socket exists, checked again on every use of a kept answer. The launcher gets them on top of the same session-bus pointers. A reachable session bus alone is not a desktop, so a headless host stays hidden and refused. The open action asks before its stat-and-launch transaction, so no spawn lands inside it. Closes #30026 (cherry picked from commit 1b8a195)
Problem / Motivation
Goal: On a Linux desktop where Kiro Crew runs as the installed service, the dashboard offers "Show in file manager" and "Open with default app" again while a desktop login is live, and a headless host still does not get them.
Since #23019 the dashboard offers those two actions only when the gateway's own environment names a display server (
DISPLAYorWAYLAND_DISPLAY). The installed Linux service is a system unit, and its environment never names one. So on every Linux desktop running the service, both actions are hidden and a reveal answers with a clipboard copy. On GNOME they worked before #23019:xdg-openfound GNOME through the session bus and rangio open. The review hold on #23019 raised this, and #30026 tracks it.Why it matters
Linux desktop users who run the gateway as the installed service lose both actions on every path chip, file view and folder panel, and get the copy fallback instead. #23019 is in v0.12.0-rc.1 through v0.12.0-rc.6, so the stable v0.12.0 would ship the loss.
Not a goal
apps/routes_enable.py), which Linux service install: an app's Open says Kiro Crew is running remotely on a desktop host #30068 tracks.What changed (motivation → approach → change)
"Show in file manager" and "Open with default app" now follow whether a desktop login is live on the host, not whether the gateway itself was started inside it:
xdg-openinstalledxdg-opengets the login's displayWhen the gateway's own environment names no display server,
desktop_launcher_available()asks the user's systemd manager, which a desktop login fills in. It runssystemctl --user show-environmentfrom the trusted system directories, with a fixed argv, no shell and a 2-second timeout, and with the environmentservice.common.systemctl_user_envgives everysystemctl --userspawn, which fills in the session-bus pointers a unit can lack. The answer is kept for 30 seconds, so a login after the gateway started shows up without a restart.Only
DISPLAY,WAYLAND_DISPLAY,XAUTHORITY,XDG_CURRENT_DESKTOPandKDE_SESSION_VERSIONare read. Each passes a plain character check for its kind, with no regular expression: a local:Ndisplay, a socket name, an absolute path, desktop names, a one- or two-digit Plasma version. A display counts only while its socket exists (a Wayland name is looked up under the runtime directoryservice.common.session_runtime_dirresolves), checked again each time a kept answer is used, so a manager still holding a finished login's variables names no session and a logout is seen at once. A reachable session bus alone is never a desktop, which keeps the headless host #23019 fixed hidden and refused.The launchers pass those values to
xdg-openas environment entries, on top of the same session-bus pointers, so a Wayland name resolves where the check found it. The open action asks before its stat-and-launch transaction, so the lookup never runs between the stat and the launch.KDE and XFCE probably failed under the service before #23019 too. Without
XDG_CURRENT_DESKTOPor a display variable,xdg-openfinds no opener for them, so the reveal fell back to the clipboard. With this change they get the login's variables wherever their login exports them to the systemd manager. On KDE that includesKDE_SESSION_VERSION, whichxdg-openneeds to pickkde-open5orkde-openover Konqueror'skfmclient. That is not verified on a desktop here.The dashboard spec (
docs/system-specs/modules/learn-cron-dashboard.md) describes the lookup. The spawn audit lists the new spawn, and the facade (kiro_crew/platform_compat.py) lists the new names.Backwards compatibility
Compatible: nothing is renamed, removed or narrowed.
desktop_launcher_available()answersTruein one more case: no display of its own, and a live desktop session in the user's systemd manager. Only then do the launchers get up to five checked variables, on top of the session-bus pointerssystemctl_user_envfills in. One visible side effect:kirocrew openrun over SSH on a Linux desktop now opens the desktop app on that desktop, asopendoes on macOS.Removes nothing: the change only adds a case where the host answers that it can open a file manager. Every case that answered
Truestill does, and the headless cases still answerFalse.Tests
Red on main's code and green here:
test/test_reveal_in_file_manager.py::TestDesktopSessionFromTheUserManager::test_a_wayland_login_reaches_the_launcher: the manager'sWAYLAND_DISPLAYandXDG_CURRENT_DESKTOPreachxdg-open. Nothing outside the allowlist does, andPATHstays pinned....::test_an_x11_login_brings_its_cookie_to_the_default_app:DISPLAYandXAUTHORITYreach the open launcher....::test_a_plasma_login_brings_its_session_version: on a Plasma login,KDE_SESSION_VERSIONreachesxdg-openwithXDG_CURRENT_DESKTOP....::test_the_longest_accepted_values_pass: a display with a screen (:12.3), eight desktop names and a two-digit Plasma version are all copied....::test_a_malformed_companion_variable_is_left_out(9 cases): a badXAUTHORITY,XDG_CURRENT_DESKTOPorKDE_SESSION_VERSIONis dropped, including a ninth desktop name, a trailing newline and a non-ASCII digit, and the live display still launches....::test_the_answer_is_kept_briefly_then_asked_again: a second ask within 30 seconds reuses the answer without a second lookup, and after 30 seconds a new login is seen....::test_a_logout_is_seen_on_a_kept_answer: once the display's socket is gone, a kept answer names no session, so a click right after a logout copies the path. No second lookup runs....::test_a_unit_without_session_pointers_still_reaches_a_wayland_login: with noXDG_RUNTIME_DIRor bus address in the gateway's environment, the login's Wayland socket is found under the directorysession_runtime_dirresolves, andxdg-opengets that directory and the bus with the display. Also red on the previous head's code.test/test_reveal_in_file_manager.py::TestUserManagerLookup::test_it_runs_one_fixed_argv_with_a_timeoutand::test_no_answer_is_no_session(4 cases: nosystemctl, a timeout, a refused spawn, a non-zero exit)....::test_it_gets_the_session_bus_a_unit_can_lack: the lookup's environment issystemctl_user_env's, so the filled-inXDG_RUNTIME_DIRandDBUS_SESSION_BUS_ADDRESSreachsystemctl, withPATHpinned. Also red on the previous head's code.test/test_dashboard_branding.py::TestBrandingEndpoint::test_branding_says_a_linux_host_needs_a_desktop_session[service-under-a-desktop-login]: the whole chain to the branding payload.test/test_dashboard_files_onloop_fs.py::TestBrowseAndReveal::test_the_desktop_question_is_asked_before_the_stat_and_launch: the order is ask, stat, launch, and the ask runs off the loop and outside the probe pool.Guards, green on main and here:
test_a_headless_host_stays_hidden_and_refused(the manager answers with a session bus and no display),test_no_user_manager_stays_hidden_and_refused,test_a_display_whose_server_is_gone_is_not_a_session,test_a_malformed_display_is_not_a_session(10 cases: another machine's display, shell text, systemctl's$'...'quoting, an empty value, a non-ASCII digit, a trailing newline, a path, a..name, a quoted name, a name with a newline),test_the_gateway_s_own_display_is_used_without_asking(nothing is asked or filled in, not even a bus it could find),test_macos_never_asks, and the branding cases[headless],[headless-with-a-user-bus]and[desktop-session].The existing tests in
TestRevealInFileManagerand the branding chain test now start with no user manager to ask, so a developer's own desktop login cannot decide a headless test.Proof: PROVEN test/test_dashboard_branding.py::TestBrandingEndpoint::test_branding_says_a_linux_host_needs_a_desktop_session[service-under-a-desktop-login], test/test_dashboard_files_onloop_fs.py::TestBrowseAndReveal::test_the_desktop_question_is_asked_before_the_stat_and_launch, test/test_platform_compat_refactor_facade.py::test_every_moved_name_is_defined_by_its_owner_and_read_through_the_facade[kiro_crew.platform_compat_trust-_ASCII_ALNUM], test/test_platform_compat_refactor_facade.py::test_every_moved_name_is_defined_by_its_owner_and_read_through_the_facade[kiro_crew.platform_compat_trust-_WAYLAND_NAME_CHARS], test/test_platform_compat_refactor_facade.py::test_every_moved_name_is_defined_by_its_owner_and_read_through_the_facade[kiro_crew.platform_compat_trust-_XAUTHORITY_CHARS] (head ebfce65)
Determinism: the 140 new and changed node ids ran green 20 of 20 times at
-n0, and 10 of 10 at-n 4 --dist loadgroup --max-worker-restart=2besidetest/test_cli_open.pyandtest/test_dashboard_handlers_core_coverage.py. They were also green in a shuffled order (seed 7867).Manual verification
systemctl --user show-environmentoutput from a live login, no branding answer ofdesktop_launcher: truefrom one, and no reveal through the system unit. No KDE or XFCE login was captured either.WAYLAND_DISPLAY=wayland-0withXDG_CURRENT_DESKTOP=ubuntu:GNOME, and an emptywayland-0file stands in for its socket under a temporaryXDG_RUNTIME_DIR. An X11 login isDISPLAY=:1withXAUTHORITY=/run/user/1000/gdm/Xauthorityand anX1file in a temporary X11 socket directory. A Plasma login isXDG_CURRENT_DESKTOP=KDEwithKDE_SESSION_VERSION=5. A patchedsubprocess.Popenrecords the argv and environmentxdg-openwould get, and the branding test readsdesktop_launcherfrom the real handler with the Wayland answer.service.commononce, 16 ms here. The user manager's environment heldDBUS_SESSION_BUS_ADDRESSandXDG_RUNTIME_DIRbut no display, and the session came back empty.gates[], the repo Semgrep rules plus CI's registry packs (diff-scoped, 0 new findings), and the flake-pattern ratchet. Every gate passes except the backend related-tests gate. Its failures on this host fail the same way on a clean checkout of the base.Related Issues
Closes #30026
Related: #23019 (added the display check), #30068 (the same blind spot in an app's Open action), #16520 (which environment an app's open command should get).
Sibling sweep
Swept: git grep -nE 'environ(.get)?(?[?"(DISPLAY|WAYLAND_DISPLAY)"' -- src/kiro_crew, and the desktop launchers in src/kiro_crew/dashboard/file_api/desktop.py
Sibling: src/kiro_crew/platform_compat_trust.py:906 -- changed here
Sibling: src/kiro_crew/apps/routes_enable.py:747 -- tracked in #30068
Sibling: src/kiro_crew/cli.py:157 -- not affected -- it decides whether a gateway started from a terminal opens a browser, and the installed service always starts with --no-open
Sibling: src/kiro_crew/slack/gateway_runtime/service_boot.py:1392 -- not affected -- the same browser auto-open at gateway start, which --no-open turns off under the service
Sibling: src/kiro_crew/cloud/login.py:1202 -- not affected -- a sign-in's browser open; when it declines, the sign-in shows its URL to follow
Sibling: src/kiro_crew/cloud/connect.py:506 -- not affected -- the same sign-in browser open, which shows its URL to follow when it declines
Sibling: src/kiro_crew/dashboard/file_api/desktop.py:142 -- not affected -- the native file picker and the screenshot route are macOS only
Pattern harvest
Rule candidate: review-prompt
Pattern: a desktop-session check reads only the gateway's own environment (
DISPLAY/WAYLAND_DISPLAY), which a gateway installed as a system service never inherits.Checklist
feat|fix|docs|style|refactor|perf|test|chore|ci|build|revert: ...)Contribution License Agreement
Contributions are accepted under the project's Apache-2.0 license; see the Licensing section of CONTRIBUTING.md.