Complete diagnostics retention semantics
This commit is contained in:
@@ -21,6 +21,31 @@ type RunDirectory struct {
|
||||
createdAt time.Time
|
||||
}
|
||||
|
||||
type RetentionDecisionInput struct {
|
||||
RetentionMode string
|
||||
RunSucceeded bool
|
||||
HasSkippedCorrections bool
|
||||
}
|
||||
|
||||
func ShouldRetainRunDirectory(input RetentionDecisionInput) bool {
|
||||
// Failed runs are always retained.
|
||||
if !input.RunSucceeded {
|
||||
return true
|
||||
}
|
||||
|
||||
switch input.RetentionMode {
|
||||
case "always":
|
||||
return true
|
||||
case "never":
|
||||
return true
|
||||
case "auto":
|
||||
return input.HasSkippedCorrections
|
||||
default:
|
||||
// Be conservative for unknown values.
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
// InvocationMetadata captures non-secret invocation details for diagnostics.
|
||||
type InvocationMetadata struct {
|
||||
Operation string `json:"operation"`
|
||||
@@ -187,20 +212,14 @@ func (r *RunDirectory) WriteChunkingSummary(summary *chunking.DetailedSummary) e
|
||||
return nil
|
||||
}
|
||||
|
||||
// TODO: In later phases, implement full "auto" semantics based on skip/report outcomes.
|
||||
func (r *RunDirectory) ApplyRetention(runSucceeded bool) error {
|
||||
if !runSucceeded {
|
||||
// Failed runs are always retained.
|
||||
return nil
|
||||
func (r *RunDirectory) ApplyRetention(input RetentionDecisionInput) error {
|
||||
decision := input
|
||||
if decision.RetentionMode == "" {
|
||||
decision.RetentionMode = r.retention
|
||||
}
|
||||
|
||||
switch r.retention {
|
||||
case "always":
|
||||
return nil
|
||||
case "never", "auto":
|
||||
return os.RemoveAll(r.path)
|
||||
default:
|
||||
// Retain by default for unknown modes; config validation should prevent this.
|
||||
if ShouldRetainRunDirectory(decision) {
|
||||
return nil
|
||||
}
|
||||
return os.RemoveAll(r.path)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user