dsh: magpie's routes wait for a slow reply as long as the gateway does (tim on Discord)
tim's first "who are you" to gemini-3.8 through the third-party plugin
magpie-gemini-web 0.8.0 took minutes in dsh and ended in 499 ("the agent
canceled the request"). dsh hung up: llm-pi-ai gives a turn up after 5
minutes with no pi-ai event (DEFAULT_STREAM_IDLE_TIMEOUT_MS, every
dsh-llm-pi-ai from 0.1.5 to 0.2.2), and the gateway's ": keepalive"
comments (keepQueued, keepQuiet) are not events. The plugin serves one
request at a time (maxConcurrency 1), dsh's own session title goes to the
same route model in parallel, and the plugin's backend sends no byte
before its first token, so the turn's 5 minutes ran out in magpie's queue
and the backend while the gateway (10 minutes for headers) and the plugin
(240s per wait, then its own 504) were still waiting.
Every one of magpie's dsh routes (patch lists and deepseek-acp's
settings.yaml, all through dshPutProviders) now has streamIdleTimeoutMs:
600000 (dshIdleWait), the gateway's upstreamHeaderWait. A value already on
the route, set in dsh's Models page or by hand, stays. Codex's
comment-blind limit is still met in the gateway (agentQuietMost); dsh's is
a route setting. The plugin's own slowness is its maintainer's and is not
changed here.
Verified:
- New tests TestDshRoutesWaitAsLongAsTheGateway and
TestDshRouteKeepsTheUsersIdleWait (internal/agent/dsh_idle_test.go),
green on mote. Broken by hand: without the field the first fails
("route magpie waits 0ms for the next event, want 600000"); without the
keep the second fails ("sync 1: the user's 120000 became 600000").
- Real dsh 0.2.1-rc.2 (headless, sandbox HOME/DSH_HOME, the route as
magpie writes it, a fake Chat server on 127.0.0.1:3561 that answers
after 8s): streamIdleTimeoutMs 3000 -> "TIMEOUT: pi-ai stream idle
timeout after 3000ms"; 600000 -> "hello there", exit 0. With headers
sent at once and ": keepalive" every second it still timed out at 3000,
so comments don't feed the watchdog. dsh-llm-pi-ai 0.1.5-rc.3,
0.1.7-rc.2, 0.2.0-rc.2 and 0.2.1-rc.5 (npm pack, read) all take the
field per provider, max MAX_TIMER_DELAY_MS.
- gofmt -l clean. On mote: go vet ./..., GOOS=linux go vet -tags nogui
./..., GOOS=windows go vet ./..., go build, GOOS=linux go build -tags
nogui, GOOS=windows go build: all ok.
- Full suite, go test -tags nogui -count=1 -timeout 45m ./..., on the
Linux box (wsl-run, magpie-desktop; mote had two full suites running)
at d714c4216 + this change: 83 packages ok; internal/agent red on
TestInstalledVersion, TestGrokInstalled,
TestCursorFolderFromTheEditorIsNotTheCLI, TestOmpDetectedWithPiDir
(#4033, #3548) and internal/gui on TestSettingsSaveKeepsWhatItDoesNotSend
(#4514) and TestColdTurnsTaken (#4510). The first five fail the same
on origin/main 15066f84f run alone there; TestColdTurnsTaken passed
alone on main and failed alone with this change (5 counts, gui only,
which this change doesn't touch), as #4510 describes.
- After rebasing on 2597c9636, internal/agent again on the Linux box: the
new tests pass; reds TestInstalledVersion, TestGrokInstalled,
TestCopilotFolderFromAnIDEPluginIsNotTheCLI,
TestQoderSettingsFromAnIDEPluginIsNotTheCLI/qoder-cn,
TestOmpDetectedWithPiDir, all the #4033 class (Qoder noted there).
Not tried: tim's own setup (the plugin is not run against a Google
account); a real 5-to-10-minute wait in dsh; Windows.
This commit is contained in:
@@ -74,6 +74,7 @@ something else shows up as drift.
|
||||
- dsh (DeepSeek Harness) sets one API per llm-pi-ai route, so magpie writes a route per protocol (`dshKinds` in [`dsh.go`](../../internal/agent/dsh.go); 01huadalang on Discord): `magpie` (Chat Completions) for most models, `magpie-responses` (`openai-responses`) for a model served on Responses, `magpie-anthropic` (`anthropic-messages`, the gateway root, `forceAdaptiveThinking` where `AdaptiveThinking` or `AdaptiveWithEffort`, so Max reaches GLM-5.3 as max) for one served on Messages, by the model's `APIs` (`dshRouteOf`). A model's `APIs` is the one its provider serves it on best (`Provider.Native`, in `magpieModels`, [`route.go`](../../internal/agent/route.go)), and Pi, omp and droid read it the same way. For a custom provider with more than one URL that is the API its Base URL was given as (`BaseAPI`), after the vendor rules (an OpenAI model on OpenAI's API, a Claude where Messages is served): a relay set to Responses whose Chat URL Detect found beside it had its GPTs on dsh's Chat route (nb5p on Discord, `TestDshCustomResponsesProvider`). dsh's bundled pi-ai (`@earendil-works/pi-ai`, dsh 0.2.1-rc.2) takes `openai-responses` as a route's `api`. A routing group has `responses` when every member is best on Responses (`allResponses`, #1594), so its tool-call arguments are relayed as they stream; any other group has none and stays on Chat, a Messages-only group too, as a Claude member's thinking is known by its own model. A route with no models is taken out. An api the user picked for a route in dsh's Models page is kept, and so are keys they added there. The start (`agent-default-model`) names its model's route, and Sync moves a start on one of magpie's routes to the route its model is now on (`dshStartOnItsRoute`), its effort and marks kept. A start on a model by an id magpie lists it by no longer, a found group's `group/auto-<slug>` (now `auto/<model>`, `provider.PublicRef`) or a renamed provider's (`provider.RenamedRef`), moves onto the id its route lists, in every profile and the home layer: dsh finds the start by that id, and the desktop app showed no model picked while its patch list held every route (zyh6036 on X, `TestDshStartOnAFoundGroupsOldIdMovesOntoItsId`). `renameFoundGroups` moves only a value applied.json records, and the start dsh read was not one (none on the owner's install either), nor is a pick made in dsh. Check asks the route the start names to list its model. A dsh session resumed on a model that has since moved routes asks for the model to be picked again, since dsh finds a model by route and id.
|
||||
- The names every agent's model list gets are `provider.Labels`' ([`modelprefs.go`](../../internal/provider/modelprefs.go)). With Provider in model names off (or own, for names the user gave), a name stands alone unless another model in the same list reads the same, when both keep their provider's after it. A routing group named as anything else in the list keeps "· routing group", and the model it shares the name with stays plain: the group found for a model served by two providers, one of them hidden from the agent, had the shown model read "GPT-6.1 Terra · MyGateway" beside its provider's plain "GPT-6.1 Sol" (nb5p on Discord; `TestPlainNames`, `TestSuffixMode`, `TestPlainOwnNamesGroups`).
|
||||
- dsh takes a model's listed `maxTokens` as every request's output and reserves it, with 65536 of headroom, out of `contextWindow` before deciding when to compact (compaction-basic's `resolveCompactSpec`: the smaller of 80% of the window and window − maxTokens − 65536). A vendor's reply limit near its window had dsh compact at 41248 of a 500000 group (#2823) or fail with no budget (524288/524288, LoKi on Discord; 131072/65536), so magpie lists it held to what leaves dsh half the window to compact in (window/2 − 65536), or to a quarter of the window where that is more (every window under 262144, as VS Code and Copilot in JetBrains hold it), on every route and in the older `llm-deepseek` entry (`dshMaxTokens`). A quarter alone cut DeepSeek's 393216 on its 1000000 window to 250000 (#3298); now it keeps all of it and dsh compacts at 541248, while 500000/393216 is held to 184464 and compacts at 250000. A Max output the user set stays as they set it (`outputOr`), even one that leaves dsh no budget. `TestDshOutputLeavesCompactionRoom`.
|
||||
- Each of magpie's routes has `streamIdleTimeoutMs: 600000` (`dshIdleWait`), the gateway's own wait for a reply's headers (`upstreamHeaderWait`, 10 minutes). llm-pi-ai gives a turn up after 5 minutes without a pi-ai event (`DEFAULT_STREAM_IDLE_TIMEOUT_MS`, 0.1.5 to 0.2.2), and the gateway's `: keepalive` comments (`keepQueued`, `keepQuiet`) are not events: real dsh 0.2.1-rc.2 timed out at a route's 3000ms with comments every second. A turn queued behind dsh's own title request on a plugin serving one request at a time (magpie-gemini-web, `maxConcurrency: 1`) was cut while the gateway and the plugin still waited, and recorded as 499 (tim on Discord). A value already on the route, set in dsh or by hand, stays (`TestDshRoutesWaitAsLongAsTheGateway`, `TestDshRouteKeepsTheUsersIdleWait`). Codex's comment-blind limit is met in the gateway instead (`agentQuietMost`).
|
||||
- While magpie serves, `KeepDshWired` writes the routes again every 30 seconds, since dsh writes over its patch list. A round that writes nothing is kept (`dshRounds`), and the next round does nothing when nothing it reads has changed since. It checks the bytes of dsh's files (every profile's `cordis.patch.yml`, the home layer, `settings.yaml`, `.env`, `.credentials.yaml`, `config.yaml`) and the gateway's address. It also checks `provider.StampNow`: no Changed, plugin change or `filememo.Forget`, the same environment, and the providers', settings' and catalog's files unchanged. The models are built again when that stamp moves, and at least every `dshModelsFor` (5 minutes) for what no stamp sees, such as another app's account file or a date-retired model. Building the whole catalog and every route each round allocated 12 GB of a user's 35.7 GB in 48 minutes (`TestDshRoundWithNothingChangedBuildsNothing`, `TestDshRoundAfterAChangeWritesAgain`).
|
||||
- DeepSeek Harness Desktop (macOS arm64 and Windows x64; no Linux build) reads the same `$DSH_HOME` or `~/.dsh` as the CLI, as its own profile `profiles/desktop` (`resolveDshHome` and `resolveDesktopPaths` in the app's `lib/main.js`; `defaultDshHome` in github.com/deepseek-ai/deepseek-harness's `packages/util/home-paths/src/index.ts` and `apps/desktop/src/paths.ts`), so it takes magpie's routes with no wiring of its own (#2279, liangjinyuan-sihan). Only that app, from deepseek-ai/deepseek-harness (bundle id `com.deepseek.dsh`, productName DeepSeek Harness in `apps/desktop/scripts/electron-builder-config.mjs`), is dsh's: the community "DeepSeek Hermes" (motongv/deepseek-hermes-desktop) v0.1.1337 took for it is not listed or written for (WuSix on Discord, `TestDshOnlyTheOfficialApp`). It is found by `/Applications/DeepSeek Harness.app`, by `%LOCALAPPDATA%\Programs\DeepSeek Harness`, or by the folder its current-user installer records under `HKCU\Software\1bf39983-50d0-5fe0-9ef4-cece76f67c5e` (`InstallLocation`), whose Uninstall key gives the version (`registered` in [`desktopapp.go`](../../internal/agent/desktopapp.go)), so a user who picked another folder is found. With the app installed but never opened there is no `~/.dsh`: the row is still listed, and connecting writes `profiles/desktop/cordis.patch.yml` from dsh's own template (`dshProfileTemplate`) with magpie's routes, which the app keeps on its first start, since it writes only the files that are missing. The notice says the app starts on it the first time it opens (`noticeDsh5`). Disconnect before that first start removes the profile magpie made when nothing else is in it (`dshTidyUnopened`); once the app has opened it, the profile stays and only magpie's entries go (`TestDshDesktopNeverOpened`, `TestDshDesktopRegisteredFolder`; the registry as 0.2.1-rc.2's installer writes it, `TestDshWindowsAsTheInstallerRegistersIt`).
|
||||
- Ante's `catalog.json` keeps user-added fields in `providers.magpie` the same way (`ante` in [`ante.go`](../../internal/agent/ante.go)); its `auth`, `http_headers`, `extra_body` and `stream_idle_timeout_secs` are what a gateway shared on the local network or reached from WSL needs to send a key. Ante starts a session on the `provider` and `model` of `settings.json`, not on what its catalog holds (#1210), so magpie sets that pair and puts back what it found there; a pick the user makes in Ante while magpie is wired is theirs and stands.
|
||||
|
||||
+24
-1
@@ -1555,6 +1555,9 @@ func dshPutProviders(providers *yaml.Node, on bool, models []catalog.Model, gw s
|
||||
if cur := yamlKey(providers, k.key); cur != nil && cur.Kind == yaml.MappingNode {
|
||||
dshKeepCompat(cur, &route)
|
||||
for j := 0; j+1 < len(route.Content); j += 2 {
|
||||
if route.Content[j].Value == dshIdleKey && yamlKey(cur, dshIdleKey) != nil {
|
||||
continue // the user's own wait, or the one magpie wrote
|
||||
}
|
||||
yamlSetKey(cur, route.Content[j].Value, route.Content[j+1])
|
||||
}
|
||||
} else {
|
||||
@@ -1612,8 +1615,28 @@ type dshPiRoute struct {
|
||||
API string `yaml:"api"`
|
||||
BaseURL string `yaml:"baseURL"`
|
||||
Models []dshPiModel `yaml:"models"`
|
||||
// StreamIdleTimeoutMs is dshIdleWait.
|
||||
StreamIdleTimeoutMs int `yaml:"streamIdleTimeoutMs,omitempty"`
|
||||
}
|
||||
|
||||
// dshIdleWait is how long llm-pi-ai waits on magpie's route for the next
|
||||
// event of a reply before it gives the turn up, in ms: the gateway's own
|
||||
// wait for a reply's headers (upstreamHeaderWait, 10 minutes). llm-pi-ai's
|
||||
// own is 5 minutes (DEFAULT_STREAM_IDLE_TIMEOUT_MS, 0.1.5 to 0.2.2), and
|
||||
// it counts pi-ai's events only: the ": keepalive" comments the gateway
|
||||
// sends while a request waits in a provider's queue (keepQueued) or on a
|
||||
// slow first byte (keepQuiet) aren't events, and pi-ai has none before the
|
||||
// reply's headers. So a turn queued behind dsh's own title request on a
|
||||
// plugin that serves one at a time (magpie-gemini-web, maxConcurrency 1)
|
||||
// was cut at 5 minutes, recorded as 499, while magpie and the plugin were
|
||||
// still within their waits (tim on Discord). Codex's comment-blind limit
|
||||
// is met by agentQuietMost in the gateway; dsh's is a setting of the
|
||||
// route. A value already on the route (one set in dsh, or by hand) stays.
|
||||
const dshIdleWait = 600000
|
||||
|
||||
// dshIdleKey is the route's field dshIdleWait goes in.
|
||||
const dshIdleKey = "streamIdleTimeoutMs"
|
||||
|
||||
// dshPiModel is one model of the route. Without contextWindow and maxTokens
|
||||
// dsh takes every model for a 128K one writing 16K at most, and without
|
||||
// input for a text-only one; without reasoningEfforts it offers none.
|
||||
@@ -1840,7 +1863,7 @@ func dshRouteConfig(models []catalog.Model, api, gw string) dshPiRoute {
|
||||
// thinking adaptively, output_config.effort on Messages.
|
||||
func dshKindConfig(k dshKind, models []catalog.Model, api, gw string) dshPiRoute {
|
||||
api = dshAPI(api, k.api)
|
||||
r := dshPiRoute{DisplayName: k.name, APIKeyEnv: dshKeyRef, API: api, BaseURL: dshBaseURL(api, gw), Models: []dshPiModel{}}
|
||||
r := dshPiRoute{DisplayName: k.name, APIKeyEnv: dshKeyRef, API: api, BaseURL: dshBaseURL(api, gw), Models: []dshPiModel{}, StreamIdleTimeoutMs: dshIdleWait}
|
||||
for _, m := range models {
|
||||
e := dshPiModel{ID: m.ID, Name: m.Name, ContextWindow: m.Context}
|
||||
if m.Output > 0 {
|
||||
|
||||
@@ -0,0 +1,109 @@
|
||||
package agent
|
||||
|
||||
import (
|
||||
"os"
|
||||
"path/filepath"
|
||||
"testing"
|
||||
|
||||
"gopkg.in/yaml.v3"
|
||||
)
|
||||
|
||||
// dshRouteIdle is streamIdleTimeoutMs of each of magpie's routes in a
|
||||
// llm-pi-ai providers mapping at path (a patch list's entry, or
|
||||
// settings.yaml's section), 0 for a route without one.
|
||||
func dshRouteIdle(t *testing.T, path string, list bool) map[string]int {
|
||||
t.Helper()
|
||||
b, err := os.ReadFile(path)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
type route struct {
|
||||
Idle int `yaml:"streamIdleTimeoutMs"`
|
||||
}
|
||||
var providers map[string]route
|
||||
if list {
|
||||
var items []struct {
|
||||
ID string `yaml:"id"`
|
||||
Config struct {
|
||||
Providers map[string]route `yaml:"providers"`
|
||||
} `yaml:"config"`
|
||||
}
|
||||
if err := yaml.Unmarshal(b, &items); err != nil {
|
||||
t.Fatalf("%v:\n%s", err, b)
|
||||
}
|
||||
for _, it := range items {
|
||||
if it.ID == dshPiRow {
|
||||
providers = it.Config.Providers
|
||||
}
|
||||
}
|
||||
} else {
|
||||
var doc map[string]struct {
|
||||
Providers map[string]route `yaml:"providers"`
|
||||
}
|
||||
if err := yaml.Unmarshal(b, &doc); err != nil {
|
||||
t.Fatalf("%v:\n%s", err, b)
|
||||
}
|
||||
providers = doc[dshPiRow].Providers
|
||||
}
|
||||
out := map[string]int{}
|
||||
for k, r := range providers {
|
||||
if isDshRoute(k) {
|
||||
out[k] = r.Idle
|
||||
}
|
||||
}
|
||||
if len(out) == 0 {
|
||||
t.Fatalf("no route of magpie's in %s:\n%s", path, b)
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
// tim on Discord: a first "who are you" to Gemini through the
|
||||
// magpie-gemini-web plugin took minutes in dsh and ended in 499.
|
||||
// llm-pi-ai gives a turn up after 5 minutes with no pi-ai event, and the
|
||||
// gateway's keepalive comments aren't events: a turn queued behind dsh's
|
||||
// own title request on a plugin serving one request at a time was cut
|
||||
// while the gateway (10 minutes for headers) and the plugin still waited.
|
||||
// magpie's routes, in every profile and in deepseek-acp's settings.yaml,
|
||||
// now wait as long as the gateway does.
|
||||
func TestDshRoutesWaitAsLongAsTheGateway(t *testing.T) {
|
||||
home, dir, web := dshRouteHome(t)
|
||||
os.WriteFile(web, []byte("# Your patch layer for this dsh profile.\n"), 0o644)
|
||||
a := dsh(home)
|
||||
if err := a.Pick("model", "magpie/deepseek/pro"); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
for _, f := range []struct {
|
||||
path string
|
||||
list bool
|
||||
}{{web, true}, {filepath.Join(dir, "settings.yaml"), false}} {
|
||||
for k, ms := range dshRouteIdle(t, f.path, f.list) {
|
||||
if ms != dshIdleWait {
|
||||
t.Fatalf("%s: route %s waits %dms for the next event, want %d", f.path, k, ms, dshIdleWait)
|
||||
}
|
||||
}
|
||||
}
|
||||
if dshIdleWait != 10*60*1000 {
|
||||
t.Fatalf("dshIdleWait %d is not the gateway's 10 minutes for a reply's headers", dshIdleWait)
|
||||
}
|
||||
}
|
||||
|
||||
// A wait set on magpie's route in dsh (or by hand), shorter or longer, is
|
||||
// the user's: a sync keeps it.
|
||||
func TestDshRouteKeepsTheUsersIdleWait(t *testing.T) {
|
||||
home, dir, web := dshRouteHome(t)
|
||||
dshKeyFixture(dir)
|
||||
os.WriteFile(web, []byte("# Your patch layer for this dsh profile.\n"+
|
||||
"- id: llm-pi-ai\n name: \"@deepseek-ai/dsh-llm-pi-ai\"\n config:\n providers:\n"+
|
||||
" magpie:\n displayName: Magpie\n apiKeyEnv: "+dshKeyRef+"\n api: openai-completions\n baseURL: "+gatewayV1()+"\n streamIdleTimeoutMs: 120000\n models:\n - id: deepseek/pro\n"+
|
||||
"- id: agent-default-model\n config:\n provider: magpie\n model: deepseek/pro\n"), 0o644)
|
||||
a := dsh(home)
|
||||
for i := 0; i < 2; i++ {
|
||||
if err := a.Sync(); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if got := dshRouteIdle(t, web, true)[dshRoute]; got != 120000 {
|
||||
b, _ := os.ReadFile(web)
|
||||
t.Fatalf("sync %d: the user's 120000 became %d:\n%s", i+1, got, b)
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user