Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Require HTTP polling for GitHub Codespaces context #5349

Merged
merged 2 commits into from
Jan 7, 2025
Merged

Conversation

benjaminpkane
Copy link
Contributor

@benjaminpkane benjaminpkane commented Jan 6, 2025

What changes are proposed in this pull request?

SSE has been shown to be an unreliable /events connection in GitHub Codespaces. This change adds the polling=true URL search parameter to a Session.url value automatically for a reliable HTTP polling connection in Codespaces. The CODESPACES=true env var indicates a Codespaces context.

Minor cleanup since Colab also requires HTTP polling.

What areas of FiftyOne does this PR affect?

  • App: FiftyOne application changes
  • Build: Build and test infrastructure changes
  • Core: Core fiftyone Python library changes
  • Documentation: FiftyOne documentation changes
  • Other

Summary by CodeRabbit

  • New Features

    • Improved context-aware HTTP polling mechanism
    • Added optional view_name parameter for session initialization
  • Refactor

    • Updated logic for determining HTTP polling requirements
    • Reorganized import statements

The changes enhance the application's adaptability in various computing environments, particularly for Codespaces and Google Colab.

@benjaminpkane benjaminpkane requested review from sashankaryal, tom-vx51 and a team January 6, 2025 20:31
@benjaminpkane benjaminpkane self-assigned this Jan 6, 2025
Copy link
Contributor

coderabbitai bot commented Jan 6, 2025

Walkthrough

The changes introduce a new function _requires_http_polling() in the context module to determine HTTP polling requirements based on specific environment conditions. The function checks for execution in Codespaces or Google Colab, returning a boolean value. This modification enhances the context-aware URL generation process by conditionally adding a polling parameter, replacing the previous unconditional Colab-specific polling logic. Additionally, the Session class's __init__ method is updated to include an optional view_name parameter, enhancing session state management without altering existing functionality.

Changes

File Change Summary
fiftyone/core/context.py - Added _requires_http_polling() function
- Modified get_url() to use new polling logic
- Reorganized import statements
fiftyone/core/session/session.py - Updated __init__ method to include view_name: str = None parameter
- Removed unused import statements

Poem

🐰 In realms of code where contexts dance,
A rabbit hops with polling's new stance.
Codespaces and Colab now shine bright,
With smarter polling, everything's right!
🌐✨ Adaptability takes its flight!


📜 Recent review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between d038a16 and d3a014e.

📒 Files selected for processing (1)
  • fiftyone/core/session/session.py (0 hunks)
💤 Files with no reviewable changes (1)
  • fiftyone/core/session/session.py
⏰ Context from checks skipped due to timeout of 90000ms (7)
  • GitHub Check: lint / eslint
  • GitHub Check: test / test-python (ubuntu-latest-m, 3.11)
  • GitHub Check: build / build
  • GitHub Check: e2e / test-e2e
  • GitHub Check: test / test-python (ubuntu-latest-m, 3.10)
  • GitHub Check: test / test-app
  • GitHub Check: build

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (2)
fiftyone/core/context.py (2)

144-153: Implementation looks good with minor optimization possible.

The function correctly implements the polling requirements check for both Codespaces and Colab environments. Consider simplifying the Colab check:

-    if _get_context() == _COLAB:
-        return True
-
-    return False
+    return _get_context() == _COLAB
🧰 Tools
🪛 Ruff (0.8.2)

150-153: Return the condition _get_context() == _COLAB directly

Replace with return _get_context() == _COLAB

(SIM103)


181-182: Consider adding a comment explaining the polling parameter.

The condition for enabling polling is clear, but it would be helpful to document why polling is required when using a proxy or in certain environments. Consider adding a comment similar to the ones in _requires_http_polling():

+    # Enable HTTP polling when using a proxy or in environments where SSE is unreliable
     if "proxy" in kwargs or _requires_http_polling():
         kwargs["polling"] = "true"
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 574a577 and d038a16.

📒 Files selected for processing (1)
  • fiftyone/core/context.py (3 hunks)
🧰 Additional context used
🪛 Ruff (0.8.2)
fiftyone/core/context.py

150-153: Return the condition _get_context() == _COLAB directly

Replace with return _get_context() == _COLAB

(SIM103)

⏰ Context from checks skipped due to timeout of 90000ms (6)
  • GitHub Check: lint / eslint
  • GitHub Check: test / test-python (ubuntu-latest-m, 3.10)
  • GitHub Check: build / build
  • GitHub Check: e2e / test-e2e
  • GitHub Check: test / test-app
  • GitHub Check: build
🔇 Additional comments (1)
fiftyone/core/context.py (1)

144-153: Consider adding unit tests for the new function.

Since this function controls critical connection behavior, it would be beneficial to add unit tests covering:

  • Codespaces environment detection
  • Colab context detection
  • Default case (neither environment)

Would you like me to help create the unit test cases?

🧰 Tools
🪛 Ruff (0.8.2)

150-153: Return the condition _get_context() == _COLAB directly

Replace with return _get_context() == _COLAB

(SIM103)

@thesteve0
Copy link

LGTM

@@ -140,6 +141,18 @@ def _get_context():
return _context


def _requires_http_polling():
### SSE is unreliable in GitHub Codespaces
if os.environ.get("CODESPACES", None) == "true":
Copy link
Contributor

Choose a reason for hiding this comment

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

how about:

Suggested change
if os.environ.get("CODESPACES", None) == "true":
if os.environ.get("CODESPACES", "false").lower() == "true":

Copy link
Contributor Author

Choose a reason for hiding this comment

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

true is precisely what we expect if we are in a GitHub Codepaces context. I think the above is sufficient

Copy link
Contributor

@minhtuev minhtuev left a comment

Choose a reason for hiding this comment

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

Very minor comments, otherwise LGTM ✅

How can I test it?

@benjaminpkane
Copy link
Contributor Author

Very minor comments, otherwise LGTM ✅

How can I test it?

import os
import fiftyone as fo

os.environ["CODESPACES"] = "true"
session = fo.Session(remote=True)

assert "polling=true" in session.url

@benjaminpkane benjaminpkane merged commit 6fbed2c into develop Jan 7, 2025
14 checks passed
@benjaminpkane benjaminpkane deleted the codespaces branch January 7, 2025 20:25
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.

4 participants