Skip to content

Commit 25e107b

Browse files
authored
Merge branch 'bobby/core-784-generate-dev-passwords' into bobby/core-784-setup-token
2 parents f5a0da2 + 070107c commit 25e107b

112 files changed

Lines changed: 4212 additions & 567 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎.github/actions/install-rcodesign/action.yml‎

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,12 @@ inputs:
2020
description: Git revision of indygreg/apple-platform-rs to build.
2121
required: false
2222
default: "0ebbd2ef3b96d5adccc30b1cad4deea38cd735c4"
23+
toolchain:
24+
description: >-
25+
Rust toolchain version to build with. Pinned so that a new stable release
26+
cannot change the compiler of the signing tool without a change here.
27+
required: false
28+
default: "1.100.0"
2329
use-cache:
2430
description: >-
2531
Restore and save the built binary with actions/cache. Signing jobs must
@@ -37,19 +43,18 @@ runs:
3743
uses: actions/cache@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0
3844
with:
3945
path: /tmp/rcodesign-bin
40-
key: rcodesign-pkcs11-${{ runner.os }}-${{ runner.arch }}-${{ inputs.rev }}-${{ hashFiles('.github/actions/install-rcodesign/pkcs11-single-init.patch') }}
46+
key: rcodesign-pkcs11-${{ runner.os }}-${{ runner.arch }}-${{ inputs.rev }}-rust${{ inputs.toolchain }}-${{ hashFiles('.github/actions/install-rcodesign/pkcs11-single-init.patch') }}
4147

4248
- name: Build rcodesign
4349
if: steps.cache-rcodesign.outputs.cache-hit != 'true'
4450
shell: bash
4551
run: |
4652
set -euo pipefail
4753
if command -v rustup >/dev/null 2>&1; then
48-
rustup toolchain install --profile minimal stable
49-
rustup default stable
54+
rustup toolchain install --profile minimal "$RUST_TOOLCHAIN"
5055
elif ! command -v cargo >/dev/null 2>&1; then
5156
./.github/scripts/retry.sh -- curl --proto '=https' --tlsv1.2 -sSfL https://sh.rustup.rs -o /tmp/rustup-init.sh
52-
sh /tmp/rustup-init.sh -y --profile minimal
57+
sh /tmp/rustup-init.sh -y --profile minimal --default-toolchain "$RUST_TOOLCHAIN"
5358
rm /tmp/rustup-init.sh
5459
fi
5560
export PATH="$HOME/.cargo/bin:$PATH"
@@ -61,7 +66,8 @@ runs:
6166
git -C "$src" checkout -q FETCH_HEAD
6267
git -C "$src" apply "$GITHUB_ACTION_PATH/pkcs11-single-init.patch"
6368
64-
./.github/scripts/retry.sh -- cargo install \
69+
# +toolchain fails if cargo is not rustup's, so the pin cannot be skipped.
70+
./.github/scripts/retry.sh -- cargo "+$RUST_TOOLCHAIN" install \
6571
--locked \
6672
--path "$src/apple-codesign" \
6773
--features pkcs11 \
@@ -71,6 +77,7 @@ runs:
7177
cp /tmp/rcodesign-install/bin/rcodesign /tmp/rcodesign-bin/rcodesign
7278
env:
7379
RCODESIGN_REV: ${{ inputs.rev }}
80+
RUST_TOOLCHAIN: ${{ inputs.toolchain }}
7481

7582
- name: Install rcodesign
7683
shell: bash

‎agent/agent_test.go‎

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -469,6 +469,39 @@ func TestAgent_Stats_Magic(t *testing.T) {
469469
)
470470
})
471471

