Skip to content

Exit PRECONDITION when the investigation record cannot be written - #61

Merged
shipmill-romamo[bot] merged 1 commit into
mainfrom
fix/56-investigation-save-precondition
Oct 9, 2026
Merged

shipmill-romamo[bot] merged 1 commit into
mainfrom
fix/56-investigation-save-precondition

Conversation

@shipmill-romamo

Copy link
Copy Markdown
Contributor

Summary

agent investigate now exits 4 PRECONDITION (code agent_investigations_unwritable), naming the investigations folder, when it cannot write its record, as D-5 (#59) settles.

  • InvestigationStore.save wraps an OSError from creating the folder or writing the record (not the id-collision FileExistsError, which still moves to the next suffix) in InvestigationError. The existing _save_investigation maps that to PRECONDITION, so the normal end and the model-unavailable save are covered with no new mapping
  • The stopped path (GeneratorExit) can't raise: treaty closes the handler itself, prints whatever close raises as a traceback, and exits 0 anyway (_close_events, then output_closed). So the handler keeps the error in cloudfall.app.stream_unrecorded, like stream_stopped, and does not set stream_stopped. cloudfall.cli then writes one JSON line to stderr ({"code": "PRECONDITION", "message": ..., "context": {"code": "agent_investigations_unwritable"}}, the same shape as the stream's warning lines) and exits 4 instead of 0/141. The record is lost; the exit stays non-zero (D-3, D-5)

Exit codes other than this case are unchanged.

Test plan

  • New: test_an_unwritable_investigations_folder_is_refused_naming_it (store level, a file where the folder goes)
  • New: test_a_record_that_cannot_be_written_exits_precondition (CLI, stream runs to the end: exit 4, PRECONDITION, folder named, no traceback on stderr)
  • New: test_a_stopped_run_whose_record_cannot_be_written_exits_precondition (real subprocess, reader closes stdout after the first turn and call: exit 4, no traceback, the stderr JSON line names the folder). Fails on main with exit 0 and the treaty traceback
  • The existing stopped-run test now shares the subprocess helper _closed_mid_run
  • uv run ruff check ., uv run mypy, uv run pytest (full suite, 469 passed), uv run cloudfall config validate --project config/examples: all pass

Fixes #56

🤖 Generated with Claude Code

InvestigationStore.save let an OSError from the write escape unwrapped, so
a run whose investigations folder could not be written crashed with a
traceback. In a stream whose reader closed stdout the crash came from the
generator's close, which treaty reports with a traceback and exit 0, so
the stopped run broke D-3.

The store now wraps the error as agent_investigations_unwritable, naming
the folder, which agent investigate already maps to PRECONDITION. The
stopped path keeps the error for cloudfall.cli, which writes it to stderr
as a JSON line and exits PRECONDITION (D-5): the record is lost, the exit
stays non-zero.

Fixes #56

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@shipmill-romamo
shipmill-romamo Bot merged commit a997733 into main Oct 9, 2026
1 check passed
@shipmill-romamo
shipmill-romamo Bot deleted the fix/56-investigation-save-precondition branch October 9, 2026 16:22
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.

agent investigate exits 0 when saving a stopped investigation fails

0 participants