Skip to content

Prevent reruns from inheriting stale browser harness state#425

Merged
Cheggin merged 2 commits into
mainfrom
responsible-court
May 9, 2026
Merged

Prevent reruns from inheriting stale browser harness state#425
Cheggin merged 2 commits into
mainfrom
responsible-court

Conversation

@Cheggin
Copy link
Copy Markdown
Collaborator

@Cheggin Cheggin commented May 9, 2026

Rerun keeps the app session id while replacing the assigned CDP target. The harness REPL was keyed only by app session id, so reruns could reuse a long-lived browser-harness-js process that still held CDP state for the prior target.

Scope the deterministic REPL port by target id as well as session id, and make the stock REPL reconnect if an existing CDP socket cannot attach to the assigned target.

Constraint: Rerun reuses the app session id but creates a replacement browser target

Rejected: Kill all harness REPL processes on rerun | broader lifecycle churn and could affect unrelated active sessions

Confidence: high

Scope-risk: narrow

Directive: Keep Browser Harness JS REPL identity aligned with the assigned target when target lifecycle changes

Tested: yarn test --run tests/unit/hl/browserHarnessEnv.test.ts

Tested: yarn test --run tests/unit/hl

Tested: yarn typecheck

Tested: yarn lint

Tested: yarn test

Not-tested: Live Electron rerun from this worktree


Summary by cubic

Prevents reruns from inheriting stale CDP state by scoping the browser-harness REPL to the target and reconnecting when attach fails. Keeps the REPL aligned with the active target across reruns.

  • Bug Fixes
    • REPL port is now derived from sessionId:targetId and applyBrowserHarnessEnv sets CDP_REPL_PORT with ctx.targetId.
    • If session.use(targetId) fails, the stock REPL closes the socket and reconnects to the assigned target.
    • Hardened Session socket lifecycle: ignore messages from stale sockets, clear state on close, and reject pending requests on teardown.
    • Added unit tests for port scoping and explicit port override.

Written for commit 9506969. Summary will update on new commits.

Rerun keeps the app session id while replacing the assigned CDP target. The harness REPL was keyed only by app session id, so reruns could reuse a long-lived browser-harness-js process that still held CDP state for the prior target.

Scope the deterministic REPL port by target id as well as session id, and make the stock REPL reconnect if an existing CDP socket cannot attach to the assigned target.

Constraint: Rerun reuses the app session id but creates a replacement browser target

Rejected: Kill all harness REPL processes on rerun | broader lifecycle churn and could affect unrelated active sessions

Confidence: high

Scope-risk: narrow

Directive: Keep Browser Harness JS REPL identity aligned with the assigned target when target lifecycle changes

Tested: yarn test --run tests/unit/hl/browserHarnessEnv.test.ts

Tested: yarn test --run tests/unit/hl

Tested: yarn typecheck

Tested: yarn lint

Tested: yarn test

Not-tested: Live Electron rerun from this worktree
Copy link
Copy Markdown

@cubic-dev-ai cubic-dev-ai Bot left a comment

Choose a reason for hiding this comment

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

No issues found across 4 files

@Cheggin Cheggin merged commit 9fdab09 into main May 9, 2026
9 checks passed
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.

1 participant