Commit Graph
2 Commits
Author SHA1 Message Date
yetone 925d6a253f trae 0.2.32: a conversation keeps its session_id when the plugin restarts
baoguo on magpie's Discord: every call seemed to be a new Trae
conversation, billed and cached as fresh; asked for one Trae session per
agent session. The plugin already sends one session_id per conversation
(0.2.6, #58): the session magpie names (the agent's own header, Claude
Code's x-claude-code-session-id, Codex's session_id, DSH's
x-deepseek-harness-session-id, OpenCode's session; else magpie's hash of
how the conversation opens), with the account, hashed. But the hash's
salt was new in each process, and magpie restarts its plugins on every
update of magpie or of any plugin, so every conversation going on then
went on under a session_id of its own from that point.

Now the salt is made once, in ~/.config/magpie/trae-session-salt
(MAGPIE_TRAE_SESSION_SALT names another file), written to a temp name
and hard-linked into place so processes starting together all read the
one that won. A file that can't be read or made, or holds anything else,
is left as it is and the process has a salt of its own, as before. The
id is derived, not cached, so there is nothing to bound or expire: the
same agent session gives the same id for good. Tests now write their
salt in a temp folder (nonet.mjs).

Run: HOME=$(mktemp -d) bun test packages/trae on mote, 243 pass, 0 fail;
bun scripts/check.mjs trae ok; conversation.test.mjs on Windows
(xiaomi-gpu), 10 pass. Broken by hand: a salt new in each process makes
"a conversation keeps its session_id when the plugin's process starts
again" fail; overwriting the file on a race makes "processes starting at
once on no salt yet all take the one that was made" fail.
Not tried: a real Trae account (none in this magpie), so whether Trae's
prompt cache follows session_id is not measured. dsh-connect-trae's
probe (docs, 11-03) saw cache_read 0 on three same-prefix requests since
10-26, which no session id would change. Claude Code subagents still
share their lead's session, as magpie names them.

Reported-by: baoguo
2026-11-06 17:36:42 +08:00
d3711248aa trae: one conversation keeps one session_id (#58)
* trae: one conversation keeps one session_id

The plugin gave every request a fresh `randomUUID()` for both `request_id`
and `session_id` (chatBody), so each request of one agent turn reached Trae
as a different session. Trae counts a conversation by the session its
requests name: a user send that takes several steps (a tool result sent back,
a retry, another function answering) was counted as several conversations,
each a row of its own in the usage detail with no conversation under it —
which is what showed as "Prompt" where the IDE's own sessions show their
title.

`session_id` is now the conversation's, as the IDE keeps one per
conversation: the session magpie (or OpenCode) names the request by, carried
from a new `chat.headers` hook, else the chat's first user message, which
every later turn repeats. Nothing is made up when neither names one — a
made-up conversation of the request's own is the splitting this ends — and
the caller then makes a fresh id per request, as before. The id is salted, so
it says nothing of the words it was made from, and keeps the UUID shape
`randomUUID()` returned. `request_id` stays the request's own.

The title column is not this fix: the IDE's titles are generated by its agent
(`session_title_message`) and reported through its hub, which has no call on
the path this plugin takes. With the session stable, Trae has one
conversation to hang a title on, once it is sent one.

* trae: a conversation is named with the account answering it too

The id a chat's session_id is made of was the conversation alone, so when
magpie failed over, or rotated, between two Trae accounts inside one
conversation, both accounts were sent the same session_id — an id the fresh
random one before it never linked, and one Trae can read one account's
conversation as another's. The account (its uid, else its name) is now part
of what the id is made of: conversationID(req, session, who), who being the
account already resolved just above the request.

The cost, as the comment says: a conversation answered by two accounts is
counted as two again, which is what it did before it was named at all.

Two tests: two accounts of one conversation (named by magpie's session and
by the chat's own first message, and an account named by its name alone) are
two conversations to Trae, and one account's two conversations stay two.
The first fails with the account left out of the id.

---------

Co-authored-by: tearslee <16331052+tearslee@users.noreply.github.com>
Co-authored-by: 李 <oncwnuKMG1gRkPtw27nJROKWWRUM@git.weixin.qq.com>
2026-10-09 11:48:59 +08:00