fix(dsh-plugin-browserskill): enforce the session cap before spawning

The concurrency cap was checked in registry.add() AFTER
`bsk session start` had already created the session, so a rejected
start leaked a live session outside the plugin's tracking (found by the
real-browser e2e: the rejected third session stayed in
`bsk session list` after dispose). Check capacity before spawning;
registry.add() keeps the same check as a backstop.
This commit is contained in:
BB-fat
2026-08-13 15:27:29 +00:00
parent 703fc64399
commit 2de7c5c6ff
3 changed files with 17 additions and 5 deletions
@@ -23,14 +23,22 @@ export class SessionRegistry {
* @throws when the configured concurrency cap is already reached.
*/
add(session: TrackedSession): void {
if (!this.sessions.has(session.sessionId) && this.sessions.size >= this.maxSessions) {
if (!this.sessions.has(session.sessionId)) this.assertCapacity();
this.sessions.set(session.sessionId, session);
this.currentId = session.sessionId;
}
/**
* Throw when starting another session would exceed the concurrency cap.
* Call BEFORE spawning a new session so a rejected start never leaks one.
*/
assertCapacity(): void {
if (this.sessions.size >= this.maxSessions) {
throw new Error(
`session limit reached (${this.maxSessions} concurrent sessions); ` +
"stop one with browser_session_stop before starting another",
);
}
this.sessions.set(session.sessionId, session);
this.currentId = session.sessionId;
}
/** Forget a stopped session; falls back to the most recent remaining one. */