Files
tutti/services/tuttid/service/agent/deleted_session_resources.go
agent-radar 2ed3415fb7
Publish Claude Code Binaries / Stage and publish binaries (push) Canceled after 0s
Publish Tutti App Runtime / Build darwin-arm64 (push) Canceled after 0s
Publish Tutti App Runtime / Build darwin-amd64 (push) Canceled after 0s
Publish Tutti App Runtime / Build linux-amd64 (push) Canceled after 0s
Publish Tutti App Runtime / Build windows-amd64 (push) Canceled after 0s
Sync Tutti Agent Skills / sync (push) Canceled after 0s
Windows Agent Adapters / Test Windows agent adapters (push) Canceled after 0s
Windows Daemon Adapters / Test Windows daemon adapters (push) Canceled after 0s
Publish Tutti App Runtime / Publish runtime catalog (push) Canceled after 0s
源码快照 @ 2026-09-01 (source-only, 剔除非源码素材)
2026-09-01 20:17:27 +08:00

46 lines
1.6 KiB
Go

package agent
import (
"context"
"errors"
"strings"
)
// CleanupPurgedSessionResources removes Tutti-owned resources after the
// canonical tombstone has been permanently purged. Soft deletion deliberately
// does not call this path because the sidecar runtime root and prompt
// attachments are part of the recoverable Session state.
func (s *Service) CleanupPurgedSessionResources(
ctx context.Context,
workspaceID string,
agentSessionID string,
) error {
workspaceID = strings.TrimSpace(workspaceID)
agentSessionID = strings.TrimSpace(agentSessionID)
if s == nil || workspaceID == "" || agentSessionID == "" {
return ErrInvalidArgument
}
// Runtime roots and copied attachments are currently keyed only by Session
// ID, not Workspace. The durable cleanup queue globally fences ID reuse
// until cleanup completes; this all-Workspace check additionally protects
// IDs that were already shared before the queue row existed. Returning
// success retires the stale queue item without touching physical resources.
identityReader, ok := s.SessionReader.(GlobalAgentSessionIdentityReader)
if !ok {
return errors.New("global agent session identity reader is unavailable")
}
exists, err := identityReader.AgentSessionIDExists(ctx, agentSessionID)
if err != nil {
return err
}
if exists {
return nil
}
runtimeErr := s.cleanupSessionResources(ctx, workspaceID, agentSessionID)
var attachmentErr error
if strings.TrimSpace(s.PromptAttachmentStore.RootDir) != "" {
attachmentErr = s.PromptAttachmentStore.DeleteSessionAttachments(workspaceID, agentSessionID)
}
return errors.Join(runtimeErr, attachmentErr)
}