Repository navigation
Report a consolidated zip that could not be built, and exit 2 - #63
Merged
stefoy merged 37 commits intoNov 25, 2026
Merged
Conversation
added 2 commits
October 28, 2026 18:19
When the disk filled up while Run-AllSubscriptions.ps1 built AllSubscriptions_ResourcesReport_<timestamp>.zip, or a per-subscription report zip was held open by another process, Compress-Archive removed the zip, but the wrapper still printed "Reporting Data File: <path>" and the same path under "Consolidated Report:", and exited 0. Adding RunSummary.log and MainSummary.html to the zip afterwards can remove an already-built zip the same way, with only a warning. The build now stops on its first error and then opens the zip to check that it holds every per-subscription zip. The same check runs after the run summary is added. When either fails, the run prints the cause, does not report the zip as written, ends with a "FAILED (consolidated zip)" banner and exits 2 (ahead of 3-5). The per-subscription report zips stay on disk.
Run-AllSubscriptions.ps1 printed the path of AllSubscriptions_ResourcesReport_<timestamp>.zip on the "Reporting Data File:" line right after the zip was built, and on the "Consolidated Report:" line of the summary, both before RunSummary.log and MainSummary.html are added to it. When adding them removed the zip (a full disk does this), the console still showed both lines for a zip that was no longer on disk, above the error that said it was lost. Both lines are now printed after the run summary is added, once the zip passed the same check again, and only then. That check also runs when the zip is already gone before the run summary is added. README: the exit code 2 row names the consolidated-zip case.
pmorgenrood
pushed a commit
to pmorgenrood/resource-discovery-for-azure
that referenced
this pull request
Oct 29, 2026
…ep state on a zip failure, no browser without a console Review council findings on the merged candidate (gpt-5.6-sol, claude-opus-5.5): - MAJOR, loop trap (awslabs#48 x awslabs#52 x awslabs#68): a subscription whose run wrote no report zip was taken off the completed list but never put on the retry list, so every -Resume collected it again, ended with exit 2 and kept the state; the retry limit never counted it. The sequential loop, the one-subscription path and the stream worker now record it as a failed run ("the run wrote no report zip"), so -ResumeFailedOnly retries it and the retry limit ends a cause that does not go away. awslabs#48's tests that asserted the old behaviour now expect the retry entry. - MAJOR, pre-existing: Get-WrapperExitCode ignored $FailedSubscriptions, so a run with failed subscriptions exited 0 ("clean run"). It now returns 2 (a report is missing from the bundle) and the README says so. - MAJOR/MINOR (awslabs#63 x awslabs#48): the resume state was cleared even when the consolidated zip could not be built, so the next -Resume collected every subscription again. The state is now kept while $BundleBuildError is set. - MAJOR (awslabs#66): the wrapper sign-in opened a browser with no console (scheduled task, CI). It now stops with exit 1 and advice, as a direct run does; -DeviceLogin and a reusable sign-in still work. Each change has a test that failed before it (RetryLimit, WrapperSignIn, RunAllSubscriptionsReconciliation).
pmorgenrood
pushed a commit
to pmorgenrood/resource-discovery-for-azure
that referenced
this pull request
Oct 30, 2026
…and exit 2 # Conflicts: # README.md
pmorgenrood
pushed a commit
to pmorgenrood/resource-discovery-for-azure
that referenced
this pull request
Oct 30, 2026
…esume cannot write its consolidated zip With awslabs#48 a -Resume run that collects nothing still carries the earlier reports into a consolidated zip, and awslabs#63 ends the run with exit 2 when that zip cannot be built. awslabs#38's read-only-folder case now expects that exit code and banner; the next -Resume, once the folder can be written, still clears everything.
pmorgenrood
pushed a commit
to pmorgenrood/resource-discovery-for-azure
that referenced
this pull request
Oct 30, 2026
…ep state on a zip failure, no browser without a console Review council findings on the merged candidate (gpt-5.6-sol, claude-opus-5.5): - MAJOR, loop trap (awslabs#48 x awslabs#52 x awslabs#68): a subscription whose run wrote no report zip was taken off the completed list but never put on the retry list, so every -Resume collected it again, ended with exit 2 and kept the state; the retry limit never counted it. The sequential loop, the one-subscription path and the stream worker now record it as a failed run ("the run wrote no report zip"), so -ResumeFailedOnly retries it and the retry limit ends a cause that does not go away. awslabs#48's tests that asserted the old behaviour now expect the retry entry. - MAJOR, pre-existing: Get-WrapperExitCode ignored $FailedSubscriptions, so a run with failed subscriptions exited 0 ("clean run"). It now returns 2 (a report is missing from the bundle) and the README says so. - MAJOR/MINOR (awslabs#63 x awslabs#48): the resume state was cleared even when the consolidated zip could not be built, so the next -Resume collected every subscription again. The state is now kept while $BundleBuildError is set. - MAJOR (awslabs#66): the wrapper sign-in opened a browser with no console (scheduled task, CI). It now stops with exit 1 and advice, as a direct run does; -DeviceLogin and a reusable sign-in still work. Each change has a test that failed before it (RetryLimit, WrapperSignIn, RunAllSubscriptionsReconciliation).
added 24 commits
November 9, 2026 10:10
… before it takes its name The wrapper transcript, the consolidated zip and MainSummary_<time>.html are named from the time to the second and were written with overwrite, so two runs in one inventory folder that start or end in the same second wrote over each other's file. Each is now created only if absent (New-RunOutputFile): today's name, or the next free one from <name>-2 to <name>-100. The consolidated zip is built under a name of its own in the folder (.rda-<guid>.partial, which no listing of the folder picks up), checked, and only then moved over the reserved name, so the reserved name is never free and a zip that fails the check never sits under the name a run ships. A failed build leaves neither file. A main summary that cannot be built leaves no empty file and is not added to the zip.
…is added The check after RunSummary.log and MainSummary.html are folded in recorded the error but left the zip under the name a run ships. That name is this run's own, so a zip that fails the check there is removed and the path is cleared, as after the check before the fold.
When the run expected report zips and the inventory folder was missing at the end, the report zip check was skipped and "Nothing to consolidate" set no exit code, so the run ended with exit 0 and no consolidated zip. One line now says that the folder, with the report zips and the resume state in it, is gone and no consolidated zip was built, and the run exits 2, as for a missing report zip. A run that expected no report zip is unchanged.
…s check The name was reserved with an empty file before the zip was built, so a run stopped part-way left an empty file under the name a run ships. The zip is now built and checked under its private name only, then moved to today's name, or the next free one, without ever writing over a file that is there (Move-RunOutputFile). A zip that fails the check after the run summary is added and cannot be removed is named in the error with "delete it, do not share it".
…e summary A run whose inventory folder is gone at the end stopped before the run summary and the auth and collector banners, and the transcript went with the folder, so that detail was lost. The FAILED line now comes after the summary and the other banners, and the run still exits 2. A main summary that fails part-way leaves no partial file. The transcript name is read from the clock once, and on Windows a folder of the same name is skipped like a file.
New-RunOutputFile creates the transcript's name before Start-Transcript runs. When the transcript then fails to start (for example one is already running in the session), the run went on and left an empty file that looks like its transcript. That file is now removed.
The zip took the name a run ships before the run summary was folded into it, so a run stopped during the fold left a zip that was never checked under that name. It now stays under its private name through the main summary, the fold and the last check, and only then moves to today's name or the next free one. The private name has no leading dot, because Compress-Archive -Update does not find a hidden file. A main summary stopped part-way is removed too (finally, not only catch). The build line and errors name the inventory folder, not a name the zip may not get. The README says a killed run can leave the private file, which is safe to delete.
A consolidated zip that passed its last check but found every name taken was reported as lost and deleted. It is now kept under its private name, which the error gives with how to use it. The README says to run one wrapper at a time per inventory folder: the zip takes every report zip written in the folder since the run started, so a second run there at the same time, of another tenant too, would mix its reports into it. It also says a run stopped after the zip was built can leave the private file.
When a checked zip could not take its name and was kept under its private name, the FAILED banner still asked to fix the cause and run again, which collects every subscription again. It now says the zip is complete and to rename the kept file. The exit-code table names that case.
When the move to the shipping name failed because the zip itself was no longer there, the error said it was kept under its private name and asked to rename it. That case is now reported as lost. The exit-code table no longer says the report zips are on disk when the inventory folder is gone.
…lock tests do The analyzer read the three inputs of the kept-zip banner test as unused, since only the dot-sourced block reads them.
…ints The consolidated-zip banner always said the per-subscription zips were still on disk, though the inventory folder can go while the zip is built, summarised or checked. It now reads the folder when it prints and says when the zips went with it.
Test-Path reads [ and ] as a wildcard, so a folder whose path holds them is 'not found' though it is there. The run then said the folder, its zips and the resume state were gone. It now checks the folder itself and, when it is there, says the consolidated zip could not be built because of the brackets, and exits 2.
In such a folder no report zip can be built (Compress-Archive reads the path as a wildcard), so the end of the run said false things about which zips were on disk. The wrapper now stops before writing anything, with exit 1 and a line naming the folder, as the one-subscription branch does; the end-of-run branch for it is gone.
…taging folder on every path The bracket stop called Exit-Wrapper before the transcript flag it reads was set, so under strict mode it failed on that instead of stopping. The staging folder that holds copies of the reports for the fold was removed only when the fold worked; it is now removed in a finally block, and named in a warning when it cannot be.
A run stopped after its zip was built leaves rda-build-<id>.partial, which holds copies of every report of that run, and nothing named it. The next run in the folder now prints a warning for each one from before it started, and leaves it in place, as it can be the zip of a run still going.
…the resume PRs edit
…elete it The warning for a left rda-build-<id>.partial said to rename it to a .zip name to use it, but such a file may be cut short or never have passed its checks, and in a plain run it holds real names. It now says so, says to delete it and not share it, and keeps the rename advice only for a file the run said it kept after its checks.
New-RunOutputFile and Move-RunOutputFile looked for a taken name with File.Exists and Directory.Exists. On the older .NET of PowerShell 7.0 to 7.2 those follow a link, so a link whose target is gone looked free: the transcript was not started, or a checked consolidated zip stayed under its private name with exit 2. Test-RunOutputNameTaken also asks Get-Item, which looks at the link itself, so the next name is tried.
The helper was added on the claim that the older .NET of PowerShell 7.0 to 7.2 follows a link whose target is gone. The runtime source says otherwise: FileSystem.FileExists on Unix falls back to lstat when stat fails in .NET Core 3.1 and .NET 5, and calls lstat first from .NET 6 on, so such a link counts as a taken name on every PowerShell 7. The helper and its tests are removed; the two tests that a dangling link makes New-RunOutputFile and Move-RunOutputFile take the next name stay, as a lock on that behaviour.
A build or check that failed removed its private rda-build-*.partial without looking whether it went. One held open or not allowed to go stayed unnamed until a later run built a zip, though it holds copies of the reports. It is now named in the FAILED (consolidated zip) error and a WARNING: delete it, do not share it.
added 10 commits
November 10, 2026 05:54
The consolidated zip is built from a second listing of the report zips, and its check compared the zip only with that listing. A zip the output check found and that was gone by then (an antivirus quarantine, storage evicted in between) was left out without a word, and the run could end with exit 0. The run now compares the two listings and stops as the output check does, with exit 2, naming the gone zips.
… edit Placed after the second listing, the check made Run-AllSubscriptions.ps1 conflict with PRs awslabs#48 and awslabs#62, sync/pr-61, sync/pr-68 and upstream-pr/wrapper-end-of-run, which edit that listing. It now runs inside the build: a zip found by the output check and gone by then fails the build (FAILED (consolidated zip), no zip, exit 2), and when every one is gone the empty-list branch says so with exit 2 too.
…ld; name the gone ones in the banner A -Resume run skips the subscriptions this run completed, so it would not collect a report whose zip went missing. The banner no longer says every report zip is still on disk when some are gone. The list of zips the output check found is set before that check, so the build reads it under strict mode.
…ip is gone -ResumeFailedOnly also skips the subscriptions this run completed, so the advice is to run again without either switch. The banner test sets its inputs with Set-Variable, as the other lifted-block tests do.
Both reads stop on an error, so the catch sets the version from $Global:Version as its comment says, and no red error is printed.
The stop refused only [ and ], but Linux and macOS allow * and ? in a folder name, and PowerShell reads them as a wildcard too: with HOME at a?b, Get-ChildItem -Path on the inventory folder listed the InventoryReports folders of every matching sibling (axb too), so the zip lookup found none, every subscription was named Report missing and collected again on each -Resume up to the retry limit. The stop now refuses [ ] * and ? with the message naming them. Test: inv[1], inv*1 and inv?1 stop with exit 1 and the message (red before).
The shortcut still said an inventory folder with brackets is stopped; the stop refuses [ ] * and ? now, and Compress-Archive reads * and ? as wildcards too. Comment only.
pmorgenrood
pushed a commit
to pmorgenrood/resource-discovery-for-azure
that referenced
this pull request
Nov 12, 2026
…wslabs#63 rewrites Printed right after the execution-time line, it made sync/pr-61 conflict with sync/pr-63, which rewrites the consolidated-report lines there. It is now printed just before the run summary failed list, still before the transcript stops.
pmorgenrood
pushed a commit
to pmorgenrood/resource-discovery-for-azure
that referenced
this pull request
Nov 17, 2026
…consolidated-zip-check)
pmorgenrood
pushed a commit
to pmorgenrood/resource-discovery-for-azure
that referenced
this pull request
Nov 17, 2026
… failure, no browser without a console Changes on the merged candidate: - loop trap (awslabs#48 x awslabs#52 x awslabs#68): a subscription whose run wrote no report zip was taken off the completed list but never put on the retry list, so every -Resume collected it again, ended with exit 2 and kept the state; the retry limit never counted it. The sequential loop, the one-subscription path and the stream worker now record it as a failed run ("the run wrote no report zip"), so -ResumeFailedOnly retries it and the retry limit ends a cause that does not go away. awslabs#48's tests that asserted the old behaviour now expect the retry entry. - pre-existing: Get-WrapperExitCode ignored $FailedSubscriptions, so a run with failed subscriptions exited 0 ("clean run"). It now returns 2 (a report is missing from the bundle) and the README says so. - (awslabs#63 x awslabs#48): the resume state was cleared even when the consolidated zip could not be built, so the next -Resume collected every subscription again. The state is now kept while $BundleBuildError is set. - (awslabs#66): the wrapper sign-in opened a browser with no console (scheduled task, CI). It now stops with exit 1 and advice, as a direct run does; -DeviceLogin and a reusable sign-in still work. Each change has a test that failed before it (RetryLimit, WrapperSignIn, RunAllSubscriptionsReconciliation).
pmorgenrood
force-pushed
the
upstream-pr/consolidated-zip-check
branch
from
November 17, 2026 23:59
fbc1cfd to
cb4844c
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Run-AllSubscriptions.ps1ends by putting every per-subscription report zip of the run intoAllSubscriptions_ResourcesReport_<timestamp>.zip, then addsRunSummary.log,MainSummary.htmland a copy of each report's HTML to it. NeitherCompress-Archivecall was checked. When a write fails,Compress-Archiveremoves the zip, but the wrapper carried on as if it had been written:Reporting Data File: .../AllSubscriptions_ResourcesReport_<timestamp>.zipandConsolidated Report: .../AllSubscriptions_ResourcesReport_<timestamp>.zip, and the run exits 0. No such file is on disk.Reporting Data File:andConsolidated Report:lines; the run then printsWARNING: Could not fold run-summary / main-summary into the consolidated zip: ... No space left on device ...and exits 0, with no consolidated zip on disk.In both cases the per-subscription report zips are still on disk.
Change
-ErrorAction Stopinsidetry/catch. Afterwards the zip is opened and must hold every per-subscription zip of the run (newGet-ConsolidatedZipProbleminFunctions/RunAllSubscriptions.Functions.ps1). Otherwise the run printsERROR: Could not build <zip>: <cause>and treats the zip as not built: no main summary and no run-summary fold, the same as a run that found no per-subscription zips.ERROR: <zip> was lost while the run summary was added to it: <reason>. A fold that fails but leaves every report in the zip stays a warning, as before.Reporting Data File:andConsolidated Report:lines for the consolidated zip are printed only once that last check passed, after the summary block and theBundle finalized:line. A zip that was not built, or was lost, never has its path printed as written.FAILED (consolidated zip)banner after the summary names the cause and the folder that still holds the per-subscription report zips, and the run exits 2.2row names this case.Behaviour change, with its exact condition
Compress-Archivefails while buildingAllSubscriptions_ResourcesReport_<timestamp>.zip; or the zip on disk afterwards cannot be opened or does not hold every per-subscription zip of the run; or the same check fails afterRunSummary.logandMainSummary.htmlare added (also when the zip is already gone at that point). Result: exit code 2 instead of 0 (or 3, 4 or 5), theFAILED (consolidated zip)banner, and noReporting Data File:orConsolidated Report:line for the consolidated zip.Reporting Data File:andConsolidated Report:lines for the consolidated zip move: they now come after the summary block and theBundle finalized:line, instead of right after the zip is built and inside the summary block. Nothing else changes for such a run.Cost: the zip's directory (not the reports in it) is read twice per run. Measured on Linux: about 4 ms for a zip with 100 per-subscription zips and 20–40 ms for 1,000. No Azure calls.
Testing
On Linux, PowerShell 7.6, Pester 5.7.1:
Tests/ConsolidatedZipBuild.Tests.ps1(16 tests) takes the bundling block, the fold block, the check after it, the banner and the exit-code statements from the wrapper's parsed source and runs them as written.Compress-Archiveis real except in three tests: a write that leaves a report out, and two folds that fail (one removes the zip, as the real cmdlet does on a full disk, one leaves it). A per-subscription zip held open by another handle is a real failure. The exit code is read from a childpwsh. One test checks in the parsed source that both path lines are printed only inside the last check. Onmainall 16 fail; with this change all 16 pass.Run-AllSubscriptions.ps1calling the realResourceInventory.ps1for three subscriptions, with stand-ins only for the Azure calls, and the report folder on a smalltmpfsso the disk fills up at the end of the run. Onmain, with 168–188 KiB free at the start, the console showsReporting Data File: .../AllSubscriptions_ResourcesReport_<timestamp>.zip, no zip is on disk and the exit code is 0. With 216–240 KiB free, the console showsReporting Data File:andConsolidated Report:for the zip, then the zip is removed while the run summary is added, exit code 0. With this change, at 176 KiB the run printsERROR: Could not build ...and at 224 KiBERROR: ... was lost while the run summary was added to it: the zip is not on disk.; neither run prints aReporting Data File:orConsolidated Report:line for the consolidated zip, and both end with the banner and exit code 2. With room to spare the zip holds every report plusRunSummary.logandMainSummary.html, both path lines followBundle finalized:, and the exit code is 0.Testsfolder gives the same results as onmain: the same failures and the same skips. PSScriptAnalyzer 1.25.0 with the repository settings reports 0 errors and the same single warning as onmain.Run-AllSubscriptions.ps1merges without conflict.README.mdconflicts in the exit-code table with Check read access and usage values up front for every subscription #38, Carry earlier reports into the -Resume bundle #48, Retry metrics or consumption a run left incomplete #61 and Keep the resume state while -ResumeFailedOnly leaves a subscription not collected #62, which change the rows for code1or2; the resolution keeps both texts (for code2: the per-subscription gap, the-Resumereport that could not be carried, and the consolidated zip). On one tree that merges this change with the open PRs Fix Cosmos DB TotalRequests: read each data point's Count #37–Mask a parent's name inside the obfuscated id of a child resource #53 together, the new test,Tests/ResumeCarry.Tests.ps1andTests/RunAllSubscriptionsReconciliation.Tests.ps1pass (100 of 100), the rest of theTestsfolder gives the same results as without this change, and the end-to-end full-disk runs give the result above.RunSummary.logandMainSummary.html, onmainand with this change, and both end with the same exit code (4, from the VMSS collector failure that Fix VMSS collector failing on Flexible scale sets #39 fixes).tmpfsthat fills up while the run summary is added: onmainthe run printedReporting Data File:andConsolidated Report:for the zip, thenWARNING: Could not fold run-summary / main-summary into the consolidated zip: ... No space left on device ..., left no consolidated zip on disk and exited 4. With this change the same run printedERROR: .../AllSubscriptions_ResourcesReport_<timestamp>.zip was lost while the run summary was added to it: the zip is not on disk.and theFAILED (consolidated zip)banner, and exited 2.Not tested: Windows and macOS; a full disk on a real drive (both the offline and the live full-disk runs use a small
tmpfs). The case where the disk fills up while the zip itself is built was not reached live: the size chosen for it filled up during collection instead (exit 2 from the per-subscription verification, onmainand with this change), so that case was checked offline only. The second commit (the path lines printed only after the last check) was checked offline only.Update: build the zip under a private name, and name what is left
rda-build-<id>.partialin the inventory folder), and takesits name only after its last check. So no file under that name is a zip that was not checked.
MainSummary_<time>.html) never write over afile that is already there: the run takes the next free name (
<name>-2,-3, up to-100). A zip that passed its checksbut found every name taken is kept under its private name, named in the banner, and the run exits 2.
.partialfile. The next run that builds a consolidated zip nameseach one in a warning, says it may be incomplete and may hold real names, and leaves it in place.
gone zips and says to run again without
-Resume.[,],*or?stops the run at once with exit 1, before anything is written:PowerShell reads them as wildcards, and
Compress-Archivefails on such a path.Version.jsonfalls back to the loaded version.2row say all of the above.Tested:
Tests/ConsolidatedZipBuild.Tests.ps1has new cases for each point; full Pester suite, test by test, with no newfailure; PSScriptAnalyzer one file at a time, with no new finding. Live runs, plain and with
-Obfuscate, were made with thisPR on top of the Az PowerShell-only PR (#66), because the test host has no Azure CLI; inventory, consumption and metrics were the
same as that base. Not run live against
main, and not run on Windows.How to test
Quick check (no Azure)
A normal run (any subscription you can read)
After the summary block the console shows
Bundle finalized:, thenReporting Data File:andConsolidated Report:forAllSubscriptions_ResourcesReport_<timestamp>.zip. The zip holds oneResourcesReport_*.zipper subscription plusRunSummary.logandMainSummary.html, and the exit code is the same as without this change.