d3fc6f2bfada18e6ae7887b79ed1e4c650ca37e1
4
Commits
| Author | SHA1 | Message | Date | |
|---|---|---|---|---|
|
|
55a190f195 |
gateway: conversations opened on one fixed message no longer share an id (#3938)
keeyangyy (#3938): with no session header, conversationID named a conversation by the raw bytes of its first user message alone. Some agents open every conversation on a message they write themselves and send what the user typed as the next user message: {"role":"user","content":"<environment_context>cwd=/w/proj ...</environment_context>"}, {"role":"user","content":"the question the user actually typed"} That message is the same in every conversation started in one folder, so all of them had one id: under Stays = session each new one was kept on the account that answered the first, and rotate never moved on. conversationOpening now says what is hashed, from the first user message on (Chat and Anthropic messages, Responses input, Gemini contents, where an omitted role is the user's): - A first user message that holds anything of the user's own is hashed alone, as the request has it, exactly as before: their words (userWords, which already tells an <environment_context> or <user_instructions> block or an instruction file from what the user typed), an image, a file or a recording (userOpens). So is one that holds a tool's result. - One the agent wrote alone is hashed with the user messages after it, in order, through the first that holds the user's own. A system or developer message between them is passed over. - A reply, a call, its output, reasoning, a tool's result (Gemini's function result too), an item without a role (Chat, Responses) or one that can't be read ends the opening. With nothing of the user's before it, the first message is hashed alone, as before. Every later turn repeats the opening before the first reply, so the id holds through the conversation. A Responses input that is one string is hashed as before. An opening of several messages is hashed as writeOpening reads them, one after another: every object's members in key order with no space between, no cache_control at any depth, and a content of one text part as that part's text. An agent marks its newest user message for the cache and moves the mark on next turn, so the typed message's bytes change at turn 2; some spell a marked message as a list of one part and an unmarked one as a plain string (dsh does). Hashed as sent, an opening of several would get a new id at its second turn, and on /v1/messages under rotate that turn would go to the other key as a new conversation (below). writeOpening reads the messages where they are: the id of a 1.1 MB body whose opening holds a screenshot allocates about 10 KB (TestOpeningHashReadsInPlace). Every conversation whose first user message is the user's own keeps the id it has, so no stick record needs moving. One that opened on an agent's message and is under way when this lands gets an id of its own on its next turn and is routed once as a new conversation: it may move to another account, and its cache there starts over. The record they all shared stays under the old id. A tool's result (Anthropic clients send it as a user message) ends the opening: it answers a call the model made, so the opening is over. A history that starts with one was cut by its client (magpie takes such orphans, TestMessagesOrphanToolResultWithoutACallBecomesText). Its opening is gone, and whatever was taken in after the cut would move the id each time the client cuts again, so its first message is hashed alone, as before. Not the issue's "first two user messages", nor every user message up to the first reply: in an ordinary conversation the second user message is the next turn, so the id would move when it arrives, and every record would need the migration the issue describes. And a run of every user message takes in what dsh sends after the typed prompt, its runtime context, where the Context page finds dsh's sessions by the typed prompt's hash alone; TestDshSessionConvsAreTheGatewayIDs and TestDshRoutesCarryTheSessionConvs go red under such a run (below). What reads the id moves with it: stickKey (session, turn and strict affinity, and rotate's spread of new conversations), the Routing trace's conv (convOf), a sealed task's lead (leadProvider, loggedAnswerers), extraBody's ${sessionId}, Kilo's task and session headers (KiloClient), X-Magpie-Conversation to plugins and OpenCode's x-opencode-session fallback (openCodeSeed). A group rule's key reads conversationID without a body, beside firstWords, which already passes over the agent's blocks, so it doesn't change. One reader rebuilds the id itself: sessions' dshConvs, which the Context page joins dsh's sessions by (joinConvs). It hashes dsh's typed prompt, a first user message of the user's own, which is still hashed alone, so its ids stay the same. Nothing else in sessions, gui or elsewhere rebuilds a "magpie-" id. The comments that named the first user message, and the Gateway routing and Providers and accounts pages, say what the id is now. Siblings left for a decision, each in an issue filed with this patch: #3988, ChatGPT accounts (conversationKey in internal/provider/codex_request.go, for a client that sends no prompt_cache_key), and #3989, Antigravity accounts (antigravitySession in internal/provider/google.go). Both hash the first user message in the provider package, and userWords is the gateway's. Not changed: a fixed first message that userWords doesn't read as the agent's is still hashed alone, so the conversations an agent opens on it still share one id. A first user message hashed alone is hashed as the request has it, cache mark and all, so a client without a session header that marks that message on its first turn only gets a new id at its second, as before. An agent that answers its own first message with a fixed reply before the user's turn ends the opening at that reply, so its first message is hashed alone too. What was run (tree 523c770b, on origin/main |
||
|
|
7fe191cec0 |
gateway: OpenCode Go's bare 400 (a model name, no error) is a 502 that rests nobody (#3740)
OpenCode's gateway answers some of s-leeq's turn-start requests with a
400 whose body is {"model":"deepseek-v4.1-flash"} and nothing else: no
error, message, code, type or param, nothing in or out, no reply id.
retryable() read it as the request's own fault, so a group stopped there
and a lone provider's turn ended on it, with a 400 nothing retries. Their
log ties it to the request, not the key: 30 of 214 requests carrying
~246K tokens of tools failed so, none of 420 under 1K, and the same
request was answered 200 some 13s to 25s after the first refusal.
openCodeBareRefusal (ported from ggbdpq's patch on the issue) reads a
400 from an OpenCode host whose body is a JSON object naming no error
field as the 502 it stands for (asBadGateway). A group asks its next
member; a lone provider is asked again within its patience (60s, with
replan pauses), which outlasts the reporter's window. Any 400 that names
something, a body that isn't a JSON object, and every other vendor's
400 go on as they came.
Changed from the patch:
- restAfterMarked rests nobody for this 502. The patch rested the key
for fallbackCooldown in a group (a scratch test showed ocgo resting
60s), over a refusal tied to request content: one heavy prompt would
have set aside a key that serves every other request.
- The body is read through a 64KB limit and put back with a
MultiReader, so nothing is cut; a body at the limit is left alone.
The patch read it whole.
- TestOpenCodeGoBare400ToldAs502 asserts at least 3 asks, not exactly
3: on current main the lone provider's patience asks 15 times.
Run on mote:
- At the pushed head (on
|
||
|
|
2d11cde056 |
provider: ${sessionId} and ${threadId} in a provider's Headers are the conversation's ids
Axel Burks on Discord (#feedback): his gateway in front of several Azure
accounts routes one conversation to one account by a session header, so
its reasoning can be read back. ${sessionId} was expanded only in Extra
body; in Headers it went out literally.
Now Sign expands ${sessionId} and ${threadId} in header values
(Provider.SentHeaders, conversation.go), with the id Extra body gets:
the agent's session header, else the id derived from the first user
message. The gateway carries it to Sign in the request's context
(WithConversation), on every API and count_tokens.
- ${threadId} is Codex's thread_id (turn metadata or thread-id header,
threadOf), which a subagent has of its own while sharing its lead's
session_id. No other agent names a thread; there it is the session's id.
Supported in Extra body too. Read only when a header or Extra body
names it (AsksThread).
- A request that is no conversation turn (model list, balance, embedding,
image, Azure/Kilo lists, a remote magpie's list) gets an id of its own,
"magpie-" and 12 random letters; Test and Detect use their
magpie-test-… id in headers and body alike. A literal placeholder is
never sent.
- Control characters (CR, LF, tab, NUL, DEL) are stripped from ids in a
header (headerSafe); with a CRLF id Go used to fail the request 502.
- GUI: Headers and Extra body hints name both placeholders, in en, zh,
zh-TW, ja, de. docs/subsystems/providers-accounts.md has a Headers row.
Run on mote at this head (rebased on
|
||
|
|
d1f57b70ee |
provider: every request to OpenCode's gateway names its conversation's session, at any port, lists, decisions, usage and the probe too, Codex's thread by its prompt_cache_key (luci on Discord)
OpenCode Go, added as a custom provider and asked from Codex, answered some users 400 "Request is missing x-opencode-session and cannot be routed efficiently", the Test button's probe too; a static header on the provider stopped the 400 but put every conversation on one backend. OpenCode's own client (packages/core, 4397ee4) sends x-opencode-session = SessionAffinity (parentID ?? fork ?? id) on every model request, and a fresh session for stateless calls; the console's inference proxy routes every /zen and /zen/go path, models and usage included, by it. - OpenCodeURL/openCodeHost: opencode.ai or a subdomain, by hostname, so a base URL naming a port (https://opencode.ai:443/zen/go/v1) is OpenCode's; IsOpenCode, OpenCodeFreeURL and openCodeRoot share it. Before, the turn's session was set only when p.Host() matched without a port. - gateway: the turn's seed is the client's own x-opencode-session, else sessionOf (X-Magpie-Session, Codex's session_id, …), else the body's prompt_cache_key, else conversationID. Without the cache key two Codex conversations opened in one folder (same environment message) were one session. - Sign: a request to OpenCode's gateway that names no session gets a fresh one (OpenCodeSession), so System One decisions and anything else signed are never refused; the user's own header still wins. - Model lists (FetchURL, FetchAtListed, FetchGemini) get a fresh session via listHeadersAt, Go's usage windows via planWindows, the probe a session of its own. - A 4xx/5xx from OpenCode's gateway logs host, path, the sent headers' names (never values), x-opencode-session's first 8 chars or "missing", and whether the provider's own header pinned it. Run (worktree, -tags nogui -p 1): - go test ./internal/gateway -run TestOpenCodeGoSessionPerConversation and -run 'OpenCode|Zen|Session|Conversation|Decide|SystemOne|UserHeader|Kilo|Cline|Gemini': ok - go test ./internal/provider -run TestOpenCodeSessionOnEveryCall and -run 'OpenCode|Zen|Sign|Header|Fetch|Model|Probe|PlanQuota|Quota|Decide|Detect|Kilo|Cline|UserAgent': ok - gofmt -l clean; go vet -tags nogui GOOS=darwin/linux/windows on both packages: ok Broken by hand: seed back to conversationID -> red (threads c and d one session); old IsOpenCode -> red (port provider's turns two sessions); Sign's backstop removed -> red; list session removed -> red. The probe's own OpenCodeClient removed stays green: Sign's backstop gives it a fresh session anyway. Not run: the full suite; no request to the real OpenCode gateway; why luci's users miss the header (port, proxy/mirror host, a client header) is not confirmed, the new log line will tell. Full suite: SUITE_LINE |