Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
openclaw: expose mysql state initialization toggle
  • Loading branch information
XnLemon committed Aug 13, 2026
commit c333e6e2f3a377d8331b60b11be71b3b74d2e88f
8 changes: 8 additions & 0 deletions openclaw/INTEGRATIONS.md
Original file line number Diff line number Diff line change
Expand Up @@ -514,6 +514,13 @@ Common config fields:
- `skip_db_init`: set true if your DB schema is pre-created
- `table_prefix`: optional prefix for table names

MySQL also accepts `state_initialization`, which defaults to `true`. Set it to
`false` only while staging the coordinated state-initialization schema
migration. This temporarily avoids the lease table and keeps lenient anonymous
A2A on its per-agent fallback; strict coordination remains fail-closed. Re-enable
it after the lease table, indexes, and `session_states.created_at TIMESTAMP(6)`
Comment thread
XnLemon marked this conversation as resolved.
Resolved
are available to every instance.

MySQL example:

```yaml
Expand All @@ -522,6 +529,7 @@ session:
config:
dsn: "user:pass@tcp(127.0.0.1:3306)/openclaw"
skip_db_init: false
state_initialization: true
table_prefix: "oc_"
```

Expand Down
15 changes: 13 additions & 2 deletions openclaw/app/sql_backends.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,16 @@ type sqlSessionConfig struct {
TablePref string `yaml:"table_prefix,omitempty"`
}

type mysqlSessionConfig struct {
sqlSessionConfig `yaml:",inline"`
StateInitialization *bool `yaml:"state_initialization,omitempty"`
}

func newMySQLSessionBackend(
deps registry.SessionDeps,
spec registry.SessionBackendSpec,
) (session.Service, error) {
var cfg sqlSessionConfig
var cfg mysqlSessionConfig
if err := registry.DecodeStrict(spec.Config, &cfg); err != nil {
return nil, err
}
Expand All @@ -51,7 +56,7 @@ func newMySQLSessionBackend(
)
}

opts := make([]sessionmysql.ServiceOpt, 0, 4)
opts := make([]sessionmysql.ServiceOpt, 0, 5)
if dsn != "" {
opts = append(opts, sessionmysql.WithMySQLClientDSN(dsn))
} else {
Expand All @@ -63,6 +68,12 @@ func newMySQLSessionBackend(
if cfg.SkipDBInit {
opts = append(opts, sessionmysql.WithSkipDBInit(true))
}
if cfg.StateInitialization != nil {
opts = append(
opts,
sessionmysql.WithStateInitialization(*cfg.StateInitialization),
)
}
if pref := strings.TrimSpace(cfg.TablePref); pref != "" {
opts = append(opts, sessionmysql.WithTablePrefix(pref))
}
Expand Down
30 changes: 30 additions & 0 deletions openclaw/app/sql_backends_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,28 @@ func TestNewMySQLSessionBackend_MissingConfigFails(t *testing.T) {
require.Contains(t, err.Error(), "requires dsn or instance")
}

func TestNewMySQLSessionBackend_StateInitializationDefaultsEnabled(
t *testing.T,
) {
_, restore := stubMySQLBuilder(t)
defer restore()

cfg := yamlNode(t, `
dsn: "mysql://demo"
skip_db_init: true
`)
svc, err := newMySQLSessionBackend(
registry.SessionDeps{},
registry.SessionBackendSpec{Config: cfg},
)
require.Nil(t, svc)
require.ErrorContains(
t,
err,
"verify state initialization schema failed",
)
}

func TestNewPostgresSessionBackend_MissingConfigFails(t *testing.T) {
t.Parallel()

Expand Down Expand Up @@ -211,6 +233,7 @@ func TestNewMySQLSessionBackend_WithDSNSucceeds(t *testing.T) {
cfg := yamlNode(t, `
dsn: "mysql://demo"
skip_db_init: true
state_initialization: false
table_prefix: "x_"
`)
svc, err := newMySQLSessionBackend(
Expand All @@ -220,6 +243,9 @@ table_prefix: "x_"
require.NoError(t, err)
require.NotNil(t, svc)
require.Equal(t, "mysql://demo", gotDSN)
availability, ok := svc.(session.StateInitializationAvailability)
require.True(t, ok)
require.False(t, availability.StateInitializationAvailable())
require.NoError(t, svc.Close())
}

Expand Down Expand Up @@ -250,6 +276,7 @@ func TestNewMySQLSessionBackend_WithInstanceSucceeds(t *testing.T) {
cfg := yamlNode(t, `
instance: "`+instanceName+`"
skip_db_init: true
state_initialization: false
`)
svc, err := newMySQLSessionBackend(
registry.SessionDeps{},
Expand All @@ -258,6 +285,9 @@ skip_db_init: true
require.NoError(t, err)
require.NotNil(t, svc)
require.Equal(t, instanceDSN, gotDSN)
availability, ok := svc.(session.StateInitializationAvailability)
require.True(t, ok)
require.False(t, availability.StateInitializationAvailable())
require.NoError(t, svc.Close())
}

Expand Down