Repository navigation
fix(workflows): isolate init step process state - #5487
WOLIKIMCHENG wants to merge 4 commits into
Conversation
Run workflow init in a child process to keep concurrent project paths and output independent while preserving CLI behavior and adapter loading. Assisted-by: Codex CLI (model: gpt-6.1-sol, autonomous)
There was a problem hiding this comment.
🟡 Changes recommended
The init subprocess retains PYTHONPATH, allowing project-local startup code to execute before bootstrap protections and bypass adapter trust checks.
4 open issues
What changed in this PR
Moves Spec Kit workflow init steps into child processes so concurrent initialization does not share the parent’s working directory or streams.
Changes:
- Uses the current Python interpreter and Spec Kit source, with an explicit working directory and captured diagnostics.
- Adds real-scaffolding regressions for concurrent execution, target paths, initialization options, and completed-step replay.
- Tests target-local adapter loading and rejection of untrusted or modified adapters.
Validation was limited to source inspection and isolated standard-library checks; project tests and before/after comparisons were not run.
| File | Description |
|---|---|
tests/workflows/test_composition_execution.py |
Tests concurrent target and stream isolation, plus resume replay. |
tests/test_workflows.py |
Adds initialization regression helpers, path and option coverage, and failure checks. |
tests/specify_cli/integrations/test_installed_adapters.py |
Tests adapter loading and trust enforcement across the child-process boundary. |
src/specify_cli/workflows/step/init/__init__.py |
Replaces in-process initialization with a pinned child-process invocation. |
Review effort: Max (adaptive)
|
Please address Copilot feedback |
Drop inherited PYTHONPATH before Python startup and explicitly disable prompting. Preserve trusted source path spelling and reject ambiguous module metadata. Cover startup injection, source layouts and Windows-safe diagnostics. Assisted-by: Codex (model: gpt-6-astra, autonomous)
|
Thanks for the review. I've addressed the feedback in Focused Linux checks and Ruff 0.15.0 passed. Native Windows testing (Python 3.14.6) completed with 75 passed and 6 skipped, plus 3 passing concurrency/resume tests. The generated resolver also passed under PowerShell 5.1. The full CI matrix was not rerun locally. |
There was a problem hiding this comment.
🟡 Changes recommended
The init child fails to preserve parent isolation flags and can resolve a relative PYTHONUSERBASE inside the target project, allowing unintended startup code execution before source pinning.
6 open issues
Anchor relative PYTHONUSERBASE before changing the child working directory · New Propagate parent interpreter isolation flags to the child · New Reject cached Specify packages that differ from the requested source · New Preserve trusted dependency paths when filtering PYTHONPATH · New Decode child output with replacement to preserve exit status · New Avoid resolving symlinks when validating the pinned package path · New
4 resolved since last review
Review effort: Max (adaptive)
Preserve interpreter restrictions, validate cached package trees, and restore trusted dependency paths after startup. Keep child status and diagnostics when output contains invalid UTF-8. Assisted-by: Codex (model: gpt-6-astra, autonomous)
There was a problem hiding this comment.
🟡 Changes recommended
Unvalidated relative PYTHONHOME and default user-base locations can allow project-controlled code to execute before bootstrap source validation.
10 open issues
Validate the default user base before launching the child · New Reject relative PYTHONHOME values before changing the child directory · New Set APPDATA to the fixture home in Windows user-base tests · New Skip symlink setup when the platform denies permission · New Skip the target-alias case when directory symlinks are unavailable · New Preserve approved dependencies under workflow and target roots · New Restore safely anchored relative PYTHONPATH dependencies · New Preserve PYTHONUSERBASE when launching with -E · New Accept disabled user-site loading in virtual environments · New Bound subprocess pipe draining and support capture cancellation · New
6 resolved since last review
Propagate parent interpreter isolation flags to the child Anchor relative PYTHONUSERBASE before changing the child working directory Avoid resolving symlinks when validating the pinned package path Decode child output with replacement to preserve exit status Preserve trusted dependency paths when filtering PYTHONPATH Reject cached Specify packages that differ from the requested source
Review effort: Max (adaptive)
|
Thanks for the detailed reproduction and work on this. Our intended model is that a project is initialized once, as a sequential bootstrap step; separate CI/CD runs already have process isolation. Could we address the fan-out scenario through sub-workflows instead, with an explicit subprocess execution boundary where isolation is needed? Sub-workflows currently share the parent process, so that would require a separate design change, but it may be a more appropriate place to address working-directory and stream isolation generally rather than introducing that machinery specifically for init. Is there a supported use case that would still require this init-specific change? AI disclosure: Posted on behalf of @mnriem by GitHub Copilot (model: GPT-6.1 Sol; interactive mode). AI assessed the implementation and drafted this comment; @mnriem approved posting it. |
Validate effective startup paths, restore approved dependencies after startup, and use cancellable capture with bounded post-exit draining. Assisted-by: Codex (model: gpt-6.1-sol, autonomous)
There was a problem hiding this comment.
🟡 Changes recommended
Unresolved critical defects can bypass adapter trust checks and terminate initialization before rollback, risking unauthorized adapter execution and partially modified projects.
11 open issues
Resolve Windows drive-relative roots against the captured parent · New Prevent relative HOME from loading forged trust grants · New Allow cancellation rollback or provide durable init recovery · New Scope capture cancellation to the owning workflow · New Close piped stdin before waiting for the child · New Set child stream encoding when Python ignores PYTHONIOENCODING · New Preserve dependency paths for adapter-launched helpers · New Report interruption before falling back to captured output · New Handle Windows process-not-found errors during cleanup · New Move shared test helpers into a dedicated module · New Make the capture timeout wrapper conditional in the regression test · New
10 resolved since last review
Skip the target-alias case when directory symlinks are unavailable Skip symlink setup when the platform denies permission Set APPDATA to the fixture home in Windows user-base tests Reject relative PYTHONHOME values before changing the child directory Validate the default user base before launching the child Bound subprocess pipe draining and support capture cancellation Accept disabled user-site loading in virtual environments Preserve PYTHONUSERBASE when launching with -E Restore safely anchored relative PYTHONPATH dependencies Preserve approved dependencies under workflow and target roots
Review effort: Max (adaptive)
| if not os.path.isabs(base): | ||
| base = os.path.join(os.getcwd(), base) |
| # bootstrap source pinning happens too late to protect that boundary. | ||
| child_env.pop("PYTHONPATH", None) | ||
| child_env["PYTHONIOENCODING"] = "utf-8" | ||
| try: |
| # Preserve the loaded package tree, including symlink/.. spelling. | ||
| # Resolving the initializer leaf can select a different package. | ||
| package_parent = os.path.dirname(os.path.dirname(source)) | ||
| result = run_captured( |
| # Preserve the loaded package tree, including symlink/.. spelling. | ||
| # Resolving the initializer leaf can select a different package. | ||
| package_parent = os.path.dirname(os.path.dirname(source)) | ||
| result = run_captured( |
| options["env"] = env | ||
| if stdin is not None: | ||
| options["stdin"] = stdin | ||
| tree = _ProcessTree(args, cwd, **options) |
| # -P omits the unsafe cwd entry but still honors PYTHONPATH. Drop it | ||
| # before startup can import project-controlled sitecustomize code; | ||
| # bootstrap source pinning happens too late to protect that boundary. | ||
| child_env.pop("PYTHONPATH", None) |
|
|
||
| stdout = result.stdout or "" | ||
| stderr = result.stderr or "" | ||
| if result.timed_out: |
| except ProcessLookupError: | ||
| pass |
| monkeypatch.setattr(gate_module, "sys", _FakeSys(tty=tty)) | ||
|
|
||
|
|
||
| def _isolate_init_home(monkeypatch, tmp_path_factory): |
| original = subprocess.run | ||
| capture = init.run_captured | ||
|
|
||
| def bounded_run(*args, **kwargs): | ||
| kwargs.setdefault("timeout", 60) | ||
| return original(*args, **kwargs) | ||
|
|
||
| def bounded_capture(*args, **kwargs): | ||
| # Harness guard only; production init has no overall runtime limit. | ||
| kwargs.setdefault("timeout", 45) | ||
| return capture(*args, **kwargs) | ||
|
|
||
| monkeypatch.setattr(subprocess, "run", bounded_run) | ||
| monkeypatch.setattr(init, "run_captured", bounded_capture) |
|
Thanks for the review. Updated in 3faedc0. The changes validate effective startup paths and restore approved dependencies only after startup. Init now uses cancellable capture with bounded post-exit draining; the Windows APPDATA fixture and symlink skips are also corrected. For the design question: one reproducible case is a controller initializing two distinct projects once each, concurrently, then running downstream work against each scaffold. The new composition test exercises real init calls and verifies both projects. Current workflow calls share the parent root and process, so wrapping init in a subworkflow does not currently provide isolation. This change leaves the general subworkflow boundary unchanged. Does this distinct-project case fit the intended workflow model, or would you prefer isolation at a general subprocess boundary? Validation: final focused startup checks passed (57 passed, 1 skipped), with earlier capture and composition checks retained. Bounded native Windows 3.12 capture checks and all 33 user-base selection oracle cases passed. Full native InitStep and Windows 3.14/3.15 CI remain unverified locally. |
|
Thanks for clarifying the concurrent initialization use case. We can’t take the init-specific isolation change, but we’d be happy to repurpose this PR to add an explicit subprocess execution boundary for sub-workflows, so each isolated invocation has its own process and project root. Your use case is a good example: the existing AI disclosure: Posted on behalf of @mnriem by GitHub Copilot (model: GPT-6.2 Sol; interactive mode). Copilot assessed the PR and drafted this comment; @mnriem directed the scope and approved posting it. |



Description
Prevent concurrent workflow init steps from redirecting each other's relative project paths or capturing another step's output. Invoke init in an isolated child process pinned to the current Python interpreter and Spec-Kit source, leaving the parent working directory and streams untouched.
Preserve initialization options, failure diagnostics, target-local adapter loading and completed-step replay. Regression tests reproduce wrong-target scaffolding before the fix and verify real generated projects afterward.
Testing
ruff check --no-cache src tests) passed..venv/bin/specify --help.venv/bin/python -m pytestusing focused pathsManual test results
Agent: Codex CLI | OS/Shell: Linux/Bash
/speckit.specifygenerated skill.venv/bin/specify. Template resolution, specification and quality checklist creation completed; no extension hooks were installed. A separate slash-command host invocation was not exercised.The init execution-boundary change maps to
specify initand the generated/speckit.specifyworkflow. The other changed files are regression tests. Real InitStep scaffolding was exercised by pytest.AI Disclosure
AI disclosure: AI-assisted tools were used to implement the fix and develop tests.