Skip to content

feat(id): multiple web listeners by flag and config (#2145) - #4118

Merged
dezren39 merged 3 commits into
mainfrom
queue/5191-2145-web-bindings
Nov 2, 2026
Merged

dezren39 merged 3 commits into
mainfrom
queue/5191-2145-web-bindings

Conversation

@dezren39

@dezren39 dezren39 commented Nov 2, 2026 •

Copy link
Copy Markdown
Member

Implements the #2145 bindings model designed in triage task 3155 (design comment on #2145). Queue task 5191.

What

  • Bindings resolution (pkgs/id/src/commands/serve.rs): ServeOptions gains web_listen: Vec<SocketAddr> plus bind_explicit/port_explicit; resolve_web_bindings resolves the listener set once at startup:
    1. repeatable --web-listen <IP:PORT> flags win entirely;
    2. else the new [web_bindings] section of defaults.conf;
    3. else one binding synthesized from legacy --bind/--port (unchanged defaults).
      --web-listen combined with an explicitly-set --bind or --port is a startup error naming the conflicting flag (clap defaults do not count — main.rs reads clap value sources).
  • Config (pkgs/id/crates/id-core): parse_defaults collects [web_bindings] lines raw into Defaults.web_bindings; parsing happens at serve startup so a malformed line fails startup naming the line. The embedded defaults.conf documents the section with commented examples only — default behavior unchanged.
  • Startup: ALL listeners bind early, before the lock write; any bind failure aborts with web: failed to bind listener <addr>: <err> — no partial start. Startup prints web: <n> listener(s) plus one web: http://host:port line per listener in binding order with actual ports. Each listener serves the same Explorer web_router with its own WebSecurity::for_bind; the non-loopback no-token warning fires per listener naming addr:port.
  • Lock file: ServeInfo gains web_bindings: Vec<String> (#[serde(default)], so pre-id(serve): a bindings model — multiple listeners by flag and config #2145 lock files still parse); web_port keeps meaning first-listener port.

Out of scope (per design): per-listener distinct tokens and program content (#2146), runtime per-user config file.

Tests

Laptop (cargo test, pkgs/id):

  • id-core lib: 57 passed — incl. new test_parse_defaults_web_bindings, test_parse_defaults_no_web_bindings_section.
  • id lib: serve filter 51 passed (default features) and 51 passed with --features web; web_bindings filter 10 passed default / 12 passed with web — incl. resolve_web_bindings precedence (flags win over config), legacy fallback, conflict errors naming --bind/--port, malformed config line named, pre-id(serve): a bindings model — multiple listeners by flag and config #2145 lock JSON still parses; web_listen CLI parse: 1 passed (repeatable + malformed rejected); serve_info: 5 passed.
  • Live smoke (laptop, --features web build): serve --ephemeral --web --web-listen 127.0.0.1:18099 --web-listen 127.0.0.1:18100 printed web: 2 listener(s) + one web: http://localhost:<port> line per listener; both listeners answered HTTP 200; lock file: "web_port": 18099, "web_bindings": ["127.0.0.1:18099", "127.0.0.1:18100"]. Occupied-port launch aborts with web: failed to bind listener 127.0.0.1:18099: Address already in use; --web-listen + --port aborts naming the conflict.
  • Smoke-driven fix included here: building one web_router per listener fails on the second identity-store open (redb is exclusive), so all listeners now share one AppState via the new web::web_routers (state built once, cloned per listener, finished with each listener's own WebSecurity).

Closes #2145


View with [code]smith Autofix with [code]smith
Need help on this PR? Tag @codesmith-bot with what you need.

Bindings model from triage task 3155: ServeOptions resolves its web
listener set once at startup -- repeatable --web-listen flags win,
else the new [web_bindings] section in defaults.conf, else the legacy
--bind/--port pair. --web-listen with an explicitly-set --bind/--port
is a startup error naming the flag. All listeners bind early; any
bind failure aborts naming the listener. Startup prints a listener
count plus one line per listener; ServeInfo gains web_bindings
(serde default) with web_port kept as the first listener port.
Routers share one AppState (identity store opens exclusively) with
per-listener WebSecurity via web::web_routers.

Queue task 5191.
@dezren39
dezren39 requested a review from a team as a code owner November 2, 2026 01:55
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 2, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-02T12:08:32.858718Z 1934206 New commits
ℹ️ 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@coderabbitai

coderabbitai Bot commented Nov 2, 2026 •

Copy link
Copy Markdown

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 2 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

Learn how review limits work.

Review configuration:

Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: de4805bc-087a-4dd8-8356-082ca91c0229
Commits

Reviewing files that changed from the base of the PR and between fb0824a and 1934206.

Files selected for processing: 8
  • doc/2026-11-02T11-47-29Z_design_web_listeners/2026-11-02T11-47-29Z_design_web_listeners.md
  • pkgs/id/crates/id-core/src/defaults.conf
  • pkgs/id/crates/id-core/src/discovery.rs
  • pkgs/id/src/cli.rs
  • pkgs/id/src/commands/serve.rs
  • pkgs/id/src/main.rs
  • pkgs/id/src/web/mod.rs
  • pkgs/id/tests/cli_integration.rs
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 7ac8f8ae3e

ℹ️ 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".

Comment thread pkgs/id/src/commands/serve.rs Outdated
Comment on lines +1373 to +1374
let web_routers = crate::web::web_routers(
store_handle.clone(),

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Skip router initialization when the web interface is disabled

In builds with the web feature, invoking serve without --web now calls web_routers with an empty security list. That function constructs AppState before iterating the list, opening both the local-events directory and .identity.redb. Consequently, a corrupt, inaccessible, or externally locked web database can now abort an otherwise web-disabled P2P server, and normal startup unnecessarily creates web persistence files. Preserve the previous web-enabled guard around state construction.

Useful? React with 👍 / 👎.

Comment thread pkgs/id/src/cli.rs
Comment on lines +366 to +367
#[arg(long = "web-listen", value_name = "IP:PORT")]
web_listen: Vec<SocketAddr>,

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Add integration tests for the new listener CLI behavior

pkgs/id/AGENTS.md explicitly requires integration tests in tests/cli_integration.rs for CLI behavior, but this change adds only unit tests and leaves that integration suite unchanged. Searching the repository tests found no coverage for web-listen, web_listen, or web_bindings. Add executable-level coverage for repeated listeners and explicit --bind/--port conflicts so the argument-source wiring in main.rs and actual multi-listener startup are checked, rather than only parsing and resolution in isolation.

AGENTS.md reference: pkgs/id/AGENTS.md:L152-L152

Useful? React with 👍 / 👎.

Comment on lines +386 to +392
/// (#2145 bindings model, designed in triage task 3155):
///
/// 1. `--web-listen` flags, when given at least once, win entirely.
/// Combining them with an explicitly-set `--bind` or `--port` is an
/// error naming the conflicting flag (clap defaults do not count).
/// 2. Else the `[web_bindings]` section of `defaults.conf`, parsed here
/// so a malformed line fails startup naming the line.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Record the listener design in the required dated document

This introduces a new serving interface and listener-precedence semantics without the dated design record required by pkgs/id/AGENTS.md. Repository-wide Markdown searches, including the pkgs/id/docs symlink target, found no corresponding multi-listener design document; the commit instead references an external issue comment. Add the prescribed dated folder and matching Markdown recording the request, design, and decisions so this interface change has the required repository architecture record.

AGENTS.md reference: pkgs/id/AGENTS.md:L168-L168

Useful? React with 👍 / 👎.

Comment thread pkgs/id/src/commands/serve.rs Outdated
Comment on lines +418 to +420
.map(|addr| WebBinding {
bind: addr.ip(),
port: addr.port(),

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Preserve the interface scope of IPv6 listener addresses

For a scoped link-local IPv6 listener such as --web-listen '[fe80::1%3]:3000', parsing succeeds, but extracting only addr.ip() and addr.port() discards the IPv6 scope ID. WebBinding::socket_addr() then reconstructs the address with scope zero, so binding cannot select the requested interface and startup fails even when the original scoped address is valid. The config-binding path performs the same lossy conversion. Retain the full SocketAddr through resolution and binding, deriving its IP separately for the security policy.

Useful? React with 👍 / 👎.

@dezren39

dezren39 commented Nov 2, 2026

Copy link
Copy Markdown
Member Author

🤖 Agent note · parked

@dezren39
dezren39 merged commit 086474e into main Nov 2, 2026
1 check passed
@dezren39
dezren39 deleted the queue/5191-2145-web-bindings branch November 2, 2026 14:34
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.

id(serve): a bindings model — multiple listeners by flag and config

1 participant