Script 'mail_helper' called by obssrc
Hello community,

here is the log from the commit of package openQA for openSUSE:Factory checked 
in at 2026-11-27 19:43:29
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Comparing /work/SRC/openSUSE:Factory/openQA (Old)
 and      /work/SRC/openSUSE:Factory/.openQA.new.1340718 (New)
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

Package is "openQA"

Fri Nov 27 19:43:29 2026 rev:914 rq:1401051 version:5.1795755868.789af64c

Changes:
--------
--- /work/SRC/openSUSE:Factory/openQA/openQA.changes    2026-11-26 
15:55:00.720835917 +0100
+++ /work/SRC/openSUSE:Factory/.openQA.new.1340718/openQA.changes       
2026-11-27 19:46:25.506434090 +0100
@@ -1,0 +2,32 @@
+Fri Nov 27 05:04:43 UTC 2026 - [email protected]
+
+- Update to version 5.1795755868.789af64c:
+  * chore(deps): Dependency cron 2026-11-27
+  * fix(gru): Reconcile orphaned Gru tasks
+  * feat(munin): Add plugin for job stats per group
+
+-------------------------------------------------------------------
+Thu Nov 26 11:54:18 UTC 2026 - [email protected]
+
+- Update to version 5.1795692061.5f354ef5:
+  * fix: Downgrade destroyed tx in `reply.exception`
+  * fix: Guard async Gru callbacks if tx is destroyed
+  * fix: Guard `before_render` against lost transaction
+  * perf: Check status before accepts in before_render
+
+-------------------------------------------------------------------
+Thu Nov 26 10:19:47 UTC 2026 - [email protected]
+
+- Update to version 5.1795688376.1dbabc4a:
+  * docs: document upfront archiving and configuration parameters
+  * feat: archive important jobs upfront when results storage is full
+  * feat: add upfront archiving configuration and validation
+  * refactor: extract important-jobs condition builder
+
+-------------------------------------------------------------------
+Thu Nov 26 05:06:28 UTC 2026 - [email protected]
+
+- Update to version 5.1795669574.57f4021c:
+  * chore(deps): Dependency cron 2026-11-26
+
+-------------------------------------------------------------------

Old:
----
  openQA-5.1795626606.295f3489.obscpio

New:
----
  openQA-5.1795755868.789af64c.obscpio

++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

Other differences:
------------------
++++++ openQA-client-test.spec ++++++
--- /var/tmp/diff_new_pack.YwBe8T/_old  2026-11-27 19:46:27.779530893 +0100
+++ /var/tmp/diff_new_pack.YwBe8T/_new  2026-11-27 19:46:27.786531191 +0100
@@ -18,7 +18,7 @@
 
 %define         short_name openQA-client
 Name:           %{short_name}-test
-Version:        5.1795626606.295f3489
+Version:        5.1795755868.789af64c
 Release:        0
 Summary:        Test package for %{short_name}
 License:        GPL-2.0-or-later

++++++ openQA-test.spec ++++++
--- /var/tmp/diff_new_pack.YwBe8T/_old  2026-11-27 19:46:27.842533576 +0100
+++ /var/tmp/diff_new_pack.YwBe8T/_new  2026-11-27 19:46:27.846533746 +0100
@@ -18,7 +18,7 @@
 
 %define         short_name openQA
 Name:           %{short_name}-test
-Version:        5.1795626606.295f3489
+Version:        5.1795755868.789af64c
 Release:        0
 Summary:        Test package for openQA
 License:        GPL-2.0-or-later

++++++ openQA-worker-test.spec ++++++
--- /var/tmp/diff_new_pack.YwBe8T/_old  2026-11-27 19:46:27.915536685 +0100
+++ /var/tmp/diff_new_pack.YwBe8T/_new  2026-11-27 19:46:27.917536770 +0100
@@ -18,7 +18,7 @@
 
 %define         short_name openQA-worker
 Name:           %{short_name}-test
-Version:        5.1795626606.295f3489
+Version:        5.1795755868.789af64c
 Release:        0
 Summary:        Test package for %{short_name}
 License:        GPL-2.0-or-later

++++++ openQA.spec ++++++
--- /var/tmp/diff_new_pack.YwBe8T/_old  2026-11-27 19:46:27.996540134 +0100
+++ /var/tmp/diff_new_pack.YwBe8T/_new  2026-11-27 19:46:28.001540347 +0100
@@ -104,7 +104,7 @@
 %define devel_requires %devel_no_selenium_requires chromedriver
 
 Name:           openQA
-Version:        5.1795626606.295f3489
+Version:        5.1795755868.789af64c
 Release:        0
 Summary:        Framework for automated system-level testing (web-frontend, 
scheduler and tools)
 Group:          Development/Tools/Other
@@ -482,9 +482,11 @@
 install -d -m 755 %{buildroot}/%{_prefix}/lib/munin/plugins
 install -m 755 contrib/munin/plugins/minion 
%{buildroot}/%{_prefix}/lib/munin/plugins/openqa_minion_
 install -m 755 contrib/munin/plugins/table_sizes 
%{buildroot}/%{_prefix}/lib/munin/plugins/table_sizes_
+install -m 755 contrib/munin/plugins/group_sizes 
%{buildroot}/%{_prefix}/lib/munin/plugins/group_sizes_
 install -d -m 755 %{buildroot}/%{_sysconfdir}/munin/plugin-conf.d
 install -m 644 contrib/munin/config/minion.config 
%{buildroot}/%{_sysconfdir}/munin/plugin-conf.d/openqa-minion
 install -m 644 contrib/munin/config/table_sizes.config 
%{buildroot}/%{_sysconfdir}/munin/plugin-conf.d/openqa-table-sizes
+install -m 644 contrib/munin/config/group_sizes.config 
%{buildroot}/%{_sysconfdir}/munin/plugin-conf.d/openqa-group-sizes
 install -m 755 contrib/munin/utils/munin-mail 
%{buildroot}/%{_datadir}/openqa/script/munin-mail
 %endif
 
@@ -951,6 +953,7 @@
 %defattr(-,root,root)
 %doc contrib/munin/config/minion.config
 %doc contrib/munin/config/table_sizes.config
+%doc contrib/munin/config/group_sizes.config
 %dir %{_datadir}/openqa/script
 %dir %{_prefix}/lib/munin
 %dir %{_prefix}/lib/munin/plugins
@@ -958,9 +961,11 @@
 %dir %{_sysconfdir}/munin/plugin-conf.d
 %{_prefix}/lib/munin/plugins/openqa_minion_
 %{_prefix}/lib/munin/plugins/table_sizes_
+%{_prefix}/lib/munin/plugins/group_sizes_
 %{_datadir}/openqa/script/munin-mail
 %config(noreplace) %{_sysconfdir}/munin/plugin-conf.d/openqa-minion
 %config(noreplace) %{_sysconfdir}/munin/plugin-conf.d/openqa-table-sizes
+%config(noreplace) %{_sysconfdir}/munin/plugin-conf.d/openqa-group-sizes
 %endif
 
 %files mcp

