Skip to content

Fix #228: Replace hardcoded port 1108 with dynamic port allocation, s… - #239

Open
Ashutosh Mishra (Ashut0sh-mishra) wants to merge 3 commits into
microsoft:mainfrom
Ashut0sh-mishra:fix/issue-228-carbon-port
Open

Fix #228: Replace hardcoded port 1108 with dynamic port allocation, s…#239
Ashutosh Mishra (Ashut0sh-mishra) wants to merge 3 commits into
microsoft:mainfrom
Ashut0sh-mishra:fix/issue-228-carbon-port

Conversation

@Ashut0sh-mishra

Copy link
Copy Markdown

Summary

Fixes #228

Problem

The Carbon Sequestration notebook fails when run more
than once simultaneously because:

  • HTTP_SERVER_PORT was hardcoded to 1108 — second run
    crashes with "port already in use"
  • Global ngrok.kill() in finally block killed tunnels
    belonging to other running instances

Fix

  • comet_server.py: Replace hardcoded port 1108 with
    find_free_port() that binds to port 0 to get an
    OS-assigned available port
  • comet_server.py: Use self.port instance variable
    for per-server port isolation
  • comet_requester.py: Remove global ngrok.kill() from
    finally block — server.shutdown() already calls
    ngrok.disconnect() for current tunnel only
  • whatif_comet_local.py: Remove global ngrok.kill()
    from del and remove unused pyngrok import

Files Changed

  • notebooks/carbon/comet_server.py
  • notebooks/carbon/comet_requester.py
  • notebooks/carbon/whatif_comet_local.py

Validation

  • No hardcoded port 1108 references remain
  • Each server instance now gets its own OS-assigned port
  • ngrok cleanup is scoped to current tunnel only

Co-authors

Co-authored-by: nik464 nikhil18chaudhary@gmail.com

@Ashut0sh-mishra

Copy link
Copy Markdown
Author

@microsoft-github-policy-service agree

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks for addressing the hard-coded webhook port. We cannot merge this as-is: the ngrok tunnel and agent lifecycle are not cleaned up, pyngrok still uses shared mutable configuration across runs, and choosing a free port before binding it retains a TOCTOU race. Please rebase onto current main, use per-run scoped configuration, bind the port atomically, and guarantee cleanup on success and failure. Note that #199 is a separate COMET API v2.5 compatibility issue.

…cation, scope ngrok cleanup

- comet_server.py: Replace HTTP_SERVER_PORT=1108 with find_free_port()
  that binds to port 0 to get an OS-assigned available port
- comet_server.py: Use self.port instance variable for per-server port
- comet_requester.py: Remove global ngrok.kill() from finally block;
  server.shutdown() already calls ngrok.disconnect() for current tunnel
- whatif_comet_local.py: Remove global ngrok.kill() from __del__;
  remove unused pyngrok import

Co-authored-by: nik464 <nikhil18chaudhary@gmail.com>
@Ashut0sh-mishra

Copy link
Copy Markdown
Author

Implemented requested changes and rebased onto current main.

  • Port binding is now atomic by binding HTTPServer directly on OS-assigned port 0 and using the bound port.
  • pyngrok now uses per-run scoped configuration (no shared mutable default config).
  • ngrok and HTTP server lifecycle cleanup is guaranteed for both success and failure paths, scoped to the current run only.
  • Removed global ngrok.kill calls from requester/local callback paths.

Keeping this PR scoped to issue #228.
Issue #199 (COMET API v2.5 compatibility) remains separate and tracked by PR #251.

@Ashut0sh-mishra

Copy link
Copy Markdown
Author

Renato L. de F. Cunha (@renatolfc) pushed requested fixes to this branch (atomic bind, per-run ngrok config, scoped lifecycle cleanup). Could you please re-review when you have time?

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Adds per-request HTTP/ngrok resources to support concurrent Carbon Sequestration runs.

Changes:

  • Uses OS-assigned HTTP ports.
  • Introduces instance-specific ngrok configuration and cleanup.
  • Removes global ngrok cleanup calls.

Reviewed changes

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

File Description
comet_server.py Adds dynamic ports and scoped ngrok lifecycle.
comet_requester.py Delegates cleanup to the server.
whatif_comet_local.py Removes global cleanup and uses a placeholder webhook.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread src/vibe_lib/vibe_lib/comet_farm/comet_server.py Outdated
Comment thread src/vibe_lib/vibe_lib/comet_farm/comet_server.py Outdated
Comment thread src/vibe_lib/vibe_lib/comet_farm/comet_server.py
- Point PyngrokConfig.config_path at the instance temp dir so
  set_auth_token never races on the shared user-wide ngrok config
- Replace ngrok.disconnect()/ngrok.kill() with a direct kill of this
  instance's ngrok process, avoiding pyngrok's shared tunnel registry
  during concurrent shutdowns
- Drop the obsolete HTTPServer.server_bind patches that suppressed
  server_port assignment and broke test_whatif_request* under the
  atomic port-0 bind, and add a test asserting ephemeral port allocation
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.

Intermittent Failure When Running Carbon Sequestration Notebook

3 participants