feat(server): write cdp_port to server.json for auto-discovery#1070
Conversation
|
Greptile (@greptileai) review |
|
Claude (@claude) review |
|
Claude finished Nikhil (@shadowfax92)'s task in 59s —— View job Code Review
Clean, minimal change overall. A few observations:
|
Greptile SummaryExposes the CDP WebSocket port in
Confidence Score: 4/5Safe to merge; the change is additive and writes a new optional field to the discovery JSON without touching any existing logic. The only observable wrinkle is that the ?? undefined coercion in main.ts is dead code — the early-exit guard already ensures cdpPort is non-null before writeServerConfig is called — but this has no effect on runtime behaviour. main.ts line 98 — the redundant null-coercion is worth cleaning up for clarity. Important Files Changed
Sequence DiagramsequenceDiagram
participant Main as Application.start()
participant Guard as CDP Port Guard
participant CDP as CdpBackend
participant HTTP as HTTP Server
participant FS as writeServerConfig()
participant JSON as server.json
Main->>Guard: if (!cdpPort) exit(GENERAL_ERROR)
Guard-->>Main: cdpPort guaranteed non-null
Main->>CDP: connect(cdpPort)
CDP-->>Main: connected
Main->>HTTP: createHttpServer(serverPort)
HTTP-->>Main: listening
Main->>FS: "writeServerConfig({ server_port, cdp_port, url, ... })"
FS->>JSON: JSON.stringify → server.json
Prompt To Fix All With AIFix the following 1 code review issue. Work through them one at a time, proposing concise fixes.
---
### Issue 1 of 1
packages/browseros-agent/apps/server/src/main.ts:98
The `?? undefined` is a no-op here. The guard at lines 58–61 exits the process when `cdpPort` is falsy (null, 0, or undefined), so by the time `writeServerConfig` is reached, `this.config.cdpPort` is guaranteed to be a valid non-null number. The null-to-undefined coercion (which would suppress the key in `JSON.stringify`) can never activate in practice.
```suggestion
cdp_port: this.config.cdpPort,
```
Reviews (1): Last reviewed commit: "feat(server): write cdp_port to server.j..." | Re-trigger Greptile |
Greptile SummaryExposes the CDP WebSocket port in
Confidence Score: 4/5Safe to merge; the change is additive and confined to startup config writing with no effect on request handling. Both files have minimal, well-scoped changes. The only notable issue is a redundant No files require special attention; Important Files Changed
Sequence DiagramsequenceDiagram
participant Caller as CLI / Agent
participant Server as BrowserOS Server (main.ts)
participant FS as ~/.browseros/server.json
Server->>Server: Check cdpPort (exit if missing)
Server->>Server: Connect CDP backend
Server->>Server: Start HTTP server
Server->>FS: "writeServerConfig({ server_port, cdp_port, url, ... })"
FS-->>Caller: auto-discovery read
Caller->>Server: Connect via HTTP (server_port)
Caller->>Server: Connect via CDP (cdp_port)
Prompt To Fix All With AIFix the following 2 code review issues. Work through them one at a time, proposing concise fixes.
---
### Issue 1 of 2
packages/browseros-agent/apps/server/src/main.ts:98
The `?? undefined` fallback is dead code. By the time execution reaches this line, `this.config.cdpPort` is guaranteed to be a truthy `number` — the guard at lines 58–61 calls `process.exit()` (a `never`-returning function) whenever `cdpPort` is falsy, so TypeScript also narrows the type to `number` here. The `?? undefined` adds noise without any runtime or type-level effect.
```suggestion
cdp_port: this.config.cdpPort,
```
### Issue 2 of 2
packages/browseros-agent/apps/server/src/main.ts:232-238
**Startup summary omits the CDP port.** Now that `cdp_port` is written to `server.json` for external tool discovery, the "Services running:" summary would be more consistent if it also logged the CDP endpoint. Operators inspecting startup output currently have to scroll back to the earlier "Connected to CDP on port X" line to find it.
Reviews (2): Last reviewed commit: "feat(server): write cdp_port to server.j..." | Re-trigger Greptile |
❌ Tests failed — 1/1063 failed
Failed tests
|
| try { | ||
| await writeServerConfig({ | ||
| server_port: this.config.serverPort, | ||
| cdp_port: this.config.cdpPort ?? undefined, |
There was a problem hiding this comment.
The
?? undefined fallback is dead code. By the time execution reaches this line, this.config.cdpPort is guaranteed to be a truthy number — the guard at lines 58–61 calls process.exit() (a never-returning function) whenever cdpPort is falsy, so TypeScript also narrows the type to number here. The ?? undefined adds noise without any runtime or type-level effect.
| cdp_port: this.config.cdpPort ?? undefined, | |
| cdp_port: this.config.cdpPort, |
Prompt To Fix With AI
This is a comment left during a code review.
Path: packages/browseros-agent/apps/server/src/main.ts
Line: 98
Comment:
The `?? undefined` fallback is dead code. By the time execution reaches this line, `this.config.cdpPort` is guaranteed to be a truthy `number` — the guard at lines 58–61 calls `process.exit()` (a `never`-returning function) whenever `cdpPort` is falsy, so TypeScript also narrows the type to `number` here. The `?? undefined` adds noise without any runtime or type-level effect.
```suggestion
cdp_port: this.config.cdpPort,
```
How can I resolve this? If you propose a fix, please make it concise.Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!
Summary
cdp_portto the~/.browseros/server.jsondiscovery file written on server startup, alongside the existingserver_port.Design
ServerDiscoveryConfiggains an optionalcdp_port?: number. Inmain.ts, the startupwriteServerConfig()call now passescdp_port: this.config.cdpPort ?? undefined. The CDP port is optional in config (cdpPort: portSchema.nullable(), set only via--cdp-port/BROWSEROS_CDP_PORT), so when absent the key is omitted from the JSON entirely rather than written asnull.Test plan
bun run typecheckpasses across all packages.--cdp-port <port>and confirm~/.browseros/server.jsoncontainscdp_port.