feat: say why a restore failed, and add the user_schemas reset mode
- the agent reports the client's primary ERROR/FATAL line with a failed restore step; the hub keeps it as failure_reason (administrators only), logs it and audits restore.failed. psql runs with VERBOSITY=terse and DETAIL/CONTEXT/statement text is dropped so row data never travels - reset mode user_schemas empties every non-system schema in the restore transaction, so multi-schema databases restore without DROP DATABASE; proven against a real PostgreSQL server Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -79,6 +79,9 @@ pub struct RestoreJob {
|
||||
pub safety_snapshot_id: Option<Uuid>,
|
||||
pub created_at: i64,
|
||||
pub updated_at: i64,
|
||||
/// Why the job failed, as the agent reported it (cleaned). Only administrators ever see it.
|
||||
#[serde(default, skip_serializing_if = "Option::is_none")]
|
||||
pub failure_reason: Option<String>,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Deserialize, Serialize)]
|
||||
@@ -95,6 +98,27 @@ pub struct RestoreLease {
|
||||
pub artifact: RestoreArtifact,
|
||||
}
|
||||
|
||||
/// Header on a restore report that carries the reason for a failure.
|
||||
pub const FAILURE_REASON_HEADER: &str = "x-tessera-failure-reason";
|
||||
const FAILURE_REASON_MAX: usize = 300;
|
||||
|
||||
/// Make a failure reason safe to store, log and send in a header: printable ASCII on one line, at most 300
|
||||
/// bytes. Anything else becomes a space (control characters) or `?` (non-ASCII). Empty input gives `None`.
|
||||
pub fn clean_failure_reason(text: &str) -> Option<String> {
|
||||
let mapped: String = text
|
||||
.chars()
|
||||
.map(|c| match c {
|
||||
c if c.is_ascii_graphic() => c,
|
||||
c if c.is_ascii() => ' ',
|
||||
_ => '?',
|
||||
})
|
||||
.collect();
|
||||
let line = mapped.split_whitespace().collect::<Vec<_>>().join(" ");
|
||||
let line: String = line.chars().take(FAILURE_REASON_MAX).collect();
|
||||
let line = line.trim_end().to_string();
|
||||
(!line.is_empty()).then_some(line)
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy, Debug, Deserialize, Serialize)]
|
||||
#[serde(rename_all = "snake_case")]
|
||||
pub enum RestoreProgress {
|
||||
|
||||
Reference in New Issue
Block a user