From a54e336e443cdcba366d39ea71e645cbed79f623 Mon Sep 17 00:00:00 2001 From: yetone Date: Thu, 29 Oct 2026 10:16:29 +0800 Subject: [PATCH] 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). --- internal/sessions/calls.go | 10 +++++++++- internal/sessions/calls_test.go | 14 ++++++++++++++ internal/sessions/traces_claude.go | 2 +- internal/sessions/traces_clients_test.go | 10 ++++++---- 4 files changed, 30 insertions(+), 6 deletions(-) diff --git a/internal/sessions/calls.go b/internal/sessions/calls.go index c41a705a3..e4d962902 100644 --- a/internal/sessions/calls.go +++ b/internal/sessions/calls.go @@ -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" +} diff --git a/internal/sessions/calls_test.go b/internal/sessions/calls_test.go index b95d4c151..4a47cdd28 100644 --- a/internal/sessions/calls_test.go +++ b/internal/sessions/calls_test.go @@ -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) + } +} diff --git a/internal/sessions/traces_claude.go b/internal/sessions/traces_claude.go index 9b18f21dd..e8d61b957 100644 --- a/internal/sessions/traces_claude.go +++ b/internal/sessions/traces_claude.go @@ -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 { diff --git a/internal/sessions/traces_clients_test.go b/internal/sessions/traces_clients_test.go index 23b87e77b..ff2d3112f 100644 --- a/internal/sessions/traces_clients_test.go +++ b/internal/sessions/traces_clients_test.go @@ -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)}, } {