ADR-0022: idx init executes in-process as a bootstrap exception
Status
Accepted
Context
ADR-0019 established that all index-related CLI commands delegate to the server via JSON-RPC, with βno in-process fallback β missing server is a clear error.β
This created a bootstrap paradox for new projects:
idx initrequires the server to be running (to forward the RPC call).idx server startrequired.idx/index.idxto exist (guard added to prevent running on uninitialized projects).- Neither command could succeed first on a clean project.
Additionally, the daemonβs watch loop already contained ensureRootIndex() which
auto-creates the index when the server starts without one β making the requireIndexExists
guard in ServerDaemonService.Start() redundant.
Decision
Two targeted changes resolve the paradox:
-
idx initexecutes in-process, not via RPC. Incmd/idx/main.go,isInitCommandroutesidx initthroughrunServer()(the same in-process path used by the daemon itself). This letsidx initrun before a server exists. When the server is already running and the user re-runsidx init, the index is rebuilt on disk and the server picks up changes on the nextidx synccall. -
idx server startno longer requires prior init. TherequireIndexExistsguard is removed fromServerDaemonService.Start(). The daemonβsensureRootIndex()inwatch_service.goalready handles the βno indexβ case gracefully, printing a user- friendly message and building the initial index before entering the watch loop.
Consequences
Positive
- Both
idx init && idx server startandidx server startalone work on clean projects. - The bootstrap paradox is eliminated without adding a new command or a complex retry loop.
- No new code paths for the init service itself β
runServer()already wired it correctly.
Trade-off
When the server is running and the user executes idx init (force re-index), the serverβs
in-memory state is not updated immediately. The user must run idx sync afterwards to
propagate the new index to the running server. This trade-off is acceptable because
forced re-init with a running server is rare, and idx sync already covers incremental
updates.