Skip to the content.

Task 69 — PostgreSQL shared state backend

Phase: 4 Initiative: 29 Status: done Owner: — Slug: postgres-shared-state

Goal

Опциональный PostgreSQL state store хранит cross-agent workflow state, shared skill registry, evaluation records и audit logs. Job-очереди используют SELECT … FOR UPDATE SKIP LOCKED для умеренно-throughput исполнения. Бэкенд активируется профилем, не обязателен.

Acceptance criteria

Sub-tasks

Scope / Likely files

src/agent/Mesh/Backends/Postgres/PostgresMeshConfig.cs, src/agent/Mesh/Backends/Postgres/PostgresMeshStateStore.cs, src/agent/Mesh/Backends/Postgres/PostgresTaskQueue.cs, src/agent/Mesh/Backends/Postgres/PostgresMeshBus.cs

Dependencies

Implementation notes

2026-08-14

Mesh/Backends/Postgres/PostgresMeshConfig.cs — 14 properties: Enabled, ConnectionString (Npgsql format), Schema (“hercules_mesh”), StateTable (“state”), TasksTable (“tasks”), DlqTable (“tasks_dlq”), ChannelPrefix (“hercules_bus_”), DefaultTtlSeconds (3600), DefaultVisibilityTimeoutSec (30), MaxDeliveryAttempts (3), UseListenNotify (true), WatchPollingIntervalMs (500), ConnectTimeoutSeconds (5), AutoCreateSchema (true), RequeueTimerIntervalMs (1000).

Mesh/Backends/Postgres/PostgresMeshStateStore.cs — IMeshStateStore over PostgreSQL JSONB:

Mesh/Backends/Postgres/PostgresTaskQueue.cs — ITaskQueue with SELECT FOR UPDATE SKIP LOCKED:

Mesh/Backends/Postgres/PostgresMeshBus.cs — IMeshBus over LISTEN/NOTIFY:

Config/AppConfig.cs — added Postgres property of type PostgresMeshConfig.

Mesh/MeshServiceExtensions.cs — extended RegisterMeshBackends to add the Postgres branch:

Hercules.csproj — added Npgsql 8.0.5 package.

Tests (tests/Hercules.Agent.Tests/Mesh/Backends/):

Validation:

Risks / Rollback

Operational overhead БД; миграции, бэкапы, connection pooling; чёткие runbooks.