Skip to content

fix(host-platform): compare the exec root in its canonical form - #2207

Merged
eric8810 merged 1 commit into
mainfrom
dim/1295-fix-macos-exec-root
Nov 26, 2026
Merged

eric8810 merged 1 commit into
mainfrom
dim/1295-fix-macos-exec-root

Conversation

@eric8810

Copy link
Copy Markdown
Collaborator

Refs #1295 · Follow-up to #2002

Why

The post-merge main macOS job still fails two host_platform_flow tests with Invalid("outside the exec root"):

  • the_host_platform_service_removes_output_and_composes_a_path
  • output_removal_refuses_traversal_and_links

exec_root_path() returns the canonical root, while the request path can use the caller's non-canonical home. On macOS the temporary home is under /var, which canonicalizes to /private/var; path.strip_prefix(root) then fails even though canonicalize_existing_prefix(path) is inside the root.

Change

remove_exec_directory strips the original <home>/.dim/exec prefix first and falls back to the canonical root. The canonical containment check and the symlink-component walk are unchanged.

Added remove_output_directory_accepts_a_symlinked_home to pin the path shape without requiring macOS.

Verification

  • cargo test -p dim-agent-capabilities --test capabilities_flow host_platform_flow::remove_output_directory_accepts_a_symlinked_home
  • cargo test -p dim-agent-capabilities --test capabilities_flow host_platform_flow::the_host_platform_service_removes_output_and_composes_a_path
  • cargo test -p dim-agent-capabilities --test capabilities_flow host_platform_flow::output_removal_refuses_traversal_and_links
  • cargo clippy -p dim-agent-capabilities --all-targets -- -D warnings
  • cargo fmt --all -- --check

A symlinked home made the output path's prefix differ from the canonical exec root on macOS. Strip the original exec root first, then the canonical root, and pin the symlinked-home removal.
@eric8810

Copy link
Copy Markdown
Collaborator Author

The symlink-home regression test and the two previously failing host_platform_flow tests pass locally; CI is green on 87a61f8996.

@yyhhyyyyyy yyhhyyyyyy left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review: #2207 fix(host-platform): compare the exec root in its canonical form

Reviewed head 87a61f8, round 1, against base ade8597 (origin/main). Scope: let output-directory removal accept a path spelled with the caller's non-canonical home, the macOS /var to /private/var shape that left two host_platform_flow tests failing on post-merge main. The PR is open, not draft, at this head, with no earlier reviews or comments.

What changed

remove_exec_directory strips the textual <home>/.dim/exec prefix first and the canonical root second (crates/dim-agent-capabilities/src/host_platform.rs:3852-3866). Containment and the symlink walk are unchanged, as is the public removeOutputDirectory face. canonicalize_existing_prefix has this one caller (host_platform.rs:3855), so no other site needs the same treatment. The new remove_output_directory_accepts_a_symlinked_home pins the shape.

Why it fixes the macOS failure

exec_root_path() canonicalizes (host_platform.rs:1085-1088), while the output path is recorded from host.home (crates/dim-agent-capabilities/src/shell_session.rs:1772-1776). On macOS the root is /private/var/... and the path is /var/..., so the old path.strip_prefix(&root) returned Invalid("outside the exec root") even though the canonical target was inside the root. The new first strip takes the components after the path's own home, and the walk still starts at the canonical root, so it checks the same entries the kernel resolves.

Containment still holds

canonicalize_existing_prefix(path) feeds the containment check before any strip, and remove_dir_all removes target, never the caller's spelling (host_platform.rs:3855-3861, 3882). .. and . are refused at 3842-3850. For a path under <home>/.dim/exec, replacing that prefix with its canonical form yields the components below the root, so the first branch cannot skip the symlink check at 3862-3881: a suffix symlink that leaves the root fails containment, and one that stays inside is caught by symlink_metadata.

Residual shapes (P3, optional)

A path inside the canonical root but under neither the caller's home nor the canonical spelling still errors with outside the exec root; no caller in this tree produces that third alias. Separately, when <home>/.dim/exec itself is absent under a non-canonical home, root stays textual (3852-3853) while target starts with the canonical home, so containment rejects a removal the doc says counts as removed (3837-3839). Reaching it needs the exec root deleted out of band while an owner row survives, because ShellSession::ensure_shell creates the output directory before recording anything (shell_session.rs:402). If wanted, compare against canonicalize_existing_prefix(&input_root) so an absent root resolves through the home alias.

On Windows the canonical root is a verbatim path and the strip is case-sensitive; current callers build both sides from the same platform home, so the case matches. I could not run a Windows host.

Verification

On macOS with isolated HOME and TMPDIR: all 30 host_platform_flow tests pass at this head with a canonical TMPDIR and with TMPDIR behind a symlink, the /var shape. Reverting only the source hunk to base reproduces both original failures at tests/host_platform_flow.rs:1696 and 1877 under the symlinked TMPDIR, and the new test fails at 1918 with either TMPDIR shape, so it pins the regression. The new test uses std::env::temp_dir() and removes its directory on success; on failure it leaves the directory behind, as the neighboring tests already do. cargo fmt --all -- --check and cargo clippy -p dim-agent-capabilities --all-targets -- -D warnings pass.

CI and cross-PR

At 87a61f8, changes, verify (linux), windows-cli, macos-native and ci-ok pass; path-filtered jobs are skipped. PR CI runs verify (linux) only (ci.yml:274), so the two fixed tests execute in the post-merge macOS job; the new test is the PR-time guard. The merge tree against origin/main is clean and git diff --check is clean. Pairwise merge trees are clean with #2178 b1387a0, #2174 5cbf19b, #2202 d43ba13, #2205 8661e3a and #2206 382f0b7. #1881 ff9825d and #2197 4dfe97f conflict, but both already conflict with origin/main alone in files this diff does not touch (docs/design/plugins/Report.md, crates/dim-app-server/src/connection.rs). #2206 edits host_platform.rs but not this function.

Unverified

  • Windows removal after the change; windows-cli does not run host_platform_flow.
  • The post-merge macOS run that carries the original failures.

Verdict: APPROVE

@zerob13 zerob13 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The change accepts the configured-home and canonical spellings without changing the resolved containment check or the below-root component checks. I verified all three affected removal cases in the exact-merge Linux job. Hui's exact-head macOS report covers all 30 HostPlatform cases with both canonical and symlinked temporary roots, including the two failing cases from main and the new regression. That closes my macOS verification hold. The post-merge main workspace run remains a separate check.

@eric8810
eric8810 merged commit aacc71d into main Nov 26, 2026
@eric8810
eric8810 deleted the dim/1295-fix-macos-exec-root branch November 26, 2026 00:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants