Skip to content

Enforce target-aware working directories - #1253

Closed
Gudge (MGudgin) wants to merge 1 commit into
mainfrom
user/gudge/process_cwd_fix
Closed

Gudge (MGudgin) wants to merge 1 commit into
mainfrom
user/gudge/process_cwd_fix

Conversation

@MGudgin

@MGudgin Gudge (MGudgin) commented Sep 23, 2026 •

Copy link
Copy Markdown
Member

This PR fixes #902 by validating process.cwd against the selected backend and lifecycle surface instead of allowing an explicit value to be silently discarded or resolved against ambient host state.

Compatibility

Surface Working-directory behavior
Ordinary v0.6-v0.8 JSON requests Existing relative-path compatibility is preserved.
Ordinary v0.9/v0.10 JSON and typed SDK requests Windows targets require a rooted Windows path; POSIX targets require an absolute POSIX path.
WSLc one-shot Requires a rooted local Windows drive path and maps it under /mnt/<drive> in every contract version. Unmappable explicit values fail loudly.
WSLc state-aware exec Requires an absolute in-container POSIX path.

Details

  • Carry working-directory compatibility from each exact contract adapter into the normalized execution request.
  • Validate one-shot, streaming, dry-run, typed SDK, and state-aware exec paths before execution or host policy changes.
  • Preserve existing omitted-cwd fallback behavior for each backend.
  • Preserve malformed sandbox-ID precedence over state-aware cwd policy errors.
  • Return actionable, escaped policy-validation diagnostics rather than silently replacing explicit values.
  • Document backend-specific path forms and omitted-cwd behavior, including Bubblewrap's native launch-directory behavior.
  • Regenerate the development schema and TypeScript wire documentation.
  • Add adapter, parser, validator, dispatcher, backend, SDK, E2E, and regression coverage.

Tests

  • cargo fmt --all -- --check
  • cargo check --workspace --all-targets
  • Full affected Rust unit suites and targeted Clippy with warnings denied
  • Node SDK build, unit tests, and WSLc integration type-check
  • .NET SDK tests: 323 passed, 27 host-dependent tests skipped
  • Exact-contract codegen and repository configuration validation
  • Rebuilt working-directory E2E tests and the [Cross-backend] process.cwd is silently discarded or resolved against host state #902 regression

@MGudgin
Gudge (MGudgin) requested review from a team and a balanced review from Copilot September 23, 2026 22:06
@MGudgin
Gudge (MGudgin) requested a review from a team as a code owner September 23, 2026 22:06
@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
There may be pipelines that require an authorized user to comment /azp run to run.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot review overview

🟡 Changes recommended

Legacy WSLc preflight and executor-backed Node typed requests do not consistently enforce the intended strict semantics.

Get a fresh assessment by requesting another Copilot review.

Review effort: Balanced
Findings: 2 Medium severity · 1 Low severity

Open (3)
What changed in this PR

This PR introduces target-aware process.cwd validation across contracts, backends, execution surfaces, and SDKs.

Changes:

  • Adds version- and backend-aware working-directory validation.
  • Preserves legacy contract compatibility while hardening WSLc mapping.
  • Updates SDKs, diagnostics, documentation, and regression coverage.
File Description
tests/​regression_tests/​test_cases/​Invoke-Issue902-RelativeWorkingDirectory.ps1 Tests strict and v0.8 behavior.
src/​testing/​wxc_e2e_tests/​tests/​e2e_working_directory.rs Adds cross-platform cwd E2E tests.
src/​core/​wxc_common/​src/​working_directory.rs Implements target-aware validation.
src/​core/​wxc_common/​src/​validator.rs Integrates one-shot and exec validation.
src/​core/​wxc_common/​src/​state_aware_dispatch.rs Tests pre-dispatch rejection.
src/​core/​wxc_common/​src/​script_runner.rs Preserves public error classifications.
src/​core/​wxc_common/​src/​policy_identity.rs Excludes compatibility metadata from identity.
src/​core/​wxc_common/​src/​models.rs Adds cwd compatibility and style models.
src/​core/​wxc_common/​src/​lib.rs Exports shared path helpers.
src/​core/​wxc_common/​src/​config_parser.rs Validates cwd during normalization.
src/​core/​wxc_common/​src/​config_deserialize.rs Exposes diagnostic escaping.
src/​core/​wxc_common/​src/​config_contract_adapters/​v0_9/​state_aware.rs Selects strict state-aware semantics.
src/​core/​wxc_common/​src/​config_contract_adapters/​v0_9/​state_aware_tests/​common.rs Tests strict adapter output.
src/​core/​wxc_common/​src/​config_contract_adapters/​v0_9/​one_shot.rs Selects strict one-shot semantics.
src/​core/​wxc_common/​src/​config_contract_adapters/​v0_9/​one_shot_tests/​common.rs Tests strict adapter output.
src/​core/​wxc_common/​src/​config_contract_adapters/​v0_8.rs Selects legacy cwd compatibility.
src/​core/​wxc_common/​src/​config_contract_adapters/​v0_7.rs Selects legacy cwd compatibility.
src/​core/​wxc_common/​src/​config_contract_adapters/​v0_6.rs Selects legacy cwd compatibility.
src/​core/​wxc_common/​src/​config_contract_adapters/​dev/​state_aware.rs Selects strict development semantics.
src/​core/​wxc_common/​src/​config_contract_adapters/​dev/​state_aware_tests/​common.rs Tests development adapter output.
src/​core/​wxc_common/​src/​config_contract_adapters/​dev/​one_shot.rs Selects strict development semantics.
src/​core/​wxc_common/​src/​config_contract_adapters/​dev/​one_shot_tests/​common.rs Tests development adapter output.
src/​core/​wxc_common/​src/​common_request_ir.rs Carries cwd compatibility metadata.
src/​core/​mxc-sdk/​README.md Documents Rust SDK cwd rules.
src/​core/​mxc_engine/​src/​run.rs Validates before runner resolution.
src/​core/​mxc_engine/​src/​policy/​exact/​mod.rs Makes typed requests strict.
src/​core/​mxc_engine/​src/​policy.rs Documents and tests typed requests.
src/​core/​mxc_engine/​src/​dispatch.rs Validates streaming requests early.
src/​core/​mxc_config_contract/​src/​dev/​stable.rs Documents development contract semantics.
src/​backends/​wslc/​common/​src/​wsl_container_runner.rs Rejects or maps one-shot cwd.
src/​backends/​wslc/​common/​src/​policy_mapping.rs Separates strict cwd mapping.
src/​backends/​windows_sandbox/​lifecycle/​src/​error.rs Corrects unavailable-backend classification.
src/​backends/​seatbelt/​common/​src/​seatbelt_runner.rs Preserves legacy relative behavior.
src/​backends/​nanvix/​runner/​src/​lib.rs Corrects test containment context.
sdk/​node/​tests/​integration/​wslc-e2e.test.ts Verifies WSLc cwd mapping.
sdk/​node/​tests/​integration/​common.test.ts Tests buffered Node rejection.
sdk/​node/​src/​types.ts Documents Node cwd requirements.
sdk/​node/​src/​sandbox.ts Updates Node API documentation.
sdk/​node/​src/​generated/​v0_10_0_alpha/​wire.ts Regenerates wire documentation.
sdk/​node/​README.md Documents Node compatibility rules.
sdk/​dotnet/​README.md Documents .NET cwd rules.
sdk/​dotnet/​Microsoft.Mxc.Sdk/​StateAwareTypes.cs Documents state-aware cwd forms.
sdk/​dotnet/​Microsoft.Mxc.Sdk/​SandboxRequest.cs Documents one-shot cwd forms.
schemas/​dev/​mxc-config.schema.0.10.0-alpha.json Updates generated schema description.
docs/​wsl/​wsl-container-getting-started.md Documents WSLc path mapping.
docs/​windows-sandbox/​windows-sandbox.md Documents Windows Sandbox cwd rules.
docs/​state-aware-lifecycle/​mxc-state-aware-sandbox-api.md Documents pre-dispatch validation.
docs/​seatbelt/​seatbelt-backend.md Documents Seatbelt compatibility.
docs/​schema.md Defines canonical cwd semantics.
docs/​lxc-support/​lxc-backend.md Documents LXC cwd behavior.
docs/​isolation-session/​state-aware-rust.md Documents IsolationSession exec rules.
docs/​isolation-session/​oneshot.md Documents IsolationSession one-shot rules.
docs/​bwrap-support/​bubblewrap-backend.md Documents Bubblewrap cwd behavior.
.github/​copilot-instructions.md Adds repository cwd invariants.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread src/core/wxc_common/src/models.rs Resolved
Copilot AI review requested due to automatic review settings September 23, 2026 22:13

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot review overview

🟡 Changes recommended

Legacy WSLc requests bypass pre-selection validation, and unresolved state-aware targets can receive incorrect error classifications.

Get a fresh assessment by requesting another Copilot review.

Review effort: Balanced
Findings: 3 Medium severity · 1 Low severity

Open (4)

Copilot AI review requested due to automatic review settings September 23, 2026 22:46
@MGudgin
Gudge (MGudgin) force-pushed the user/gudge/process_cwd_fix branch from 3bc3eed to cef27b9 Compare September 23, 2026 22:46

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot review overview

🟡 Changes recommended

The IsolationSession one-shot documentation describes a broader Windows path form than the validator accepts.

Get a fresh assessment by requesting another Copilot review.

Review effort: Balanced
Findings: 1 Low severity

Open (1)
Resolved since last review (4)

Comment thread docs/isolation-session/oneshot.md Resolved
Copilot AI review requested due to automatic review settings September 23, 2026 23:24
@MGudgin
Gudge (MGudgin) force-pushed the user/gudge/process_cwd_fix branch from cef27b9 to 91f29d0 Compare September 23, 2026 23:24

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot review overview

🟡 Changes recommended

WSLc parent-directory components are mapped with POSIX rather than rooted Windows semantics, potentially selecting the wrong container directory.

Get a fresh assessment by requesting another Copilot review.

Review effort: Balanced
Findings: 1 High severity

Open (1)
Resolved since last review (1)

Copilot AI review requested due to automatic review settings September 23, 2026 23:32
@MGudgin
Gudge (MGudgin) force-pushed the user/gudge/process_cwd_fix branch from 91f29d0 to 18a3050 Compare September 23, 2026 23:32

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot review overview

🔵 Needs a closer look

Cross-platform path semantics, compatibility behavior, generated contracts, and multiple SDK surfaces warrant final human validation.

Review effort: Balanced
Findings: None

Resolved since last review (1)

Comment thread docs/schema.md Resolved
Copilot AI review requested due to automatic review settings September 23, 2026 23:51
@MGudgin
Gudge (MGudgin) force-pushed the user/gudge/process_cwd_fix branch from 18a3050 to a39273e Compare September 23, 2026 23:51
Comment thread docs/schema.md Resolved

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

🕐

Copilot AI review requested due to automatic review settings September 24, 2026 20:01
@MGudgin

Copy link
Copy Markdown
Member Author

Soham Das (@SohamDas2021), Jeff Whiteside (@jsidewhite), I've scoped this back (and hopefully you can see the diffs)

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot review overview

🟡 Changes recommended

Public Rust and Node API documentation currently misstates which Windows path forms are accepted for one-shot WSLc versus Windows backends.

Get a fresh assessment by requesting another Copilot review.

Review effort: Balanced
Findings: 2 Low severity

Open (2)

Comment thread sdk/node/src/sandbox.ts Resolved
Comment thread src/core/mxc_engine/src/policy.rs Resolved
Copilot AI review requested due to automatic review settings September 24, 2026 20:14

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot review overview

🟡 Changes recommended

Three user-facing documentation statements conflict with implemented path compatibility and accepted forms.

Get a fresh assessment by requesting another Copilot review.

Review effort: Balanced
Findings: 1 Low severity

Open (1)
Resolved since last review (2)
Previously missed (2)

In code that hasn't changed since last review

Low severity Limit whitespace fallback documentation to applicable backends

docs/​schema.md:298

This compatibility statement is too broad. Bubblewrap and LXC treat only the empty string as omitted (bwrap_command.rs:556-564, lxc_runner.rs:52-60), so a legacy whitespace-only value is passed to --chdir/cd rather than falling back. Limit the documented fallback to the backends that use resolved_working_directory_with (ProcessContainer and Seatbelt).

