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
Re-upload sessions when GCS is enabled after a local-only sync
shukieshah3cff6356c7af
diff --git a/cli/beacon/internal/devincloud/pull.go b/cli/beacon/internal/devincloud/pull.goindex b42d8cb7..c8f509e3 100644--- a/cli/beacon/internal/devincloud/pull.go+++ b/cli/beacon/internal/devincloud/pull.go@@ -77,12 +77,15 @@ func PullOnce(ctx context.Context, client *Client, opts PullOptions) (sum Summar// Skip sessions already finalized, or unchanged since the last sweep.// "Unchanged" relies on updated_at as the session's last-modified signal// (new messages bump it); --full-resync (ForceRefresh) bypasses both- // skips when that assumption can't be trusted or for a backfill.+ // skips when that assumption can't be trusted or for a backfill. A session+ // whose snapshot still needs uploading (e.g. upload was disabled on an+ // earlier run and is now enabled) is never skipped on the upload account.if !opts.ForceRefresh {- if ss.Done {+ uploadSatisfied := opts.Upload == nil || ss.UploadedAt == s.UpdatedAt+ if ss.Done && uploadSatisfied {continue}- if _, seen := state.Sessions[s.SessionID]; seen && ss.UpdatedAt == s.UpdatedAt && ss.Status == s.Status && len(ss.Emitted) > 0 {+ if _, seen := state.Sessions[s.SessionID]; seen && ss.UpdatedAt == s.UpdatedAt && ss.Status == s.Status && len(ss.Emitted) > 0 && uploadSatisfied {continue}}@@ -160,6 +163,7 @@ func processSession(ctx context.Context, client *Client, s Session, ss *SessionSif err := opts.Upload.Upload(ctx, obj, data); err != nil {return fmt.Errorf("upload: %w", err)}+ ss.UploadedAt = s.UpdatedAtsum.Uploaded++}diff --git a/cli/beacon/internal/devincloud/pull_test.go b/cli/beacon/internal/devincloud/pull_test.goindex ea9fea31..f9e2adcd 100644--- a/cli/beacon/internal/devincloud/pull_test.go+++ b/cli/beacon/internal/devincloud/pull_test.go@@ -25,6 +25,40 @@ func (f *fakeUploader) Upload(_ context.Context, objectName string, data []byte)return nil}+func TestUploadEnabledLaterStillUploads(t *testing.T) {+ dir := t.TempDir()+ logPath := filepath.Join(dir, "runtime.jsonl")+ statePath := filepath.Join(dir, "state.json")+ client := pullTestServer(t)++ // First sweep with upload disabled: local sync only.+ if _, err := PullOnce(context.Background(), client, PullOptions{Write: true, LogPath: logPath, StatePath: statePath}); err != nil {+ t.Fatalf("first (no upload): %v", err)+ }++ // Second sweep, session unchanged, upload now enabled: must NOT be skipped.+ up := &fakeUploader{}+ if _, err := PullOnce(context.Background(), client, PullOptions{+ Write: true, LogPath: logPath, StatePath: statePath, Upload: up, UploadPrefix: "agent-traces",+ }); err != nil {+ t.Fatalf("second (upload on): %v", err)+ }+ if up.calls != 1 {+ t.Fatalf("expected unchanged session to upload once upload was enabled, got %d uploads", up.calls)+ }++ // Third sweep, still unchanged and already uploaded: now skipped (no re-upload).+ up2 := &fakeUploader{}+ if _, err := PullOnce(context.Background(), client, PullOptions{+ Write: true, LogPath: logPath, StatePath: statePath, Upload: up2, UploadPrefix: "agent-traces",+ }); err != nil {+ t.Fatalf("third: %v", err)+ }+ if up2.calls != 0 {+ t.Fatalf("expected no re-upload once UploadedAt matches updated_at, got %d", up2.calls)+ }+}+func pullTestServer(t *testing.T) *Client {srv := fakeDevinAPI(t, `{"items":[{"session_id":"s1","status":"suspended","user_id":"user-1","created_at":1000,"updated_at":1600,"acus_consumed":1}diff --git a/cli/beacon/internal/devincloud/state.go b/cli/beacon/internal/devincloud/state.goindex 007236f9..52c473a4 100644--- a/cli/beacon/internal/devincloud/state.go+++ b/cli/beacon/internal/devincloud/state.go@@ -18,6 +18,7 @@ type SessionState struct {Status string `json:"status"`Done bool `json:"done"` // final status; skip henceforthEndedEmitted bool `json:"ended_emitted"` // session.ended emitted for the current terminal episode+ UploadedAt int64 `json:"uploaded_at"` // updated_at at which this session's snapshot was last uploaded to GCSEmitted map[string]bool `json:"emitted"` // dedup ids for started + message events}