Skip to content

fix(startup): avoid portal re-entry during file manager activation - #1811

Merged
l0gicgate merged 3 commits into
lgse:mainfrom
zhufengme:fix/1810-file-manager-portal-startup
Oct 23, 2026
Merged

l0gicgate merged 3 commits into
lgse:mainfrom
zhufengme:fix/1810-file-manager-portal-startup

Conversation

@zhufengme

Copy link
Copy Markdown
Contributor

Description

Avoid the circular portal wait during cold FileManager1 activation by adding
no-portals to GDK_DEBUG before GTK initialization for
--gapplication-service. Reuse the existing safe re-exec path, preserve other
debug flags (including non-UTF-8 bytes), and stop interpreting options after
--. Normal application launches, helper modes and the FileChooser backend do
not acquire this override.

With xdg-desktop-portal 1.22.1, OpenDirectory synchronously waits for ShowItems.
GTK can synchronously query that same portal's host registry before Strata's
FileManager1 interface is ready, producing a roughly 25-second circular wait.
Moving the reply earlier in the ShowItems handler would not fix this startup
ordering problem.

This deliberately scoped compatibility mitigation disables GTK portal use for
the lifetime of the service-activated process. It does not make the desktop
portal's dispatch asynchronous; that remains the preferable upstream fix.
The packaging documentation records the tradeoff.

Visual evidence

N/A — startup responsiveness and D-Bus behavior; no visual layout changes.

How to test

  1. On a desktop using GTK 4.24.1 and xdg-desktop-portal 1.22.1, configure the
    FileManager1 activation service to execute the built Strata binary with
    --gapplication-service. Remove any external GDK_DEBUG=no-portals
    workaround so this exercises the application fix.
  2. Close the main Strata process, then click Show in folder beside a Chromium
    download. The cold-start case is essential: an already-running Strata
    process does not exercise GTK initialization.
  3. Confirm Strata opens promptly and the portal journal has no
    Failed to call ShowItems timeout. Repeat with Strata already running.
  4. Launch Strata normally and use the separate FileChooser portal backend;
    neither launch should acquire this FileManager1-specific override.

Expected result: Cold and warm reveals succeed without the 25-second
stall, and other portal consumers remain responsive.

Related issue

Closes #1810

@zhufengme

Copy link
Copy Markdown
Contributor Author

Local validation and scope

The change is confined to the FileManager1 activation launch path, but it shares
the existing GTK environment re-exec helper. I therefore ran the full Rust and
GUI suites, including the existing FileManager1 reveal, normal startup and
FileChooser scenarios. No existing QA scenario exercises a D-Bus cold activation
before GTK has initialized, so those scenarios alone are not evidence for the
reported deadlock.

Environment: the project's verified pinned test image,
sha256:d8bf7eb45b87a52921d41f7fa734eee167180f8ab2d4f2d734347df6d06e8d13.
Docker was explicitly authorized by the reporter and invoked through a local
pkexec docker wrapper. GUI checks used private Xvfb and private D-Bus; the
desktop bus/display were not used for source-build validation.

  • STRATA_CONTAINER_ENGINE=<authorized-docker-wrapper> ./scripts/quality.sh test:
    3,484 Rust tests passed, 11 ignored by the existing suite; 27 QA harness unit
    tests passed. GUI scenarios were intentionally not executed by this command.
  • After correcting an empty GDK_DEBUG value's leading separator,
    python3 scripts/test-headless.py tests::file_manager_activation selected and
    passed both new regressions. The full earlier Rust suite was not repeated for
    that bounded correction.
  • STRATA_CONTAINER_ENGINE=<authorized-docker-wrapper> ./scripts/qa.sh:
    564 passed, 0 failed, 0 ignored on the corrected implementation.
  • Final pre-push ./scripts/quality.sh fmt and ./scripts/quality.sh clippy
    both passed in the same pinned container (Clippy uses all targets/features
    and treats warnings as errors).
  • A separate isolated cold-activation probe owned
    org.freedesktop.portal.Desktop and synchronously called ShowItems without
    dispatching callbacks, reproducing the caller-side blocking condition. The
    D-Bus activation entry invoked the built binary with only
    --gapplication-service; no external no-portals override was supplied.
    The corrected binary replied successfully in 0.415 seconds and presented
    its window in 319 ms. The container uses GTK 4.22.5; the original real
    desktop reproduction used GTK 4.24.1 and xdg-desktop-portal 1.22.1.

The original desktop reproduction and successful local service-entry workaround
are recorded in #1810. The source-built binary was validated in isolation, not
installed over the reporter's desktop executable. The compatibility tradeoff
(GTK portal use disabled for the service-activated process, potentially inherited
by subprocesses) remains explicit; this does not fix synchronous dispatch in
xdg-desktop-portal itself.

zhufengme and others added 2 commits October 22, 2026 08:15
The FileManager1 service restart adds no-portals to GDK_DEBUG, and every
program Strata launched afterwards inherited it. GDK's no-portals wins over
its sandbox check, so a Flatpak GTK app opened from that Strata lost its
portal file chooser and settings.

