Skip to content

Commit 3707ba5

Browse files
robstolarzclaude
andcommitted
fix: address review feedback on --ssh-after-step
- Early-exit waitForLogMarker when attempt reaches terminal status instead of polling forever if a step before the debug step fails - Remove duplicate "Connecting to sandbox" message (already in waitForSandbox) - Fix printSSHInfo to use run ID for `depot ci ssh` suggestion - Remove arbitrary 10min timeout on log marker polling (rely on terminal status check and context cancellation instead) Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 991d3c4 commit 3707ba5

File tree

2 files changed

+11
-11
lines changed

2 files changed

+11
-11
lines changed

pkg/cmd/ci/run.go

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -240,9 +240,8 @@ This command is in beta and subject to change.`,
240240
if sshAfterStep > 0 {
241241
fmt.Fprintf(os.Stderr, "Run 'touch /tmp/depot-continue' to resume the workflow. (Your session will not end.)\n")
242242
}
243-
fmt.Fprintf(os.Stderr, "Connecting to sandbox %s...\n", sandboxID)
244243
if !helpers.IsTerminal() {
245-
return printSSHInfo(sandboxID, sessionID, "")
244+
return printSSHInfo(resp.RunId, sandboxID, sessionID, "")
246245
}
247246
return pty.Run(ctx, pty.SessionOptions{
248247
Token: tokenVal,
@@ -513,14 +512,8 @@ func formatStatus(s civ1.CIRunStatus) string {
513512
// appears. This is used to detect when the injected debug step is running.
514513
func waitForLogMarker(ctx context.Context, token, orgID, runID, jobKey, marker string) error {
515514
const pollInterval = 3 * time.Second
516-
const timeout = 10 * time.Minute
517-
518-
deadline := time.Now().Add(timeout)
519515

520516
for {
521-
if time.Now().After(deadline) {
522-
return fmt.Errorf("timed out waiting for log marker (waited %s)", timeout)
523-
}
524517

525518
// Resolve the latest attempt ID for the job.
526519
resp, err := api.CIGetRunStatus(ctx, token, orgID, runID)
@@ -554,6 +547,12 @@ func waitForLogMarker(ctx context.Context, token, orgID, runID, jobKey, marker s
554547
continue
555548
}
556549

550+
// Early exit if the job has already completed — the marker will never appear.
551+
switch attempt.Status {
552+
case "finished", "failed", "cancelled":
553+
return fmt.Errorf("job completed before debug step was reached (status: %s)", attempt.Status)
554+
}
555+
557556
lines, err := api.CIGetJobAttemptLogs(ctx, token, orgID, attempt.AttemptId)
558557
if err == nil {
559558
for _, line := range lines {

pkg/cmd/ci/ssh.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ This command is in beta and subject to change.`,
7373
}
7474

7575
if info || !helpers.IsTerminal() {
76-
return printSSHInfo(sandboxID, sessionID, output)
76+
return printSSHInfo(runID, sandboxID, sessionID, output)
7777
}
7878

7979
return pty.Run(ctx, pty.SessionOptions{
@@ -276,12 +276,13 @@ func workflowErrorMessage(resp *civ1.GetRunStatusResponse) string {
276276
return ""
277277
}
278278

279-
func printSSHInfo(sandboxID, sessionID, output string) error {
279+
func printSSHInfo(runID, sandboxID, sessionID, output string) error {
280280
if output == "json" {
281281
enc := json.NewEncoder(os.Stdout)
282282
enc.SetIndent("", " ")
283283
return enc.Encode(map[string]string{
284284
"host": "api.depot.dev",
285+
"run_id": runID,
285286
"sandbox_id": sandboxID,
286287
"session_id": sessionID,
287288
"ssh_command": fmt.Sprintf("ssh %s@api.depot.dev", sandboxID),
@@ -293,7 +294,7 @@ func printSSHInfo(sandboxID, sessionID, output string) error {
293294
fmt.Printf("Password: Your Depot API token ($DEPOT_TOKEN)\n")
294295
fmt.Println()
295296
fmt.Printf("Connect interactively:\n")
296-
fmt.Printf(" depot ci ssh %s\n", sandboxID)
297+
fmt.Printf(" depot ci ssh %s\n", runID)
297298
fmt.Println()
298299
fmt.Printf("Or via SSH directly:\n")
299300
fmt.Printf(" ssh %s@api.depot.dev\n", sandboxID)

0 commit comments

Comments
 (0)