Skip to content

fix: propagate helm postgres pool variables to db connection - #3032

Merged
EItanya merged 5 commits into
kagent-dev:mainfrom
jcopi:jcopi/postgres-idle-connections
Oct 3, 2026
Merged

EItanya merged 5 commits into
kagent-dev:mainfrom
jcopi:jcopi/postgres-idle-connections

Conversation

@jcopi

@jcopi jcopi commented Oct 2, 2026

Copy link
Copy Markdown
Contributor

Use database pool environment variables rendered by the helm chart

{{- with .Values.database.postgres.pool }}
{{- if and (hasKey . "maxConns") (ne .maxConns nil) }}
DB_MAX_CONNS: {{ .maxConns | quote }}
{{- end }}
{{- if and (hasKey . "minConns") (ne .minConns nil) }}
DB_MIN_CONNS: {{ .minConns | quote }}
{{- end }}
{{- if .maxConnIdleTime }}
DB_MAX_CONN_IDLE_TIME: {{ .maxConnIdleTime | quote }}
{{- end }}
{{- if .maxConnLifetime }}
DB_MAX_CONN_LIFETIME: {{ .maxConnLifetime | quote }}
{{- end }}
{{- end }}

in the database.Connect. Defaults are pulled from pgx so if no database.postgres.pool values are set there should be no behavior change.

jcopi added 2 commits October 2, 2026 08:35
…tion

Signed-off-by: Joel Copi <joel.copi@solo.io>
Signed-off-by: Joel Copi <joel.copi@solo.io>
@github-actions github-actions Bot added the bug Something isn't working label Oct 2, 2026
@jcopi
jcopi marked this pull request as ready for review October 2, 2026 14:20
@jcopi
jcopi requested a review from a team as a code owner October 2, 2026 14:20
Comment thread go/core/pkg/env/database.go Outdated
@jcopi
jcopi force-pushed the jcopi/postgres-idle-connections branch from c12a3e8 to 1d72e8d Compare October 2, 2026 14:55
@EItanya
EItanya enabled auto-merge October 2, 2026 15:37
Comment thread go/core/pkg/app/app.go
db, err := database.Connect(ctx, &database.PostgresConfig{
URL: dbURL,
VectorEnabled: vectorEnabled,
MaxConns: new(int32(kagentenv.PostgresDatabaseMaxConns.Get())),

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

always non-nil here overrides pool_max_conns set in the url

Comment thread go/core/pkg/env/database.go Outdated
"KAGENT_POSTGRES_DATABASE_URL_FILE", "",
"File containing the PostgreSQL connection URL; takes precedence over KAGENT_POSTGRES_DATABASE_URL in the controller.", ComponentDatabase, ComponentController,
)
PostgresDatabaseMaxConns = RegisterIntVar("KAGENT_POSTGRES_DATABASE_MAX_CONNS", max(4, runtime.NumCPU()), "Maximum size of the PostgreSQL connection pool", ComponentDatabase, ComponentController)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

env docs render numcpu, so env-docs-check differs per machine

Signed-off-by: Joel Copi <joel.copi@solo.io>
auto-merge was automatically disabled October 2, 2026 15:44

Head branch was pushed to by a user without write access

@EItanya
EItanya added this pull request to the merge queue Oct 3, 2026
Merged via the queue into kagent-dev:main with commit 72a28f0 Oct 3, 2026
30 checks passed
EItanya added a commit that referenced this pull request Oct 3, 2026
Several controller workers query PostgreSQL every second even when there
is no pending work, which keeps serverless databases active. This makes
sandbox expiration, scheduled-run reservation and execution, and runtime
revision cleanup intervals configurable through the existing environment
accessors, preserving current defaults. Workers reject nonpositive
intervals.

Session quiescence stays fixed at one second because longer intervals
leave actors running after task completion or while waiting for input.
#3040 tracks waking these workers in memory after settlement, with
slower recovery scans. This PR does not eliminate all idle database
polling.

Agent and sandbox-template preparation checks also stay fixed at one
second. They scan cached state and do not query PostgreSQL once
preparation and cleanup are settled, so slowing them would delay
readiness without helping the database become idle.

Forward-ports
[dd889a1](dd889a1)
to the current MCPServer and RemoteMCPServer controllers: discovery
keeps its existing cadence, while unchanged catalogs skip PostgreSQL
writes. Failed writes and deletion invalidate the cached observation so
retries still reach the database. `LastConnected` records the last
persisted connected observation.

Uses the PostgreSQL pool configuration from #3032. Defaults and latency
tradeoffs stay in the existing environment-variable reference, including
the 30-second lateness window for cron firings.

Validation: affected Go packages with the race detector, including an
MCP test that closes the PostgreSQL pool before repeating unchanged
discovery; Go lint; Helm controller/database tests; generated
environment documentation check.

---------

Signed-off-by: Eitan Yarmush <eitan.yarmush@solo.io>
alexdarbyshire pushed a commit to alexdarbyshire/kagent that referenced this pull request Oct 5, 2026
…dev#3032)

Use database pool environment variables rendered by the helm chart

https://github.com/kagent-dev/kagent/blob/4dce53de7a27ac48fff6b459fbf3b5e507a6d759/helm/kagent/templates/controller-configmap.yaml#L69-L82
in the `database.Connect`. Defaults are pulled from pgx so if no
`database.postgres.pool` values are set there should be no behavior
change.

---------

Signed-off-by: Joel Copi <joel.copi@solo.io>
alexdarbyshire pushed a commit to alexdarbyshire/kagent that referenced this pull request Oct 5, 2026
…t-dev#3038)

Several controller workers query PostgreSQL every second even when there
is no pending work, which keeps serverless databases active. This makes
sandbox expiration, scheduled-run reservation and execution, and runtime
revision cleanup intervals configurable through the existing environment
accessors, preserving current defaults. Workers reject nonpositive
intervals.

Session quiescence stays fixed at one second because longer intervals
leave actors running after task completion or while waiting for input.
kagent-dev#3040 tracks waking these workers in memory after settlement, with
slower recovery scans. This PR does not eliminate all idle database
polling.

Agent and sandbox-template preparation checks also stay fixed at one
second. They scan cached state and do not query PostgreSQL once
preparation and cleanup are settled, so slowing them would delay
readiness without helping the database become idle.

Forward-ports
[dd889a1](kagent-dev@dd889a1)
to the current MCPServer and RemoteMCPServer controllers: discovery
keeps its existing cadence, while unchanged catalogs skip PostgreSQL
writes. Failed writes and deletion invalidate the cached observation so
retries still reach the database. `LastConnected` records the last
persisted connected observation.

Uses the PostgreSQL pool configuration from kagent-dev#3032. Defaults and latency
tradeoffs stay in the existing environment-variable reference, including
the 30-second lateness window for cron firings.

Validation: affected Go packages with the race detector, including an
MCP test that closes the PostgreSQL pool before repeating unchanged
discovery; Go lint; Helm controller/database tests; generated
environment documentation check.

---------

Signed-off-by: Eitan Yarmush <eitan.yarmush@solo.io>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants