Files
tutti/packages/agent/store-sqlite/migrations_goal_state_v4.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

52 lines
1.8 KiB
Go

package storesqlite
import (
"context"
"fmt"
)
// V4 preserves the first provider acceptance time and its attempt baseline so
// repeated safe clear retries cannot extend the convergence deadline forever.
func (s *Store) applyWorkspaceAgentGoalStateV4(ctx context.Context) error {
applied, err := s.hasMigration(ctx, schemaMigrationWorkspaceAgentGoalStateV4)
if err != nil || applied {
return err
}
tx, err := s.db.BeginTx(ctx, nil)
if err != nil {
return err
}
defer func() { _ = tx.Rollback() }()
for _, column := range []struct{ name, ddl string }{
{"accepted_at_unix_ms", `ALTER TABLE workspace_agent_goal_control_operations ADD COLUMN accepted_at_unix_ms INTEGER`},
{"accepted_attempt", `ALTER TABLE workspace_agent_goal_control_operations ADD COLUMN accepted_attempt INTEGER NOT NULL DEFAULT 0`},
} {
exists, columnErr := hasColumnTx(ctx, tx, "workspace_agent_goal_control_operations", column.name)
if columnErr != nil {
return columnErr
}
if !exists {
if _, columnErr = tx.ExecContext(ctx, column.ddl); columnErr != nil {
return fmt.Errorf("add goal accepted column %s: %w", column.name, columnErr)
}
}
}
if _, err = tx.ExecContext(ctx, `UPDATE workspace_agent_goal_control_operations
SET accepted_at_unix_ms = CASE
WHEN accepted_at_unix_ms IS NULL OR accepted_at_unix_ms = 0 THEN updated_at_unix_ms
ELSE accepted_at_unix_ms
END,
accepted_attempt = CASE
WHEN accepted_attempt = 0 THEN attempt
ELSE accepted_attempt
END
WHERE provider_phase = 'accepted'
AND (accepted_at_unix_ms IS NULL OR accepted_at_unix_ms = 0 OR accepted_attempt = 0)`); err != nil {
return fmt.Errorf("backfill accepted goal operation baseline: %w", err)
}
if err = recordMigrationTx(ctx, tx, schemaMigrationWorkspaceAgentGoalStateV4); err != nil {
return err
}
return tx.Commit()
}