fix(sys): keep read-only Flatpak probes non-interactive; document AI kind values
Some checks are pending
ci / test (push) Waiting to run

This commit is contained in:
Phoebus 2026-09-29 04:28:12 -07:00
parent d96aae1cfa
commit 52dbdf4422
9 changed files with 107 additions and 5 deletions

View file

@ -5,6 +5,24 @@ this file is the curated, human-readable summary.
## Unreleased — Fast defaults with user-controlled source builds
- **Headless read-only probes can no longer block; real-agent VM re-verification
(2026-09-29).** Driving the powerful model (host `opencode` agent,
`deepseek-v4.1-flash`) with `sys` **inside the VM**, a `sys ask "search for
firefox"` hung: the AI investigation ran Flatpak, whose `search` hard-codes a
privileged `appstream-update`, and polkit fell back to a `pkttyagent` password
prompt on the headless console. Fix: `CommandSpec::detached()` runs host-root
Flatpak commands in a new session with no controlling terminal (`setsid
--wait`), so the prompt is impossible; the refresh fails fast and Flatpak uses
cached data. Falls back when `setsid` is absent. Also fixed a prompt gap: the
install/assistant prompts listed a `kind` argument without its allowed values,
so a capable model emitted `kind:"gui"`; both prompts now enumerate
`base-system|desktop-app|developer-tool|cli-tool|unclassified` and clarify that
`gui` is a separate boolean. VM re-verification with the real agent
(`serial-boot-20260929T111941Z-2be30b89`, driver PASS=8; zero auth prompts):
`list` and `search` return valid, evidence-grounded Assistant Plans, the
hostile instruction is refused, and the constrained install stops before any
mutation. Gates: `cargo fmt`, `clippy --workspace --all-targets -- -D warnings`,
`cargo test --workspace` 844 passed / 0 failed.
- **VM live AI: real capable agent, and a local-model prompt fix (2026-09-29).**
Booted the golden overlay and, from inside the guest, reached the host's real
`opencode` agent through the loopback tunnel: `sys ask "list installed

View file

@ -37,6 +37,17 @@ commit it. It should be short and current; use `git log` for detail.
objects; a capable model is still required, and a 4096-token local context
can be exceeded by the one-shot correction turn. Source conversion and
tuned-kernel builds remain NotRun (multi-hour compiles).
- **Real powerful model via the host agent, `sys` in the VM (2026-09-29,
VM-VERIFIED):** four requests through `opencode`/`deepseek-v4.1-flash`:
`list` and `search firefox` return valid grounded plans; `install firefox
--flatpak` as the user stops before mutation; hostile shell/private-file
instruction refused (`serial-boot-20260929T111941Z-2be30b89`, PASS=8, zero
auth prompts). A read-only Flatpak probe had hung on Flatpak's interactive
`appstream-update` (pkttyagent) on the headless console; `CommandSpec::detached()`
now runs host-root Flatpak commands with no controlling terminal. The install
prompt now enumerates the allowed `kind` values (a capable model had guessed
`kind:"gui"`). The install investigation itself still stops on the model's own
request-count/formatting limits and fails closed (no `sys` defect).
- **First VM test loop on the golden image (2026-09-28, VM-VERIFIED):** booted a
fresh overlay of the installed `phoebus-headless-80g.qcow2` with the static
`sys` from HEAD and found two real defects, both fixed. (1) Unprivileged

View file

@ -100,6 +100,7 @@ Booting that recovery entry offline remains a manual gate.
| AI connected-model path over a real local stub | yes | yes (4 e2e cases: valid plan executes; request has no home path/credential; shell + smuggled key + malformed fail closed) | no (local stub, not a live model) | n/a |
| Live real-agent call (`opencode` backend) | yes | yes (`sys ask "list installed packages"` → valid plan + digest, exit 0; hostile shell/private-file instruction refused and downgraded; OpenCode tools disabled; no credential in the log) | yes — host direct (2026-09-28) and **from inside the installed VM through the loopback tunnel** (`serial-boot-20260929T102703Z-ffd1ec25`, `live-agent` + `live-agent-hostile-rejected`) with `opencode-go/deepseek-v4.1-flash` | n/a |
| Local model through the direct sandbox (VM) | yes | yes (real Qwen2.5-1.5B GGUF via `llama-server`; both sandbox scopes reached the model; schema-noncompliant output failed closed) | VM-run 2026-09-29: reached and failed closed; a 1.5B model is too weak for exact typed plans and its 4096-token context was exceeded by the correction turn — a capable model is required (a capable agent produces valid plans) | n/a |
| Read-only host-root probes never block on a prompt | yes | yes (`CommandSpec::detached` runs host-root Flatpak in a new session via `setsid --wait`, no controlling terminal; field-preserving unit test) | yes (VM: real-agent `sys ask "search for firefox"` completed with zero auth prompts, `serial-boot-20260929T111941Z-2be30b89`) | n/a |
| Privilege derived only from the process identity | yes | yes (an environment variable cannot forge uid 0; the removed `PHOEBUS_ALLOW_UNPRIVILEGED_EXEC` regression test) | no | n/a |
| AI OS sandbox (systemd hardened unit) | yes | yes (argv + sandboxed-send; system properties for root, user-manager subset for non-root) | yes (`serial-boot-20260929T092147Z-6f88907a`: `AI_ROOT_RC=0` system sandbox, `AI_USER_RC=0` `--user` sandbox; previously the user path hung on a polkit `manage-units` prompt) | no |
| Unprivileged read-only AI plan completes | yes | yes (transaction recording best-effort for non-root; mandatory for privileged mutations) | yes (`serial-boot-20260929T092147Z-6f88907a`: `AI_NOSANDBOX_RC=0` as `phoebus`) | n/a |

View file

@ -60,6 +60,17 @@ the static `sys` built from HEAD; the base image was never modified.
concrete action-object example, which made the small model emit action objects;
a capable model is still required for valid plans, and a very small local
context can be exceeded by the one-shot correction turn.
- **Powerful model via the host agent, `sys` in the VM
(`serial-boot-20260929T105651Z` → `…T111941Z-2be30b89`, driver PASS=8):** four
real requests through the host `opencode`/`deepseek-v4.1-flash` agent:
`list` → valid grounded plan; `search firefox` → valid grounded plan;
`install firefox --flatpak` (unprivileged) → stopped before mutation;
hostile shell/private-file instruction → refused. The first run hung on
`org.freedesktop.Flatpak.appstream-update` (a `pkttyagent` password prompt from
a read-only Flatpak probe in an inactive session); after the
`CommandSpec::detached()` fix the re-run completed with **zero auth prompts**.
The install investigation itself stopped on the model's own request-count /
formatting limits and failed closed (no `sys` defect).
## 2026-09-28 Headless dual-target golden install (Run 13) & detached boot proven

View file

@ -102,7 +102,10 @@ non-empty reason. For a pure question or a search summary, return an empty \
you were given: never invent package names, versions, descriptions, sizes, \
installation status or availability.
Rules: prefer inspection before mutation. Do not choose a software lane by \
Rules: prefer inspection before mutation. Where an action takes a `kind`, it is \
exactly one of base-system, desktop-app, developer-tool, cli-tool, unclassified; a \
GUI application is kind desktop-app plus a separate `gui` boolean. \
Do not choose a software lane by \
category alone: use choose_package to compare the available lanes against the \
machine (architecture, memory, storage, GPU, Wayland) and the user's \
preferences, or install_package for an explicit Portage request. Base system \

View file

@ -179,8 +179,10 @@ Each reply is ONE JSON object with version 2 and a `kind`:
1. Investigate (read-only evidence): \
{\"version\":2,\"kind\":\"investigate\",\"requests\":[<action>,...]}. Allowed actions: \
discover_candidates (query, optional kind/gui/requires_sandbox), inspect_candidate \
(backend, id), check_backend (backend), inspect_installation (application).
discover_candidates (query; optional kind — exactly one of base-system, desktop-app, \
developer-tool, cli-tool, unclassified), inspect_candidate (backend, id), check_backend \
(backend), inspect_installation (application). A GUI app is kind desktop-app plus \
\"gui\":true; gui is a boolean, never a kind value.
2. Ask the user about intent (only when system facts cannot answer): \
{\"version\":2,\"kind\":\"ask\",\"question\":\"...\"}. Use this sparingly, e.g. whether \

View file

@ -97,7 +97,15 @@ pub(crate) fn target_spec(
args: &[String],
) -> CommandSpec {
if is_host_root(root) {
CommandSpec::new(stage, operation, program).args(args.iter().cloned())
let spec = CommandSpec::new(stage, operation, program).args(args.iter().cloned());
// A Flatpak probe/operation can trigger a privileged appstream refresh
// that prompts for a password; run it without a controlling terminal so
// it can never block. Other programs keep the console.
if program == "flatpak" {
spec.detached()
} else {
spec
}
} else {
portage::chroot_spec(stage, operation, root, program, args)
}

View file

@ -57,6 +57,30 @@ impl CommandSpec {
self
}
/// Run this command in a new session with no controlling terminal, so an
/// interactive authentication prompt cannot block an unattended query.
///
/// Flatpak's `search`/`list` hard-code an appstream metadata refresh that
/// goes through its privileged system helper; when polkit does not treat the
/// session as active (headless/peripheral console), the helper falls back to
/// a `pkttyagent` password prompt and blocks. Detaching makes that prompt
/// impossible: the refresh fails fast and Flatpak continues with cached
/// data. Falls back to the original command when `setsid` is unavailable.
pub fn detached(mut self) -> Self {
if crate::exec::find_in_path("setsid").is_none() {
return self;
}
let program = std::mem::take(&mut self.program);
let original = std::mem::take(&mut self.args);
let mut args = Vec::with_capacity(original.len() + 2);
args.push("--wait".to_string());
args.push(program);
args.extend(original);
self.program = "setsid".to_string();
self.args = args;
self
}
pub fn stdin(mut self, bytes: impl Into<Vec<u8>>) -> Self {
self.stdin = Some(bytes.into());
self
@ -333,6 +357,24 @@ mod tests {
assert_eq!(spec.program, "mkfs.btrfs");
}
#[test]
fn detached_wraps_with_setsid_and_preserves_fields() {
if crate::exec::find_in_path("setsid").is_none() {
return;
}
let spec = CommandSpec::new("query", "package catalogue", "flatpak")
.args(["--version"])
.stdin(vec![1, 2, 3])
.env("A", "b");
let detached = spec.detached();
assert_eq!(detached.program, "setsid");
assert_eq!(detached.args, vec!["--wait", "flatpak", "--version"]);
assert_eq!(detached.stdin, Some(vec![1, 2, 3]));
assert_eq!(detached.env, vec![("A".to_string(), "b".to_string())]);
assert_eq!(detached.stage, "query");
assert_eq!(detached.operation, "package catalogue");
}
#[test]
fn recording_runner_records_and_responds() {
let runner = RecordingRunner::new();

View file

@ -50,7 +50,13 @@ fn lane_matches(candidate: Backend, filter: Backend) -> bool {
fn spec(root: &Path, program: &str, args: &[&str]) -> CommandSpec {
let args: Vec<String> = args.iter().map(|s| s.to_string()).collect();
if crate::actions::is_host_root(root) {
CommandSpec::new("query", "package catalogue", program).args(args)
let spec = CommandSpec::new("query", "package catalogue", program).args(args);
// Flatpak may prompt for a privileged appstream refresh; detach it.
if program == "flatpak" {
spec.detached()
} else {
spec
}
} else {
portage::chroot_spec("query", "package catalogue", root, program, &args)
}