Low severity Qualify target-absolute cwd rule for current-contract behavior

sdk/​node/​src/​types.ts:20

ProcessConfig also represents raw exact-version configs, and v0.6-v0.8 deliberately retain relative cwd acceptance for ordinary backends. The unqualified target-absolute statement conflicts with the compatibility behavior documented in sdk/node/README.md:538-539; qualify it as the current-contract rule.

Comment thread src/core/mxc-sdk/README.md Resolved

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

🕐

@microsoft-github-policy-service microsoft-github-policy-service Bot added the Needs-Author-Feedback Waiting for additional information or action from the issue or pull-request author. label Sep 24, 2026
Comment thread docs/schema.md Resolved

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

:shipit:

This PR fixes #902 by validating process.cwd against the selected backend and
lifecycle surface instead of allowing silent fallback to ambient host state.

Details

* Carry working-directory compatibility from each exact contract adapter.
* Preserve v0.6-v0.8 relative-path behavior for ordinary backends.
* Require target-absolute paths for current contracts and typed SDK requests.
* Accept rooted Windows paths for ordinary Windows backends.
* Require absolute POSIX paths for Bubblewrap, LXC, and Seatbelt.
* Map one-shot WSLc local-drive paths under `/mnt/<drive>` and fail loudly when
  an explicit value cannot be mapped.
* Keep state-aware WSLc exec cwd values in the container POSIX namespace.
* Validate one-shot, streaming, dry-run, typed SDK, and state-aware exec paths.
* Preserve malformed sandbox-ID precedence over state-aware cwd policy errors.
* Document backend defaults and regenerate development contract artifacts.

Tests

* `cargo fmt --all -- --check`
* `cargo check --workspace --all-targets`
* Full affected Rust unit suites and targeted Clippy with warnings denied
* Node SDK build, unit tests, and WSLc integration type-check
* .NET SDK tests: 323 passed, 27 host-dependent tests skipped
* Exact-contract codegen and repository configuration validation
* Rebuilt working-directory E2E tests and the #902 regression

Co-authored-by: Copilot <[email protected]>
Copilot-Session: 65717fe2-44ac-4aa4-9629-24ae8c7d1f5e
Generated-with: gpt-5.6-sol

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot review overview

🟡 Changes recommended

Exact one-shot JSON still bypasses the promised policy_validation envelope, and affected error documentation is inconsistent.

Get a fresh assessment by requesting another Copilot review.

Review effort: Balanced
Findings: 1 Medium severity · 2 Low severity

Open (3)
Resolved since last review (1)

scope,
working_directory_compatibility,
)
.map_err(WxcError::Validation)?;
Comment on lines +198 to +200
// This selects validation compatibility only. Once accepted, it does
// not change how the chosen directory is enforced by the backend.
working_directory_compatibility: _excluded_working_directory_compatibility,
let mut envelope = serde_json::json!({
"error": {
"code": "backend_error",
"code": error_code(response),
@MGudgin

Copy link
Copy Markdown
Member Author

Closing this PR because the implementation is not converging.

The review exposed two public-contract problems that require design work beyond the scope of this change:

  • Exact one-shot JSON cwd validation currently occurs during parsing, which prevents it from producing the intended typed policy_validation result.
  • The shared one-shot envelope mapping changes error codes for every backend, rather than only classifying cwd validation failures.

Issue #902 remains open. The next attempt should split the work into smaller changes: a minimal WSLc one-shot fail-loud fix that preserves its existing path contract, and a separately designed relative-cwd contract change with an explicit parsing and public-error model.

@microsoft-github-policy-service microsoft-github-policy-service Bot removed Needs-Attention Requires attention or a decision from the MXC maintainers. Needs-Author-Feedback Waiting for additional information or action from the issue or pull-request author. labels Sep 24, 2026
@MGudgin
Gudge (MGudgin) deleted the user/gudge/process_cwd_fix branch October 3, 2026 01:36
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.

[Cross-backend] process.cwd is silently discarded or resolved against host state

4 participants