perf(models): start from the cached catalog and refresh in the background
Every host start awaited a full catalog request before the provider registered, costing one HTTPS round-trip (up to the discovery timeout on a hanging connection) even when a cache written seconds earlier was on disk. Register the cached catalog immediately and run the live refresh in the background; the live result re-registers the provider when it arrives. A first start without a cache still awaits the live catalog. The background refresh is aborted on session_shutdown so print mode does not wait for it. Closes #63 (cherry picked from commit 142191f9420fe90460cdc3cbae70e26d0c000860)
This commit is contained in:
@@ -753,6 +753,37 @@ try {
|
||||
modelsDelayMs = 0
|
||||
delete env.COMMANDCODE_MODELS_TIMEOUT_MS
|
||||
|
||||
console.log("[pi-local] cached catalog starts without waiting for slow discovery")
|
||||
const warmup = await runPi(
|
||||
["--no-extensions", "-e", EXT_PATH, "--list-models", "commandcode"],
|
||||
20_000,
|
||||
)
|
||||
assert.equal(warmup.code, 0, warmup.stderr)
|
||||
assert.doesNotThrow(() => accessSync(modelsCachePath, constants.R_OK))
|
||||
modelsDelayMs = 5_000
|
||||
requestCount = 0
|
||||
const cachedStartedAt = Date.now()
|
||||
const cachedPrint = await runPi(
|
||||
[
|
||||
"--no-extensions",
|
||||
"-e",
|
||||
EXT_PATH,
|
||||
"-p",
|
||||
"say mock token",
|
||||
"--provider",
|
||||
"commandcode",
|
||||
"--model",
|
||||
TEST_MODEL,
|
||||
],
|
||||
30_000,
|
||||
)
|
||||
const cachedElapsedMs = Date.now() - cachedStartedAt
|
||||
assert.equal(cachedPrint.code, 0, cachedPrint.stderr)
|
||||
assert.match(cachedPrint.stdout, /mock-pi-ok/)
|
||||
assert.equal(requestCount, 1)
|
||||
assert.ok(cachedElapsedMs < 5_000, `cached start took ${cachedElapsedMs}ms`)
|
||||
modelsDelayMs = 0
|
||||
|
||||
console.log("[pi-local] print mode with reasoning and tool schemas")
|
||||
requestCount = 0
|
||||
const print = await runPi(
|
||||
|
||||
Reference in New Issue
Block a user