Skip to content

fix: make lifecycle teardown failure-safe - #73

Merged
codeforester merged 1 commit into
mainfrom
bug/51-20260802-lifecycle-teardown
Aug 2, 2026
Merged

fix: make lifecycle teardown failure-safe#73
codeforester merged 1 commit into
mainfrom
bug/51-20260802-lifecycle-teardown

Conversation

@codeforester

Copy link
Copy Markdown
Contributor

Summary

Make lifecycle teardown failure-safe when history persistence, cleanup hooks, logger handlers, or the cleanup call itself fails.

The lifecycle now:

  • treats history persistence as an observable best-effort finalizer;
  • runs cleanup while the invocation context is still active;
  • guarantees context reset in a nested finally;
  • prevents ordinary cleanup failures from changing the primary command outcome;
  • continues teardown when cleanup hooks or logger flush/close operations fail;
  • omits log_path from history records when file logging is disabled.

This fixes the release-blocking leak where a history writer exception left the current Context active, retained the temp directory and logger handlers, and could mask the command's own exception.

Issue

Fixes #51

Parent roadmap: #50

Validation

  • uv run --no-project --with pytest --with click --with pyyaml python -m pytest tests/test_app_lifecycle.py tests/test_generic_core.py — 9 passed
  • uv run --no-project --with pytest --with click --with pyyaml python -m pytest — 115 passed
  • ./tests/validate.sh — passed
  • python3 -m compileall -q lib/python/base_cli tests — passed
  • Essential Ruff checks (E4,E7,E9,F) on changed Python files — passed
  • git diff --check — passed

Notes

This PR intentionally does not finalize run.json or change interrupt/exit-code semantics. Those broader outcome contracts are next in the train under #52 and depend on this teardown guarantee.

Checklist

  • Branch name follows <category>/<issue>-<YYYYMMDD>-<slug>, and its category prefix matches the issue's single standard category label.
  • Pull request is scoped to one issue.
  • Pull request body explains what changed and how it was validated.
  • Relevant project checks pass.
  • Documentation/changelog is updated for the behavior change.
  • Pull request includes Fixes #51.

@codeforester
codeforester marked this pull request as ready for review August 2, 2026 13:33
@codeforester
codeforester merged commit 72d3650 into main Aug 2, 2026
17 checks passed
@codeforester
codeforester deleted the bug/51-20260802-lifecycle-teardown branch August 2, 2026 13:33
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.

Make lifecycle teardown failure-safe

1 participant