Skip to content

Conversation

leynos
Copy link
Owner

@leynos leynos commented Jun 12, 2025

Summary

  • implement a basic WireframeServer
  • export the new server module
  • add Tokio, futures and num_cpus deps
  • document worker-based server startup in the roadmap

Testing

  • cargo fmt
  • cargo clippy -- -D warnings
  • cargo test
  • markdownlint docs/roadmap.md
  • nixie docs

https://chatgpt.com/codex/tasks/task_e_684a273f985c8322a9734a0131abcf4c

Summary by Sourcery

Add a skeleton for a new async server to host WireframeApp instances using Tokio, configure it for multi-threaded workers, and hook in graceful shutdown. Update project structure and docs accordingly.

New Features:

  • Introduce WireframeServer module with async multi-threaded worker spawning and Ctrl+C graceful shutdown.
  • Expose the server module in the public API (lib.rs).

Build:

  • Add tokio, futures, and num_cpus dependencies to Cargo.toml.

Documentation:

  • Mark WireframeServer implementation and describe worker-based startup in the roadmap documentation.

Summary by CodeRabbit

  • New Features
    • Introduced a new server component that allows concurrent handling of connections using worker tasks, each with its own application instance.
    • Added support for graceful shutdown triggered by Ctrl+C, ensuring all workers stop accepting new connections.
  • Documentation
    • Updated the roadmap to reflect the completion and details of the new server implementation.

Copy link
Contributor

sourcery-ai bot commented Jun 12, 2025

Reviewer's Guide

Introduces a Tokio-based WireframeServer skeleton with per-worker WireframeApp factories and graceful Ctrl+C shutdown, exports the new server module, adds async runtime dependencies, and updates the roadmap documentation to describe the startup workflow.

Sequence Diagram for WireframeServer Startup and Shutdown

sequenceDiagram
    actor User
    participant Main as "WireframeServer.run()"
    participant TokioRuntime
    participant Worker as "Worker Task"
    participant Listener as "TcpListener"
    participant SignalHandler as "Ctrl+C Signal Handler"

    User->>Main: Call run()
    activate Main
    Main->>Listener: TcpListener::bind(addr)
    Listener-->>Main: listener instance
    Main->>Main: Create shutdown_tx broadcast channel
    loop For each worker (self.workers)
        Main->>Main: shutdown_rx = shutdown_tx.subscribe()
        Main->>TokioRuntime: tokio::spawn(worker_logic with app_factory, listener_ref, shutdown_rx)
        TokioRuntime->>Worker: Start task
        activate Worker
        Worker->>Worker: app = app_factory()
        Worker->>Worker: Enter tokio::select! loop (listen on Listener.accept() & shutdown_rx.recv())
    end
    Main->>SignalHandler: Listen for tokio::signal::ctrl_c()
    deactivate Main

    User-->>SignalHandler: Sends Ctrl+C Signal
    activate SignalHandler
    SignalHandler-->>Main: Notify Ctrl+C received
    deactivate SignalHandler
    activate Main
    Main->>Worker: shutdown_tx.send(()) (broadcast to all workers)
    activate Worker
    Worker->>Worker: Receives shutdown via shutdown_rx, breaks select! loop
    Worker-->>TokioRuntime: Task terminates
    deactivate Worker
    Main-->>User: run() returns Ok(())
    deactivate Main
Loading

Class Diagram for WireframeServer

classDiagram
    class WireframeServer~F~ {
        <<struct>>
        -factory: F
        -addr: Option<SocketAddr>
        -workers: usize
        +new(factory: F) WireframeServer~F~
        +workers(count: usize) WireframeServer~F~
        +bind(addr: SocketAddr) Result~WireframeServer~F~~~
        +run() async Result~()~
    }
    class WireframeApp {
        %% Existing component, details omitted as it's referenced by the factory F
    }
    WireframeServer~F~ ..> WireframeApp : "factory F produces instances of"
    class SocketAddr
    class Result~T~
Loading

File-Level Changes

Change Details Files
Implement and export a Tokio-driven WireframeServer skeleton
  • Create WireframeServer struct with new, workers, bind, and run methods
  • Spawn per-thread worker tasks using tokio::spawn and num_cpus::get()
  • Use a broadcast channel to trigger graceful shutdown on Ctrl+C
  • Require bind before running and leave connection handling as a TODO placeholder
src/server.rs
src/lib.rs
Add async runtime and utility dependencies
  • Add tokio with net, signal, rt-multi-thread, macros, and sync features
  • Include futures for async combinators
  • Add num_cpus to determine default worker count
Cargo.toml
Update roadmap to document worker-based server startup
  • Mark WireframeServer as implemented
  • Describe spawning of worker tasks via Tokio with per-worker WireframeApp instances
  • Explain Ctrl+C-triggered graceful shutdown notifying all workers
