{"draft":null,"from":25,"to":26,"files":[{"path":"client/src/api.ts","added":50,"removed":6,"diff":"--- a/client/src/api.ts\n+++ b/client/src/api.ts\n@@ -85,6 +85,17 @@\n \treturn sent === undefined ? baseMs : baseMs + Math.floor(Buffer.byteLength(sent) / 100_000) * 1000;\n }\n \n+/**\n+ * How long a publish or a land may take before the client stops waiting: the\n+ * server gives one request up to 2 minutes of work, so a small body can still\n+ * take that long (a large merge). Waiting less reported publishes as failed\n+ * that went on to land.\n+ */\n+export const PUBLISH_TIMEOUT_MS = 150_000;\n+\n+/** The most versions the server's log sends at once. */\n+export const LOG_PAGE = 200;\n+\n /** A query string from the values that are set (null and undefined are left out). */\n function query(values: Record<string, string | number | null | undefined>): URLSearchParams {\n \tconst q = new URLSearchParams();\n@@ -168,10 +179,16 @@\n \t\t};\n \t}\n \n-\tasync json<T>(method: \"GET\" | \"POST\", path: string, body?: unknown, server = this.config.server): Promise<T> {\n+\tasync json<T>(\n+\t\tmethod: \"GET\" | \"POST\",\n+\t\tpath: string,\n+\t\tbody?: unknown,\n+\t\tserver = this.config.server,\n+\t\tatLeastMs = 0,\n+\t): Promise<T> {\n \t\tlet res: Response | undefined;\n \t\tconst sent = body === undefined ? undefined : JSON.stringify(body);\n-\t\tconst timeoutMs = timeoutFor(this.timeoutMs, sent);\n+\t\tconst timeoutMs = Math.max(atLeastMs, timeoutFor(this.timeoutMs, sent));\n \t\t// A connection that never opened is tried once more, IPv4 first (#37, GAME - UI/UX: one IPv6\n \t\t// address timed out, and the same command went through seconds later). Nothing went out, so\n \t\t// a POST is as safe to send again as a GET.\n@@ -375,7 +392,13 @@\n \t}\n \n \tpublish(message: string, asIs = false): Promise<PublishAnswer> {\n-\t\treturn this.json(\"POST\", this.agentPath(\"publish\"), { message, ...(asIs ? { asIs: true } : {}) });\n+\t\treturn this.json(\n+\t\t\t\"POST\",\n+\t\t\tthis.agentPath(\"publish\"),\n+\t\t\t{ message, ...(asIs ? { asIs: true } : {}) },\n+\t\t\tundefined,\n+\t\t\tPUBLISH_TIMEOUT_MS,\n+\t\t);\n \t}\n \n \t/** One change (#44). */\n@@ -709,7 +732,7 @@\n \n \t/** Land never queues: with the merge queue on, the server refuses it (#39). */\n \tland(message: string): Promise<Exclude<PublishAnswer, { queued: number }>> {\n-\t\treturn this.json(\"POST\", this.agentPath(\"land\"), { message });\n+\t\treturn this.json(\"POST\", this.agentPath(\"land\"), { message }, undefined, PUBLISH_TIMEOUT_MS);\n \t}\n \n \tdraftSync(): Promise<DraftSyncAnswer> {\n@@ -731,10 +754,31 @@\n \t}\n \n \t/** The versions of a space, newest first; with `path`, only those that changed it. */\n-\tlog(where: Where, limit?: number, path?: string): Promise<LogAnswer> {\n-\t\treturn this.json(\"GET\", `/log?${query({ ...where, limit, path })}`);\n+\t/**\n+\t * The versions newest first, below `before` when it's given. The server\n+\t * sends at most LOG_PAGE at a time, so a longer log is read page by page,\n+\t * following each page's next. `next` on the answer says older ones are left.\n+\t */\n+\tasync log(where: Where, limit?: number, path?: string, before?: number): Promise<LogAnswer> {\n+\t\tlet page = await this.#logPage(where, limit === undefined ? undefined : Math.min(limit, LOG_PAGE), path, before);\n+\t\tconst versions = [...page.versions];\n+\t\twhile (limit !== undefined && versions.length < limit && page.next !== undefined) {\n+\t\t\tpage = await this.#logPage(where, Math.min(limit - versions.length, LOG_PAGE), path, page.next);\n+\t\t\tversions.push(...page.versions);\n+\t\t}\n+\t\tconst { next, ...rest } = page;\n+\t\treturn { ...rest, versions, ...(next !== undefined ? { next } : {}) };\n \t}\n \n+\t#logPage(\n+\t\twhere: Where,\n+\t\tlimit: number | undefined,\n+\t\tpath: string | undefined,\n+\t\tbefore: number | undefined,\n+\t): Promise<LogAnswer> {\n+\t\treturn this.json(\"GET\", `/log?${query({ ...where, limit, path, before })}`);\n+\t}\n+\n \tshow(version: number, where: Where): Promise<ShowAnswer> {\n \t\treturn this.json(\"GET\", `/show?${query({ version, ...where })}`);\n \t}"}],"unmatched":[]}