Files
magpie/internal/provider/migrate_workbuddy.go
T
yetone afa5a50dce workbuddy: moved users get plugin 0.1.24, where a refused sign-in on a chat over 2 MiB says the 401 and to sign in again instead of 502 ECONNRESET (wyp on Discord)
wyp's WorkBuddy AI chats worked for a while, then every turn failed with
"502 WorkBuddy AI: ECONNRESET: The socket connection was closed
unexpectedly". Measured against the real endpoint from a sandbox HOME:
WorkBuddy's front door (www.workbuddy.ai and copilot.tencent.com) answers
a token it refuses with 401 only for a body up to 2097152 bytes. From
2097153 bytes on, it resets the connection without replying. So once a long
session is past 2 MiB and the sign-in is refused, every turn is a reset,
and Claude Code's "server-side issue, usually temporary" is wrong here.
Keep-alive reuse was ruled out: the server closes an idle connection with a
FIN at 60s, and Bun opens a new connection at 59.99s and 59.995s.

The fix is in the plugin (magpie-community/plugins 9a4ec86, npm 0.1.24).
When a chat over 2 MiB fails with no reply, it asks the meter once. On a
401 it returns that 401 with the remedy, kept as the plugin's other 401s
are. The chat is never sent again. This commit raises the mover's min so
keepMovedCurrent brings moved users to 0.1.24. The note also records
0.1.23 (plugins #138), which the min had skipped.

Run: gofmt -l on the file: clean. Plugin: bun test packages/workbuddy, 97
pass. Broken by hand (the new path rethrows at once), 3 of the 5 new
socket-fake tests go red. npm view --prefer-online shows 0.1.24.
Not run: go vet (darwin/linux/windows, -tags nogui) and go test, because
the disk had 0-1 GB free (df -g /), below the 3 GB floor. The change is
the one min string and its comment. Not run either: magpie's gateway end
to end with 0.1.24.

Full suite: SUITE_LINE
2026-10-15 23:08:03 +08:00

84 lines
5.1 KiB
Go

package provider
import (
"encoding/json"
"errors"
"time"
)
// WorkBuddy's and WorkBuddy AI's accounts on
// @magpie-community/opencode-workbuddy-auth (one package, a provider for
// each build). The desktop app's own sign-in goes as a marker ({source:
// "desktop"}, the package from 0.1.1 on): the plugin reads the app's file
// on each request, as the built-in does, so no refresh token is held by
// both. An account magpie signed in goes whole.
func init() {
for _, w := range []*wbSite{wbCN, wbAI} {
movers[w.id] = &mover{
pkg: "@magpie-community/opencode-workbuddy-auth",
min: "0.1.24", // a refused sign-in on a chat over 2 MiB says the 401 and to sign in again: WorkBuddy's front door resets such a request instead of answering, so it read as 502 ECONNRESET (wyp on Discord); 0.1.23: credits used up leave the free models counted out of the credits window, so an account is not ranked spent for them (plugins #138); 0.1.22: an MCP server's tool schemas reach Kimi and DeepSeek: an enum with no type, or of several types, is typed, and true or false where a schema goes is {} or {"not": {}}, so they aren't 400 11133 "Invalid request parameters" (plugins #122); 0.1.21: a model free only at night (Hy4 preview) is never said free, and a whole-day discount shows the price before it, from WorkBuddy's modelPromotions (plugins #121); 0.1.20: tool results followed by the user's message reach WorkBuddy AI's gemini-3.8-flash, not 400 "the conversation must end with a user message" (plugins #113); 0.1.19: an enterprise account's card shows its credits, from the enterprise meter WorkBuddy's usage page reads (#1904); 0.1.18: WorkBuddy 5.6+ keeps its desktop sign-in encrypted, and the plugin says so and points to the browser sign-in instead of a 502 (plugins #18); 0.1.17: a restricted account's 403 11140 ends in provider.WBRestrictedHint, so it rests 2h as restricted (#1849); 0.1.16: WorkBuddy AI's GLM models are text-only, so magpie's image-describing model reads their images (Yirasumi on Discord); 0.1.15: a system prompt sent as a developer message passes the channel check, an object tool_choice is sent as WorkBuddy takes it, and max_completion_tokens goes as max_tokens so the cap holds (plugins #96); 0.1.14: the Credits window says when the soonest credits left run out, for Smart routing to spend them first (cdredfox on X); an enterprise account names its enterprise, so it lists and uses the enterprise's models, not the personal plan's (plugins #75); a chat's tools get shapes WorkBuddy AI's models take, so ZCode's and DeepSeek Harness's chats on deepseek-v4.1-flash aren't 400 "Invalid request parameters" (wyh on Discord); one user send is one request in the usage list: every step carries one X-Conversation-Request-ID, and both builds name the client (使用端) (plugins #48); credits used up (code 14018) say so, with the nested error message (plugins #25); Codex's and Claude Code's chats pass WorkBuddy's channel check (#182); a failure's status and its sign-in mark as the built-in's; each model's credit rate; the sign-in renewed ahead of time through auth.refresh; the credits' count beside their share (#659)
agents: []string{w.id},
out: func() ([]Moving, error) {
var out []Moving
for _, a := range wbLogins(w) {
m := Moving{User: a.User, First: a.Active, On: a.On, Lapsed: a.Lapsed != "", Own: a.own, Plan: a.Plan}
if a.own {
m.Auth = map[string]any{"type": "oauth", "source": "desktop", "access": "", "refresh": "", "expires": 0,
"accountId": a.User, "uid": a.creds.UID}
} else {
c := a.creds
m.Auth = map[string]any{"type": "oauth", "access": c.Access, "refresh": c.Refresh, "expires": c.ExpiresAt,
"accountId": a.User, "uid": c.UID, "domain": c.Domain}
if c.RefreshExpiresAt > 0 {
m.Auth["refreshExpiresAt"] = c.RefreshExpiresAt
}
if c.TokenType != "" {
m.Auth["tokenType"] = c.TokenType
}
}
out = append(out, m)
}
return out, nil
},
back: func(ls []savedLogin, user string, auth map[string]any) ([]savedLogin, string, error) {
if str(auth["source"]) != "" {
// the desktop app's: nothing of it was the plugin's
return ls, firstNonEmpty(user, str(auth["accountId"])), nil
}
c := wbCreds{UID: str(auth["uid"]), Access: str(auth["access"]), Refresh: str(auth["refresh"]),
ExpiresAt: msOf(auth["expires"]), RefreshExpiresAt: msOf(auth["refreshExpiresAt"]),
Domain: str(auth["domain"]), TokenType: str(auth["tokenType"])}
if c.UID == "" || c.Access == "" {
return ls, "", errors.New(w.name + ": an unreadable plugin sign-in")
}
if user == "" {
user = str(auth["accountId"])
}
i := backInto(&ls, w.id, user)
b, err := json.Marshal(c)
if err != nil {
return ls, "", err
}
ls[i].Auth, ls[i].Lapsed, ls[i].Seen = b, "", time.Now().UTC().Truncate(time.Second)
wbTokens.Lock()
delete(wbTokens.m, w.id+"|"+c.UID)
wbTokens.Unlock()
return ls, ls[i].User, nil
},
}
}
}
// msOf is a time in unix ms as JSON gave it.
func msOf(v any) int64 {
switch n := v.(type) {
case float64:
return int64(n)
case int64:
return n
case int:
return int64(n)
}
return 0
}