Commit Graph
3 Commits
Author SHA1 Message Date
yetone 1e7122e161 workbuddy 0.1.47: a conversation's ids are one account's own
leaves5760 on Discord: every account of a group of WorkBuddy accounts gets
403 "request illegal", WorkBuddy saying the account is restricted for
abnormal behaviour.

X-Conversation-ID and X-Conversation-Request-ID were derived from the
session (or first user message) and the turn alone, with a salt per
process. One magpie session spread over several accounts therefore sent the
same conversation and turn ids under every account's X-User-Id. WorkBuddy's
own client (5.9.3, @genie/agent-cli 2.165.0) is signed in as one account,
so a conversation never shows up under two. The ids now also hash the
account (uid, enterpriseId, and for a key account the key), and a chat sent
again after a 401 as another account (a sign-in saved since) gets that
account's ids. The same account keeps stable ids as before.

This is a divergence from the official client found by reading its
bundle, not a verified cause of the restriction. Not changed, reported
only: no X-Private-Data, traceparent/baggage, reasoning_summary "auto",
or the client's /v2/report telemetry.

Run on mote at this tree: HOME=$(mktemp -d) bun test in packages/workbuddy,
209 pass 0 fail; bun scripts/check.mjs exit 0.
Broken by hand: with the account left out of the ids, both new tests
(conversation.test.mjs, unauthorized.test.mjs) fail; with reattend a no-op,
the 401 test fails.
Not tried: a real WorkBuddy account (none used, by the task's rule).
2026-10-29 15:37:53 +08:00
yetone f4d48ac3ee workbuddy 0.1.43: a chat names the model's default effort as WorkBuddy's client does, and goes gzipped
troilus1011 on X: WorkBuddy's DeepSeek in OpenCode through magpie thought
at low and high, never at the default. OpenCode's default variant names
no reasoning_effort, and WorkBuddy doesn't think without one: measured on
www.workbuddy.ai with 0.1.42, deepseek-v4.1-flash gave 0 reasoning
tokens with no effort (2 of 2), 0 at none, 16/37 at low, 34/56 at high.
WorkBuddy's own client (CLI 2.165.0 in WorkBuddy 5.9.3,
configureThinkingSettings) sends the session's effort, else the
reasoningEffort setting, else the model's reasoning.defaultEffort from
/v3/config, which is "high" for this model on both builds. A chat that
names no effort now gets the model's own defaultEffort when its listed
levels hold it, read from the same cached /v3/config list (one read per
minute; a failed read leaves the chat as it came and is not retried on
every chat). An effort the client names, none included, is untouched and
the list isn't read for it. Models with no reasoning config get nothing.

runmiNeverstop on X: 2.89 GB up to copilot.tencent.com through magpie.
WorkBuddy's client gzips a model request's body (GzipRequestProcessor,
on with productFeatures.RequestBodyGzip, true in both builds'
product.json and not turned off by the remote config); the plugin sent
it as plain JSON. Agent chat JSON (the whole history each turn, tool
schemas) compresses several-fold, so the upload was several times what
the official client sends for the same turns. A chat-completions body
now goes gzipped with Content-Encoding: gzip on both builds;
unanswered() weighs the gzipped size against the front door's 2 MiB.
Claude's Messages route goes as it came (not tried gzipped live).

Run (on mote, HOME=$(mktemp -d) bun test in packages/workbuddy): 197
pass, 0 fail. bun scripts/check.mjs: exit 0. Fakes that parse the sent
body gunzip it (testdata/unz.mjs); reset.test.mjs's 2 MiB bodies are
random base64 so they stay over 2 MiB on the wire.
Live (www.workbuddy.ai, a real account in a sandbox HOME): with 0.1.43
the default sent reasoning_effort high gzipped and thought (34 and 51
reasoning tokens), none stayed 0, low and high as before, all 200. A
gzipped chat answered 200 the same as a plain one.
Broken by hand: origin/main's index.mjs with the new
default-effort.test.mjs: 5 of 8 red (default effort, failed-read reuse,
both gzip tests, defaultEffortOf); the 3 that pass guard what must not
change (named efforts, models without a default, Messages).
Not tried: a live chat on the China build (copilot.tencent.com answered
401 to every token available here, its /v3/config read fine); Messages
gzipped; the reporters' own OpenCode sessions end to end.
2026-10-28 22:23:20 +08:00
yetone f658842089 workbuddy 0.1.31: a 401 is renewed once and sent again; a refused sign-in says to sign in again
wenchen855443 on X: with WorkBuddy as the provider, requests return 401.
Until now a chat 401 was passed on as WorkBuddy's HTML APISIX page with
X-Magpie-Sign-In: kept. A token is renewed only near its end, and a
browser sign-in's token lasts about 340 days. So a token WorkBuddy
refused before then was sent again on every request, for months.
Nothing renewed it and nothing told the user what to do.