++++++ openQA-5.1795626606.295f3489.obscpio -> 
openQA-5.1795755868.789af64c.obscpio ++++++
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' 
old/openQA-5.1795626606.295f3489/contrib/munin/config/group_sizes.config 
new/openQA-5.1795755868.789af64c/contrib/munin/config/group_sizes.config
--- old/openQA-5.1795626606.295f3489/contrib/munin/config/group_sizes.config    
1970-01-01 01:00:00.000000000 +0100
+++ new/openQA-5.1795755868.789af64c/contrib/munin/config/group_sizes.config    
2026-11-27 06:04:28.000000000 +0100
@@ -0,0 +1,6 @@
+[group_sizes_openqa]
+#user root
+#env.db_host 127.0.0.1
+#env.db_port 5432
+#env.db_user user
+#env.db_pass pass
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' 
old/openQA-5.1795626606.295f3489/contrib/munin/plugins/group_sizes 
new/openQA-5.1795755868.789af64c/contrib/munin/plugins/group_sizes
--- old/openQA-5.1795626606.295f3489/contrib/munin/plugins/group_sizes  
1970-01-01 01:00:00.000000000 +0100
+++ new/openQA-5.1795755868.789af64c/contrib/munin/plugins/group_sizes  
2026-11-27 06:04:28.000000000 +0100
@@ -0,0 +1,177 @@
+#!/usr/bin/perl
+package group_sizes;
+use strict;
+use warnings;
+use DBI;
+use v5.26;
+use experimental qw(signatures);
+
+# Munin multigraph plugin to monitor PostgreSQL group sizes (jobs, modules,
+# result_size) in the 'openqa' database.
+#
+# Usage
+#
+# To measure groups in the openqa db, add this to
+# /etc/munin/plugin-conf.d/openqa-group-sizes
+#
+#   [group_sizes_openqa]
+#   user root
+#   env.db_host 127.0.0.1
+#   env.db_host /var/run/postgresql
+#   env.db_port 5432
+#   env.db_user user
+#   env.db_pass pass
+#
+# Put script into /usr/lib/munin/plugins/group_sizes_ (or symlink)
+#
+# Create a symlink in /etc/munin/plugins:
+# group_sizes_openqa -> /usr/lib/munin/plugins/group_sizes_
+
+my ($db_name) = $0 =~ m/group_sizes_(\w+)/;
+$db_name ||= $ENV{db_name} || 'openqa';
+my $db_host = $ENV{db_host} // '';
+my $db_port = $ENV{db_port} // '';
+my $db_user = $ENV{db_user} // 'postgres';
+my $db_pass = $ENV{db_pass} // '';
+
+my $dsn = "dbi:Pg:dbname=$db_name";
+$dsn .= ";host=$db_host" if $db_host ne '';
+$dsn .= ";port=$db_port" if $db_port ne '';
+
+$db_name =~ tr/A-Za-z0-9/_/c;
+
+my %graphs = (
+    jobs => {
+        title => 'Jobs per group',
+        description => 'Number of jobs per job group',
+        vlabel => 'Jobs',
+        base => 1000,
+    },
+    job_modules => {
+        title => 'Job modules per group',
+        description => 'Sum of job_module entries per job group',
+        vlabel => 'Job modules',
+        base => 1000,
+    },
+    result_size => {
+        title => 'Result sizes per group',
+        description => 'Sum of result_size per job group',
+        vlabel => 'Bytes',
+        base => 1024,
+    },
+);
+
+my @graph_types = sort keys %graphs;
+
+sub fetch_data () {
+    my $dbh = DBI->connect(
+        $dsn,
+        $db_user,
+        $db_pass,
+        { RaiseError => 1, AutoCommit => 1, PrintError => 0 }
+    );
+
+    # Fetch group names
+    my %parents;
+    my %groups = (0 => {name => 'none'});
+    {
+        my $sql = 'SELECT id, name FROM job_group_parents';
+        my $sth = $dbh->prepare($sql);
+        $sth->execute();
+        %parents = %{$sth->fetchall_hashref('id')};
+        $sql = 'SELECT id, name, parent_id FROM job_groups';
+        $sth = $dbh->prepare($sql);
+        $sth->execute();
+        my %childs = %{$sth->fetchall_hashref('id')};
+        for my $id (keys %childs) {
+            my $row = $childs{$id};
+            my $name = '';
+            if (my $parent_id = $row->{parent_id}) {
+                $name = "$parents{$parent_id}->{name} / ";
+            }
+            $name .= $row->{name};
+            $groups{$row->{id}}->{name} = $name;
+        }
+    }
+
+    my %tasks = (
+        jobs => {
+            sql => 'SELECT COALESCE(group_id, 0) AS group_id, COUNT(*) AS 
jobs, COALESCE(sum(result_size), 0)::bigint AS result_size FROM jobs j GROUP BY 
COALESCE(group_id, 0)',
+            fields => [qw(jobs result_size)],
+        },
+        job_modules => {
+            sql => 'SELECT COALESCE(j.group_id, 0) As group_id, COUNT(*) AS 
job_modules FROM jobs j JOIN job_modules jm ON jm.job_id=j.id GROUP BY 
COALESCE(j.group_id, 0)',
+            fields => [qw(job_modules)],
+        },
+    );
+    for my $type (sort keys %tasks) {
+        my $sql = $tasks{$type}->{sql};
+        my $sth = $dbh->prepare($sql);
+        $sth->execute();
+
+        my $data = $sth->fetchall_hashref('group_id');
+        for my $id (keys %$data) {
+            my $row = $data->{$id};
+            my $group_id = $row->{group_id};
+            for my $field (@{$tasks{$type}->{fields}}) {
+                $groups{$group_id}->{$field} = $row->{$field};
+            }
+        }
+    }
+    for my $id (keys %groups) {
+        unless (defined $groups{$id}->{jobs}) {
+            delete $groups{$id};
+            next;
+        }
+        $groups{$id}->{$_} //= 0 for @graph_types
+    }
+    return \%groups;
+}
+
+sub main () {
+    my $groups = fetch_data();
+    if (defined $ARGV[0] && $ARGV[0] eq 'config') {
+        config($groups);
+    }
+    else {
+        data($groups);
+    }
+}
+
+sub config ($groups) {
+    for my $type (@graph_types) {
+        print <<~"EOM";
+            multigraph ${db_name}_${type}_by_group
+            graph_title $db_name $graphs{$type}->{title}
+            graph_args --base $graphs{$type}->{base} -l 0
+            graph_vlabel $graphs{$type}->{vlabel}
+            graph_category openqa_groups
+            graph_info $graphs{$type}->{description}
+            EOM
+        # Sort groups from largest to smallest for this specific graph's legend
+        my @sorted = sort {
+            $groups->{$b}->{$type} <=> $groups->{$a}->{$type}
+            || $groups->{$a}->{name} cmp $groups->{$b}->{name}
+        } keys %$groups;
+        for my $id (@sorted) {
+            print <<~"EOM";
+                g_$id.label $groups->{$id}->{name}
+                g_$id.type GAUGE
+                g_$id.min 0
+                EOM
+        }
+        print "\n";
+    }
+}
+
+sub data ($groups) {
+    for my $type (@graph_types) {
+        say "multigraph ${db_name}_${type}_by_group";
+        for my $id (sort { $a <=> $b } keys %$groups) {
+            say "g_$id.value " . ($groups->{$id}->{$type} // 0);
+        }
+        print "\n";
+    }
+}
+
+main() unless caller;
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' old/openQA-5.1795626606.295f3489/dist/rpm/openQA.spec 
new/openQA-5.1795755868.789af64c/dist/rpm/openQA.spec
--- old/openQA-5.1795626606.295f3489/dist/rpm/openQA.spec       2026-11-25 
18:10:06.000000000 +0100
+++ new/openQA-5.1795755868.789af64c/dist/rpm/openQA.spec       2026-11-27 
06:04:28.000000000 +0100
@@ -483,9 +483,11 @@
 install -d -m 755 %{buildroot}/%{_prefix}/lib/munin/plugins
 install -m 755 contrib/munin/plugins/minion 
%{buildroot}/%{_prefix}/lib/munin/plugins/openqa_minion_
 install -m 755 contrib/munin/plugins/table_sizes 
%{buildroot}/%{_prefix}/lib/munin/plugins/table_sizes_
+install -m 755 contrib/munin/plugins/group_sizes 
%{buildroot}/%{_prefix}/lib/munin/plugins/group_sizes_
 install -d -m 755 %{buildroot}/%{_sysconfdir}/munin/plugin-conf.d
 install -m 644 contrib/munin/config/minion.config 
%{buildroot}/%{_sysconfdir}/munin/plugin-conf.d/openqa-minion
 install -m 644 contrib/munin/config/table_sizes.config 
%{buildroot}/%{_sysconfdir}/munin/plugin-conf.d/openqa-table-sizes
+install -m 644 contrib/munin/config/group_sizes.config 
%{buildroot}/%{_sysconfdir}/munin/plugin-conf.d/openqa-group-sizes
 install -m 755 contrib/munin/utils/munin-mail 
%{buildroot}/%{_datadir}/openqa/script/munin-mail
 %endif
 
@@ -952,6 +954,7 @@
 %defattr(-,root,root)
 %doc contrib/munin/config/minion.config
 %doc contrib/munin/config/table_sizes.config
+%doc contrib/munin/config/group_sizes.config
 %dir %{_datadir}/openqa/script
 %dir %{_prefix}/lib/munin
 %dir %{_prefix}/lib/munin/plugins
@@ -959,9 +962,11 @@
 %dir %{_sysconfdir}/munin/plugin-conf.d
 %{_prefix}/lib/munin/plugins/openqa_minion_
 %{_prefix}/lib/munin/plugins/table_sizes_
+%{_prefix}/lib/munin/plugins/group_sizes_
 %{_datadir}/openqa/script/munin-mail
 %config(noreplace) %{_sysconfdir}/munin/plugin-conf.d/openqa-minion
 %config(noreplace) %{_sysconfdir}/munin/plugin-conf.d/openqa-table-sizes
+%config(noreplace) %{_sysconfdir}/munin/plugin-conf.d/openqa-group-sizes
 %endif
 
 %files mcp
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' old/openQA-5.1795626606.295f3489/docs/UsersGuide.md 
new/openQA-5.1795755868.789af64c/docs/UsersGuide.md
--- old/openQA-5.1795626606.295f3489/docs/UsersGuide.md 2026-11-25 
18:10:06.000000000 +0100
+++ new/openQA-5.1795755868.789af64c/docs/UsersGuide.md 2026-11-27 
06:04:28.000000000 +0100
@@ -1821,22 +1821,56 @@
 #archive_preserved_important_jobs = 0
 ```
 
-When archiving is enabled important job results are moved to the archive
-directory once they reach the expiration for regular job logs. This
-happens as part of the normal cleanup. In the web UI an icon indicates that
-a job was archived.
+When archiving is enabled, important job results can be moved to the archive
+directory in two different ways:
+
+1.  **Retention-based archiving (on log expiration):** Important job results
+    are moved once they exceed the retention period for regular job logs. This
+    happens as part of the normal cleanup.
+2.  **Space-driven upfront archiving (under storage pressure):** Important job
+    results whose retention has not yet expired are moved upfront to free up
+    space when the results file system runs full. This is triggered during
+    cleanup when the free space on the results file system falls below the
+    percentage configured by `archive_important_jobs_min_free_percentage`.
+
+In the web UI, an icon indicates that a job was archived.
 
 This means a job is "in the archive" if:
 
 1.  it is important.
-2.  its age is between the retention of regular jobs and important jobs.
+2.  its age is between the retention of regular jobs and important jobs or it
+    was archived upfront under storage pressure.
 3.  thresholds for space-aware cleanup do not prevent the cleanup of job 
results
     from happening at all (because if the cleanup is skipped, also archiving is
     skipped).
 
+Upfront archiving under storage pressure can be tuned using the settings
+`archive_important_jobs_min_free_percentage`, `archive_keep_free_percentage`,
+and `archive_max_duration` under the `[archiving]` section in the 
configuration.
+
+Only important jobs are considered: regular jobs are subject to deletion by
+design, so archiving them would consume archive space and I/O without 
preserving
+results that openQA intends to keep.
+
+The upfront archiving process runs sequentially starting from the oldest
+important unarchived job in a final state and checks the configured boundaries
+before moving each job's results. It stops immediately if:
+
+- The free space on the results file system reaches the target threshold
+  (`archive_important_jobs_min_free_percentage`).
+- The free space on the archive file system drops below the safety floor
+  (`archive_keep_free_percentage`).
+- The time budget for archiving is exhausted (`archive_max_duration`).
+- The free space on the results or archive file system cannot be determined 
(for
+  example when the archive directory does not exist yet).
+- No further eligible important unarchived jobs are left in final states.
+
 > **NOTE:**
-> Archiving does **not** prevent cleanup. If an archived important job exceeds
-> the retention for important jobs it is still subject to cleanup.
+> Upfront archiving only frees up results storage space if the results 
directory
+> and the archive directory are on separate file systems; the phase is skipped
+> when both are on the same device. Archiving does **not** prevent cleanup: if 
an
+> archived important job exceeds the retention for important jobs, it is still
+> subject to deletion during the standard cleanup.
 
 ### Space-aware cleanup
 
@@ -1850,13 +1884,14 @@
 thresholds.
 
 To help distinguish between the different storage-aware thresholds in openQA,
-three distinct configuration families exist:
+four distinct configuration families exist:
 
 | Threshold family           | Section         | Description & purpose         
                                                                                
     | Example configuration keys                                               
                                                                |
 | -------------------------- | --------------- | 
------------------------------------------------------------------------------------------------------------------
 | 
----------------------------------------------------------------------------------------------------------------------------------------
 |
 | **Scheduler Suspension**   | `[scheduler]`   | Suspends job scheduling and 
assignments when free storage space drops too low to prevent full storage 
depletion.   | 
`results_min_free_storage_space_percentage`<br>`archive_min_free_storage_space_percentage`<br>`assets_min_free_storage_space_percentage`
 |
 | **Cleanup Lower Bound**    | `[misc_limits]` | Deletes older logs and 
results (independently of time retentions) until the specified free percentage 
is restored. | 
`result_cleanup_min_free_percentage`<br>`archive_cleanup_min_free_percentage`   
                                                         |
 | **Cleanup Skip Threshold** | `[misc_limits]` | Skips or aborts the cleanup 
job early if there is already sufficient free headroom, saving system I/O 
resources.   | 
`result_cleanup_max_free_percentage`<br>`asset_cleanup_max_free_percentage`     
                                                         |
+| **Upfront Archiving**      | `[archiving]`   | Moves results of important 
jobs to the archive before their retention expires when results storage runs 
low.       | 
`archive_important_jobs_min_free_percentage`<br>`archive_keep_free_percentage`  
                                                         |
 
 In addition to these thresholds, `cleanup_min_free_dry_run` in `[misc_limits]` 
is a
 switch: instead of cleaning up, it evaluates the space-aware cleanup and 
accounts
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' old/openQA-5.1795626606.295f3489/etc/openqa/openqa.ini 
new/openQA-5.1795755868.789af64c/etc/openqa/openqa.ini
--- old/openQA-5.1795626606.295f3489/etc/openqa/openqa.ini      2026-11-25 
18:10:06.000000000 +0100
+++ new/openQA-5.1795755868.789af64c/etc/openqa/openqa.ini      2026-11-27 
06:04:28.000000000 +0100
@@ -390,6 +390,9 @@
 ## Maximum number of retries with exponential back-off for GruJobs to wait for 
a
 ## GruTask to appear in the database
 #wait_for_grutask_retries = 6
+## Minimum age in seconds of a GruTask before the scheduler checks whether its
+## Minion job is missing or has finished/failed without cleaning up
+#gru_task_reconcile_grace = 300
 ## Maximum size of MCP results in bytes (to prevent performance issues)
 # mcp_max_result_size = 500000
 ## Minimum storage duration for scheduled products
@@ -445,6 +448,15 @@
 ## considered important to
 ## 
"${OPENQA_ARCHIVEDIR:-${OPENQA_BASEDIR:-/var/lib}/openqa/archive}/testresults"
 #archive_preserved_important_jobs = 0
+## Archive important job results upfront during cleanup while the free space on
+## the results file system is below this percentage (0 disables)
+#archive_important_jobs_min_free_percentage = 0
+## Stop upfront archiving when the free space on the archive file system would
+## drop below this percentage
+#archive_keep_free_percentage = 5
+## Maximum duration in seconds spent on upfront archiving per cleanup run
+## (0 for no limit)
+#archive_max_duration = 300
 
 [worker_reservation]
 ## Default duration for a worker reservation (e.g. 5h, 2d, 3600)
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' old/openQA-5.1795626606.295f3489/lib/OpenQA/Scheduler.pm 
new/openQA-5.1795755868.789af64c/lib/OpenQA/Scheduler.pm
--- old/openQA-5.1795626606.295f3489/lib/OpenQA/Scheduler.pm    2026-11-25 
18:10:06.000000000 +0100
+++ new/openQA-5.1795755868.789af64c/lib/OpenQA/Scheduler.pm    2026-11-27 
06:04:28.000000000 +0100
@@ -8,6 +8,7 @@
 use Mojo::Server::Daemon;
 use Scalar::Util qw(looks_like_number);
 use Time::Seconds;
+use OpenQA::App;
 use OpenQA::Log qw(log_debug setup_log);
 use OpenQA::Schema;
 use OpenQA::Scheduler::Model::Jobs;
@@ -94,7 +95,7 @@
     push @{$self->plugins->namespaces}, 'OpenQA::Shared::Plugin';
     $self->plugin('Gru');
 
-    # check for stale jobs every 2 minutes
+    # check for stale jobs and orphaned Gru tasks every 2 minutes
     Mojo::IOLoop->recurring(ONE_MINUTE * 2 => \&_check_stale);
 
     # initial schedule
@@ -109,8 +110,9 @@
 
 sub schema ($self = undef) { OpenQA::Schema->singleton }
 
-# uncoverable statement
-# uncoverable statement count:2
-sub _check_stale ($self = undef) { 
OpenQA::Scheduler::Model::Jobs->singleton->incomplete_and_duplicate_stale_jobs }
+sub _check_stale ($self = undef) {
+    
OpenQA::Scheduler::Model::Jobs->singleton->incomplete_and_duplicate_stale_jobs;
+    OpenQA::App->singleton->gru->reconcile_gru_tasks;
+}
 
 1;
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' old/openQA-5.1795626606.295f3489/lib/OpenQA/Setup.pm 
new/openQA-5.1795755868.789af64c/lib/OpenQA/Setup.pm
--- old/openQA-5.1795626606.295f3489/lib/OpenQA/Setup.pm        2026-11-25 
18:10:06.000000000 +0100
+++ new/openQA-5.1795755868.789af64c/lib/OpenQA/Setup.pm        2026-11-27 
06:04:28.000000000 +0100
@@ -316,6 +316,7 @@
             assets_max_limit => 200000,
             max_online_workers => 1000,
             wait_for_grutask_retries => 6,    # exponential, ~4 minutes
+            gru_task_reconcile_grace => 5 * ONE_MINUTE,
             worker_limit_retry_delay => ONE_HOUR / 4,
             mcp_max_result_size => 500000,
             scheduled_product_min_storage_duration => 34,
@@ -332,6 +333,9 @@
         },
         archiving => {
             archive_preserved_important_jobs => 0,
+            archive_important_jobs_min_free_percentage => 0,
+            archive_keep_free_percentage => 5,
+            archive_max_duration => 300,
         },
         worker_reservation => {%{+WORKER_RESERVATION_DURATION_DEFAULTS}, 
comment_required => 1},
         job_details_archive => {
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' 
old/openQA-5.1795626606.295f3489/lib/OpenQA/Shared/Plugin/Gru.pm 
new/openQA-5.1795755868.789af64c/lib/OpenQA/Shared/Plugin/Gru.pm
--- old/openQA-5.1795626606.295f3489/lib/OpenQA/Shared/Plugin/Gru.pm    
2026-11-25 18:10:06.000000000 +0100
+++ new/openQA-5.1795755868.789af64c/lib/OpenQA/Shared/Plugin/Gru.pm    
2026-11-27 06:04:28.000000000 +0100
@@ -10,7 +10,7 @@
 use OpenQA::App;
 use OpenQA::Schema;
 use OpenQA::Shared::GruJob;
-use OpenQA::Log qw(log_debug log_info);
+use OpenQA::Log qw(log_debug log_info log_warning);
 use OpenQA::Utils qw(sharedir);
 use Mojo::Pg;
 use Mojo::Promise;
@@ -18,6 +18,9 @@
 use Mojo::JSON qw(decode_json);
 use Feature::Compat::Try;
 use HTTP::Status qw(:constants);
+use List::Util qw(any);
+use Scalar::Util qw(looks_like_number);
+use Time::HiRes ();
 
 use constant TRACK_INTERVAL => $ENV{OPENQA_GRU_TASK_TRACK_INTERVAL} // 0.5;
 
@@ -186,6 +189,66 @@
     }
 }
 
+sub reconcile_gru_tasks ($self) {
+    try { $self->_reconcile_gru_tasks }
+    catch ($e) { log_warning "Failed to reconcile Gru tasks: $e" }
+}
+
+sub _fail_task ($schema, $gru_id, $message) {
+    my $gru = $schema->resultset('GruTasks')->find($gru_id) or return;
+    $gru->fail($message);
+}
+
+sub _reconcile_gru_tasks ($self) {
+    my $app = $self->app;
+    my $grace = $app->config->{misc_limits}->{gru_task_reconcile_grace};
+    die '"gru_task_reconcile_grace" is invalid (must be number >= 0)' if 
!looks_like_number $grace || $grace < 0;
+
+    my $schema = OpenQA::Schema->singleton;
+    my $sth = $schema->storage->dbh->prepare(<<~'SQL');
+        SELECT
+            gt.id AS gru_id,
+            count(mj.id) FILTER (WHERE mj.id is not null AND mj.notes -> 
'obsolete' is null) AS minion_job_count,
+            array_agg(DISTINCT mj.state::text) AS states,
+            any_value(DISTINCT mj.result #>> '{}') FILTER (WHERE mj.state = 
'failed' AND mj.result is not null) AS result,
+            any_value(mj.notes ->> 'user_error') AS user_error,
+            extract(EPOCH FROM max(mj.finished)) AS finished
+        FROM gru_tasks gt
+        LEFT JOIN minion_jobs mj ON mj.notes @> jsonb_build_object('gru_id', 
gt.id)
+        WHERE gt.t_created < NOW() - (? * INTERVAL '1 second')
+        GROUP BY gru_id
+        ORDER BY gt.id
+        SQL
+    $sth->execute($grace);
+
+    my $cutoff = Time::HiRes::time - $grace;
+    my $gru_tasks = $sth->fetchall_hashref([qw(gru_id)]);
+    for my $gru_id (keys %$gru_tasks) {
+        my $gru_info = $gru_tasks->{$gru_id};
+        if ($gru_info->{minion_job_count} < 1) {
+            log_info "Failing Gru task $gru_id because no matching Minion job 
exists";
+            _fail_task($schema, $gru_id, 'no matching Minion job found');
+            next;
+        }
+        my $minion_job_states = $gru_info->{states};
+        next if any { $_ eq 'inactive' || $_ eq 'active' } @$minion_job_states;
+        if (my $user_error = $gru_info->{user_error}) {
+            log_info "Failing Gru task $gru_id because its Minion job reported 
a user error: $user_error";
+            _fail_task($schema, $gru_id, $user_error);
+        }
+        elsif (any { $_ eq 'finished' } @$minion_job_states) {
+            log_info "Deleting Gru task $gru_id because its Minion job 
finished without cleaning up";
+            $schema->resultset('GruTasks')->search({id => $gru_id})->delete;
+        }
+        elsif (any { $_ eq 'failed' } @$minion_job_states) {
+            next if ($gru_info->{finished} // 0) > $cutoff;
+            my $reason = $gru_info->{result} // 'Minion job failed';
+            log_info "Failing Gru task $gru_id because its Minion job failed: 
$reason";
+            _fail_task($schema, $gru_id, $reason);
+        }
+    }
+}
+
 sub enqueue ($self, $task, $args = [], $options = {}, $jobs = []) {
     my $ttl = $options->{ttl};
     my $limit = $options->{limit} ? $options->{limit} : undef;
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' 
old/openQA-5.1795626606.295f3489/lib/OpenQA/Task/Job/Limit.pm 
new/openQA-5.1795755868.789af64c/lib/OpenQA/Task/Job/Limit.pm
--- old/openQA-5.1795626606.295f3489/lib/OpenQA/Task/Job/Limit.pm       
2026-11-25 18:10:06.000000000 +0100
+++ new/openQA-5.1795755868.789af64c/lib/OpenQA/Task/Job/Limit.pm       
2026-11-27 06:04:28.000000000 +0100
@@ -34,6 +34,18 @@
 
     # prevent multiple limit_results_and_logs tasks and 
limit_screenshots_task/archive_job_results to run in parallel
     my $app = $job->app;
+    my $archiving_cfg = $app->config->{archiving};
+    my $min_free = 
$archiving_cfg->{archive_important_jobs_min_free_percentage};
+    my $keep_free = $archiving_cfg->{archive_keep_free_percentage};
+    my $max_dur = $archiving_cfg->{archive_max_duration};
+
+    return 
$job->fail(_format_percentage_error(archive_important_jobs_min_free_percentage 
=> $min_free))
+      unless _is_valid_percentage($min_free);
+    return $job->fail(_format_percentage_error(archive_keep_free_percentage => 
$keep_free))
+      unless _is_valid_percentage($keep_free);
+    return $job->fail("Configured archive_max_duration ($max_dur) is not a 
non-negative number")
+      if !looks_like_number($max_dur) || $max_dur < 0;
+
     return $job->retry({delay => ONE_MINUTE})
       unless my $process_job_results_guard = 
$app->minion->guard('process_job_results_task', ONE_DAY);
     return $job->finish('Previous limit_results_and_logs job is still active')
@@ -50,6 +62,20 @@
         dir => resultdir,
       );
 
+    try {
+        _archive_important_jobs_upfront(
+            job => $job,
+            archiving_cfg => $archiving_cfg,
+            min_free => $min_free,
+            keep_free => $keep_free,
+            max_dur => $max_dur,
+        );
+    }
+    catch ($e) {
+        log_warning "Unable to archive important jobs upfront: $e";
+        $job->note(archiving_stopped => "error: $e");
+    }
+
     # create temporary job group outside of DB to collect
     # jobs without job_group_id
     my $schema = $app->schema;
@@ -259,6 +285,119 @@
     return (0, "Unable to cleanup enough results from $from");
 }
 
+sub _build_important_conditions ($schema, $job) {
+    my $job_groups = $schema->resultset('JobGroups');
+    my %important_builds_with_version;
+    my %important_builds_without_version;
+    for my $job_group ($job_groups->all) {
+        my ($important_builds_with_version, $important_builds_without_version) 
= @{$job_group->important_builds};
+        $important_builds_with_version{$_} = 1 for 
@$important_builds_with_version;
+        $important_builds_without_version{$_} = 1 for 
@$important_builds_without_version;
+    }
+    my @important_builds_with_version = keys %important_builds_with_version;
+    my @important_builds_without_version = keys 
%important_builds_without_version;
+    my @important_cond = (
+        -or => [
+            TAG_ID_COLUMN, => {-in => \@important_builds_with_version},
+            BUILD => {-in => \@important_builds_without_version}]);
+    my @not_important_cond = (
+        TAG_ID_COLUMN, => {-not_in => \@important_builds_with_version},
+        BUILD => {-not_in => \@important_builds_without_version});
+    $job->note(important_builds_with_version => 
\@important_builds_with_version);
+    $job->note(important_builds_without_version => 
\@important_builds_without_version);
+    return (\@not_important_cond, \@important_cond);
+}
+
+sub _free_percentage ($dir) {
+    my ($available_bytes, $total_bytes);
+    try { ($available_bytes, $total_bytes) = check_df($dir) }
+    catch ($e) {
+        log_warning "Upfront archiving skipped: $e";
+        return undef;
+    }
+    return $available_bytes / $total_bytes * 100;
+}
+
+sub _dirs_on_same_device ($dir_a, $dir_b) {
+    my $device_a = (stat $dir_a)[0];
+    my $device_b = (stat $dir_b)[0];
+    return defined $device_a && defined $device_b && $device_a == $device_b;
+}
+
+sub _archive_important_jobs_upfront (%args) {
+    my ($job, $cfg, $min_free, $keep_free, $max_dur) = @args{qw(job 
archiving_cfg min_free keep_free max_dur)};
+    return if !$cfg->{archive_preserved_important_jobs} || $min_free <= 0;
+    if (_dirs_on_same_device(resultdir(), archivedir())) {
+        $job->note(archived_jobs => 0);
+        $job->note(archiving_stopped => 'resultdir and archivedir are on the 
same device');
+        return;
+    }
+
+    my $signal_guard = OpenQA::Task::SignalGuard->new($job);
+    my $app = $job->app;
+    my $schema = $app->schema;
+    my $jobs_rs = $schema->resultset('Jobs');
+    my (undef, $important_cond) = _build_important_conditions($schema, $job);
+    my $start_time = time;
+    my $archive_jobs_count = 0;
+    my $archiving_stopped_reason = '';
+    my @skipped_ids;
+
+    while (1) {
+        if ($max_dur > 0 && (time - $start_time) >= $max_dur) {
+            $archiving_stopped_reason = 'time budget exceeded';
+            last;
+        }
+        my $results_free = _free_percentage(resultdir());
+        if (!defined $results_free) {
+            $archiving_stopped_reason = 'unable to determine results storage 
usage';
+            last;
+        }
+        if ($results_free >= $min_free) {
+            $archiving_stopped_reason = 'results threshold reached';
+            last;
+        }
+        my $archive_free = _free_percentage(archivedir());
+        if (!defined $archive_free) {
+            $archiving_stopped_reason = 'unable to determine archive storage 
usage';
+            last;
+        }
+        if ($archive_free <= $keep_free) {
+            $archiving_stopped_reason = 'archive floor reached';
+            last;
+        }
+        my $candidate = $jobs_rs->search(
+            {
+                @$important_cond,
+                archived => 0,
+                state => {-in => [FINAL_STATES]},
+                (@skipped_ids ? (id => {-not_in => \@skipped_ids}) : ()),
+            },
+            {order_by => {-asc => 'id'}, rows => 1})->first;
+        if (!$candidate) {
+            $archiving_stopped_reason = 'no candidates left';
+            last;
+        }
+        my $job_id = $candidate->id;
+        my $guard = $app->minion->guard("process_job_results_for_$job_id", 
ONE_DAY);
+        if (!$guard) {
+            push @skipped_ids, $job_id;
+            next;
+        }
+        log_info "Archiving important job $job_id";
+        try {
+            $candidate->archive($signal_guard);
+            $archive_jobs_count++;
+        }
+        catch ($e) {
+            log_warning "Failed to archive job $job_id: $e";
+            push @skipped_ids, $job_id;
+        }
+    }
+    $job->note(archived_jobs => $archive_jobs_count);
+    $job->note(archiving_stopped => $archiving_stopped_reason);
+}
+
 sub _ensure_results_below_threshold ($job, @) {
     my $ensure_task_retry_on_termination_signal_guard = 
OpenQA::Task::SignalGuard->new($job);
     # prevent multiple limit_* tasks to run in parallel
@@ -302,36 +441,18 @@
     return $job->finish('Done, no jobs present') unless $max_job_id;
 
     # determine important builds (for each group)
-    my $job_groups = $schema->resultset('JobGroups');
-    my %important_builds_with_version;
-    my %important_builds_without_version;
-    for my $job_group ($job_groups->all) {
-        my ($important_builds_with_version, $important_builds_without_version) 
= @{$job_group->important_builds};
-        $important_builds_with_version{$_} = 1 for 
@$important_builds_with_version;
-        $important_builds_without_version{$_} = 1 for 
@$important_builds_without_version;
-    }
-    my @important_builds_with_version = keys %important_builds_with_version;
-    my @important_builds_without_version = keys 
%important_builds_without_version;
-    my @important_cond = (
-        -or => [
-            TAG_ID_COLUMN, => {-in => \@important_builds_with_version},
-            BUILD => {-in => \@important_builds_without_version}]);
-    my @not_important_cond = (
-        TAG_ID_COLUMN, => {-not_in => \@important_builds_with_version},
-        BUILD => {-not_in => \@important_builds_without_version});
-    $job->note(important_builds_with_version => 
\@important_builds_with_version);
-    $job->note(important_builds_without_version => 
\@important_builds_without_version);
+    my ($not_important_cond, $important_cond) = 
_build_important_conditions($schema, $job);
 
     # delete results as far as necessary on the results dir and the archive dir
     my $jobs = $schema->resultset('Jobs');
     my ($ok_ar, @message_ar)
       = defined $min_free_percentage_ar
-      ? _delete_results($dry, $jobs, $max_job_id, \@not_important_cond, 
\@important_cond, \$margin_bytes_ar,
+      ? _delete_results($dry, $jobs, $max_job_id, $not_important_cond, 
$important_cond, \$margin_bytes_ar,
         \$margin_bytes, 1)
       : (1);
     my ($ok, @message)
-      = _delete_results($dry, $jobs, $max_job_id, \@not_important_cond, 
\@important_cond, \$margin_bytes,
-        \$margin_bytes, 0);
+      = _delete_results($dry, $jobs, $max_job_id, $not_important_cond, 
$important_cond, \$margin_bytes, \$margin_bytes,
+        0);
     my $method = $ok && $ok_ar ? 'finish' : 'fail';
     $job->$method(join "\n", @message, @message_ar);
 }
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' 
old/openQA-5.1795626606.295f3489/lib/OpenQA/WebAPI/Controller/Admin/Needle.pm 
new/openQA-5.1795755868.789af64c/lib/OpenQA/WebAPI/Controller/Admin/Needle.pm
--- 
old/openQA-5.1795626606.295f3489/lib/OpenQA/WebAPI/Controller/Admin/Needle.pm   
    2026-11-25 18:10:06.000000000 +0100
+++ 
new/openQA-5.1795755868.789af64c/lib/OpenQA/WebAPI/Controller/Admin/Needle.pm   
    2026-11-27 06:04:28.000000000 +0100
@@ -108,6 +108,7 @@
         }
     )->then(
         sub ($result) {
+            return unless $self->tx;    # uncoverable statement
             my $removed_ids = ($result->{removed_ids} //= []);
             $self->emit_event(openqa_needle_delete => {id => $removed_ids}) if 
@$removed_ids;
             $self->render(json => $result);
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' 
old/openQA-5.1795626606.295f3489/lib/OpenQA/WebAPI/Controller/Step.pm 
new/openQA-5.1795755868.789af64c/lib/OpenQA/WebAPI/Controller/Step.pm
--- old/openQA-5.1795626606.295f3489/lib/OpenQA/WebAPI/Controller/Step.pm       
2026-11-25 18:10:06.000000000 +0100
+++ new/openQA-5.1795755868.789af64c/lib/OpenQA/WebAPI/Controller/Step.pm       
2026-11-27 06:04:28.000000000 +0100
@@ -436,6 +436,8 @@
         }
     )->then(
         sub ($result) {
+            return unless $self->tx;    # uncoverable statement
+
             # handle request for overwrite
             if ($result->{requires_overwrite}) {
                 my $initial_request = $self->req->params->to_hash;
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' 
old/openQA-5.1795626606.295f3489/lib/OpenQA/WebAPI/Controller/Test.pm 
new/openQA-5.1795755868.789af64c/lib/OpenQA/WebAPI/Controller/Test.pm
--- old/openQA-5.1795626606.295f3489/lib/OpenQA/WebAPI/Controller/Test.pm       
2026-11-25 18:10:06.000000000 +0100
+++ new/openQA-5.1795755868.789af64c/lib/OpenQA/WebAPI/Controller/Test.pm       
2026-11-27 06:04:28.000000000 +0100
@@ -206,7 +206,7 @@
         task_name => 'git_clone',
         task_description => 'cloning test distribution',
         task_args => {testcasedir($distri, $preset->{version}) => $casedir}    
# uncoverable statement
-      )->then(sub ($result) { $self->render(json => $result) })    # 
uncoverable statement
+      )->then(sub ($result) { return unless $self->tx; $self->render(json => 
$result) })    # uncoverable statement
       ->catch(sub ($error, @) { $self->reply->gru_result($error, 
HTTP_BAD_REQUEST) });
 }
 
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' 
old/openQA-5.1795626606.295f3489/lib/OpenQA/WebAPI/Plugin/Helpers.pm 
new/openQA-5.1795755868.789af64c/lib/OpenQA/WebAPI/Plugin/Helpers.pm
--- old/openQA-5.1795626606.295f3489/lib/OpenQA/WebAPI/Plugin/Helpers.pm        
2026-11-25 18:10:06.000000000 +0100
+++ new/openQA-5.1795755868.789af64c/lib/OpenQA/WebAPI/Plugin/Helpers.pm        
2026-11-27 06:04:28.000000000 +0100
@@ -264,6 +264,7 @@
     $app->helper(find_job_or_render_not_found => 
\&_find_job_or_render_not_found);
     $app->helper(
         'reply.gru_result' => sub ($c, $result, $error_code = 200) {
+            return unless $c->tx;
             return $c->render(json => $result, status => $error_code);
         });
 
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' old/openQA-5.1795626606.295f3489/lib/OpenQA/WebAPI.pm 
new/openQA-5.1795755868.789af64c/lib/OpenQA/WebAPI.pm
--- old/openQA-5.1795626606.295f3489/lib/OpenQA/WebAPI.pm       2026-11-25 
18:10:06.000000000 +0100
+++ new/openQA-5.1795755868.789af64c/lib/OpenQA/WebAPI.pm       2026-11-27 
06:04:28.000000000 +0100
@@ -540,11 +540,19 @@
     $reactor->unsubscribe('error');    # avoid default handling of always 
logging an error
     $reactor->on(error => \&_handle_exception);
 
+    $app->helper(
+        'reply.exception' => sub ($c, $error) {
+            return log_debug 'Connection lost (e.g. closed by client), abort 
processing request'
+              if ($error // '') =~ m/Transaction already destroyed/;
+            return $c->helpers->reply->http_exception($error);
+        });
+
     # add method to be called before rendering
     $app->hook(
         before_render => sub ($c, $args) {
+            return unless $c->tx;
             # return errors as JSON if accepted but HTML not
-            if (!$c->accepts('html') && $c->accepts('json') && $args->{status} 
&& $args->{status} != HTTP_OK) {
+            if ($args->{status} && $args->{status} != HTTP_OK && 
!$c->accepts('html') && $c->accepts('json')) {
                 # the JSON API might already provide JSON in some error cases 
which must be preserved
                 (($args->{json} //= {})->{error_status}) = $args->{status};
             }
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' 
old/openQA-5.1795626606.295f3489/t/14-grutasks-reconciliation.t 
new/openQA-5.1795755868.789af64c/t/14-grutasks-reconciliation.t
--- old/openQA-5.1795626606.295f3489/t/14-grutasks-reconciliation.t     
1970-01-01 01:00:00.000000000 +0100
+++ new/openQA-5.1795755868.789af64c/t/14-grutasks-reconciliation.t     
2026-11-27 06:04:28.000000000 +0100
@@ -0,0 +1,158 @@
+#!/usr/bin/env perl
+# Copyright SUSE LLC
+# SPDX-License-Identifier: GPL-2.0-or-later
+
+use Test::Most;
+use Mojo::Base -signatures;
+
+use FindBin;
+use lib "$FindBin::Bin/lib", 
"$FindBin::Bin/../external/os-autoinst-common/lib";
+use DateTime;
+use Mojo::Log;
+use OpenQA::App;
+use OpenQA::Jobs::Constants;
+use OpenQA::Scheduler;
+use OpenQA::Test::TimeLimit '20';
+use OpenQA::Test::Database;
+use Test::Mojo;
+use Test::MockModule;
+use Test::Output qw(combined_like);
+use Test::Warnings ':report_warnings';
+
+my $schema = OpenQA::Test::Database->new->create(fixtures_glob => 
'01-jobs.pl');
+my $t = Test::Mojo->new('OpenQA::WebAPI');
+my $app = $t->app;
+my $minion = $app->minion;
+my $gru_tasks = $schema->resultset('GruTasks');
+my $gru_dependencies = $schema->resultset('GruDependencies');
+my $jobs = $schema->resultset('Jobs');
+my $job = $jobs->find(99927);
+OpenQA::App->set_singleton($app);
+$app->log(Mojo::Log->new(level => 'info'));
+$app->config->{misc_limits}->{gru_task_reconcile_grace} = 0;
+$minion->add_task(test_gru_task => sub { });
+
+sub reset_job ($job) { $job->update({state => SCHEDULED, result => NONE, 
reason => undef}) }
+
+sub enqueue_gru_task ($app, $job = undef) { 
$app->gru->enqueue('test_gru_task', [], {}, $job ? [$job->id] : []) }
+
+sub dequeue_minion_job ($minion, $id) {
+    my $worker = $minion->worker->register;
+    return ($worker->dequeue(0, {id => $id}), $worker);
+}
+
+sub make_gru_task_old ($id) {
+    my $dt = DateTime->now(time_zone => 'UTC')->subtract(hours => 2);
+    $gru_tasks->find($id)->update({t_created => 
$schema->storage->datetime_parser->format_datetime($dt)});
+}
+
+subtest 'failed Minion job is reconciled' => sub {
+    reset_job($job);
+    my $ids = enqueue_gru_task($app, $job);
+    make_gru_task_old($ids->{gru_id});
+    my ($minion_job, $worker) = dequeue_minion_job($minion, $ids->{minion_id});
+    $minion->backend->fail_job(
+        $ids->{minion_id},
+        $minion_job->info->{retries},
+        'Job terminated unexpectedly (exit code: 11, signal: 0)'
+    );
+    $worker->unregister;
+    combined_like { $app->gru->reconcile_gru_tasks } qr/Failing Gru task \d+ 
because its Minion job failed/,
+      'failure logged';
+    is $gru_tasks->find($ids->{gru_id}), undef, 'Gru task deleted';
+    is $gru_dependencies->count, 0, 'dependency deleted';
+    $job->discard_changes;
+    is $job->result, INCOMPLETE, 'dependent job marked as incomplete';
+    like $job->reason, qr/preparation failed: Job terminated unexpectedly/, 
'reason passed to dependent job';
+};
+
+subtest 'missing Minion job is reconciled' => sub {
+    reset_job($job);
+    my $ids = enqueue_gru_task($app, $job);
+    make_gru_task_old($ids->{gru_id});
+    $minion->backend->remove_job($ids->{minion_id});
+    combined_like { $app->gru->reconcile_gru_tasks } qr/Failing Gru task \d+ 
because no matching Minion job exists/,
+      'missing job logged';
+    is $gru_tasks->find($ids->{gru_id}), undef, 'Gru task deleted';
+    is $gru_dependencies->count, 0, 'dependency deleted';
+    $job->discard_changes;
+    is $job->result, INCOMPLETE, 'dependent job marked as incomplete';
+};
+
+subtest 'finished Minion job with leftover Gru task is reconciled' => sub {
+    reset_job($job);
+    my $ids = enqueue_gru_task($app, $job);
+    make_gru_task_old($ids->{gru_id});
+    my ($minion_job, $worker) = dequeue_minion_job($minion, $ids->{minion_id});
+    $minion->backend->finish_job($ids->{minion_id}, 
$minion_job->info->{retries}, 'done');
+    $worker->unregister;
+    combined_like { $app->gru->reconcile_gru_tasks } qr/Deleting Gru task \d+ 
because its Minion job finished/,
+      'finished job logged';
+    is $gru_tasks->find($ids->{gru_id}), undef, 'Gru task deleted';
+    is $gru_dependencies->count, 0, 'dependency deleted';
+    $job->discard_changes;
+    is $job->state, SCHEDULED, 'dependent job remains scheduled';
+};
+
+subtest 'user error in finished Minion job is reconciled as failure' => sub {
+    reset_job($job);
+    my $ids = enqueue_gru_task($app, $job);
+    make_gru_task_old($ids->{gru_id});
+    my ($minion_job, $worker) = dequeue_minion_job($minion, $ids->{minion_id});
+    $minion_job->note(user_error => 'bad input');
+    $minion->backend->finish_job($ids->{minion_id}, 
$minion_job->info->{retries}, 'done');
+    $worker->unregister;
+    combined_like { $app->gru->reconcile_gru_tasks } qr/user error: bad 
input/, 'user error logged';
+    is $gru_tasks->find($ids->{gru_id}), undef, 'Gru task deleted';
+    $job->discard_changes;
+    is $job->result, INCOMPLETE, 'dependent job marked as incomplete';
+    like $job->reason, qr/preparation failed: bad input/, 'user error passed 
to dependent job';
+};
+
+subtest 'pending Minion job is not reconciled' => sub {
+    reset_job($job);
+    my $ids = enqueue_gru_task($app, $job);
+    make_gru_task_old($ids->{gru_id});
+    $app->gru->reconcile_gru_tasks;
+    is $gru_tasks->find($ids->{gru_id})->id, $ids->{gru_id}, 'Gru task kept';
+    is $gru_dependencies->count, 1, 'dependency kept';
+    $minion->backend->remove_job($ids->{minion_id});
+    $gru_tasks->find($ids->{gru_id})->delete;
+};
+
+subtest 'obsolete Minion job is not considered a pending job' => sub {
+    reset_job($job);
+    my $ids = enqueue_gru_task($app, $job);
+    make_gru_task_old($ids->{gru_id});
+    my ($minion_job, $worker) = dequeue_minion_job($minion, $ids->{minion_id});
+    $minion_job->note(obsolete => 1);
+    $minion->backend->fail_job($ids->{minion_id}, 
$minion_job->info->{retries}, 'obsolete');
+    $worker->unregister;
+    combined_like { $app->gru->reconcile_gru_tasks } qr/Failing Gru task \d+ 
because no matching Minion job exists/,
+      'obsolete job treated as missing';
+    is $gru_tasks->find($ids->{gru_id}), undef, 'Gru task deleted';
+    is $gru_dependencies->count, 0, 'dependency deleted';
+};
+
+subtest 'recently failed Minion job is not reconciled immediately' => sub {
+    reset_job($job);
+    my $ids = enqueue_gru_task($app, $job);
+    make_gru_task_old($ids->{gru_id});
+    my ($minion_job, $worker) = dequeue_minion_job($minion, $ids->{minion_id});
+    local $app->config->{misc_limits}->{gru_task_reconcile_grace} = 4 * 60 * 
60;
+    $minion->backend->fail_job($ids->{minion_id}, 
$minion_job->info->{retries}, 'temporary failure');
+    $worker->unregister;
+    $app->gru->reconcile_gru_tasks;
+    is $gru_tasks->find($ids->{gru_id})->id, $ids->{gru_id}, 'Gru task kept';
+    $minion->backend->remove_job($ids->{minion_id});
+    $gru_tasks->find($ids->{gru_id})->delete;
+};
+
+subtest 'errors during reconciliation are logged' => sub {
+    my $mock = Test::MockModule->new('OpenQA::Shared::Plugin::Gru');
+    $mock->redefine(_reconcile_gru_tasks => sub { die 'reconciliation failed' 
});
+    combined_like { $app->gru->reconcile_gru_tasks } qr/Failed to reconcile 
Gru tasks: reconciliation failed/,
+      'reconciliation error logged';
+};
+
+done_testing;
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' old/openQA-5.1795626606.295f3489/t/14-grutasks.t 
new/openQA-5.1795755868.789af64c/t/14-grutasks.t
--- old/openQA-5.1795626606.295f3489/t/14-grutasks.t    2026-11-25 
18:10:06.000000000 +0100
+++ new/openQA-5.1795755868.789af64c/t/14-grutasks.t    2026-11-27 
06:04:28.000000000 +0100
@@ -580,6 +580,52 @@
             $job->discard_changes;
             ok $job->archived, 'job archived';
         };
+
+        subtest 'important jobs are archived upfront while results storage is 
low' => sub {
+            my $g_mock = 
Test::MockModule->new('OpenQA::Schema::Result::JobGroups');
+            $g_mock->redefine(important_builds => sub { [[], ['imp']] });
+
+            my $parent_job = $jobs->find(99938);
+            my $job = $jobs->create(
+                {
+                    id => 199935,
+                    TEST => 'test-upfront-archiving',
+                    BUILD => 'imp',
+                    result_dir => '00199935-test-upfront-archiving',
+                    group_id => $parent_job->group_id,
+                    state => DONE,
+                    result => PASSED,
+                    t_created => time2str('%Y-%m-%d %H:%M:%S', time - ONE_DAY 
* 3, 'UTC'),
+                    logs_present => 1,
+                    archived => 0,
+                });
+            $job->discard_changes;
+            $job->group->update({keep_results_in_days => 10, 
keep_important_results_in_days => 20});
+            my $filename = create_temp_job_log_file($job->result_dir);
+            $job->comments->create({text => 'label:linked from test.domain', 
user_id => $user->id});
+
+            my $archiving = $app->config->{archiving};
+            local $archiving->{archive_preserved_important_jobs} = 1;
+            local $archiving->{archive_important_jobs_min_free_percentage} = 
20;
+            local $archiving->{archive_keep_free_percentage} = 5;
+            local $archiving->{archive_max_duration} = 300;
+
+            my $device_mock = 
Test::MockModule->new('OpenQA::Task::Job::Limit');
+            $device_mock->redefine(_dirs_on_same_device => 0);
+
+            my $df_mock = Test::MockModule->new('Filesys::Df', no_auto => 1);
+            my $df_call_count = 0;
+            $df_mock->redefine(
+                df => sub ($dir, @) {
+                    return {bavail => 10, blocks => 100} if $dir !~ 
/testresults/;
+                    return {bavail => ($df_call_count++ == 0 ? 15 : 25), 
blocks => 100};
+                });
+
+            run_gru_job($app, 'limit_results_and_logs');
+            $job->discard_changes;
+            is $job->archived, 1, 'job was archived upfront because results 
storage was full';
+            ok -e path($job->result_dir, path($filename)->basename), 'results 
exist under archive path';
+        };
     };
 };
 
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' 
old/openQA-5.1795626606.295f3489/t/20-stale-job-detection.t 
new/openQA-5.1795755868.789af64c/t/20-stale-job-detection.t
--- old/openQA-5.1795626606.295f3489/t/20-stale-job-detection.t 2026-11-25 
18:10:06.000000000 +0100
+++ new/openQA-5.1795755868.789af64c/t/20-stale-job-detection.t 2026-11-27 
06:04:28.000000000 +0100
@@ -102,6 +102,20 @@
     ok $mock_singleton_called, 'mocked singleton method has been called';
 };
 
+subtest '_check_stale invokes stale job detection and Gru task reconciliation' 
=> sub {
+    my $jobs_mock = Test::MockModule->new('OpenQA::Scheduler::Model::Jobs');
+    my $stale_jobs_called = 0;
+    $jobs_mock->redefine(incomplete_and_duplicate_stale_jobs => sub { 
$stale_jobs_called++ });
+    my $gru_mock = Test::MockModule->new('OpenQA::Shared::Plugin::Gru');
+    my $reconcile_called = 0;
+    $gru_mock->redefine(reconcile_gru_tasks => sub { $reconcile_called++ });
+
+    OpenQA::Scheduler::_check_stale;
+
+    is $stale_jobs_called, 1, 'stale job detection invoked';
+    is $reconcile_called, 1, 'Gru task reconciliation invoked';
+};
+
 done_testing();
 
 1;
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' old/openQA-5.1795626606.295f3489/t/27-errorpages.t 
new/openQA-5.1795755868.789af64c/t/27-errorpages.t
--- old/openQA-5.1795626606.295f3489/t/27-errorpages.t  2026-11-25 
18:10:06.000000000 +0100
+++ new/openQA-5.1795755868.789af64c/t/27-errorpages.t  2026-11-27 
06:04:28.000000000 +0100
@@ -6,6 +6,7 @@
 use FindBin;
 use lib "$FindBin::Bin/lib", 
"$FindBin::Bin/../external/os-autoinst-common/lib";
 use Test::Mojo;
+use Test::Output qw(combined_like);
 use Test::Warnings ':report_warnings';
 use OpenQA::Test::Case;
 use OpenQA::Test::TimeLimit '10';
@@ -21,6 +22,8 @@
     is_deeply [$dom->find('h1')->map('text')->each], ['Page not found'], 
'correct page';
     is_deeply [$dom->find('h2')->map('text')->each], ['Available routes'], 
'available routes shown';
     ok index($t->tx->res->text, 'Each entry contains the') >= 0, 'description 
shown';
+
+    $t->get_ok('/unavailable_page', {Accept => 
'application/json'})->status_is(404)->json_is('/error_status' => 404);
 };
 
 subtest 'error pages shown for OpenQA::WebAPI::Controller::Step' => sub {
@@ -80,5 +83,35 @@
     };
 };
 
+subtest 'before_render hook with destroyed transaction' => sub {
+    my $c = $t->app->build_controller;
+    delete $c->{tx};
+    lives_ok { $t->app->plugins->emit_hook(before_render => $c, {status => 
404}) }
+    'before_render does not crash when transaction is destroyed';
+};
+
+subtest 'reply.gru_result helper' => sub {
+    my $c = $t->app->build_controller;
+    delete $c->{tx};
+    is $c->reply->gru_result({error => 'fail'}), undef, 'returns undef when 
transaction is destroyed';
+
+    $c = $t->app->build_controller;
+    ok $c->reply->gru_result({ok => 1}), 'renders when transaction is present';
+};
+
+subtest 'reply.exception helper' => sub {
+    my $c = $t->app->build_controller;
+    delete $c->{tx};
+    combined_like {
+        $c->helpers->reply->exception('Transaction already destroyed');
+    }
+    qr/debug.*abort processing/, 'destroyed transactions logged as debug 
message';
+
+    my $c2 = $t->app->build_controller;
+    combined_like {
+        $c2->helpers->reply->exception('Some regular error');
+    }
+    qr/error.*Some regular error/, 'regular exceptions logged as errors';
+};
 
 done_testing;
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' old/openQA-5.1795626606.295f3489/t/42-df-based-cleanup.t 
new/openQA-5.1795755868.789af64c/t/42-df-based-cleanup.t
--- old/openQA-5.1795626606.295f3489/t/42-df-based-cleanup.t    2026-11-25 
18:10:06.000000000 +0100
+++ new/openQA-5.1795755868.789af64c/t/42-df-based-cleanup.t    2026-11-27 
06:04:28.000000000 +0100
@@ -21,6 +21,7 @@
 use Test::MockModule;
 use Test::Mojo;
 use Test::Warnings ':report_warnings';
+use Time::Seconds;
 
 my $schema = OpenQA::Test::Database->new->create(fixtures_glob => 
'03-users.pl');
 my $t = Test::Mojo->new('OpenQA::WebAPI');
@@ -50,6 +51,31 @@
     like $job->{result}, qr|.*result_cleanup_min_free_percentage.*foo.*not.*|, 
'result cleanup skipped early';
 };
 
+subtest 'abort limit results and logs task early in case of misconfigured 
upfront archiving' => sub {
+    my %invalid_settings = (
+        archive_important_jobs_min_free_percentage => 'foo',
+        archive_keep_free_percentage => 101,
+        archive_max_duration => 'unlimited',
+    );
+    for my $setting (sort keys %invalid_settings) {
+        my $value = $invalid_settings{$setting};
+        local $app->config->{archiving}->{$setting} = $value;
+        my $job;
+        combined_like { $job = run_gru_job($app, limit_results_and_logs => []) 
}
+        qr/Gru job error: Configured \Q$setting\E .* is not/, "error about 
invalid $setting is logged";
+        is $job->{state}, 'failed', "limit results and logs task fails for 
invalid $setting";
+        like $job->{result}, qr/\Q$setting\E \(\Q$value\E\) is not/, "failure 
names $setting and its invalid value";
+    }
+};
+
+subtest 'unknown free space of a nonexistent directory does not die' => sub {
+    my $missing = path(resultdir(), 'nonexistent');
+    my $percentage;
+    combined_like { $percentage = 
OpenQA::Task::Job::Limit::_free_percentage("$missing") }
+    qr/Upfront archiving skipped: Unable to determine storage usage of 
'\Q$missing\E'/, 'logs the missing directory';
+    ok !defined $percentage, 'reports unknown free space instead of dying';
+};
+
 # provide fake data for df
 my $df_mock = Test::MockModule->new('Filesys::Df', no_auto => 1);
 my %df_main_storage = (bavail => 11, blocks => 100);
@@ -440,4 +466,208 @@
     $schema->txn_rollback;
 };
 
+subtest 'upfront archiving in limit_results_and_logs' => sub {
+    $schema->txn_begin;
+    $schema->resultset('Jobs')->delete;
+
+    my $g_foo = $job_groups->create({name => 'foo'});
+    my $job_unimportant = $jobs->create(
+        {TEST => 'unimportant-job', BUILD => 'unimp', group_id => $g_foo->id, 
state => 'done', result => 'passed'});
+    my $job_important = $jobs->create(
+        {TEST => 'important-job', BUILD => 'imp', group_id => $g_foo->id, 
state => 'done', result => 'passed'});
+    my $job_important_2 = $jobs->create(
+        {TEST => 'important-job-2', BUILD => 'imp', group_id => $g_foo->id, 
state => 'done', result => 'passed'});
+
+    my $job_groups_mock = 
Test::MockModule->new('OpenQA::Schema::Result::JobGroups');
+    $job_groups_mock->redefine(important_builds => sub { [['none_tag'], 
['imp']] });
+
+    my @archived_ids;
+    my $archive_mock = Test::MockModule->new('OpenQA::Schema::Result::Jobs');
+    $archive_mock->redefine(
+        archive => sub ($self, @) {
+            push @archived_ids, $self->id;
+            $self->update({archived => 1});
+            return '/path/to/archive/' . $self->id;
+        });
+
+    my %storage_data = (
+        resultdir() => {bavail => 15, blocks => 100},
+        archivedir() => {bavail => 10, blocks => 100});
+    my $df_mock = Test::MockModule->new('Filesys::Df', no_auto => 1);
+    $df_mock->redefine(
+        df => sub ($dir, @) {
+            my $data = $storage_data{$dir} // {bavail => 100, blocks => 100};
+            return ref $data eq 'CODE' ? $data->() : $data;
+        });
+
+    my $archiving = $app->config->{archiving};
+    local $archiving->{archive_preserved_important_jobs} = 1;
+    local $archiving->{archive_important_jobs_min_free_percentage} = 20;
+    local $archiving->{archive_keep_free_percentage} = 5;
+    local $archiving->{archive_max_duration} = 300;
+
+    subtest 'does not archive if results and archive are on the same device' 
=> sub {
+        @archived_ids = ();
+        $jobs->search({id => [$job_important->id, 
$job_important_2->id]})->update({archived => 0});
+        path(resultdir())->make_path;
+        path(archivedir())->make_path;
+
+        my $minion_job;
+        combined_like { $minion_job = run_gru_job($app, limit_results_and_logs 
=> []) }
+        qr/Resuming|Starting/s, 'runs cleanup job';
+
+        is_deeply \@archived_ids, [], 'nothing archived when results and 
archive share a device';
+        is $minion_job->{notes}->{archived_jobs}, 0, 'notes 0 archived jobs';
+        is $minion_job->{notes}->{archiving_stopped}, 'resultdir and 
archivedir are on the same device',
+          'notes correct stopping reason';
+    };
+
+    my $device_mock = Test::MockModule->new('OpenQA::Task::Job::Limit');
+    $device_mock->redefine(_dirs_on_same_device => 0);
+
+    subtest 'archives the oldest important job until the results threshold is 
reached' => sub {
+        @archived_ids = ();
+        $jobs->search({id => [$job_important->id, 
$job_important_2->id]})->update({archived => 0});
+        my $df_call_count = 0;
+        $storage_data{resultdir()} = sub { {bavail => $df_call_count++ == 0 ? 
15 : 25, blocks => 100} };
+
+        my $minion_job;
+        combined_like { $minion_job = run_gru_job($app, limit_results_and_logs 
=> []) }
+        qr/Archiving important job @{[$job_important->id]}/, 'logs archiving 
of first job';
+
+        is_deeply \@archived_ids, [$job_important->id],
+          'only the first important job was archived before threshold was 
reached';
+        ok !$jobs->find($job_unimportant->id)->archived, 'unimportant job was 
not archived';
+        is $minion_job->{notes}->{archived_jobs}, 1, 'notes exact count of 
archived jobs';
+        is $minion_job->{notes}->{archiving_stopped}, 'results threshold 
reached', 'notes correct stopping reason';
+    };
+
+    subtest 'stops when the archive floor is reached' => sub {
+        @archived_ids = ();
+        $jobs->search({id => [$job_important->id, 
$job_important_2->id]})->update({archived => 0});
+        $storage_data{resultdir()} = {bavail => 15, blocks => 100};
+        $storage_data{archivedir()} = {bavail => 4, blocks => 100};
+
+        my $minion_job;
+        combined_like { $minion_job = run_gru_job($app, limit_results_and_logs 
=> []) }
+        qr/Resuming|Starting/s, 'runs cleanup job';
+        is_deeply \@archived_ids, [], 'no jobs archived as archive space is 
too low';
+        is $minion_job->{notes}->{archived_jobs}, 0, 'notes 0 archived jobs';
+        is $minion_job->{notes}->{archiving_stopped}, 'archive floor reached', 
'stops due to archive floor';
+    };
+
+    subtest 'stops when the time budget is exceeded' => sub {
+        @archived_ids = ();
+        $jobs->search({id => [$job_important->id, 
$job_important_2->id]})->update({archived => 0});
+        $storage_data{resultdir()} = {bavail => 15, blocks => 100};
+        $storage_data{archivedir()} = {bavail => 10, blocks => 100};
+        local $app->config->{archiving}->{archive_max_duration} = 1;
+
+        my $slow_archive_mock = 
Test::MockModule->new('OpenQA::Schema::Result::Jobs');
+        $slow_archive_mock->redefine(
+            archive => sub ($self, @) {
+                sleep 1;
+                push @archived_ids, $self->id;
+                $self->update({archived => 1});
+                return '/path/to/archive/' . $self->id;
+            });
+
+        my $minion_job;
+        combined_like { $minion_job = run_gru_job($app, limit_results_and_logs 
=> []) }
+        qr/Archiving/s, 'runs cleanup job';
+        is_deeply \@archived_ids, [$job_important->id], 'only one job archived 
as second check exceeded budget';
+        is $minion_job->{notes}->{archived_jobs}, 1, 'notes 1 archived job';
+        is $minion_job->{notes}->{archiving_stopped}, 'time budget exceeded', 
'stops due to time budget';
+    };
+
+    subtest 'continues and skips on archive exception' => sub {
+        @archived_ids = ();
+        $jobs->search({id => [$job_important->id, 
$job_important_2->id]})->update({archived => 0});
+        $storage_data{resultdir()} = {bavail => 15, blocks => 100};
+        $storage_data{archivedir()} = {bavail => 10, blocks => 100};
+
+        my $throw_once = 1;
+        my $failing_archive_mock = 
Test::MockModule->new('OpenQA::Schema::Result::Jobs');
+        $failing_archive_mock->redefine(
+            archive => sub ($self, @) {
+                if ($throw_once && $self->id == $job_important->id) {
+                    $throw_once = 0;
+                    die 'mocked archive failure';
+                }
+                push @archived_ids, $self->id;
+                $self->update({archived => 1});
+                return '/path/to/archive/' . $self->id;
+            });
+
+        my $minion_job;
+        combined_like { $minion_job = run_gru_job($app, limit_results_and_logs 
=> []) }
+        qr/Failed to archive job @{[$job_important->id]}/, 'logs copy 
exception and continues';
+
+        is_deeply \@archived_ids, [$job_important_2->id],
+          'first job failed and skipped, second job archived successfully';
+        is $minion_job->{notes}->{archived_jobs}, 1, 'notes 1 archived job';
+        is $minion_job->{notes}->{archiving_stopped}, 'no candidates left', 
'notes finished candidates';
+    };
+
+    subtest 'skips jobs which are currently processed by another task' => sub {
+        @archived_ids = ();
+        $jobs->search({id => [$job_important->id, 
$job_important_2->id]})->update({archived => 0});
+        $storage_data{resultdir()} = {bavail => 15, blocks => 100};
+        $storage_data{archivedir()} = {bavail => 10, blocks => 100};
+        my $guard = $app->minion->guard('process_job_results_for_' . 
$job_important->id, ONE_DAY);
+
+        my $minion_job;
+        combined_like { $minion_job = run_gru_job($app, limit_results_and_logs 
=> []) }
+        qr/Archiving important job @{[$job_important_2->id]}/, 'archives the 
next candidate';
+
+        is_deeply \@archived_ids, [$job_important_2->id], 'skipped the job 
which is currently processed';
+        is $minion_job->{notes}->{archived_jobs}, 1, 'notes 1 archived job';
+        is $minion_job->{notes}->{archiving_stopped}, 'no candidates left', 
'notes no further candidates';
+    };
+
+    subtest 'continues cleanup when storage usage cannot be determined' => sub 
{
+        @archived_ids = ();
+        $jobs->search({id => [$job_important->id, 
$job_important_2->id]})->update({archived => 0});
+        $storage_data{resultdir()} = {};
+
+        my $minion_job;
+        combined_like { $minion_job = run_gru_job($app, limit_results_and_logs 
=> []) }
+        qr/Upfront archiving skipped: Unable to determine storage usage/, 
'logs unknown results storage usage';
+        is_deeply \@archived_ids, [], 'no jobs archived when results storage 
usage is unknown';
+        is $minion_job->{state}, 'finished', 'cleanup task still finishes';
+        is $minion_job->{notes}->{archiving_stopped}, 'unable to determine 
results storage usage',
+          'notes unknown results storage usage';
+
+        $storage_data{resultdir()} = {bavail => 15, blocks => 100};
+        $storage_data{archivedir()} = {};
+
+        combined_like { $minion_job = run_gru_job($app, limit_results_and_logs 
=> []) }
+        qr/Upfront archiving skipped: Unable to determine storage usage/, 
'logs unknown archive storage usage';
+        is_deeply \@archived_ids, [], 'no jobs archived when archive storage 
usage is unknown';
+        is $minion_job->{state}, 'finished', 'cleanup task still finishes';
+        is $minion_job->{notes}->{archiving_stopped}, 'unable to determine 
archive storage usage',
+          'notes unknown archive storage usage';
+        $storage_data{archivedir()} = {bavail => 10, blocks => 100};
+    };
+
+    subtest 'continues cleanup when upfront archiving fails unexpectedly' => 
sub {
+        @archived_ids = ();
+        $jobs->search({id => [$job_important->id, 
$job_important_2->id]})->update({archived => 0});
+        $storage_data{resultdir()} = {bavail => 15, blocks => 100};
+        $storage_data{archivedir()} = {bavail => 10, blocks => 100};
+
+        my $limit_mock = Test::MockModule->new('OpenQA::Task::Job::Limit');
+        $limit_mock->redefine(_build_important_conditions => sub { die "mocked 
condition failure\n" });
+
+        my $minion_job;
+        combined_like { $minion_job = run_gru_job($app, limit_results_and_logs 
=> []) }
+        qr/Unable to archive important jobs upfront: mocked condition 
failure/, 'logs unexpected error and continues';
+        is_deeply \@archived_ids, [], 'no jobs archived after the error';
+        is $minion_job->{state}, 'finished', 'cleanup task still finishes';
+        like $minion_job->{notes}->{archiving_stopped}, qr/error: mocked 
condition failure/, 'notes the error';
+    };
+
+    $schema->txn_rollback;
+};
+
 done_testing();
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' old/openQA-5.1795626606.295f3489/t/46-munin.t 
new/openQA-5.1795755868.789af64c/t/46-munin.t
--- old/openQA-5.1795626606.295f3489/t/46-munin.t       2026-11-25 
18:10:06.000000000 +0100
+++ new/openQA-5.1795755868.789af64c/t/46-munin.t       2026-11-27 
06:04:28.000000000 +0100
@@ -138,4 +138,113 @@
     is $out, $exp, 'data output';
 };
 
+subtest group_sizes => sub {
+    my $script = "$Bin/../contrib/munin/plugins/group_sizes";
+    require $script;
+
+    subtest fetch_data => sub {
+        use Test::MockModule;
+        use Test::MockObject;
+        my $dbi = Test::MockModule->new('DBI');
+        my $dbh = Test::MockObject->new;
+        my $sth = Test::MockObject->new;
+        $dbi->redefine(connect => $dbh);
+        $dbh->mock(prepare => sub { $sth });
+        $sth->set_true('execute');
+        my @test_data = (
+            {
+                1 => {id => 1, name => 'P1'},
+                2 => {id => 2, name => 'P2'},
+            },
+            {
+                1 => {id => 1, name => 'G1', parent_id => 2},
+                2 => {id => 2, name => 'G2', parent_id => 1},
+                3 => {id => 3, name => 'G3', parent_id => 1},
+            },
+            {
+                1 => {group_id => 1, job_modules => 100},
+                2 => {group_id => 2, job_modules => 200},
+                3 => {group_id => 3, job_modules => 300},
+            },
+            {
+                1 => {group_id => 1, jobs => 10, result_size => 1000},
+                2 => {group_id => 2, jobs => 20, result_size => 2000},
+                3 => {group_id => 3, jobs => 30, result_size => 3000},
+            },
+        );
+        my $state = 0;
+        $sth->mock(fetchall_hashref => sub { $test_data[$state++] });
+        my $data = group_sizes::fetch_data();
+        my $expected = {
+            1 => {name => 'P2 / G1', jobs => 10, job_modules => 100, 
result_size => 1000},
+            2 => {name => 'P1 / G2', jobs => 20, job_modules => 200, 
result_size => 2000},
+            3 => {name => 'P1 / G3', jobs => 30, job_modules => 300, 
result_size => 3000},
+        };
+        is_deeply $data, $expected, 'fetch_data as expected';
+    };
+
+    subtest graph => sub {
+        my %groups = (
+            24 => {
+                name => 'Parent / Some',
+                jobs => 1234,
+                job_modules => 30_000,
+                result_size => 50_000_000,
+            },
+        );
+        my $exp = <<~'EOM';
+        multigraph openqa_job_modules_by_group
+        graph_title openqa Job modules per group
+        graph_args --base 1000 -l 0
+        graph_vlabel Job modules
+        graph_category openqa_groups
+        graph_info Sum of job_module entries per job group
+        g_24.label Parent / Some
+        g_24.type GAUGE
+        g_24.min 0
+
+        multigraph openqa_jobs_by_group
+        graph_title openqa Jobs per group
+        graph_args --base 1000 -l 0
+        graph_vlabel Jobs
+        graph_category openqa_groups
+        graph_info Number of jobs per job group
+        g_24.label Parent / Some
+        g_24.type GAUGE
+        g_24.min 0
+
+        multigraph openqa_result_size_by_group
+        graph_title openqa Result sizes per group
+        graph_args --base 1024 -l 0
+        graph_vlabel Bytes
+        graph_category openqa_groups
+        graph_info Sum of result_size per job group
+        g_24.label Parent / Some
+        g_24.type GAUGE
+        g_24.min 0
+
+        EOM
+        my $out = stdout_from {
+            group_sizes::config(\%groups);
+        };
+        is $out, $exp, 'config output';
+
+        $exp = <<~'EOM';
+        multigraph openqa_job_modules_by_group
+        g_24.value 30000
+
+        multigraph openqa_jobs_by_group
+        g_24.value 1234
+
+        multigraph openqa_result_size_by_group
+        g_24.value 50000000
+
+        EOM
+        $out = stdout_from {
+            group_sizes::data(\%groups);
+        };
+        is $out, $exp, 'data output';
+    };
+};
+
 done_testing;
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' old/openQA-5.1795626606.295f3489/tools/ci/autoinst.sha 
new/openQA-5.1795755868.789af64c/tools/ci/autoinst.sha
--- old/openQA-5.1795626606.295f3489/tools/ci/autoinst.sha      2026-11-25 
18:10:06.000000000 +0100
+++ new/openQA-5.1795755868.789af64c/tools/ci/autoinst.sha      2026-11-27 
06:04:28.000000000 +0100
@@ -1 +1 @@
-5.044000-d4232ccbdbf1acdda2578afc80d1effb074ca1a7
\ No newline at end of file
+5.044000-8b57692179b29b93f8ce7a785c581edfc09561d2
\ No newline at end of file

++++++ openQA.obsinfo ++++++
--- /var/tmp/diff_new_pack.YwBe8T/_old  2026-11-27 19:46:50.007469465 +0100
+++ /var/tmp/diff_new_pack.YwBe8T/_new  2026-11-27 19:46:50.013469718 +0100
@@ -1,5 +1,5 @@
 name: openQA
-version: 5.1795626606.295f3489
-mtime: 1795626606
-commit: 295f34894de503642cf56a5cb528c1192c10cc90
+version: 5.1795755868.789af64c
+mtime: 1795755868
+commit: 789af64c45c856f578e9611b5d956f770896bb24
 

Reply via email to