docs/roadmap.md

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link
Contributor

coderabbitai bot commented Jun 12, 2025

Warning

Rate limit exceeded

@leynos has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 1 minutes and 3 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

📥 Commits

Reviewing files that changed from the base of the PR and between d047817 and 03f24d1.

📒 Files selected for processing (2)
  • Cargo.toml (1 hunks)
  • src/server.rs (1 hunks)

Walkthrough

The changes introduce a new Tokio-based asynchronous server implementation, WireframeServer, with configurable worker tasks and graceful shutdown support. Dependencies for async runtime, futures, and CPU detection are added, documentation is updated to reflect server completion, and the server module is publicly exposed in the library.

Changes

File(s) Change Summary
Cargo.toml Added dependencies: tokio (with features), futures, and num_cpus.
docs/roadmap.md Marked WireframeServer as complete; expanded description to detail Tokio usage and graceful shutdown behaviour.
src/lib.rs Publicly exposed the server module.
src/server.rs Added new WireframeServer struct with async worker management, bind, and graceful shutdown support.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant WireframeServer
    participant WorkerTask
    participant WireframeApp
    participant OS

    User->>WireframeServer: new(factory)
    User->>WireframeServer: workers(count)
    User->>WireframeServer: bind(addr)
    User->>WireframeServer: run()
    WireframeServer->>OS: Bind TCP listener
    loop For each worker
        WireframeServer->>WorkerTask: Spawn async task
        WorkerTask->>WireframeApp: Create via factory
        WorkerTask->>OS: Accept TCP connections
    end
    OS-->>WireframeServer: Ctrl+C signal
    WireframeServer->>WorkerTask: Broadcast shutdown
    WorkerTask->>OS: Stop accepting connections
Loading

Possibly related PRs

Poem

In the warren of code where async dreams dwell,
A server awakens, with Tokio as its shell.
Workers abound, each with a task,
Ready for shutdown at the OS’s ask.
Now the roadmap’s checked, the future is bright—
Hop along, dear dev, your server’s alight!
🐇✨

✨ Finishing Touches
  • 📝 Docstrings were successfully generated. (🔄 Check again to generate docstrings again)

🪧 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.
    • Explain this complex logic.
    • 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 explain this code block.
    • @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 explain its main purpose.
    • @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.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

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.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @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.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

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

@sourcery-ai sourcery-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.

Hey @leynos - I've reviewed your changes and they look great!

Here's what I looked at during the review
  • 🟡 General issues: 3 issues found
  • 🟢 Security: all looks good
  • 🟢 Testing: all looks good
  • 🟢 Complexity: all looks good
  • 🟢 Documentation: all looks good

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

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: 3

🧹 Nitpick comments (2)
Cargo.toml (1)

9-11: Restrict Tokio’s default features to curb compile-time bloat.

Tokio pulls in many sub-crates by default. When you already list the concrete features you need (net, signal, rt-multi-thread, macros, sync), add default-features = false to avoid accidentally compiling unused extras such as IO-URING or time.

-tokio = { version = "1", features = ["net", "signal", "rt-multi-thread", "macros", "sync"] }
+tokio = { version = "1", default-features = false, features = ["net", "signal", "rt-multi-thread", "macros", "sync"] }
src/server.rs (1)

75-97: Minor concurrency issues inside worker loop.

  1. Using a broadcast buffer of 1 risks discarding the shutdown message if tasks lag.
  2. Accept-error handling only logs; a repeated fatal error (e.g. EMFILE) causes a tight loop. Consider exponential back-off or bubbling the error.
  3. _app is instantiated but never used; if its drop impl does clean-up, moving it inside the accept loop might be safer.
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 3dec921 and 693d92b.

⛔ Files ignored due to path filters (1)
  • Cargo.lock is excluded by !**/*.lock
📒 Files selected for processing (4)
  • Cargo.toml (1 hunks)
  • docs/roadmap.md (1 hunks)
  • src/lib.rs (1 hunks)
  • src/server.rs (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: coverage
🔇 Additional comments (2)
src/lib.rs (1)

3-3: Publicly exporting the server module looks good.

The new module is now discoverable to downstream crates and matches the crate’s layering.

docs/roadmap.md (1)

20-24: Roadmap update is consistent with the implementation.

Tick-marking WireframeServer here mirrors the new code – no issues.

coderabbitai bot added a commit that referenced this pull request Jun 12, 2025
…ads`

Docstrings generation was requested by @leynos.

* #6 (comment)

The following files were modified:

* `src/server.rs`
Copy link
Contributor

coderabbitai bot commented Jun 12, 2025

Note

Generated docstrings for this pull request at #7

…ads` (#7)

Docstrings generation was requested by @leynos.

* #6 (comment)

The following files were modified:

* `src/server.rs`

Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant