Repository navigation
feat(core): add browser session contracts - #24
ElbertePlinio wants to merge 6 commits into
Conversation
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 202b237728
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| if (stat !== undefined && stat.pgrp === pgid) { | ||
| members.push(pid); |
There was a problem hiding this comment.
Treat zombie group members as terminated
When a killed child is reparented to a non-reaping PID 1 (common in containers), it remains in /proc with state Z and the same process group. This check counts that zombie as a live group member, so stopProcessGroupVerified() never observes an empty group and waits until returning survived even after SIGKILL; browser cleanup can then spend the full timeout or misreport a successful teardown as failed. Parse the stat state and exclude zombies from live group membership.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in 9e28b3e. /proc state is now parsed and zombie (Z) entries are excluded from live process-group membership, with a synthetic parser regression test. Group teardown now treats zombie-only groups as terminated instead of timing out or reporting survived.
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: bdf0b0cc67
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| isPidAlive(xvfbPid) && | ||
| processIdentityMatches({ | ||
| pid: browser.browserPid, | ||
| startTicks: browser.browserStartTimeTicks, | ||
| }) |
There was a problem hiding this comment.
Treat surviving browser groups as alive
When the recorded browser process is only a launcher/group leader that exits after spawning the real browser (for example a distro chromium wrapper), the process group can still contain the usable browser while processIdentityMatches returns false. In that case reapDeadRunningSessions will classify the session as dead and then stopProcessGroupVerified will kill the still-running browser group; the liveness check should also consider verified process-group members for the recorded browser PGID before reaping.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Not applying this suggestion because it conflicts with the PID-reuse safety boundary: the recorded leader identity is the authority, and a bare PGID with no matching leader cannot be proven to belong to PickLab. The #18 lifecycle implementation will keep a stable supervised group leader and fail startup if that identity disappears. This contract-only PR exposes no browser-session creator.
| } from "./proc.js"; | ||
|
|
||
| export type SessionType = "desktop" | "android" | "desktop+android"; | ||
| export type SessionType = "desktop" | "android" | "desktop+android" | "browser"; |
There was a problem hiding this comment.
Handle browser sessions in destroy-all paths
Adding browser to the persisted SessionType makes these records appear in listSessions(), but the CLI and MCP destroy helpers still switch only on desktop and android (packages/cli/src/commands/session.ts and packages/mcp-server/src/tools/session.ts). When an internal browser session exists, picklab session destroy --all or session_destroy(all=true) reports Cannot destroy ... type "browser" and leaves the browser/display processes and session record behind instead of using the new cleanup support.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Correct for the future lifecycle integration, but intentionally deferred to the existing #18 implementation slice: this PR adds internal record/process contracts only and exposes no CLI/MCP path that can create a browser record. The browser lifecycle branch adds create/status/destroy and destroy-all dispatch together, with regression coverage, before browser sessions become user-creatable.
| if (leader !== undefined && leader.startTicks !== identity.startTicks) { | ||
| return { outcome: "reused", signaled: false }; | ||
| } | ||
| if (leader === undefined && listProcessGroupMembers(identity.pid).length === 0) { |
There was a problem hiding this comment.
Treat missing group leaders as reused
If the recorded browser PID has exited and that numeric PID/PGID is later reused by an unrelated process group whose leader has already exited but still has children, this branch falls through because listProcessGroupMembers(identity.pid) is non-empty and signalGroup then kills the unrelated group without ever verifying the new leader's start time. That breaks the PID-reuse protection this helper is meant to provide for stale browser session records; the initial cleanup path should fail closed when the leader cannot be identity-checked rather than signaling an unverifiable PGID.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in f6eedbd. If the recorded leader is gone while the numeric PGID still has members, teardown now returns reused without signalling. A regression test captures the leader identity, lets it exit while a child remains, and proves the unverifiable group is not killed.
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: e943c91e1a
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
|
|
||
| /** Read a process's start time in clock ticks, or undefined if it is gone. */ | ||
| export function readProcessStartTicks(pid: number): number | undefined { | ||
| return readProcStat(pid)?.startTicks; |
There was a problem hiding this comment.
Treat zombie process identities as dead
When the recorded browser process exits but remains unreaped as a zombie while Xvfb is still running, /proc/<pid>/stat still exists with the same start ticks, so processIdentityMatches continues to return true and isSessionProcessAlive will keep the browser session marked running. Since parseProcStat already exposes state, this helper should ignore Z entries before returning a live identity/start time so the reaper can remove dead browser sessions.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in 788fc81. readProcessStartTicks now returns undefined for zombie (Z) states, so zombie leaders no longer satisfy browser identity/liveness checks. A mocked /proc regression test covers both start-tick and identity reads.
|
@codex review |
|
Codex Review: Didn't find any major issues. Keep it up! Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 3506392a7b
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| const browser = record.browser; | ||
| if (browser?.browserPid !== undefined) { | ||
| try { | ||
| await stopProcessGroupVerified({ | ||
| pid: browser.browserPid, |
There was a problem hiding this comment.
Stop the browser group before killing its display
When reaping a browser session whose Chrome is still alive, the loop just above first terminates desktop.xvfbPid; if losing the X server makes the browser process-group leader exit before this block runs, stopProcessGroupVerified treats the remaining group as unverifiable/reused and does not signal surviving renderer children. That leaves browser children running while the session record is deleted, so the verified browser group should be stopped before tearing down the desktop helpers.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Valid. This is a new P2 on the fourth and final allowed review round, so PR #24 is left open and will not merge. The fix must stop the verified browser group before VNC/Xvfb helpers; it is tracked in #18 and will be applied in the browser lifecycle branch with regression coverage. No fifth Codex round will be requested.
|
Superseded by #26, which includes the final teardown-order fix, additional fail-closed hardening, full validation, and a clean review on the corrected HEAD. |
Changed
browsersession type andbrow-*IDs.This is PR 2 of the computer-use roadmap. It settles shared contracts only; Chrome launch, profile lifecycle, and CLI/MCP browser creation remain in the later #18 slice.
Validated
bun run typecheckbun run test— 579 passed, 1 skippedbun run test:coverage— thresholds metbun run buildNot tested
Risk
/proc, matching PickLab's current Linux desktop scope.Refs #18
Refs #17