Skip to content

fix: pre-seed kubo Routing config so pkc-js init does not restart kubo - #144

Merged
Rinse12 merged 1 commit into
masterfrom
fix/preseed-kubo-routing-config
Sep 2, 2026
Merged

fix: pre-seed kubo Routing config so pkc-js init does not restart kubo#144
Rinse12 merged 1 commit into
masterfrom
fix/preseed-kubo-routing-config

Conversation

@Rinse12

@Rinse12 Rinse12 commented Sep 1, 2026

Copy link
Copy Markdown
Member

Problem

pkc-js (>= 0.0.46, still true in 0.0.89) rewrites the connected kubo node's Routing config during its init (setupKuboHttpRouters) and POSTs /shutdown to kubo whenever the router endpoint set changed — always true on a repo pkc-js hasn't configured yet. The daemon's keepKuboUp restarts kubo as pkc-js expects, but that opens a multi-second window right after the ready banner where kubo's API refuses connections. Early CLI commands can burn their whole budget inside it: on windows-latest CI (run 33471620931), bitsocial community create blocked on pkc-js's signer-key import retrying ECONNREFUSED against the restarting kubo and blew the completion-time test's 10s budget.

Fix

pkc-js builds its desired Routing value deterministically from httpRoutersOptions and only shuts kubo down when the endpoint set differs. The daemon knows those options (it passes them to pkc-js), so startKuboNode now writes the equivalent Routing config (plus Provide.DHT.SweepEnabled=false) into the kubo config file before spawning kubo, on every start (like ensureIpnsPubsubEnabled) — covering fresh repos and router-list changes on existing repos alike. pkc-js's endpoint comparison then sees no change and never issues the shutdown.

Notes:

  • Routing is effectively owned by pkc-js — it overwrites the section unconditionally at init (_mergeRouterConfigs starts from its own Routers set) — so this preserves no less user state than pkc-js itself would.
  • keepKuboUp and the restart machinery stay: still needed for external kubo nodes and as a safety net. If a pkc-js upgrade changes its Routing mapping, behavior degrades gracefully back to a one-time restart, and the new regression test catches that at upgrade time (pkc-js versions are pinned exactly).

Test

test/cli/daemon-no-kubo-restart-on-fresh-start.test.ts: fresh daemon start + a full community create (which forces pkc-js through its kubo interactions), then asserts the daemon log has no "Will attempt to restart it" and exactly one "Started kubo ipfs process with pid". Red before the fix (restart observed ~50ms after the ready banner), green after. pkc-js's own router-setup log lines never reach the daemon log file (its bundled logger doesn't pick up the daemon's debug config), so the assertions anchor on the daemon's own logging.

Full suite: 44 files, 342 passed, 1 skipped.

Closes #143

Summary by CodeRabbit

  • Bug Fixes

    • Improved IPFS startup reliability when HTTP router settings are configured.
    • Prevented unnecessary Kubo shutdown and restart cycles during a fresh daemon start.
    • Ensured configured HTTP router options are applied consistently when launching the node.
  • Tests

    • Added regression coverage confirming fresh daemon starts launch Kubo only once without triggering an unnecessary restart.

pkc-js (>= 0.0.46) rewrites the connected kubo node's Routing config
during its init and POSTs /shutdown to kubo whenever the router endpoint
set changed — always true on a repo pkc-js hasn't configured yet —
expecting the daemon's keepKuboUp to restart it. That restart opens a
multi-second window right after the ready banner where kubo's API
refuses connections, and early CLI commands can burn their whole budget
inside it (observed as a community-create timeout on windows CI).

Write the equivalent Routing config (plus Provide.DHT.SweepEnabled=false)
into the kubo config file before spawning kubo, on every start: pkc-js's
endpoint comparison then sees no change and never issues the shutdown.
Running on every start (like ensureIpnsPubsubEnabled) also covers router
list changes on existing repos. Routing is effectively owned by pkc-js —
it overwrites the section unconditionally at init — so this preserves no
less user state than pkc-js itself would. If a pkc-js upgrade changes
its mapping, behavior degrades back to a one-time restart and the new
regression test catches it at upgrade time.
@coderabbitai

coderabbitai Bot commented Sep 1, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Team

Run ID: f5227521-23b9-46c1-acf1-352362d6e521

📥 Commits

Reviewing files that changed from the base of the PR and between 776daaa and 65f3c58.

📒 Files selected for processing (3)
  • src/cli/commands/daemon.ts
  • src/ipfs/startIpfs.ts
  • test/cli/daemon-no-kubo-restart-on-fresh-start.test.ts

Included review availability: Your plan provides up to 1 included review per hour; 0 remain after this review.


📝 Walkthrough

Walkthrough