472+
t.Run("TracksZed", func(t *testing.T) {
473+
t.Parallel()
474+
if runtime.GOOS == "windows" {
475+
t.Skip("Uses a POSIX shell comment to mimic Zed's proxy command")
476+
}
477+
ctx, cancel := context.WithTimeout(context.Background(), testutil.WaitLong)
478+
defer cancel()
479+
conn, agentClient, stats, _, _ := setupAgent(t, agentsdk.Manifest{}, 0)
480+
sshClient, err := conn.SSHClient(ctx)
481+
require.NoError(t, err)
482+
defer sshClient.Close()
483+
session, err := sshClient.NewSession()
484+
require.NoError(t, err)
485+
defer session.Close()
486+
stdin, err := session.StdinPipe()
487+
require.NoError(t, err)
488+
// Zed sends no app name; the agent detects its proxy command line.
489+
err = session.Start("cat # .zed_server/zed-remote-server-stable-1.0.0 proxy --identifier test")
490+
require.NoError(t, err)
491+
require.Eventuallyf(t, func() bool {
492+
s, ok := <-stats
493+
return ok && s.SessionCounts["zed"] == 1 && s.SessionCounts["ssh"] == 0
494+
}, testutil.WaitLong, testutil.IntervalFast, "never saw zed session")
495+
496+
_ = stdin.Close()
497+
require.NoError(t, session.Wait())
498+
499+
assertConnectionReport(t, agentClient,
500+
proto.ConnectEvent{Method: proto.Connection_METHOD_SSH, AppName: "zed"},
501+
proto.DisconnectEvent{Reason: string(codersdk.DisconnectReasonGraceful)},
502+
)
503+
})
504+
472505
for _, shutdown := range []bool{false, true} {
473506
name := "TracksJetBrains"
474507
if shutdown {

‎agent/agentssh/agentssh.go‎

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -363,7 +363,15 @@ func (s *Server) SessionCounts() map[string]int64 {
363363
return maps.Clone(s.sessionCounts)
364364
}
365365

366-
func extractAppName(env []string) (appName, rawAppName string, filteredEnv []string) {
366+
// isZedProxyCommand reports whether rawCommand starts Zed's remote server
367+
// proxy, the long-lived session Zed keeps open for a remote project. Zed sets
368+
// no app name, so its command line is the only signal.
369+
func isZedProxyCommand(rawCommand string) bool {
370+
return strings.Contains(rawCommand, "zed-remote-server") &&
371+
strings.Contains(rawCommand, " proxy --identifier ")
372+
}
373+
374+
func extractAppName(env []string, rawCommand string) (appName, rawAppName string, filteredEnv []string) {
367375
// Match the full assignment so a longer variable such as
368376
// CODER_SSH_SESSION_TYPE_FOO=bar is not mistaken for this one.
369377
prefix := AppNameEnvironmentVariable + "="
@@ -373,6 +381,10 @@ func extractAppName(env []string) (appName, rawAppName string, filteredEnv []str
373381
rawAppName = value
374382
}
375383
}
384+
// An explicit app name wins over detection.
385+
if rawAppName == "" && isZedProxyCommand(rawCommand) {
386+
rawAppName = "zed"
387+
}
376388

377389
if rawAppName == "" {
378390
appName = string(codersdk.AppFamilySSH)
@@ -502,7 +514,7 @@ func (s *Server) sessionHandler(session ssh.Session) {
502514
logger.Info(ctx, "handling ssh session")
503515

504516
env := session.Environ()
505-
appName, rawAppName, env := extractAppName(env)
517+
appName, rawAppName, env := extractAppName(env, session.RawCommand())
506518
family := codersdk.AppNameFamily(appName)
507519
if family == codersdk.AppFamilyUnknown {
508520
logger.Debug(ctx, "unrecognized ssh session type",

‎agent/agentssh/appname_internal_test.go‎

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,36 +19,44 @@ func TestExtractAppName(t *testing.T) {
1919
}
2020

2121
for _, tc := range []struct {
22-
name string
23-
env []string
22+
name string
23+
env []string
24+
rawCommand string
2425
// keepEnv, when set, must survive filtering.
2526
keepEnv string
2627
want string
2728
}{
28-
{"NoEnvDefaultsToSSH", []string{"FOO=bar"}, "FOO=bar", "ssh"},
29-
{"EmptyValueDefaultsToSSH", envWith(""), "", "ssh"},
30-
{"VSCode", envWith("vscode"), "", "vscode"},
31-
{"JetBrainsLegacyCasing", envWith("JetBrains"), "", "jetbrains"},
32-
{"UnknownTypeNormalized", envWith("Cursor-Nightly"), "", "cursor_nightly"},
33-
{"LastInstanceWins", append(envWith("vscode"), AppNameEnvironmentVariable+"=cursor"), "", "cursor"},
29+
{"NoEnvDefaultsToSSH", []string{"FOO=bar"}, "", "FOO=bar", "ssh"},
30+
{"EmptyValueDefaultsToSSH", envWith(""), "", "", "ssh"},
31+
{"VSCode", envWith("vscode"), "", "", "vscode"},
32+
{"JetBrainsLegacyCasing", envWith("JetBrains"), "", "", "jetbrains"},
33+
{"UnknownTypeNormalized", envWith("Cursor-Nightly"), "", "", "cursor_nightly"},
34+
{"LastInstanceWins", append(envWith("vscode"), AppNameEnvironmentVariable+"=cursor"), "", "", "cursor"},
35+
// Command shapes Zed sends over SSH (crates/remote/src/transport/ssh.rs).
36+
{"ZedProxy", nil, "cd; env RUST_LOG=info .zed_server/zed-remote-server-stable-1.28.1+stable.390.e8bc16ac proxy --identifier workspace-2 --reconnect", "", "zed"},
37+
{"ZedProxyQuotedPath", nil, "cd; env '.zed_server/zed-remote-server-preview-0.201.0' proxy --identifier 'abc-1'", "", "zed"},
38+
{"ZedVersionProbeIsSSH", nil, "cd; .zed_server/zed-remote-server-stable-0.200.0 version", "", "ssh"},
39+
{"ExplicitAppNameWinsOverZed", envWith("vscode"), "cd; env .zed_server/zed-remote-server-stable-0.200.0 proxy --identifier abc", "", "vscode"},
3440
// A variable that merely starts with the same characters is a
3541
// different variable, not an app name.
3642
{
3743
"LongerVariableIgnored",
3844
[]string{AppNameEnvironmentVariable + "_FOO=bar"},
45+
"",
3946
AppNameEnvironmentVariable + "_FOO=bar",
4047
"ssh",
4148
},
4249
{
4350
"LongerVariableDoesNotShadowAppName",
4451
append(envWith("cursor"), AppNameEnvironmentVariable+"_FOO=bar"),
52+
"",
4553
AppNameEnvironmentVariable + "_FOO=bar",
4654
"cursor",
4755
},
4856
} {
4957
t.Run(tc.name, func(t *testing.T) {
5058
t.Parallel()
51-
appName, _, filteredEnv := extractAppName(tc.env)
59+
appName, _, filteredEnv := extractAppName(tc.env, tc.rawCommand)
5260
require.Equal(t, tc.want, appName)
5361
for _, kv := range filteredEnv {
5462
require.NotContains(t, kv, AppNameEnvironmentVariable+"=")

‎aibridge/intercept/responses/reqpayload.go‎

Lines changed: 34 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,11 @@ const (
2828

2929
var (
3030
constCustomToolCallOutput = string(constant.ValueOf[constant.CustomToolCallOutput]())
31+
constDeveloper = string(constant.ValueOf[constant.Developer]())
3132
constFunctionCallOutput = string(constant.ValueOf[constant.FunctionCallOutput]())
3233
constInputText = string(constant.ValueOf[constant.InputText]())
34+
constReasoning = string(constant.ValueOf[constant.Reasoning]())
35+
constSystem = string(constant.ValueOf[constant.System]())
3336
constUser = string(constant.ValueOf[constant.User]())
3437

3538
reqPathContent = string(constant.ValueOf[constant.Content]())
@@ -75,26 +78,41 @@ func (p RequestPayload) correlatingToolCallID() *string {
7578
}
7679

7780
arr := items.Array()
78-
if len(arr) == 0 {
79-
return nil
80-
}
81+
for i := len(arr) - 1; i >= 0; i-- {
82+
item := arr[i]
83+
84+
// Clients can append items that don't start a new turn after a tool
85+
// result. For example, Codex appends a developer message recording an
86+
// approved command prefix. Look past them to find the tool result.
87+
role := item.Get(reqPathRole).String()
88+
itemType := item.Get(reqPathType).String()
89+
if role == constDeveloper || role == constSystem || itemType == constReasoning {
90+
continue
91+
}
8192

82-
// Both function and custom (freeform) tool results reference the
83-
// originating tool call by call_id. Codex sends custom_tool_call_output
84-
// for custom tools such as apply_patch.
85-
last := arr[len(arr)-1]
86-
switch last.Get(reqPathType).String() {
87-
case constFunctionCallOutput, constCustomToolCallOutput:
88-
default:
89-
return nil
90-
}
93+
// The first remaining item decides. Anything other than a tool result,
94+
// such as a user message, means a new turn. Stopping here matters
95+
// because the full history is resent on every request, so a new prompt
96+
// always has older tool results earlier in the input.
97+
//
98+
// Both function and custom (freeform) tool results reference the
99+
// originating tool call by call_id. Codex sends custom_tool_call_output
100+
// for custom tools such as apply_patch.
101+
switch itemType {
102+
case constFunctionCallOutput, constCustomToolCallOutput:
103+
default:
104+
return nil
105+
}
91106

92-
callID := last.Get(reqPathCallID).String()
93-
if callID == "" {
94-
return nil
107+
callID := item.Get(reqPathCallID).String()
108+
if callID == "" {
109+
return nil
110+
}
111+
112+
return &callID
95113
}
96114

97-
return &callID
115+
return nil
98116
}
99117

100118
// LastUserPrompt returns input text with the "user" role from the last input

‎aibridge/intercept/responses/reqpayload_internal_test.go‎

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,36 @@ func TestCorrelatingToolCallID(t *testing.T) {
123123
name: "missing call id",
124124
payload: []byte(`{"input":[{"type":"function_call_output","output":"ok"}]}`),
125125
},
126+
{
127+
name: "tool result followed by developer message",
128+
payload: []byte(`{"model":"gpt-5","input":[{"role":"user","content":"hi"},{"type":"custom_tool_call","call_id":"call_custom","name":"exec","input":"pwd"},{"type":"custom_tool_call_output","call_id":"call_custom","output":"/home"},{"type":"message","role":"developer","content":[{"type":"input_text","text":"Approved command prefix saved"}]}]}`),
129+
wantCall: new("call_custom"),
130+
},
131+
{
132+
name: "tool result followed by system, developer and reasoning items",
133+
payload: []byte(`{"model":"gpt-5","input":[{"role":"user","content":"hi"},{"type":"function_call_output","call_id":"call_abc","output":"r1"},{"role":"system","content":"sys"},{"type":"reasoning","id":"rs_1","summary":[]},{"role":"developer","content":"dev"}]}`),
134+
wantCall: new("call_abc"),
135+
},
136+
{
137+
name: "user message followed by developer message after older tool result",
138+
payload: []byte(`{"model":"gpt-5","input":[{"type":"function_call_output","call_id":"call_first","output":"r1"},{"role":"user","content":"hi"},{"role":"developer","content":"dev"}]}`),
139+
},
140+
{
141+
name: "only developer and system messages",
142+
payload: []byte(`{"model":"gpt-5","input":[{"role":"system","content":"sys"},{"role":"developer","content":"dev"}]}`),
143+
},
144+
{
145+
name: "assistant message after tool result stops the walk",
146+
payload: []byte(`{"model":"gpt-5","input":[{"role":"user","content":"hi"},{"type":"function_call_output","call_id":"call_abc","output":"r1"},{"type":"message","role":"assistant","content":[{"type":"output_text","text":"done"}]},{"role":"developer","content":"dev"}]}`),
147+
},
148+
{
149+
name: "tool call after tool result stops the walk",
150+
payload: []byte(`{"model":"gpt-5","input":[{"role":"user","content":"hi"},{"type":"function_call_output","call_id":"call_abc","output":"r1"},{"type":"function_call","call_id":"call_next","name":"exec","arguments":"{}"},{"role":"developer","content":"dev"}]}`),
151+
},
152+
{
153+
name: "tool result missing call id followed by developer message does not fall back to older result",
154+
payload: []byte(`{"model":"gpt-5","input":[{"type":"function_call_output","call_id":"call_first","output":"r1"},{"type":"function_call_output","output":"r2"},{"role":"developer","content":"dev"}]}`),
155+
},
126156
}
127157

128158
for _, tc := range tests {

0 commit comments

Comments
 (0)