What changed (packages/workbuddy/index.mjs):
- A chat or usage summary answered 401 is renewed once, whatever the
  token's time, then sent once more. The request body is sent as it
  was, and only a body that can be resent is retried. The first 401's
  body is cancelled. A second 401 is never renewed.
- Before spending the refresh token, a newer token another process saved
  (getAuth) is taken first. This is also checked after a refused refresh,
  for the case where another process spent the refresh token at the same
  moment (part of plugins#332).
- A desktop sign-in never spends the app's refresh token here. The plugin
  drops the token it held, reads the app's file again, and retries only
  if the token there changed.
- When there is no new token, or the retry is refused too, the plugin
  answers 401 with authentication_error. The message names why ("it
  refused the refresh token too (…)", "there is no refresh token to renew
  it with", "it refused the token renewed for it too") and says where to
  sign in again: Providers → WorkBuddy [AI] → this account's Sign in again,
  or WorkBuddy desktop for a desktop sign-in. The >2 MiB ECONNRESET note
  stays in that message.
- readDesktop marks its result source: "desktop". Before this,
  unanswered's desktop wording could never show.

Marking the account expired:
- The plugin sends X-Magpie-Sign-In: expired (usage: signIn) only when
  WorkBuddy itself says the sign-in is gone:
  - the refresh token was refused (HTTP 401 / invalid_grant);
  - the access token was refused with WWW-Authenticate error=
    "invalid_token" and no refresh token was left, or one had ended;
  - a just-renewed token was refused with invalid_token.
- Why mark it at all: a marked account leaves routing, so the user's
  other accounts serve; the row says to sign in again; and a dead
  account stops spending a refresh on every request.
- Why not on every 401: WorkBuddy answers some paths with a bare 401
  even for a good sign-in (magpie's workbuddy_checkin_test). A refresh
  that fails for another reason (5xx, network) also leaves the account
  as it is.
- A desktop sign-in is never marked: the app's file is read on every
  request, so signing in to the app again fixes it.
- A success after a renewal sends "renewed", which clears a mark.
- auth.refresh (refreshed()) still never marks the account, because a
  refresh token spent by another process there could read as refused.

What WorkBuddy does (www.workbuddy.ai, 2026-10-23, the owner's real
workbuddy-ai sign-in copied into a sandbox HOME):
- Chat with a wrong or garbage token: 401, HTML APISIX page,
  WWW-Authenticate: Bearer realm="copilot", error="invalid_token".
- Chat with an empty token: 401, no WWW-Authenticate.
- The meter: the same 401. /v3/config: 200 to a bad token.
- Refresh with a wrong refresh token: HTTP 401 {"code":12153,"msg":"12153:
  refresh token failed:400 Bad Request: invalid_grant: Invalid refresh
  token"}. With garbage: 401, code 12153 "token format error".
- A real refresh: 200; both tokens rotate, and both expiries are about
  340 days out.
- The old access token still answered 200 after the refresh.
- The rotated tokens were written back to the live plugin-auth.json under
  its lock (temp + rename, only workbuddy-ai's entry changed). The live
  gateway answered workbuddy-ai/deepseek-v4.1-flash with 200 afterwards.

Run at this tree (652f06d + this change):
- HOME=$(mktemp -d) bun test: 2329 pass, 0 fail, 197 files.
- bun scripts/check.mjs: ok.
- New unauthorized.test.mjs (12 tests): renew then 200 (renewed, saved,
  new Bearer); refresh refused → sign in again, expired; transient refresh
  failure → kept; no second renew or retry; no refresh token
  (expired with invalid_token, kept on a bare 401); a token another
  process saved is taken; desktop re-read and never marked; usage renew;
  usage refused → expired.
- Existing tests that pinned the old pass-through were updated:
  signin.test.mjs, usage.test.mjs, reset.test.mjs.

Broken by hand:
- With origin/main's index.mjs, all 12 new tests are red.
- Without the renewed guard: the "isn't renewed twice" test goes red.
- With gone() always false: the 3 marking tests go red.
- Without the newer() check: the 2 "another process saved" tests go red.

Not tried:
- Reusing an old refresh token after rotation, which risks revoking the
  owner's session. Whether WorkBuddy refuses it, or revokes the session,
  is unknown.
- The China build (www.codebuddy.cn) was not probed for a real 401.
- A desktop sign-in with real accounts.
- The reporter's case is unknown: their site, their sign-in kind, and the
  401's body. So is what revokes a WorkBuddy access token before its end;
  a refresh by another process does not.
2026-10-23 22:13:05 +08:00