Launches that fail say why: command, exit status and what it printed
CI / test (push) Canceled after 17m11s

V: "kwi not starting from app menu or dock". Kwi is a Flatpak, and bwrap died
before it opened a window ("Can't find source path /run/user/1000/doc/by-app/
org.kde.kwi"); Chandra forked apps and forgot them, so the failure only reached
the session log and the click did nothing visible.

Every app the Applications menu, the dock, Super+1..9 and session restore start
now runs under a small monitor (sys spawn-watch, compositor/sys/sys_stub.c): it
copies the app's output to the session log as before, keeps its last 2 KiB,
and reports how sh -c CMD exited on a socket the main loop wakes on. The shell
(compositor/shell/launch.mbt) shows a red error notice for 15 s, and logs it,
when the app exits non-zero or by a signal within 30 s, or exits 0 without ever
opening a window here (after a 2 s grace for single-instance hand-offs): the
first line says what happened, then the command and the last lines it printed,
repeats folded ("(3 times)"). Status 127/126 say "command not found" / "not
executable". Launched apps no longer inherit the compositor's fds.

chandra-ctl launch ID starts a desktop app exactly as the dock does.

Tests: compositor/host/launch_test.mbt (bwrap-style failure incl. drawn notice,
127, SIGSEGV, exit 0 without a window, an app that keeps running), unit tests
in launch.mbt. Checked end to end with build/wasmhost + compositor.wasm
headless and a Flatpak-style kwi desktop file: chandra-ctl launch org.kde.kwi
shows the notice.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01DPL5hiGJWeuHiTgtoyB4kb
This commit is contained in:
Claude committed 2026-11-26 05:48:39 +00:00
1 parent 77fcc4db1c
commit 50149e6b99
18 files changed
+686 -30

No files matched your search

+86
View File
@@ -0,0 +1,86 @@
///| Watched launches (compositor/shell/launch.mbt): an app that fails to start shows an error
/// notice with the command, its exit status and the last lines it printed.
///| Step `comp` until the shell shows an error notice or `ms` pass.
fn wait_notice(comp : @host.ChandraCompositor, ms : Int) -> Array[String] {
let t0 = @sys.monotonic_ms()
while (@sys.monotonic_ms() - t0).to_int() < ms {
comp.step()
if comp.shell.notice_frames > 0 && comp.shell.notice_lines.length() > 0 {
return comp.shell.notice_lines
}
@sys.sleep_ms(20)
}
[]
}
///|
test "a launch that fails shows the command, the exit status and what it printed" {
let comp = new_comp("launch-fail")
// What V's Flatpak kwi did: bwrap can't set up the sandbox, prints why and exits 1.
let cmd = "echo starting; for i in 1 2 3; do echo \"bwrap: Can't find source path /run/user/1000/doc/by-app/org.kde.kwi: No such file or directory\" >&2; done; exit 1"
assert_true(comp.shell.start_app("org.kde.kwi", cmd))
assert_eq(comp.shell.launch_fds().length(), 1)
let lines = wait_notice(comp, 5000)
assert_true(lines.length() >= 3)
assert_true(lines[0].has_prefix("Could not start org.kde.kwi: exited with status 1 after"))
assert_eq(lines[1], "Command: " + cmd)
assert_eq(lines[2], "starting")
assert_eq(
lines[3],
"bwrap: Can't find source path /run/user/1000/doc/by-app/org.kde.kwi: No such file or directory (3 times)",
)
// Drawn above the panel: a red edge at the notice's left side.
let f = comp.compose_frame()
let mut red = 0
for y = 0; y < 720; y = y + 1 {
for x = 0; x < 1280; x = x + 1 {
let i = (y * f.width + x) * 4
if f.data[i].to_int() > 200 && f.data[i + 1].to_int() < 100 && f.data[i + 2].to_int() < 100 {
red = red + 1
}
}
}
assert_true(red > 100)
ignore(@sys.write_file_bytes("/tmp/chandra-launch-notice.png", @renderer.encode_png(f)))
assert_eq(comp.shell.launch_fds().length(), 0)
}
///|
test "a command that isn't installed says so" {
let comp = new_comp("launch-127")
assert_true(comp.shell.start_app("nothere", "chandra-no-such-program-xyz --flag"))
let lines = wait_notice(comp, 5000)
assert_eq(lines[0], "Could not start nothere: failed: command not found (status 127)")
assert_true(lines[2].contains("chandra-no-such-program-xyz"))
}
///|
test "an app killed by a signal while starting says which" {
let comp = new_comp("launch-sig")
assert_true(comp.shell.start_app("crashy", "kill -SEGV $$"))
let lines = wait_notice(comp, 5000)
assert_true(lines[0].has_prefix("Could not start crashy: was killed by SIGSEGV after"))
assert_eq(lines[2], "It printed nothing. More in ~/.local/state/chandra/session.log")
}
///|
test "an app that exits 0 without ever opening a window is reported, after a grace period" {
let comp = new_comp("launch-nowin")
assert_true(comp.shell.start_app("handoff", "echo 'handed the launch to the running instance'"))
let t0 = @sys.monotonic_ms()
let lines = wait_notice(comp, 6000)
assert_true((@sys.monotonic_ms() - t0).to_int() >= 1900) // waited for a window first
assert_true(lines[0].has_prefix("Could not start handoff: exited (status 0) after"))
assert_true(lines[0].has_suffix("without opening a window"))
assert_eq(lines[2], "handed the launch to the running instance")
}
///|
test "an app that keeps running is not reported, and its output still reaches the log" {
let comp = new_comp("launch-ok")
assert_true(comp.shell.start_app("stays", "echo up; sleep 3"))
let lines = wait_notice(comp, 1500)
assert_eq(lines, [])
assert_eq(comp.shell.launch_fds().length(), 1)
}