From 6c8759ed9f80d553fc019d624070433526c90e38 Mon Sep 17 00:00:00 2001 From: Rohit Goswami Date: Thu, 19 Nov 2026 00:58:15 +0000 Subject: [PATCH 1/2] fix: propagate summary write failures A run treated summary destination failures as warnings and retained exit status 0, so callers could accept a successful run after its summary write failed. Summary files now use the shared atomic writer, and a summary failure makes the command return status 1. The CLI reproducer is `run` with the usual `--site` and `--target` values after creating `summary.json` as a directory in the run directory; the command now reports the destination error through its exit status. The new test `a_summary_destination_directory_fails_the_run` in `tests/summary.rs` checks that a directory at the JSON summary destination makes an otherwise successful run fail. --- changelog.d/+summary-write-status.bugfix.md | 1 + docs/examples/summary.sh | 4 +-- docs/orgmode/howto/follow-runs.org | 4 +-- docs/orgmode/reference/exit-status.org | 5 ++-- docs/orgmode/reference/run-summary.org | 8 +++--- src/main.rs | 27 ++++++++++++--------- tests/summary.rs | 10 ++++---- 7 files changed, 32 insertions(+), 27 deletions(-) create mode 100644 changelog.d/+summary-write-status.bugfix.md diff --git a/changelog.d/+summary-write-status.bugfix.md b/changelog.d/+summary-write-status.bugfix.md new file mode 100644 index 00000000..5babe6f5 --- /dev/null +++ b/changelog.d/+summary-write-status.bugfix.md @@ -0,0 +1 @@ +Return a failed status when a run summary cannot be written. diff --git a/docs/examples/summary.sh b/docs/examples/summary.sh index 881cd309..8f8b9492 100644 --- a/docs/examples/summary.sh +++ b/docs/examples/summary.sh @@ -57,8 +57,8 @@ expect_line ' "kind": "status",' run 'mkdir -p site/logs/20261117_100000/summary.json eb-pipeline run --site site.toml --list example.list --target zen4 --build-type production --log-stamp 20261117_100000; echo "exit $?"' -expect_line 'exit 0' -expect_line 'WARN [summary] zen4: no summary written: $WORK/site/logs/20261117_100000/summary.json: Is a directory (os error 21)' +expect_line 'exit 1' +expect_line 'ERROR [main] -: cannot write run summary: $WORK/site/logs/20261117_100000/summary.json: Is a directory (os error 21)' cp site.toml notify.toml printf '\n[notify]\nwebhook_env = "SUMMARY_WEBHOOK"\nwhen = "problems"\n' >>notify.toml diff --git a/docs/orgmode/howto/follow-runs.org b/docs/orgmode/howto/follow-runs.org index 36d97416..f90cafa2 100644 --- a/docs/orgmode/howto/follow-runs.org +++ b/docs/orgmode/howto/follow-runs.org @@ -233,13 +233,13 @@ With no lines left after classification, =stack oom= is not started. |------------------------------------------------------------------------------------------------------------------------------+----------------------------------------------------------------------------------------------------------------+--------------------------------------------------------------------------------------| | =INFO [status] -: no runs under LOG_ROOT= | No run has written under the =log_root= of the site file: none has run yet, or the runs use another site file. | Give =status= the site file that the runs use. | | =RUN no summary.json: the run is still going, or ended before writing one= | The run has not ended, or it stopped before it wrote its summary. | Wait for the run to end, or read the logs in its run directory. | -| =WARN [summary] TARGET: no summary written: PATH: ERROR= | The run could not write its summary. | Fix what =ERROR= names, such as the permissions or the free space of the log root. | +| =ERROR [main] -: cannot write run summary: PATH: ERROR= | The run could not write its summary. | Fix what =ERROR= names, such as the permissions or the free space of the log root. | | =WARN [notify] TARGET: SUMMARY_WEBHOOK is unset or empty; nothing sent= | The variable that =webhook_env= names is not set where eb-pipeline runs. | Set it there, as step 4 says. | | =WARN [notify] TARGET: the URL in SUMMARY_WEBHOOK must start with http:// or https://; nothing sent= | The variable holds something other than a URL with its scheme. | Put the URL of the webhook in it, with =https://= or =http://=. | | =WARN [notify] TARGET: POST of summary.json to URL failed: curl exited 7: ERROR= | Nothing took the connection at the host and port of the URL. | Check the URL, and that the service of the webhook, or the listener of step 5, runs. | | =WARN [notify] TARGET: POST of summary.json to URL failed: curl exited 22: curl: (22) The requested URL returned error: 500= | The webhook answered with an HTTP error. | Read what its service logged for the POST. | -A summary that is not written or not sent leaves the exit status of the run as it was. +A summary that cannot be written fails the run. A summary that is not sent leaves the exit status of the run as it was. ** Related diff --git a/docs/orgmode/reference/exit-status.org b/docs/orgmode/reference/exit-status.org index 186b8b2f..1177905a 100644 --- a/docs/orgmode/reference/exit-status.org +++ b/docs/orgmode/reference/exit-status.org @@ -44,6 +44,7 @@ An error that ends a command is written to stderr as =ERROR [main] -: MESSAGE=. - =run=: =eb-stack stack sbom= could not be started, exited with a status other than 0, or wrote no =sbom.cdx.json=, after a clean build. - =run=: =eb-keep-logs rotate= exited with a status other than 0 and 75. - =run=: a log file, a log directory, the list of selected lines or the result file could not be written. +- =run= or =watch=: the run summary could not be written. - =plan=: the shard plan given to =--shard-plan= could not be read, or the plan could not be written to =--out=. - =plan= or =run=: =[attest]= is enabled and =rfc9162-sidecar= could not be started or exited with a status other than 0. - =verify=: the inclusion proof does not meet its checkpoint, or the blob file does not match the proof. @@ -52,7 +53,7 @@ An error that ends a command is written to stderr as =ERROR [main] -: MESSAGE=. - =audit=: =--out-dir= or its working directory could not be created, an =eb-stack= subcommand exited non-zero or its log could not be read, a rebuild list could not be copied, or =--strict= saw one or more backport items. A failed =eb-keep-logs failed= after a failed line leaves the status as it is, with a =WARN= line. -So does a run summary that cannot be written, or sent to the webhook of =[notify]=, as [[file:run-summary.org][The run summary]] says, and a record of =[watch]= that fails, as [[file:watch.org][The watch state and plan]] says. +So does a summary that cannot be sent to the webhook of =[notify]=, as [[file:run-summary.org][The run summary]] says, and a record of =[watch]= that fails, as [[file:watch.org][The watch state and plan]] says. *** 2 @@ -112,7 +113,7 @@ An attestation helper killed by a signal reports and returns =128 + signal=. ** When several apply A signal ends a run with 130 or 143, and a usage error with 2, whatever else happened before. -This holds for a result file or a metrics file that cannot be written after the signal: the run reports the error and still exits 130 or 143. +This holds for a result file, a metrics file or a run summary that cannot be written after the signal: the run reports the error and still exits 130 or 143. Otherwise the first of these that applies is the status of the run: 1. a line or a phase failed: 1; diff --git a/docs/orgmode/reference/run-summary.org b/docs/orgmode/reference/run-summary.org index 61411542..b2bdb7b3 100644 --- a/docs/orgmode/reference/run-summary.org +++ b/docs/orgmode/reference/run-summary.org @@ -58,9 +58,9 @@ zen4 Each run takes the lock =.summary.lock= of the run directory, reads =summary.json=, replaces the entry of its own target and keeps the others, and writes both files anew through a rename, so that a reader never sees half of one. A later run of the same target with the same stamp replaces that target's entry. A =summary.json= with another =schema_version= is replaced. -One that does not parse is kept, and the run warns that no summary was written, so one target cannot erase the other target entries that may still be recoverable. +One that does not parse is kept, and the run fails without replacing it, so one target cannot erase the other target entries that may still be recoverable. -A summary that cannot be written is a warning, and the run exits as it would have without it. +A summary that cannot be written fails the run. Here a directory is in the way of =summary.json=: #+begin_src bash @@ -71,8 +71,8 @@ eb-pipeline run --site site.toml --list example.list --target zen4 --build-type #+begin_example INFO [licences] zen4: not configured ... -WARN [summary] zen4: no summary written: $WORK/site/logs/20261117_100000/summary.json: Is a directory (os error 21) -exit 0 +ERROR [main] -: cannot write run summary: $WORK/site/logs/20261117_100000/summary.json: Is a directory (os error 21) +exit 1 #+end_example ** summary.json diff --git a/src/main.rs b/src/main.rs index 6ac290a5..9dd165eb 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1106,10 +1106,12 @@ fn cmd_plan_or_run(c: &Common, m: Mode) -> Result { watch::record_run(&planner, &lines, &res, before); } apply_pending_signal(&mut res); - write_summary(&s, &res, "run", result, None, &planner.offline_wrapper); + let mut output_errors = Vec::new(); + if let Err(f) = write_summary(&s, &res, "run", result, None, &planner.offline_wrapper) { + output_errors.push(f.msg); + } apply_pending_signal(&mut res); let value = to_sorted(&res); - let mut output_errors = Vec::new(); if let Some(p) = result { if let Err(f) = write_json(&value, Some(p)) { output_errors.push(f.msg); @@ -1159,8 +1161,8 @@ fn apply_pending_signal(res: &mut RunResult) { res.exit_code = code; } -/// Merge a target's run into its run directory's summary; a problem is a -/// warning and leaves the run's exit code as it is. +/// Merge a target's run into its run directory's summary. A problem writing +/// the summary fails the command. fn write_summary( s: &schema::Site, res: &RunResult, @@ -1168,7 +1170,7 @@ fn write_summary( result: Option<&Path>, watch: Option, offline_wrapper: &[String], -) { +) -> Result<(), Fail> { let dir = summary::run_dir(res); let entry = summary::entry(res, command, result, watch); match summary::record(&s.site.name, entry, &dir) { @@ -1191,13 +1193,12 @@ fn write_summary( &dir.join(summary::JSON), offline_wrapper, ); + Ok(()) } - Err(e) => log( - "WARN", - "summary", - &res.target, - &format!("no summary written: {e}"), - ), + Err(e) => Err(Fail::new( + exit::FAILED, + format!("cannot write run summary: {e}"), + )), } } @@ -1597,7 +1598,9 @@ fn cmd_watch(w: &WatchArgs) -> Result { } drop_work(); } - write_summary(&s, &res, "watch", w.result, Some(to_sorted(&doc)), &[]); + if let Err(f) = write_summary(&s, &res, "watch", w.result, Some(to_sorted(&doc)), &[]) { + return Err(signal_outranks(res.exit_code, f)); + } if let Some(p) = w.result { write_json(&to_sorted(&res), Some(p)).map_err(|f| signal_outranks(res.exit_code, f))?; } diff --git a/tests/summary.rs b/tests/summary.rs index 4370da7e..649ccbf5 100644 --- a/tests/summary.rs +++ b/tests/summary.rs @@ -142,10 +142,10 @@ fn a_corrupt_summary_is_not_replaced_by_one_target() { std::fs::write(&path, corrupt).unwrap(); let repeated = run(&t, "cpu", STAMP, LIST, &[]); - assert_eq!(code(&repeated), 0, "{}", stderr(&repeated)); + assert_eq!(code(&repeated), 1, "{}", stderr(&repeated)); assert_eq!(std::fs::read(&path).unwrap(), corrupt); assert!( - stderr(&repeated).contains("no summary written: cannot parse"), + stderr(&repeated).contains("cannot write run summary: cannot parse"), "{}", stderr(&repeated) ); @@ -184,13 +184,13 @@ fn a_dry_run_writes_no_summary() { } #[test] -fn a_summary_that_cannot_be_written_leaves_the_exit_code() { +fn a_summary_destination_directory_fails_the_run() { let t = setup(""); std::fs::create_dir_all(t.run_dir(STAMP).join("summary.json")).unwrap(); let o = run(&t, "cpu", STAMP, LIST, &[]); - assert_eq!(code(&o), 0, "{}", stderr(&o)); + assert_eq!(code(&o), 1, "{}", stderr(&o)); assert!( - stderr(&o).contains("WARN [summary] cpu: no summary written: "), + stderr(&o).contains("ERROR [main] -: cannot write run summary: "), "{}", stderr(&o) ); From c1d498cc96fa786fc50161916bd3281619d51815 Mon Sep 17 00:00:00 2001 From: Rohit Goswami Date: Thu, 26 Nov 2026 10:07:54 +0000 Subject: [PATCH 2/2] test: expect a refused summary to fail the run A summary file of the wrong kind, a bundle manifest, and other refused destinations still expected a warning and exit 0. They now expect status 1 and the summary write error, and the file is left unchanged. --- tests/offline_bundle.rs | 4 ++-- tests/summary.rs | 14 +++++++------- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/tests/offline_bundle.rs b/tests/offline_bundle.rs index 47615421..6b6dc320 100644 --- a/tests/offline_bundle.rs +++ b/tests/offline_bundle.rs @@ -367,9 +367,9 @@ fn a_bundle_manifest_is_not_taken_for_a_run_summary() { let again = run(&f, &[]); let stderr = String::from_utf8_lossy(&again.stderr); - assert_eq!(again.status.code(), Some(0), "{stderr}"); + assert_eq!(again.status.code(), Some(1), "{stderr}"); assert!( - stderr.contains("no summary written: ") && stderr.contains(why), + stderr.contains("cannot write run summary: ") && stderr.contains(why), "{stderr}" ); assert_eq!(std::fs::read_to_string(&summary).unwrap(), manifest); diff --git a/tests/summary.rs b/tests/summary.rs index 3ca4eeb8..5c0833cc 100644 --- a/tests/summary.rs +++ b/tests/summary.rs @@ -166,7 +166,7 @@ fn a_summary_with_another_kind_is_not_merged() { let gpu = run(&t, "gpu", STAMP, LIST, &[]); - assert_eq!(code(&gpu), 0, "{}", stderr(&gpu)); + assert_eq!(code(&gpu), 1, "{}", stderr(&gpu)); assert_eq!(std::fs::read_to_string(&path).unwrap(), foreign); assert!( stderr(&gpu).contains("kind `result` is not `summary`"), @@ -283,19 +283,19 @@ fn status_of_runs(t: &T) -> String { } /// `record` and `status` on `text` as `summary.json`: both refuse it with -/// `why`, and the run leaves the file as it was. +/// `why`, the run fails, and the file is left as it was. fn assert_refused_and_kept(text: &str, why: &str) { let (t, path) = with_summary_file(text); let o = run(&t, "gpu", STAMP, LIST, &[]); - assert_eq!(code(&o), 0, "{}", stderr(&o)); + assert_eq!(code(&o), 1, "{}", stderr(&o)); assert_eq!(std::fs::read_to_string(&path).unwrap(), text); let err = stderr(&o); - let warning = err + let error = err .lines() - .find(|l| l.starts_with("WARN [summary] gpu: no summary written: ")) - .unwrap_or_else(|| panic!("no summary warning in {err}")); - assert!(warning.contains(why), "{warning}"); + .find(|l| l.starts_with("ERROR [main] -: cannot write run summary: ")) + .unwrap_or_else(|| panic!("no summary error in {err}")); + assert!(error.contains(why), "{error}"); let shown = status_of_runs(&t); assert!(