The State Store, event capture and Gateway conversations already serve from PostgreSQL. This deletes internal/store and internal/infrastructure/edastore, the SQLite gateway session store and openProductionTaskStore, and the -db recovery path on a legacy task file; backup, restore, validate and rollback work on the database database_url names. - The binding-secret cipher moves to internal/infrastructure/bindingcipher and ToolCall to internal/infrastructure/postgres. - NewSessionStoreMemory is now a pure in-memory store that passes the shared SessionStore conformance suite. - Tests run against PostgreSQL through internal/infrastructure/postgres/pgstore; legacyimport/legacyfixture writes the legacy files the import and the boot gate read. - The cron dialect is owned in internal/domain/scheduling, so github.com/pocketbase/pocketbase and pocketbase/dbx leave go.mod. modernc.org/sqlite stays for the one-time import (legacyread). - The UI and Messaging architecture gates ban the Postgres and legacy readers in place of internal/store.
70 lines
2.8 KiB
Go
70 lines
2.8 KiB
Go
package controlplane
|
|
|
|
import (
|
|
"context"
|
|
"encoding/json"
|
|
"errors"
|
|
"fmt"
|
|
"time"
|
|
|
|
"github.com/samcharles93/archie-core/internal/config"
|
|
"github.com/samcharles93/archie-core/internal/domain/storecontract"
|
|
"github.com/samcharles93/archie-core/internal/domain/workflow"
|
|
)
|
|
|
|
const WorkflowExecutionSettingsKind = "workflow-execution-settings"
|
|
|
|
type executionSettingsDocument struct {
|
|
MaxModelToolSteps int `json:"max_model_tool_steps"`
|
|
MaxRuntimeSeconds int64 `json:"max_runtime_seconds"`
|
|
MaxConsecutiveGateFailures int `json:"max_consecutive_gate_failures"`
|
|
}
|
|
|
|
// ImportWorkflowExecutionSettings preserves the focused bootstrap API for callers
|
|
// that do not own the complete legacy configuration document.
|
|
func (s *Server) ImportWorkflowExecutionSettings(ctx context.Context, settings workflow.ExecutionSettings) (int64, error) {
|
|
resource, err := s.store.Resource(ctx, WorkflowExecutionSettingsKind)
|
|
if err == nil {
|
|
return resource.Version, nil
|
|
}
|
|
if !errors.Is(err, storecontract.ErrResourceNotFound) {
|
|
return 0, err
|
|
}
|
|
value, err := encodeSettings(settings)
|
|
if err != nil {
|
|
return 0, err
|
|
}
|
|
value, err = workflowDefinition().Decode(value)
|
|
if err != nil {
|
|
return 0, err
|
|
}
|
|
resource, err = s.store.PutResource(ctx, storecontract.ResourceWrite{Kind: WorkflowExecutionSettingsKind, Value: value, Actor: "system:migration", Source: "legacy-config", RequestID: "import:" + WorkflowExecutionSettingsKind, ExpectedVersion: 0, At: time.Now().UTC()})
|
|
return resource.Version, err
|
|
}
|
|
|
|
func workflowDefinition() Definition {
|
|
return Definition{
|
|
Kind: WorkflowExecutionSettingsKind, Title: "Workflow execution settings", ApplyMode: "live", Document: executionSettingsDocument{},
|
|
Seed: func(cfg config.Config) any {
|
|
return executionSettingsDocument{cfg.Budgets.MaxSteps, int64(time.Duration(cfg.Budgets.WallClock) / time.Second), cfg.Budgets.GateMaxFailures}
|
|
},
|
|
Validate: func(input []byte) error { _, err := decodeSettings(input); return err },
|
|
}
|
|
}
|
|
|
|
func encodeSettings(s workflow.ExecutionSettings) ([]byte, error) {
|
|
return json.Marshal(executionSettingsDocument{s.MaxModelToolSteps, int64(s.MaxRuntime / time.Second), s.MaxConsecutiveGateFailures})
|
|
}
|
|
|
|
func decodeSettings(value []byte) (workflow.ExecutionSettings, error) {
|
|
var document executionSettingsDocument
|
|
if err := json.Unmarshal(value, &document); err != nil {
|
|
return workflow.ExecutionSettings{}, fmt.Errorf("%w: invalid JSON: %w", ErrValidation, err)
|
|
}
|
|
settings := workflow.ExecutionSettings{MaxModelToolSteps: document.MaxModelToolSteps, MaxRuntime: time.Duration(document.MaxRuntimeSeconds) * time.Second, MaxConsecutiveGateFailures: document.MaxConsecutiveGateFailures}
|
|
if err := settings.Validate(); err != nil {
|
|
return workflow.ExecutionSettings{}, fmt.Errorf("%w: %w", ErrValidation, err)
|
|
}
|
|
return settings, nil
|
|
}
|