The daemon now passes HTTP router options to Kubo startup. Startup pre-seeds matching routing configuration before Kubo spawns. A regression test verifies that a fresh daemon start performs one Kubo start without a restart.

Changes

HTTP router startup configuration

Layer / File(s) Summary
Build and pre-seed routing configuration
src/ipfs/startIpfs.ts
The startup flow builds deterministic Kubo routing settings for the configured HTTP routers and writes matching Routing and Provide.DHT.SweepEnabled values before Kubo starts.
Daemon startup wiring and regression validation
src/cli/commands/daemon.ts, src/ipfs/startIpfs.ts, test/cli/daemon-no-kubo-restart-on-fresh-start.test.ts
The daemon passes HTTP router options to startKuboNode. The regression test verifies one Kubo start and no restart during a fresh daemon start.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Merge Risk: 🔵 Low · up to 65f3c

The daemon now persists routing settings before starting Kubo, avoiding an unnecessary restart during initialization. Because the live configuration file is rewritten directly, an interrupted write or concurrent local change could leave Kubo unable to start until the configuration is repaired; this is a bounded mergeable risk requiring owner awareness.

Sequence Diagram(s)

sequenceDiagram
  participant Daemon
  participant startKuboNode
  participant KuboConfig
  participant Kubo
  participant pkc-js
  Daemon->>startKuboNode: pass HTTP router options
  startKuboNode->>KuboConfig: pre-seed Routing configuration
  startKuboNode->>Kubo: spawn Kubo
  pkc-js->>Kubo: initialize router configuration
  Kubo-->>Daemon: remain running without restart
Loading
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 75.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 4 functions across 3 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes the primary change: pre-seeding Kubo Routing configuration to prevent pkc-js from restarting Kubo.
Linked Issues check ✅ Passed The changes satisfy issue #143. They pre-seed the deterministic Routing configuration and set Provide.DHT.SweepEnabled=false before Kubo starts, pass router options through the daemon startup path, re…
Out of Scope Changes check ✅ Passed All changes support issue #143. The startup configuration changes, daemon option propagation, and regression test are directly related to preventing unnecessary Kubo restarts.
Full details: Linked Issues check

Explanation

The changes satisfy issue #143. They pre-seed the deterministic Routing configuration and set Provide.DHT.SweepEnabled=false before Kubo starts, pass router options through the daemon startup path, retain restart handling, and add a regression test for fresh daemon starts.

  • Fix all pre-merge checks with AI
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/preseed-kubo-routing-config

Warning

Some tools did not complete. Review the errors below.

🔧 ESLint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

src/cli/commands/daemon.ts

Oops! Something went wrong! :(

ESLint: 8.27.0

Error: ESLint configuration in --config » eslint-config-oclif is invalid:

  • Unexpected top-level property "__esModule".

Referenced from: /.eslintrc
at ConfigValidator.validateConfigSchema (/.eslint-tmp/node_modules/@eslint/eslintrc/dist/eslintrc.cjs:2156:19)
at ConfigArrayFactory._normalizeConfigData (/.eslint-tmp/node_modules/@eslint/eslintrc/dist/eslintrc.cjs:2998:19)
at ConfigArrayFactory._loadConfigData (/.eslint-tmp/node_modules/@eslint/eslintrc/dist/eslintrc.cjs:2963:21)
at ConfigArrayFactory._loadExtendedShareableConfig (/.eslint-tmp/node_modules/@eslint/eslintrc/dist/eslintrc.cjs:3264:21)
at ConfigArrayFactory._loadExtends (/.eslint-tmp/node_modules/@eslint/eslintrc/dist/eslintrc.cjs:3135:25)
at ConfigArrayFactory._normalizeObjectConfigDataBody (/.eslint-tmp/node_modules/@eslint/eslintrc/dist/eslintrc.cjs:3074:25)
at _normalizeObjectConfigDataBody.next ()
at ConfigArrayFactory._normalizeObjectConfigData (/.eslint-tmp/node_modules/@eslint/eslintrc/dist/eslintrc.cjs:3019:20)
at _normalizeObjectConfigData.next ()
at ConfigArrayFactory.loadFile (/.eslint-tmp/node_modules/@eslint/eslintrc/dist/eslintrc.cjs:2829:16)

src/ipfs/startIpfs.ts

ESLint skipped: the matched ESLint configuration already failed (config-incompatibility).

test/cli/daemon-no-kubo-restart-on-fresh-start.test.ts

ESLint skipped: the matched ESLint configuration already failed (config-incompatibility).


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

Comment @coderabbitai help to get the list of available commands.

@Rinse12
Rinse12 merged commit 2a09397 into master Sep 2, 2026
4 checks passed
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.

Pre-seed kubo Routing config so pkc-js init doesn't shut down and restart kubo on every fresh start

1 participant