Skip to content

fix: make stdio redirection scoped and exception-safe - #243

Closed
Ayoubbelguellaoui wants to merge 1 commit into
openecos-projects:mainfrom
Ayoubbelguellaoui:main
Closed

fix: make stdio redirection scoped and exception-safe#243
Ayoubbelguellaoui wants to merge 1 commit into
openecos-projects:mainfrom
Ayoubbelguellaoui:main

Conversation

@Ayoubbelguellaoui

Copy link
Copy Markdown
Contributor

What Changed

  • Replaced process-global stdout/stderr redirection in chipcompiler/utility/log.py with a thread-safe, context-managed _StdioRedirect implementation that safely saves and restores file descriptors even upon exceptions.

Updated chipcompiler/engine/flow.py, chipcompiler/engine/rerun.py, and agent/engine.py to ensure step-level log redirects close cleanly.

Updated chipcompiler/runtime/operations.py to treat event publisher exceptions as non-fatal and wrapped active operation tracking in finally blocks to guarantee cleanup.

Added and updated tests in test/cli/rendering/test_progress.py, test/runtime/test_events.py, and test/runtime/test_operations.py to cover stdio restoration, thread isolation under concurrency, and resilient operation tracking.

Scope

Select the areas touched by this PR:

  • CLI - command behavior, Typer command surface, output formats, or workspace commands.
  • Flow/runtime - workspace lifecycle, EngineFlow, step execution, logs, metrics, or artifacts.
  • EDA integration - Yosys, ECC-Tools, DreamPlace, KLayout, PDKs, or native/runtime wrappers.
  • Build/package - Nix, PyInstaller, wheels, uv.lock, or release artifacts.
  • CI/release - GitHub Actions, version checks, changelog, or release automation.
  • Tests/docs only

Runtime And Packaging Impact

  • No runtime or packaging impact
  • CLI output or machine-readable contract changed
  • Workspace layout, flow state, or artifact paths changed
  • Native toolchain or wrapper behavior changed
  • ecc-tools or ecc-dreamplace dependency changed
  • PyInstaller, Nix, or release artifact changed

Notes:

  • Fixed critical bugs where process-global stdio redirection corrupts concurrent flow logs, and where event publisher failures leave active operations permanently uncleaned.

Validation

List the commands you ran. Mark checks that are not applicable as N/A.

  • uv run pytest test/
  • uv run ruff check chipcompiler test
  • uv run ruff format --check chipcompiler test
  • PyInstaller smoke: ecc --help, ecc --version, ecc version --json
  • Nix smoke: nix run .#cli -- --help
  • Manual flow smoke:
  • Other: - uv run pytest test/ — 1460 passed, 8 skipped, 4 xfailed, 2 environment-related failures.

Skipped checks and reason:

Checklist

  • I kept the change scoped to ECC.
  • I updated docs or user-facing CLI text where behavior changed.
  • I included lockfile or version metadata updates when dependencies changed.
  • I documented any submodule updates and why they are needed.
  • I did not include local caches, virtual environments, or generated build outputs.
  • I explained skipped validation and remaining risk.

@Ayoubbelguellaoui Ayoubbelguellaoui changed the title stdio redirection + operation cleanup fix: make stdio redirection scoped and exception-safe Aug 25, 2026
@Emin017

Emin017 commented Aug 25, 2026

Copy link
Copy Markdown
Member

Thank you for your contribution! However, does this PR have any overlapping parts with #236?

@Ayoubbelguellaoui

Copy link
Copy Markdown
Contributor Author

There is some overlap at the step-execution/runtime level, particularly around EngineFlow and failure cleanup, but the two PRs address different issues.

PR #236 focuses on containing tool failures, persisting Incomplete, interrupted-operation recovery, and terminal failure state propagation.

This PR focuses specifically on making process-global stdout/stderr redirection scoped and exception-safe, isolating concurrent redirects, and guaranteeing runtime operation cleanup when event publishing fails.

The overlap is therefore limited to the surrounding execution/cleanup paths; the implementations address separate failure modes.

@Emin017

Emin017 commented Aug 25, 2026

Copy link
Copy Markdown
Member

This PR focuses specifically on making process-global stdout/stderr redirection scoped and exception-safe, isolating concurrent redirects, and guaranteeing runtime operation cleanup when event publishing fails.

The overlap is therefore limited to the surrounding execution/cleanup paths; the implementations address separate failure modes.

Got it, I just merged #236. Could you rebase and resolve the conflicts?

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.

2 participants