Skip to content

[Bug]: ReexecOnHost fails with "Portal call failed" when devsy runs from a Flatpak sandbox cwd that does not exist on the host #1836

Closed

Description

@DarkGhostHunter

Before submitting

  • I have searched existing issues to confirm this is not a duplicate
  • I am running the latest version of Devsy

What happened?

When devsy runs inside another application's Flatpak sandbox (not Devsy's own sh.devsy.app), ReexecOnHost() in pkg/flatpak/flatpak.go re-executes the command on the host with flatpak-spawn --host <host-binary> ... and no --directory. flatpak-spawn then asks the portal to start the host process in the caller's working directory. If that directory exists only inside the sandbox, the portal fails and devsy exits 1 before doing anything.

Real-world trigger: Claude Desktop (Flatpak com.anthropic.ClaudeDesktop) connects to a dev container through the SSH host that Devsy writes to ~/.ssh/config:

Host <workspace>.devsy
  ProxyCommand "/tmp/.mount_Devsy.../resources/bin/devsy" workspace ssh --stdio --context default --user vscode <workspace> --workdir "/workspaces/<workspace>"

The app's launcher does cd /app/extra/claude-desktop (a path that exists only inside that Flatpak) and then runs ssh, which runs the ProxyCommand, which runs devsy. devsy sees /.flatpak-info, takes the re-exec path, and the portal call fails. The app sees only ssh: Connection closed by UNKNOWN port 65535.

The same ssh <workspace>.devsy from a normal host shell works. Running ssh inside the sandbox from a directory that exists on the host (for example /tmp) also works.

What did you expect to happen instead?

devsy should start the host process in a directory that exists on the host (for example $HOME), or skip the re-exec when it is not running inside Devsy's own Flatpak. The ProxyCommand should connect to the dev container.

Steps to reproduce

From inside any Flatpak sandbox that has /tmp shared with the host (so the Devsy AppImage mount is visible) and a working directory that exists only in the sandbox:

  1. Use a workspace created with a Docker/Podman provider and let Devsy write its SSH host entry.
  2. Inside the sandbox: cd /app/extra/claude-desktop (any sandbox-only directory works).
  3. Run devsy workspace ssh --stdio --context default --user vscode <workspace> --debug
    (or ssh <workspace>.devsy true).
  4. See the error below.

Minimal check of the portal behaviour, without Devsy:

cd /app/extra/claude-desktop
flatpak-spawn --host true

devcontainer.json

No response

Error output / logs

{"level":"debug","msg":"re-executing on host via flatpak-spawn: args=[workspace ssh --stdio --context default --user vscode <workspace> --debug]"}
Portal call failed: Failed to start command: Falló al cambiar a la carpeta «/app/extra/claude-desktop» (No existe el fichero o el directorio)
{"kind":"error","outcome":"error","code":"UNKNOWN","message":"command failed with exit code 1"}

From the SSH client (ssh -vv):

debug1: Executing proxy command: exec "/tmp/.mount_Devsy.../resources/bin/devsy" workspace ssh --stdio ...
Portal call failed: Failed to start command: Falló al cambiar a la carpeta «/app/extra/claude-desktop» ...
Connection closed by UNKNOWN port 65535

How often does this happen?

Every time

Operating system

Linux

Linux distribution (if applicable)

Bluefin (Fedora 44 Silverblue base), kernel 7.x

Architecture

AMD64

Desktop app or CLI?

CLI only

Devsy version

v1.24.0

Devsy provider

Docker

Provider version

Podman provider (PODMAN_PATH=podman)

Screenshots

No response

Anything else?

Suggested fix in pkg/flatpak/flatpak.go:

  1. Pass a valid directory to flatpak-spawn. Use --directory=$HOME, or the current directory only if it exists on the host. This is a one-line change to spawnArgs.
  2. Only re-execute when running inside Devsy's own Flatpak. InSandbox() only checks that /.flatpak-info exists, so it is also true in any other app's sandbox. Compare the name= key in /.flatpak-info with sh.devsy.app.
  3. Optionally, retry once with --directory=$HOME if the portal call fails on the directory.

Workaround until fixed: make the ProxyCommand change to a host-valid directory first. ssh adds its own exec, so the cd has to be inside sh -c:

ProxyCommand sh -c 'cd "$HOME" && exec /tmp/.mount_Devsy.../resources/bin/devsy workspace ssh --stdio --context default --user vscode <workspace> --workdir /workspaces/<workspace>'

I tested this from /app/extra/claude-desktop and it connects. Devsy owns the # Devsy Start/End block in ~/.ssh/config, so the edit is lost when Devsy rewrites it. The /tmp/.mount_... path in that block also changes on every AppImage start.

Related, but a different bug: #634 (closed).

Activity

  1. skevetter commented on Nov 13, 2026

    @skevetter
    Contributor

    OpenSpec change: flatpak-host-spawn-directory

    Classification: bug, code change required.

    proposal.md

    Why

    ReexecOnHost in pkg/flatpak/flatpak.go runs flatpak-spawn --host <binary> <args> without --directory. The portal starts the host process in the caller's working directory. When devsy runs inside another application's Flatpak sandbox and the working directory exists only in that sandbox (for example /app/extra/claude-desktop), the portal fails with "Failed to start command" and devsy exits 1 before doing any work.

    Root cause

    flatpak-spawn forwards the sandbox cwd to the host portal. Sandbox-only paths do not exist on the host. cmd.Dir is unset and no --directory flag is passed.

    What changes

    • ReexecOnHost passes --directory=<dir> to flatpak-spawn.
    • <dir> is the current working directory unless it lies under /app (a path that exists only inside a sandbox). In that case <dir> is $HOME.
    • If the working directory cannot be read, $HOME is used. If $HOME is empty the flag is omitted.

    Out of scope

    Restricting re-exec to Devsy's own Flatpak (sh.devsy.app). Re-exec is also needed from other apps' sandboxes to reach the host container runtime. A retry on portal failure.

    design.md

    Relative path arguments (for example devsy up .) keep their meaning because the real cwd is forwarded whenever it can exist on the host. Only sandbox-only roots fall back to $HOME. The directory choice is a pure function so it is unit tested without a Flatpak runtime.

    tasks.md

    1. Implementation

    • 1.1 Add hostSpawnDirectory(cwd, home string) string in pkg/flatpak/flatpak.go
    • 1.2 Insert --directory=<dir> before --host args in ReexecOnHost

    2. Tests

    • 2.1 Unit test hostSpawnDirectory for host-visible cwd, /app cwd, /app/x cwd, /application cwd, empty cwd, empty home
    • 2.2 Unit test the spawn argument builder
    specs/flatpak-host-reexec/spec.md

    ADDED Requirements

    Requirement: Host re-exec uses a host-valid working directory

    ReexecOnHost SHALL start the host process in a directory that exists on the host.

    Scenario: Working directory exists on the host

    • WHEN the cwd is /home/user/project
    • THEN flatpak-spawn is invoked with --directory=/home/user/project

    Scenario: Working directory exists only in the sandbox

    • WHEN the cwd is /app/extra/claude-desktop or /app
    • THEN flatpak-spawn is invoked with --directory=$HOME

    Scenario: Path prefix is not a sandbox root

    • WHEN the cwd is /application/data
    • THEN the cwd is kept

    Scenario: No usable directory

    • WHEN the cwd is unreadable and $HOME is empty
    • THEN no --directory flag is passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions