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(cloud): keep one upload position per sandbox log, not per run id
shukieshahdd389e149f1d
diff --git a/cli/beacon-hooks/internal/cloudshuttle/asymptote.go b/cli/beacon-hooks/internal/cloudshuttle/asymptote.goindex 12fa6a8e..653508a3 100644--- a/cli/beacon-hooks/internal/cloudshuttle/asymptote.go+++ b/cli/beacon-hooks/internal/cloudshuttle/asymptote.go@@ -62,7 +62,9 @@ func asymptoteConfigured(cfg Config) bool {// shuttle state. `snapshot` is a consistent copy of the log; `size` its length.func uploadAsymptoteIncremental(ctx context.Context, cfg Config, snapshot string, size int64) error {offset := int64(0)- if st, err := readState(cfg.StatePath); err == nil && st.Provider == cfg.Provider && st.RunID == cfg.RunID && st.LastSize > 0 && st.LastSize <= size {+ // The position belongs to the log, not the run id, for the reason stateObjectMatchesConfig gives:+ // keyed by run id, every switch between a Cursor agent and its subagent resent the whole log.+ if st, err := readState(cfg.StatePath); err == nil && st.Provider == cfg.Provider && st.LastSize > 0 && st.LastSize <= size {offset = st.LastSize}if offset >= size {diff --git a/cli/beacon-hooks/internal/cloudshuttle/asymptote_test.go b/cli/beacon-hooks/internal/cloudshuttle/asymptote_test.goindex 8d1e334f..768c97ba 100644--- a/cli/beacon-hooks/internal/cloudshuttle/asymptote_test.go+++ b/cli/beacon-hooks/internal/cloudshuttle/asymptote_test.go@@ -245,3 +245,34 @@ func TestSessionStartShipsALogWhoseRunNeverUploaded(t *testing.T) {t.Fatalf("no .previous-* copy should be left behind: %v", matches)}}++// The agent and its Cursor subagent take turns uploading one log under different run ids. Each+// upload sends only the lines no upload has sent yet.+func TestManagedUploadDoesNotResendWhenTheConversationChanges(t *testing.T) {+ server, calls := startFakeIngest(t, 200)+ cfg := asymptoteConfig(t, server)+ cfg.Provider = "cursor_cloud"+ cfg.RunID = "bc-89723c38-a074-4c36-98cc-95e9da5f8dd3"+ subagent := cfg+ subagent.RunID = "bc-80383700-254c-5f11-8bff-de4e1cd943c0"++ appendLines(t, cfg.LogPath, `{"event":1}`, `{"event":2}`)+ if err := Upload(context.Background(), cfg, true); err != nil {+ t.Fatal(err)+ }+ appendLines(t, cfg.LogPath, `{"event":3}`)+ if err := Upload(context.Background(), subagent, true); err != nil {+ t.Fatal(err)+ }+ appendLines(t, cfg.LogPath, `{"event":4}`)+ if err := Upload(context.Background(), cfg, true); err != nil {+ t.Fatal(err)+ }+ var sent []string+ for _, call := range *calls {+ sent = append(sent, call.lines...)+ }+ if got := strings.Join(sent, "|"); got != `{"event":1}|{"event":2}|{"event":3}|{"event":4}` {+ t.Fatalf("lines sent = %s, want each line once", got)+ }+}diff --git a/cli/beacon-hooks/internal/cloudshuttle/shuttle.go b/cli/beacon-hooks/internal/cloudshuttle/shuttle.goindex bfc0dcb5..20ba16b0 100644--- a/cli/beacon-hooks/internal/cloudshuttle/shuttle.go+++ b/cli/beacon-hooks/internal/cloudshuttle/shuttle.go@@ -229,13 +229,21 @@ func uploadObjectName(cfg Config) string {return ObjectName(cfg)}+// stateObjectMatchesConfig reports whether the state's object is this log's, so the upload rewrites+// it rather than starting another.+//+// The state follows the log, not the run id. A sandbox runs one agent, and a new run in it starts at+// a session start, which removes the log and the state (ResetFromEnv). Within a run the run id can+// still change: Cursor gives each subagent a conversation id of its own, and BEACON_RUN_ID is seeded+// from the conversation id of each hook. Matching the run id started a new object, holding the whole+// log again, every time the agent and a subagent took turns.func stateObjectMatchesConfig(st state, cfg Config) bool {objectName := strings.TrimSpace(st.LastObject)if objectName == "" {return false}if st.Provider != "" || st.RunID != "" {- return st.Provider == cfg.Provider && st.RunID == cfg.RunID+ return st.Provider == cfg.Provider}provider := objectkey.CleanPart(defaultString(cfg.Provider, "unknown"))runID := objectkey.CleanPart(defaultString(cfg.RunID, "unknown"))diff --git a/cli/beacon-hooks/internal/cloudshuttle/shuttle_test.go b/cli/beacon-hooks/internal/cloudshuttle/shuttle_test.goindex 2098bd39..7f259765 100644--- a/cli/beacon-hooks/internal/cloudshuttle/shuttle_test.go+++ b/cli/beacon-hooks/internal/cloudshuttle/shuttle_test.go@@ -12,6 +12,7 @@ import ("encoding/hex""encoding/json""encoding/pem"+ "fmt""io""net/http""net/http/httptest"@@ -493,3 +494,50 @@ func pemKey(t *testing.T, key *rsa.PrivateKey) string {}return string(pem.EncodeToMemory(&pem.Block{Type: "PRIVATE KEY", Bytes: data}))}++// A Cursor subagent reports a conversation id of its own, which becomes the run id of its hooks.+// The agent and its subagent share one sandbox log, so they must keep rewriting one object.+func TestUploadKeepsOneObjectWhenTheConversationChanges(t *testing.T) {+ current := time.Date(2026, 11, 13, 21, 5, 36, 0, time.UTC)+ restore := stubNowFunc(t, func() time.Time { return current })+ defer restore()+ var uploadedPaths []string+ server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {+ uploadedPaths = append(uploadedPaths, r.URL.EscapedPath())+ w.WriteHeader(http.StatusOK)+ }))+ defer server.Close()++ dir := t.TempDir()+ logPath := filepath.Join(dir, "runtime.jsonl")+ cfg := Config{+ Upload: uploadS3,+ LogPath: logPath,+ StatePath: filepath.Join(dir, "state.json"),+ Bucket: "bucket",+ Prefix: "prefix",+ Provider: "cursor_cloud",+ RunID: "bc-89723c38-a074-4c36-98cc-95e9da5f8dd3",+ S3Region: "us-west-2",+ S3AccessKeyID: "AKIATEST",+ S3SecretKey: "secret",+ S3Endpoint: server.URL,+ }+ for i, runID := range []string{cfg.RunID, "bc-80383700-254c-5f11-8bff-de4e1cd943c0", cfg.RunID} {+ appendLines(t, logPath, fmt.Sprintf(`{"event":%d}`, i))+ next := cfg+ next.RunID = runID+ current = current.Add(time.Minute)+ if err := Upload(context.Background(), next, true); err != nil {+ t.Fatalf("Upload %d returned error: %v", i, err)+ }+ }+ if len(uploadedPaths) != 3 {+ t.Fatalf("uploaded paths = %v, want 3 uploads", uploadedPaths)+ }+ for _, p := range uploadedPaths[1:] {+ if p != uploadedPaths[0] {+ t.Fatalf("a subagent's upload started another object: %v", uploadedPaths)+ }+ }+}