Record the original GDK_DEBUG when restarting, and restore it on the GIO
launch contexts, terminal, program, action and Settings restart commands.
@l0gicgate
l0gicgate force-pushed the fix/1810-file-manager-portal-startup branch from f3fa682 to 87b0946 Compare October 22, 2026 19:52
@github-actions github-actions Bot added the fix label Oct 22, 2026
@l0gicgate

Copy link
Copy Markdown
Contributor

Review and cleanup

Branch rebuilt on the rewritten main (c94eeb00). main was force-pushed to drop commit attribution, so this branch still carried the pre-rewrite bdf0e98c and 225e074f. I cherry-picked f3fa6825 onto the new main unchanged (authorship kept, now 198d729c) and force-pushed with a lease on f3fa6825. @zhufengme, if you have a local copy of the branch, reset it to the new head (git fetch && git reset --hard <remote>/fix/1810-file-manager-portal-startup) instead of pulling.

Review against the description and #1810.

  • The --gapplication-service launch re-execs with no-portals appended to GDK_DEBUG, and keeps the other flags, including non-UTF-8 bytes. The re-exec'd process sees no-portals and does not loop. Confirmed by tests::file_manager_activation_preserves_debug_flags_and_stops_restarting.
  • Normal launches, --portal, helper modes, and arguments after -- are untouched. Confirmed by tests::file_manager_activation_leaves_other_launches_and_literal_paths_alone. Both tests are kept: they guard the restart loop and the scope.
  • Checked by hand: under a private Xvfb and D-Bus, a cold strata --gapplication-service runs with GDK_DEBUG=no-portals (or misc:no-portals when GDK_DEBUG=misc).

Fixes pushed

  • 87b09468 fix(startup): keep the no-portals override out of launched programs. Every program the service-activated Strata launched inherited GDK_DEBUG=no-portals for the rest of that process's life. GDK's no-portals takes precedence over its sandbox check, so a Flatpak GTK app opened from Strata after a cold Show in folder lost its portal file chooser and settings. The restart now records the original value in STRATA_ORIGINAL_GDK_DEBUG. The new child_environment module restores it on:

    • the GIO launch contexts (Open With, default apps, context menu, web links, the AUR page),
    • terminal and Omarchy presentation commands,
    • executable and .sh launches, file actions,
    • the Settings restart, which starts a plain launch.

    docs/packaging.md now describes this instead of the inheritance tradeoff. The restart also passes the computed value through instead of computing it twice. New tests: child_environment::tests::launched_commands_see_the_original_gdk_debug (spawns a real child) and child_environment::tests::launch_contexts_pass_the_original_gdk_debug.

Validation

  • ./scripts/test-headless.py -- child_environment:: tests::file_manager_activation ui::terminal:: adapters::local_jobs:: ui::settings::tests::restart ui::browser::desktop ui::open_with: 49 passed, 0 failed
  • cargo fmt --all --check and cargo clippy --all-targets --all-features -- -D warnings (native): clean
  • Not run: qa.sh. No QA scenario exercises D-Bus cold activation, and the other changes only touch the environment given to launched programs.

CI: all checks green as of 20:09 UTC on 87b09468 (QA scenarios skipped: manual-dispatch only).

@zhufengme

Copy link
Copy Markdown
Contributor Author

Thanks for the cleanup and for addressing the inherited environment. I reviewed 87b0946; restoring the original value at the launch boundaries is a useful improvement over the documented tradeoff in my initial patch.

One remaining launch boundary appears to be src/services/file_providers/transport.rs, in run() → spawn: the provider is still created with Command::new(&manifest.command[0]) ... .spawn() without child_environment::restore_command. This gives third-party providers both the added GDK_DEBUG=no-portals and the internal STRATA_ORIGINAL_GDK_DEBUG marker. Providers can launch applications themselves: the bundled integrations/localsend/provider.py, LocalSend.open(), uses subprocess.Popen with the inherited environment. The covered file-action path in adapters/local_jobs.rs is separate from this provider transport.

Suggested follow-up: restore the environment on the provider command before spawning it, and exercise a real provider (or a provider fixture that launches a child) to verify the original debug flags reach the child and the internal marker does not. This is a static-review finding; the inheritance path is present, but I have not reproduced a user-visible LocalSend failure.

A second useful follow-up is to promote the isolated cold-activation probe into a maintained regression: own the portal name on a private bus, synchronously call FileManager1 without dispatching callbacks, activate Strata from its service entry without an external no-portals override, and require a successful response within a short deadline. The parameter-policy tests and warm FileManager1 QA scenario do not exercise that startup ordering. My earlier full QA results apply to the initial patch, not to the new child-environment changes; the current CI Rust results are green and the QA job is skipped, as noted above.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix(startup): avoid circular portal wait during FileManager1 cold activation

2 participants