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
Address cloud shuttle review findings
shukieshahbc9ecae31849
diff --git a/cli/beacon-hooks/cmd/endpoint_events.go b/cli/beacon-hooks/cmd/endpoint_events.goindex 20d7969c..c6b1c9ae 100644--- a/cli/beacon-hooks/cmd/endpoint_events.go+++ b/cli/beacon-hooks/cmd/endpoint_events.go@@ -42,7 +42,9 @@ func emitHookEvent(logger *logging.Logger, action, category, severity, message sif err := logger.EndpointEvent(action, category, severity, message, fields); err != nil {logger.Error("Failed to write endpoint event", "error", err.Error(), "action", action)}- uploadCloudTelemetry(logger, false)+ if !isFinalUploadAction(action) {+ uploadCloudTelemetry(logger, false)+ }}func uploadCloudTelemetry(logger *logging.Logger, force bool) {@@ -53,6 +55,15 @@ func uploadCloudTelemetry(logger *logging.Logger, force bool) {}}+func isFinalUploadAction(action string) bool {+ switch action {+ case "tool.completed", "session.ended":+ return true+ default:+ return false+ }+}+func sessionFields(sessionID string, input map[string]interface{}) map[string]interface{} {fields := map[string]interface{}{}session := map[string]interface{}{}diff --git a/cli/beacon-hooks/internal/cloudshuttle/shuttle.go b/cli/beacon-hooks/internal/cloudshuttle/shuttle.goindex a9fba054..8d0261bd 100644--- a/cli/beacon-hooks/internal/cloudshuttle/shuttle.go+++ b/cli/beacon-hooks/internal/cloudshuttle/shuttle.go@@ -59,6 +59,7 @@ type serviceAccount struct {type state struct {LastUpload string `json:"last_upload,omitempty"`LastSize int64 `json:"last_size,omitempty"`+ LastObject string `json:"last_object,omitempty"`}type tokenResponse struct {@@ -85,7 +86,7 @@ func ConfigFromEnv() Config {CredentialsB64: strings.TrimSpace(os.Getenv("BEACON_CLOUD_GCS_CREDENTIALS_B64")),Interval: interval,Provider: firstEnvDefault("claude_code_web", "BEACON_RUN_PROVIDER"),- RunID: firstEnvDefault(stableFallbackRunID(statePath), "BEACON_RUN_ID", "CLAUDE_CODE_REMOTE_SESSION_ID"),+ RunID: resolveRunID(statePath),UserID: firstEnvDefault("unknown", "BEACON_CLOUD_USER_ID_HASH", "BEACON_CLOUD_USER_ID"),Repository: firstEnv("BEACON_RUN_REPOSITORY"),GCSEndpoint: firstEnvDefault(defaultGCSEndpoint, "BEACON_CLOUD_GCS_ENDPOINT"),@@ -101,7 +102,10 @@ func ResetFromEnv() error {if strings.TrimSpace(os.Getenv("BEACON_ORIGIN")) != "cloud" {return nil}- for _, path := range []string{cfg.LogPath, cfg.LogPath + ".lock", cfg.StatePath, cfg.StatePath + ".run-id"} {+ if err := preserveExistingLog(cfg); err != nil {+ return err+ }+ for _, path := range []string{cfg.LogPath + ".lock", cfg.StatePath, cfg.StatePath + ".run-id"} {if path == "" {continue}@@ -109,6 +113,14 @@ func ResetFromEnv() error {return err}}+ if cfg.Interval > 0 {+ if err := writeState(cfg.StatePath, state{+ LastUpload: time.Now().UTC().Format(time.RFC3339),+ LastSize: 0,+ }); err != nil {+ return err+ }+ }return nil}@@ -154,6 +166,7 @@ func Upload(ctx context.Context, cfg Config, force bool) error {return writeState(cfg.StatePath, state{LastUpload: time.Now().UTC().Format(time.RFC3339),LastSize: info.Size(),+ LastObject: objectName,})}@@ -202,7 +215,11 @@ func snapshotLog(logPath string) (string, func(), error) {return "", func() {}, err}defer syscall.Flock(int(lock.Fd()), syscall.LOCK_UN)- defer lock.Close()+ defer func() {+ if err := lock.Close(); err != nil {+ fmt.Fprintf(os.Stderr, "cloudshuttle: failed to close lock file %s.lock: %v\n", logPath, err)+ }+ }()source, err := os.Open(logPath)if err != nil {@@ -381,6 +398,44 @@ func writeState(path string, st state) error {return os.WriteFile(path, data, 0644)}+func preserveExistingLog(cfg Config) error {+ info, err := os.Stat(cfg.LogPath)+ if err != nil {+ if os.IsNotExist(err) {+ return nil+ }+ return err+ }+ if info.Size() == 0 {+ return os.Remove(cfg.LogPath)+ }+ if st, err := readState(cfg.StatePath); err == nil && st.LastObject != "" && cfg.Bucket != "" && cfg.CredentialsB64 != "" {+ snapshot, cleanup, err := snapshotLog(cfg.LogPath)+ if err == nil {+ defer cleanup()+ ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)+ defer cancel()+ if token, tokenErr := accessToken(ctx, cfg.CredentialsB64); tokenErr == nil {+ if uploadErr := uploadObject(ctx, cfg.GCSEndpoint, cfg.Bucket, st.LastObject, snapshot, token); uploadErr == nil {+ return os.Remove(cfg.LogPath)+ }+ }+ }+ }+ preservedPath := fmt.Sprintf("%s.previous-%d", cfg.LogPath, time.Now().UTC().UnixNano())+ if err := os.Rename(cfg.LogPath, preservedPath); err != nil && !os.IsNotExist(err) {+ return err+ }+ return nil+}++func resolveRunID(statePath string) string {+ if runID := firstEnv("BEACON_RUN_ID", "CLAUDE_CODE_REMOTE_SESSION_ID"); runID != "" {+ return runID+ }+ return stableFallbackRunID(statePath)+}+func stableFallbackRunID(statePath string) string {path := statePath + ".run-id"if data, err := os.ReadFile(path); err == nil {diff --git a/cli/beacon-hooks/internal/cloudshuttle/shuttle_test.go b/cli/beacon-hooks/internal/cloudshuttle/shuttle_test.goindex 013c42b2..a9c6a8a5 100644--- a/cli/beacon-hooks/internal/cloudshuttle/shuttle_test.go+++ b/cli/beacon-hooks/internal/cloudshuttle/shuttle_test.go@@ -58,11 +58,14 @@ func TestResetFromEnvRemovesCloudRuntimeFiles(t *testing.T) {if err := ResetFromEnv(); err != nil {t.Fatalf("ResetFromEnv returned error: %v", err)}- for _, path := range []string{logPath, logPath + ".lock", statePath, statePath + ".run-id"} {+ for _, path := range []string{logPath, logPath + ".lock", statePath + ".run-id"} {if _, err := os.Stat(path); !os.IsNotExist(err) {t.Fatalf("%s still exists, stat err=%v", path, err)}}+ if _, err := os.Stat(statePath); err != nil {+ t.Fatalf("state path should be recreated to throttle first periodic upload: %v", err)+ }}func TestUploadSendsJSONLToGCS(t *testing.T) {@@ -150,6 +153,17 @@ func TestStableFallbackRunIDReusesGeneratedValue(t *testing.T) {}}+func TestResolveRunIDPrefersEnvironmentWithoutFallbackSideEffect(t *testing.T) {+ statePath := filepath.Join(t.TempDir(), "shuttle-state.json")+ t.Setenv("CLAUDE_CODE_REMOTE_SESSION_ID", "cse_env")+ if got := resolveRunID(statePath); got != "cse_env" {+ t.Fatalf("resolveRunID = %q, want cse_env", got)+ }+ if _, err := os.Stat(statePath + ".run-id"); !os.IsNotExist(err) {+ t.Fatalf("fallback run-id file should not be created when env run id exists: %v", err)+ }+}+func mustRSAKey(t *testing.T) *rsa.PrivateKey {t.Helper()key, err := rsa.GenerateKey(rand.Reader, 2048)diff --git a/cli/beacon-hooks/internal/logging/logging.go b/cli/beacon-hooks/internal/logging/logging.goindex d9a37551..b03d8b01 100644--- a/cli/beacon-hooks/internal/logging/logging.go+++ b/cli/beacon-hooks/internal/logging/logging.go@@ -233,7 +233,7 @@ func writeEndpointJSON(path string, event map[string]interface{}) error {}func endpointLogPath() string {- if path := os.Getenv("BEACON_ENDPOINT_LOG"); path != "" {+ if path := firstEnv("BEACON_ENDPOINT_LOG", "BEACON_CLOUD_LOG_PATH", "BEACON_LOG_PATH", "BEACON_RUNTIME_LOG"); path != "" {return path}if os.Getenv("BEACON_ENDPOINT_MODE") == "" {