sessions: Desktop's Code tab in its 3p mode is Claude Desktop's, not Claude Code's

cybercaius (Discord #help) runs Claude Desktop through magpie's gateway
and saw Desktop's work listed under another agent. Desktop set to a
gateway is in its third-party inference mode, and Desktop 2.7032 then
starts its Code tab's Claude Code with CLAUDE_CODE_ENTRYPOINT
"claude-desktop-3p" (its nK: type "3p" -> "claude-desktop-3p", else
"claude-desktop"; the value is in Claude Code's own entrypoint enum).
The calls reader (calls.go) and the trace reader (traces_claude.go)
only took "claude-desktop", so every call from such a session was
counted as Claude Code's. Both now ask one desktopEntrypoint.

This is what Desktop's transcripts say. The gateway's own attribution
of a live request (agentOf, by key then User-Agent) is not changed:
with Desktop's own key magpie-claude-desktop it already names Desktop,
and the reporter's misattributed title request was not reproduced.

Run on mote: go test ./internal/sessions -run
'TestCallsDesktop3pCodeTab|TestClaudeTraceSubagentsShareSessionWithoutIDCollisions|TestCalls'
ok. Broken by hand: both readers back on == "claude-desktop" ->
TestCallsDesktop3pCodeTab and the trace test's claude-desktop-3p case
fail. Rebased on origin/main bc247a8cc: go test -tags nogui
./internal/sessions on the Linux box (WSL magpie-desktop), the whole
package, ok; go vet for Linux and Windows ok.
Not tried: a real Desktop 3p session's transcript (the value is read
from Desktop's asar, not captured from a file).
This commit is contained in:
yetone
2026-10-29 12:42:52 +08:00
parent 89407112ca
commit a54e336e44
4 changed files with 30 additions and 6 deletions
+9 -1
View File
@@ -762,7 +762,7 @@ func claudeCallLine(st *callFile, b []byte) {
if c.Session == "" {
c.Session = st.Session
}
if st.Agent == "claude" && l.Entrypoint == "claude-desktop" {
if st.Agent == "claude" && desktopEntrypoint(string(l.Entrypoint)) {
c.Agent = "claude-desktop"
}
if l.APIError {
@@ -1223,3 +1223,11 @@ func ReadCallSource(s CallSource) []Call {
callsMu.Unlock()
return st.Calls
}
// desktopEntrypoint is a Claude Code transcript's entrypoint when Claude
// Desktop ran it for its Code tab: "claude-desktop", or
// "claude-desktop-3p" in its third-party inference mode (Desktop 2.7032's
// nK: type "3p"), the mode a gateway such as magpie's is set in.
func desktopEntrypoint(e string) bool {
return e == "claude-desktop" || e == "claude-desktop-3p"
}
+14
View File
@@ -789,3 +789,17 @@ func TestCallsCoworkMSIX(t *testing.T) {
t.Fatalf("calls: %+v", cs)
}
}
// Desktop's Code tab in its third-party inference mode, the one a gateway
// is set in, writes "claude-desktop-3p" (cybercaius: its calls were
// counted as Claude Code's).
func TestCallsDesktop3pCodeTab(t *testing.T) {
d := setupCalls(t)
writeLines(t, filepath.Join(d.claude, "projects", "-p", "s3p.jsonl"),
swap(swap(claudeMsg("m1", "claude-haiku-5-5", 1, 2, 3, 4, 1), `"entrypoint":"cli"`, `"entrypoint":"claude-desktop-3p"`), `"sessionId":"sess1"`, `"sessionId":"s3p"`))
writeLines(t, filepath.Join(d.claude, "projects", "-p", "sess1.jsonl"), claudeMsg("m2", "claude-opus-5-5", 1, 2, 3, 4, 2))
cs := Calls(time.Time{})
if len(cs) != 2 || cs[0].Agent != "claude" || cs[1].Agent != "claude-desktop" || cs[1].Session != "s3p" {
t.Fatalf("calls: %+v", cs)
}
}
+1 -1
View File
@@ -68,7 +68,7 @@ func (c *traceCursor) claude(line []byte, bodies bool) []TraceSpan {
if o.SessionID != "" {
c.session = o.SessionID
}
if o.Entrypoint == "claude-desktop" {
if desktopEntrypoint(o.Entrypoint) {
c.agent = "claude-desktop"
}
type block struct {
+6 -4
View File
@@ -384,8 +384,10 @@ func TestGeminiParallelToolResultsStayWithTheirCalls(t *testing.T) {
}
func TestClaudeTraceSubagentsShareSessionWithoutIDCollisions(t *testing.T) {
for _, agent := range []string{"claude", "claude-desktop"} {
t.Run(agent, func(t *testing.T) {
// Desktop's Code tab writes "claude-desktop", or "claude-desktop-3p"
// in its third-party inference mode (cybercaius, a gateway setup)
for entry, agent := range map[string]string{"claude": "claude", "claude-desktop": "claude-desktop", "claude-desktop-3p": "claude-desktop"} {
t.Run(entry, func(t *testing.T) {
testenv.SetHome(t, t.TempDir())
t.Setenv("CODEX_HOME", t.TempDir())
t.Setenv("PI_CODING_AGENT_DIR", t.TempDir())
@@ -405,8 +407,8 @@ func TestClaudeTraceSubagentsShareSessionWithoutIDCollisions(t *testing.T) {
// No sessionId is required: child paths provide the parent session ID.
var lines []string
for _, event := range []map[string]any{
{"type": "user", "uuid": "old", "entrypoint": agent, "timestamp": since.Add(-time.Minute), "message": map[string]any{"content": "PRIVATE-OLD"}},
{"type": "user", "uuid": "same-user", "entrypoint": agent, "timestamp": since, "message": map[string]any{"content": "PRIVATE-NEW"}},
{"type": "user", "uuid": "old", "entrypoint": entry, "timestamp": since.Add(-time.Minute), "message": map[string]any{"content": "PRIVATE-OLD"}},
{"type": "user", "uuid": "same-user", "entrypoint": entry, "timestamp": since, "message": map[string]any{"content": "PRIVATE-NEW"}},
{"type": "assistant", "timestamp": since.Add(time.Second), "message": map[string]any{"id": "same-message", "model": "claude-sonnet", "stop_reason": "end_turn", "content": []map[string]string{{"type": "text", "text": "PRIVATE-ANSWER"}}, "usage": map[string]int{"input_tokens": 10, "output_tokens": 5}}},
{"type": "system", "subtype": "turn_duration", "timestamp": since.Add(2 * time.Second)},
} {