[core24] Non-core24 runs in managed mode are not being correctly logged
Metadata
Current evaluation
Fixed managed-mode detection by consistently using SNAPCRAFT_MANAGED_MODE, restoring LXD log discovery. Merged in canonical/snapcraft#4638 (187777a36).
Resolution: closed resolved
Reason: PR #4638 unified application managed-mode checks on SNAPCRAFT_MANAGED_MODE, preventing the in-instance Emitter from writing logs to a host-specific path.
Evaluated by: mr-cal-bot
No scores available.
Issue body
### Bug Description
The fallback logic in `feature/craft-application` has an issue with handling of logs in managed (lxd/etc) instances. The flow is this - let's say that the command is "snapcraft pull".
1) "Snapcraft-1" starts up on the host;
2) Realizes that the project has a non-core24 base, and falls back;
3) core22/core20 code picks up the execution, prepares the lxd instance;
4) launches Snapcraft in the instance with `SNAPCRAFT_MANAGED_MODE` set;
5) "Snapcraft-2" starts up inside the instance;
6) Like in 2, falls back to non-core24 code. However, **before this**, the Emitter is initialized - Snapcraft-2 thinks it's running on host because it's looking at `CRAFT_MANAGED_MODE` and not at `SNAPCRAFT_MANAGED_MODE`;
7) core22/core20 code in Snapcraft-2 picks up the execution, creates the lifecycle, runs "pull", finishes;
8) core22/core20 code **in Snapcraft-1** tries to read the instance logs, but fails because Snapcraft-2 put it in `/root/.local/state/snapcraft/logs` because it thought it was running on host.
### To Reproduce
Run a lifecycle command on any core22/core20 project using a Snapcraft snap from `feature/craft-application`, then look at the generated logs. The instance logs are not present.
### Environment
Jammy
### snapcraft.yaml
```shell
name: simple-snap
version: "1.0"
summary: Build a simple confined snap
description: |
Build a simple confined snap to test the build process.
base: core22
confinement: strict
parts:
hello:
plugin: nil
```
### Relevant log output
```shell
# ... removed the log before this
2024-02-23 14:52:19.913 Executing in container: lxc --project snapcraft exec local:snapcraft-hello-try-on-amd64-for-amd64-17455838 -- env PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/snap/bin SNAPCRAFT_MANAGED_MODE=1 chown root:root /root/.bashrc
2024-02-23 14:52:20.022 Emitter: Pausing control of the terminal
2024-02-23 14:52:28.830 Emitter: Resuming control of the terminal
2024-02-23 14:52:28.831 Executing in container: lxc --project snapcraft exec local:snapcraft-hello-try-on-amd64-for-amd64-17455838 -- env PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/snap/bin SNAPCRAFT_MANAGED_MODE=1 test -f /tmp/snapcraft.log
2024-02-23 14:52:28.995 Could not find log file /tmp/snapcraft.log in instance.
# ...
```
### Additional context
_No response_
Evaluation history
| Date | Model | Scores | Action | Summary |
|---|---|---|---|---|
| stealth/space-bunny-alpha | — | closed resolved | Fixed managed-mode detection by consistently using SNAPCRAFT_MANAGED_MODE, restoring LXD log discovery. Merged in canonical/snapcraft#4638 (187777a36). | |
| stealth/space-bunny-alpha | — | closed resolved | Fixed by merged PR #4638 (commit 187777a36), which replaced CRAFT_MANAGED_MODE checks with SNAPCRAFT_MANAGED_MODE so non-core24 fallback runs write logs where the host process expects them. | |
| stealth/space-bunny-alpha | — | closed resolved | Fixed by merged PR canonical/snapcraft#4638 (187777a36), which standardized managed-mode checks on SNAPCRAFT_MANAGED_MODE so non-core24 instance logs remain accessible. | |
| stealth/space-bunny-alpha | — | closed resolved | Fixed by merged PR #4638 (187777a36), standardizing application managed-mode checks on SNAPCRAFT_MANAGED_MODE so nested instances write logs where the host can retrieve them. | |
| qwen/qwen3.6-35b-a3b | — | — | Corrected environment variable check for managed mode fallback logic, fixing missing instance logs for non-core24 bases. Merged in pull request #4638. | |
| qwen/qwen3.6-35b-a3b | — | — | Fixed a fallback logic bug causing non-core24 managed mode runs to write logs to an incorrect path. Resolved by correcting the environment variable check and merged in canonical/snapcraft#4638. | |
| qwen/qwen3.6-35b-a3b | — | — | Resolved a logging failure in non-core24 managed mode where incorrect environment variable checks caused logs to be saved to the wrong directory. Fixed and merged in pull request #4638. | |
| qwen3.6-35b-a3b-mtp-q6 | — | — | Fixed incorrect log path for non-core24 managed mode runs by correcting the environment variable check. Merged in pull request #4638. |
Update history
No update history recorded yet.
Related work
-
Likely Fixed By:
canonical/snapcraft#4638
(confidence 100%)
Merged commit 187777a36 directly fixes #4610.
Related issues
| Issue | Project | State | Summary | Similarity |
|---|---|---|---|---|
| #4638 fix(application): use SNAPCRAFT_MANAGED_MODE everywhere | snapcraft | merged | Merged PR #4638 (commit 187777a36) unified application managed-mode checks on SNAPCRAFT_MANAGED_MODE, fixing logs being written to ephemeral in-LXD locations; closes #4610. Spread test failures were not fixed. | |
| #4832 `SNAPCRAFT_BUILD_ENVIRONMENT` takes priority over `--use-lxd` | snapcraft | open | Triaged bug: PR #4329 fixed core22 precedence for SNAPCRAFT_BUILD_ENVIRONMENT, but core24 remains unverified and its spread test is restricted to Ubuntu 22.04; CRAFT_MANAGED_MODE precedence is intentional. |