The cross-harness, self-improving memory layer for AI agents. Join our community: https://discord.com/invite/zdNChS2fBu
Go agent-ai-cliagent-harnessesagent-securitybrowser-extensionciclaude-codecloudcodexcursordetection-engineeringjevknowledge-basememorymobile-device-managementobservabilitysecuritysecurity-information-and-event-managementsecurity-toolstelemetrytraces
Fix Devin Cloud connector issues flagged by Cursor Bugbot
shukieshah2efa0306d23a
diff --git a/cli/beacon/cmd/cloud_devin_pull.go b/cli/beacon/cmd/cloud_devin_pull.goindex 1fb73ad4..747586b1 100644--- a/cli/beacon/cmd/cloud_devin_pull.go+++ b/cli/beacon/cmd/cloud_devin_pull.go@@ -23,7 +23,6 @@ var devinPullOpts struct {state stringlogPath stringprint bool- once boolwatch boolinterval time.DurationnoUpload bool@@ -58,8 +57,7 @@ func init() {f.StringVar(&devinPullOpts.state, "state", "", "Dedup state file path (default ~/.beacon/cloud/devin/<org>/state.json)")f.StringVar(&devinPullOpts.logPath, "log-path", "", "Runtime JSONL log path (default resolved endpoint log)")f.BoolVar(&devinPullOpts.print, "print", false, "Print mapped events as JSON without writing or uploading (dry run)")- f.BoolVar(&devinPullOpts.once, "once", true, "Run a single sweep and exit")- f.BoolVar(&devinPullOpts.watch, "watch", false, "Poll continuously on --interval")+ f.BoolVar(&devinPullOpts.watch, "watch", false, "Poll continuously on --interval (default: a single sweep then exit)")f.DurationVar(&devinPullOpts.interval, "interval", time.Minute, "Poll interval for --watch")f.BoolVar(&devinPullOpts.noUpload, "no-upload", false, "Never upload to GCS even when BEACON_CLOUD_GCS_* is set")f.BoolVar(&devinPullOpts.userMode, "user", true, "Use per-user endpoint log paths")diff --git a/cli/beacon/internal/devincloud/mapper.go b/cli/beacon/internal/devincloud/mapper.goindex 659f33be..4363e8f3 100644--- a/cli/beacon/internal/devincloud/mapper.go+++ b/cli/beacon/internal/devincloud/mapper.go@@ -1,6 +1,7 @@package devincloudimport (+ "fmt""strings""time"@@ -81,8 +82,11 @@ func MapSession(s Session, msgs []Message) []MappedEvent {}if IsTerminal(s.Status) {+ // Key the ended event by updated_at: a suspended session may resume and+ // suspend again, and each suspension is a distinct end-of-activity. A+ // fixed ":ended" key would suppress every end after the first.out = append(out, MappedEvent{- DedupID: s.SessionID + ":ended",+ DedupID: fmt.Sprintf("%s:ended:%d", s.SessionID, s.UpdatedAt),Event: sessionLifecycleEvent(s, "session.ended", "Devin Cloud session ended", s.UpdatedAt),})}diff --git a/cli/beacon/internal/devincloud/mapper_test.go b/cli/beacon/internal/devincloud/mapper_test.goindex 000079d7..e10a1d85 100644--- a/cli/beacon/internal/devincloud/mapper_test.go+++ b/cli/beacon/internal/devincloud/mapper_test.go@@ -29,8 +29,8 @@ func TestMapSessionProducesLifecycleAndMessages(t *testing.T) {}}- // Dedup ids: lifecycle synthetic, messages use event_id.- wantIDs := []string{"sess1:started", "e1", "e2", "sess1:ended"}+ // Dedup ids: lifecycle synthetic (ended keyed by updated_at), messages use event_id.+ wantIDs := []string{"sess1:started", "e1", "e2", "sess1:ended:1600"}for i, want := range wantIDs {if mapped[i].DedupID != want {t.Fatalf("event %d dedup id = %q, want %q", i, mapped[i].DedupID, want)@@ -81,6 +81,21 @@ func TestMapSessionProducesLifecycleAndMessages(t *testing.T) {}}+func TestMapSessionReEndsOnNewSuspension(t *testing.T) {+ // Same session suspended at two different updated_at values must produce two+ // distinct ended dedup ids so a re-suspension after resume isn't suppressed.+ first := MapSession(Session{SessionID: "s", Status: "suspended", UpdatedAt: 100}, nil)+ second := MapSession(Session{SessionID: "s", Status: "suspended", UpdatedAt: 200}, nil)+ id1 := first[len(first)-1].DedupID+ id2 := second[len(second)-1].DedupID+ if id1 == id2 {+ t.Fatalf("re-suspension produced same ended id %q; would be deduped away", id1)+ }+ if id1 != "s:ended:100" || id2 != "s:ended:200" {+ t.Fatalf("ended ids = %q,%q, want s:ended:100, s:ended:200", id1, id2)+ }+}+func TestMapSessionNonTerminalHasNoEnded(t *testing.T) {s := Session{SessionID: "sess2", Status: "working", UserID: "u", CreatedAt: 10}mapped := MapSession(s, nil)diff --git a/cli/beacon/internal/devincloud/pull.go b/cli/beacon/internal/devincloud/pull.goindex 1e7e4417..b9b9cc49 100644--- a/cli/beacon/internal/devincloud/pull.go+++ b/cli/beacon/internal/devincloud/pull.go@@ -41,14 +41,22 @@ type Summary struct {// PullOnce performs one sweep: list sessions, fetch messages for changed// sessions, map to Beacon events, emit new ones (print/write), and upload each// changed session's full snapshot. State makes it idempotent across runs.-func PullOnce(ctx context.Context, client *Client, opts PullOptions) (Summary, error) {- var sum Summary-+func PullOnce(ctx context.Context, client *Client, opts PullOptions) (sum Summary, err error) {state, err := LoadState(opts.StatePath)if err != nil {return sum, fmt.Errorf("load state: %w", err)}+ // Persist dedup progress no matter how we return. Events are appended to the+ // runtime log as each session is processed, so if a later session errors we+ // must still save the progress made — otherwise the next sweep re-emits+ // already-written events and duplicates log lines.+ defer func() {+ if saveErr := state.Save(opts.StatePath); saveErr != nil && err == nil {+ err = fmt.Errorf("save state: %w", saveErr)+ }+ }()+sessions, err := client.ListSessions(ctx)if err != nil {return sum, err@@ -99,14 +107,14 @@ func PullOnce(ctx context.Context, client *Client, opts PullOptions) (Summary, ess.UpdatedAt = s.UpdatedAtss.Status = s.Status- if IsFinal(s.Status) && ss.Emitted[s.SessionID+":ended"] {+ // A final session (finished/expired) can never resume, and its ended+ // event was emitted in this sweep, so stop polling it. Suspended stays+ // pollable in case it resumes.+ if IsFinal(s.Status) {ss.Done = true}}- if err := state.Save(opts.StatePath); err != nil {- return sum, fmt.Errorf("save state: %w", err)- }return sum, nil}diff --git a/cli/beacon/internal/devincloud/pull_test.go b/cli/beacon/internal/devincloud/pull_test.goindex 0ee0d1fb..9ee6b6b7 100644--- a/cli/beacon/internal/devincloud/pull_test.go+++ b/cli/beacon/internal/devincloud/pull_test.go@@ -2,6 +2,8 @@ package devincloudimport ("context"+ "net/http"+ "net/http/httptest""os""path/filepath""strings"@@ -124,6 +126,53 @@ func TestPullOnceDedupsAcrossRuns(t *testing.T) {}}+func TestPullOncePersistsStateOnError(t *testing.T) {+ dir := t.TempDir()+ logPath := filepath.Join(dir, "runtime.jsonl")+ statePath := filepath.Join(dir, "state.json")++ var s2Calls int+ mux := http.NewServeMux()+ mux.HandleFunc("/v3/organizations/"+testOrg+"/sessions", func(w http.ResponseWriter, _ *http.Request) {+ _, _ = w.Write([]byte(`{"items":[+ {"session_id":"s1","status":"suspended","user_id":"u","created_at":10,"updated_at":20},+ {"session_id":"s2","status":"suspended","user_id":"u","created_at":10,"updated_at":20}+ ],"has_next_page":false,"total":2}`))+ })+ mux.HandleFunc("/v3/organizations/"+testOrg+"/sessions/s1/messages", func(w http.ResponseWriter, _ *http.Request) {+ _, _ = w.Write([]byte(`{"items":[{"event_id":"e1","source":"user","message":"hi","created_at":10}],"has_next_page":false}`))+ })+ mux.HandleFunc("/v3/organizations/"+testOrg+"/sessions/s2/messages", func(w http.ResponseWriter, _ *http.Request) {+ s2Calls+++ if s2Calls == 1 {+ http.Error(w, `{"detail":"boom"}`, http.StatusInternalServerError)+ return+ }+ _, _ = w.Write([]byte(`{"items":[{"event_id":"e2","source":"user","message":"yo","created_at":10}],"has_next_page":false}`))+ })+ srv := httptest.NewServer(mux)+ defer srv.Close()+ client := New(testOrg, "cog_test", WithBaseURL(srv.URL), WithRetry(0, 0))++ opts := PullOptions{Write: true, LogPath: logPath, StatePath: statePath}++ // First sweep: s1 succeeds and is written; s2 errors -> PullOnce returns error.+ if _, err := PullOnce(context.Background(), client, opts); err == nil {+ t.Fatal("expected error from failing session")+ }+ afterFirst := len(nonEmptyLines(t, logPath)) // s1: started + prompt + ended = 3++ // Second sweep: s1 must be skipped (state persisted), s2 now succeeds.+ if _, err := PullOnce(context.Background(), client, opts); err != nil {+ t.Fatalf("second sweep: %v", err)+ }+ total := len(nonEmptyLines(t, logPath))+ added := total - afterFirst+ if added != 3 { // only s2's started + prompt + ended; s1 not re-emitted+ t.Fatalf("second sweep added %d lines, want 3 (s1 not duplicated)", added)+ }+}+func nonEmptyLines(t *testing.T, path string) []string {t.Helper()data, err := os.ReadFile(path)