Skip to content

work parallel: register and monitor the spawned session fleet in sessions.json - #120

Open
CSalcedoDataBI wants to merge 1 commit into
mainfrom
issue-101-work-parallel-register-and-monitor-the
Open

work parallel: register and monitor the spawned session fleet in sessions.json#120
CSalcedoDataBI wants to merge 1 commit into
mainfrom
issue-101-work-parallel-register-and-monitor-the

Conversation

@CSalcedoDataBI

Copy link
Copy Markdown
Owner

Closes #101

…ad sessions (#101)

Two defects in the parallel-session monitor:

1. MODE 2 listing assigned the live session list to $sessions at SCRIPT
   scope. PowerShell variable names are case-insensitive, so it aliased the
   [switch]$Sessions parameter and threw 'Cannot convert Object[] to
   SwitchParameter' on EVERY listing (even with an empty registry). The
   'Sesiones activas' fleet display therefore never rendered. Rename to
   $liveSessions (and the same name inside Show-SessionFleet for hygiene).

2. Read-SessionRegistry pruned dead entries with
   $alive | ConvertTo-Json -AsArray | Set-Content — but an empty pipe emits
   nothing, so when ALL sessions were dead the file was never rewritten and
   the stale entries survived. Extract ConvertTo-SessionRegistryJson, which
   returns an explicit '[]' for the empty case; use it in both writers.

Add Pester coverage: ConvertTo-SessionRegistryJson (empty/single/multi) and
a source guard that MODE 2 uses $liveSessions, not the colliding name.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR addresses Issue #101 by making the parallel-session registry (.agentic-bi-ops/sessions.json) reliably serialize as a JSON array (including the empty case) and by avoiding a PowerShell variable/parameter name collision that can break MODE 2 session listing.

Changes:

  • Added ConvertTo-SessionRegistryJson to ensure session registry writes always produce a JSON array string, including emitting [] when empty.
  • Updated session registry prune/write paths to use the new serializer helper.
  • Added Pester tests covering empty/single/multi session serialization and preventing $sessions from colliding with [switch]$Sessions.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.

File Description
plugins/agentic-bi-ops/scripts/Board-Work.ps1 Adds a dedicated JSON serializer for the session registry and updates registry write sites; renames MODE 2/monitor listing variable to avoid the $Sessions switch collision.
plugins/agentic-bi-ops/tests/Board-Work.Tests.ps1 Adds regression tests for sessions.json serialization and for preventing $sessions assignment that aliases the [switch]$Sessions script parameter.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines 179 to 182
$alive = @($entries | Where-Object { $_.sessionPid -and (Get-Process -Id $_.sessionPid -ErrorAction SilentlyContinue) })
if ($alive.Count -ne $entries.Count) {
# Pipe (not -InputObject) or a passed array gets double-wrapped by -AsArray
$alive | ConvertTo-Json -Depth 4 -AsArray | Set-Content $p
Set-Content -Path $p -Value (ConvertTo-SessionRegistryJson $alive)
}
Comment on lines 216 to 220
host = $env:COMPUTERNAME
started = (Get-Date -Format "yyyy-MM-dd HH:mm")
}
$entries | ConvertTo-Json -Depth 4 -AsArray | Set-Content $p
Set-Content -Path $p -Value (ConvertTo-SessionRegistryJson $entries)
}
Comment on lines +628 to +630
# $liveSessions (not $sessions): even here inside a function the name would
# shadow the [switch]$Sessions param and invites the issue-#101 footgun.
$liveSessions = @(Read-SessionRegistry)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

work parallel: register and monitor the spawned session fleet in sessions.json

2 participants