Skip to content

Commit 1861d55

Browse files
morlutocursoragent
authored andcommitted
fix(runtime): preserve bootstrap failures during cleanup
1 parent 0f7a445 commit 1861d55

2 files changed

Lines changed: 34 additions & 2 deletions

File tree

src/jacobian/runtime/bootstrap.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,9 @@ def bootstrap_services(root: str | Path, options: RuntimeOptions) -> CoreService
6868
capabilities=capabilities,
6969
reasoning_log=reasoning_log,
7070
)
71-
except BaseException:
72-
store.close()
71+
except BaseException as exc:
72+
try:
73+
store.close()
74+
except BaseException as cleanup_exc:
75+
exc.add_note(f"service bootstrap cleanup also failed: {cleanup_exc}")
7376
raise

tests/composition/runtime/test_runtime_lifecycle.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -469,6 +469,35 @@ def failing_install(*args: object, **kwargs: object) -> None:
469469
reopened.close()
470470

471471

472+
def test_bootstrap_cleanup_failure_preserves_primary_failure(
473+
tmp_path: Path,
474+
monkeypatch: pytest.MonkeyPatch,
475+
) -> None:
476+
from jacobian.storage.repository import ArtifactRepository
477+
478+
def failing_install(*args: object, **kwargs: object) -> None:
479+
raise RuntimeError("bootstrap failure")
480+
481+
original_close = ArtifactRepository.close
482+
483+
def close_then_fail(store: ArtifactRepository) -> None:
484+
original_close(store)
485+
raise OSError("store close failure")
486+
487+
monkeypatch.setattr(
488+
"jacobian.runtime.bootstrap.install_sat_artifacts",
489+
failing_install,
490+
)
491+
monkeypatch.setattr(ArtifactRepository, "close", close_then_fail)
492+
493+
with pytest.raises(RuntimeError, match="bootstrap failure") as caught:
494+
create_runtime(tmp_path)
495+
496+
assert caught.value.__notes__ == [
497+
"service bootstrap cleanup also failed: store close failure"
498+
]
499+
500+
472501
def test_close_failure_keeps_store_closable_on_retry(
473502
tmp_path: Path,
474503
monkeypatch: pytest.MonkeyPatch,

0 commit comments

Comments
 (0)