Skip to content

fix(workflows): isolate init step process state - #5487

Open
WOLIKIMCHENG wants to merge 1 commit into
github:mainfrom
WOLIKIMCHENG:fix/workflow-init-process-isolation
Open

WOLIKIMCHENG wants to merge 1 commit into
github:mainfrom
WOLIKIMCHENG:fix/workflow-init-process-isolation

Conversation

@WOLIKIMCHENG

Copy link
Copy Markdown
Contributor

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

  • 59 focused InitStep, concurrent workflow, resume and adapter-trust tests passed.
  • 169 existing init-command tests and 2 adapter compatibility tests passed.
  • 10 follow-up checks covering invalid arguments, launch failures, stream diagnostics, source pinning and integration errors passed.
  • Ruff 0.15.0 (ruff check --no-cache src tests) passed.
  • Tested locally with .venv/bin/specify --help
  • Ran relevant existing tests with .venv/bin/python -m pytest using focused paths
  • Tested with a sample project

Manual test results

Agent: Codex CLI | OS/Shell: Linux/Bash

Command tested Notes
/speckit.specify generated skill Followed the generated skill in a scratch project scaffolded with this checkout's .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 init and the generated /speckit.specify workflow. The other changed files are regression tests. Real InitStep scaffolding was exercised by pytest.

AI Disclosure

  • I did use AI assistance (described below)

AI disclosure: AI-assisted tools were used to implement the fix and develop tests.

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)
@WOLIKIMCHENG
WOLIKIMCHENG requested a review from mnriem as a code owner November 19, 2026 07:04
Copilot AI adaptive review requested due to automatic review settings November 19, 2026 07:04

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.

🟡 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)

# click >= 8.2 captures stderr separately; older versions mix it into
# stdout and raise when ``result.stderr`` is accessed.
package_parent = str(Path(specify_cli.__file__).resolve().parent.parent)
child_env = os.environ.copy()
Comment thread tests/test_workflows.py
_assert_init_scaffold(tmp_path, "py")
assert (tmp_path / ".specify/presets/lean/preset.yml").is_file()

def test_relative_root_preserves_symlink_parent_semantics(self, tmp_path, monkeypatch):
Comment thread tests/test_workflows.py
monkeypatch.setattr(subprocess, "run", fail)
result = InitStep().execute({"id": "init", "project": "demo"}, StepContext(project_root=str(tmp_path)))
assert result.status == StepStatus.FAILED
assert str(tmp_path) in result.error and "fixture launch denied" in result.error
Comment thread tests/test_workflows.py
assert result.error and result.error != "SystemExit: 1"
assert result.output["stderr"].strip()
assert state == (os.getcwd(), sys.stdin, sys.stdout, sys.stderr, dict(os.environ))
assert not (tmp_path / "escape").exists()
@mnriem

mnriem commented Nov 19, 2026

Copy link
Copy Markdown
Collaborator

Please address Copilot feedback

@mnriem mnriem added the triage-must-have Verdict: high-value, important work for Spec Kit — do first label Nov 19, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

triage-must-have Verdict: high-value, important work for Spec Kit — do first

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants