Skip to content

fix: register operations in worker threads so replication WS can dispatch them - #523

Merged
kriszyp merged 1 commit into
mainfrom
fix/register-operation-worker-threads
May 13, 2026
Merged

fix: register operations in worker threads so replication WS can dispatch them#523
kriszyp merged 1 commit into
mainfrom
fix/register-operation-worker-threads

Conversation

@kriszyp

@kriszyp kriszyp commented May 13, 2026

Copy link
Copy Markdown
Member

Summary

Re-enable server.registerOperation and the operation function map in worker threads so plugin operations (e.g. replication's add_node_back) are actually registered. After 40600bf moved the HTTP operations API to main-thread-only, server.registerOperation was no longer set up in worker threads — module-level calls like server.registerOperation?.({...}) in setNode.ts silently no-op'd because the optional-chain short-circuits when the method is undefined.

This broke inter-node cluster setup. add_node opens a WebSocket to the target node's replication port (9933) and sends add_node_back. The WS handler runs in a worker thread and dispatches via server.operation(), which looks up in the operation function map. Since add_node_back was never registered in the worker, every cluster setup attempt fails with:

Operation 'add_node_back' not found and connection was required to sign certificate

This blocks fullyConnectedReplication.test.mjs, replicationLoad.test.mjs, and anything else exercising multi-node clustering.

Fix

In components/componentLoader.ts, when not on the main thread, eagerly require serverHelpers/serverUtilities (which installs server.operation, server.registerOperation, and initializes the operation function map). This does NOT load the fastify HTTP layer — that stays main-thread-only per 40600bf.

Verification

Verified locally:

  • fullyConnectedReplication.test.mjs — 12/12 pass (6 RocksDB + 6 LMDB; previously 0/12).
  • replicationLoad.test.mjs connect nodes and Deploy app and test replication now pass; remaining failures are unrelated concurrency / many-database issues.
  • New issue135-replicated-search-after-restart.test.mjs in harper-pro (Scenario B) now runs successfully.

Review attention

The conditional require approach mirrors the existing main-thread-only operationsServer require. It's a minimal change but the failure mode (silent no-op via ?.) is exactly the same class of issue, so the same fix shape should be considered for any future plugin that uses server.registerOperation from a worker-loaded module.

🤖 Generated with Claude Sonnet 4.6 (1M context)

…atch them

After 40600bf moved the HTTP operations API to the main thread only,
`server.registerOperation` was no longer wired up in worker threads. Plugins
that call `server.registerOperation?.({...})` at module load time (e.g.
replication's setNode.ts, clusterStatus.ts) silently no-op'd in workers
because the optional-chain short-circuits when the method is undefined.

This breaks inter-node replication setup: `add_node` opens a WebSocket to the
target node's replication port (9933) and sends `add_node_back`. The WS
handler runs in a worker thread and dispatches via `server.operation()`, which
looks up in the operation function map. Since `add_node_back` was never
registered in the worker, every cluster setup attempt fails with:

  "Operation 'add_node_back' not found and connection was required to sign
  certificate"

This blocks `fullyConnectedReplication.test.mjs`, `replicationLoad.test.mjs`,
and anything else that exercises multi-node clustering.

Fix: in worker threads, eagerly require `serverHelpers/serverUtilities`
directly, which installs `server.operation`, `server.registerOperation`, and
initializes the operation function map without binding the fastify HTTP layer
(that stays main-thread-only per the original change).

Verified by re-running `fullyConnectedReplication.test.mjs` — 12/12 pass
(6 RocksDB + 6 LMDB). `replicationLoad.test.mjs` `connect nodes` and
`Deploy app and test replication` now pass; remaining failures
(`replicate across many databases`, `replicate insert/upsert across all nodes`)
are unrelated concurrency / many-database issues.

Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>
@claude

claude Bot commented May 13, 2026

Copy link
Copy Markdown
Contributor

Reviewed; no blockers found.

@kriszyp
kriszyp merged commit e8a5cca into main May 13, 2026
23 of 25 checks passed
@kriszyp
kriszyp deleted the fix/register-operation-worker-threads branch May 13, 2026 17:29
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.

2 participants