Fix false OrphanTreeEntry findings from ignorable chars in TaskCache Ids #6
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "fix/guid-canonicalization-ignorable-chars"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
What does this PR do?
Fixes a false-positive bug where
Test-ScheduledTaskHealth.ps1andGet-TaskCacheSummary.ps1reported a large batch of
OrphanTreeEntryfindings on hosts whose tasks are actually healthy.Root cause: some
TaskCache\Tree"Id" values carry a stray ignorable character (forexample a zero-width space) after the GUID. The registry and PowerShell hashtables
(culture-aware) ignore such characters, but a .NET
HashSetkeyed withOrdinalIgnoreCasetreats them as significant. GUID comparison through that
HashSettherefore failed to matchthe clean
TaskCache\Tasks\{GUID}subkey names.On the machine that surfaced this,
Get-TaskCacheSummaryreported 197 of 213 Tree nodes asorphaned, but a direct
Test-Pathcheck confirmed 187 of them do have their Tasks key -the tasks were healthy; the comparison was wrong.
Fix: normalize GUIDs by extracting the canonical 8-4-4-4-12 hex pattern with a regex, which
discards any surrounding or embedded stray characters before comparison.
Get-TaskCacheSummary.ps1-Format-Guidnow regex-extracts the canonical GUID.Test-ScheduledTaskHealth.ps1- addsConvertTo-CanonicalGuidand applies it when readingTree Id values and Tasks subkey names.
OrphanTaskEntryfindings keep the real subkey namefor the backup/removal registry paths.
How was this tested?
before the fix the string comparison failed; after the fix both scripts report zero false
orphans.
(no Tree node) are still detected.
Checklist
Some TaskCache\Tree 'Id' values carry a stray ignorable character (e.g. a zero-width space) after the GUID. The registry and PowerShell hashtables (culture-aware) ignore such characters, but a .NET HashSet keyed with OrdinalIgnoreCase treats them as significant. GUID comparison via that HashSet therefore failed to match the clean TaskCache\Tasks\{GUID} subkey names, producing a large batch of false OrphanTreeEntry findings (observed: 197 of 213 on a host whose tasks were actually healthy). Normalize GUIDs by extracting the canonical 8-4-4-4-12 hex pattern with a regex, which discards any surrounding or embedded stray characters before comparison: - Get-TaskCacheSummary.ps1: Format-Guid now regex-extracts the canonical GUID. - Test-ScheduledTaskHealth.ps1: add ConvertTo-CanonicalGuid and apply it when reading Tree Id values and Tasks subkey names. OrphanTaskEntry findings keep the real subkey name for backup/removal paths. Verified against fixtures: a host with zero-width-space Tree Ids now reports zero false orphans, while genuinely orphaned Tree and Tasks entries are still detected. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>