Skip to content

fix(local-api): probe the collections list, so a large library cannot hide a running Zotero (#102) - #103

Merged
oscardvs merged 1 commit into
mainfrom
fix/102-cheap-local-probe
Sep 30, 2026
Merged

oscardvs merged 1 commit into
mainfrom
fix/102-cheap-local-probe

Conversation

@oscardvs

Copy link
Copy Markdown
Owner

Fixes #102.

What was wrong

The local API liveness probe asked Zotero for /api/users/0/items?limit=1 with a 1.5 s budget (2 s at startup). Zotero answers that request by running a library-wide search, loading every item it returns and sorting them all, and only then slicing off one item (server_localAPI.js, LocalAPIEndpoint.init and Items._runGet). So the request costs the size of the library, whatever the limit says. On the reporter's 166,338 items every probe ran out of budget, localApi stayed false for the life of the process, and every read went to the cloud, where the library-wide full-text search timed out. curl has no budget, which is why it "worked".

Both theories in the report were already ruled out by the code: the desktop transport is node:http, which sends no User-Agent, and every request carries x-zotero-connector-api-version, which is precisely the header Zotero's browser check exempts (server.js, _processEndpoint). The base URL has been 127.0.0.1 since the first release. A bare localApi: false gave the reporter nothing to rule either out with.

What changes

  • The probe (and ping, and the Zotero 10 write client's own probe) ask for /api/users/0/collections?limit=1. Same endpoint class, so a switched-off local API still answers 403 and a proxy rewriting the Host header still answers 400, and the same Last-Modified-Version and Zotero-Server-ID headers come back. Cost: a few hundred entries at most.
  • The outcome of the latest probe is kept on the live Capabilities object (localProbe): up, unreachable, timeout with its budget, or http with the status.
  • The startup line says why: Capabilities: cloud=none, localApi=false (nothing listening on 127.0.0.1:23999), localGroups=0.
  • zotero_whoami reports localApiProbe and chooses its remedy by it: a 403 is "Zotero is running but its local API is switched off", a timeout names the budget and where Zotero's debug output shows its own timing, a refused connection names the port and ZOTERO_LOCAL_PORT.

Verified

  • Against the Zotero 10.0.3 on this machine (1,534 items) the items probe already takes several times the collections probe; both carry the same headers.
  • node dist/index.js over stdio with the real Zotero: localApi: true, localApiProbe: {"kind":"up"}. Against a dead port: localApi: false, localApiProbe: {"kind":"unreachable"}, and the summary names the port and ZOTERO_LOCAL_PORT.
  • npm test: 2751 passed, 8 skipped. typecheck, typecheck:tests and eslint on the changed files are clean.

Not shipped here: a settings-pane field for the port. ZOTERO_LOCAL_PORT exists and is documented; Zotero only listens on loopback, so there is no base URL to configure beyond it.

… hide a running Zotero (#102)

The liveness probe asked the desktop app for /users/0/items?limit=1 with a
1.5 s budget (2 s at startup). Zotero answers that request by running a
library-wide search, loading every item it returns and sorting them all
before it slices off one, so the cost is the size of the library whatever
the limit says. On a library of 166,338 items every probe timed out, the
local API was reported absent for the life of the process, and every read
went to the cloud Web API, where a library-wide full-text search then timed
out. curl has no budget, which is why it "worked".

The probe now asks for /users/0/collections?limit=1: the same endpoint
class, so a switched-off local API still answers 403 and a proxy that
rewrites the Host header still answers 400, over a list that is a few
hundred entries at most. Zotero 10 desktop writes read their server id and
library version off the same request, since both headers come on every
local API response.

The probe's outcome is now kept on the live capability object and reported:
the startup Capabilities line says why localApi is false, and zotero_whoami
carries localApiProbe (unreachable, timeout with its budget, or the HTTP
status Zotero answered) and chooses its remedy by it. The reporter's two
theories (a browser User-Agent, an IPv6 localhost) were both already
impossible, and a bare `localApi: false` gave nothing to rule them out with.
@oscardvs
oscardvs merged commit d88a9eb into main Sep 30, 2026
2 checks passed
@oscardvs
oscardvs deleted the fix/102-cheap-local-probe branch September 30, 2026 06:49
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.

Local API never detected (localApi: false) on Zotero 9.0.6 / Windows 11, although /api/ answers 200 via curl

1 participant