Skip to content

fix: set envoy upstream idle timeout - #1101

Merged
ironcommit merged 1 commit into
mainfrom
fix/ci-job-92312717122
Aug 7, 2026
Merged

fix: set envoy upstream idle timeout#1101
ironcommit merged 1 commit into
mainfrom
fix/ci-job-92312717122

Conversation

@ironcommit

@ironcommit ironcommit commented Aug 5, 2026

Copy link
Copy Markdown
Contributor

Summary

This centralizes the connection keep-alive fix in this PR. Before this change, Envoy could keep pooled upstream HTTP/1 connections around longer than the Uvicorn API kept idle sockets open, which allowed intermittent reuse of a closed backend connection. This PR makes the API keep-alive timeout explicit, sets Envoy's upstream idle timeout below it, and validates the rendered Envoy configs in chart-aware CI instead of general unit tests.

Changes

  • Adds a keep_alive_timeout_seconds platform runner setting with validation and propagates it through direct, socket-bound, reload, embedded, and background Uvicorn startup paths.
  • Adds --keep-alive-timeout-seconds to nemo services run, start, and restart, preserving the previous value on restart unless explicitly overridden.
  • Vendors the local service keep-alive changes into the generated Python SDK package and updates the CLI reference docs.
  • Adds Helm values for API keep-alive and Envoy upstream idle timeout, with a Helm guard that requires Envoy's upstream idle timeout to be a positive whole-second value lower than the API keep-alive timeout.
  • Updates the base Helm Envoy config and Authentik reference Envoy configs to use explicit HTTP/1 upstream options and a 4s upstream idle timeout against the 5s API keep-alive default.
  • Moves Envoy config validation out of the unit suite and into Helm/auth-idp CI paths, using the deployment-specific Envoy images for Helm/Auth (v1.37.0) and the static Compose gateway (v1.36.2).

Type of Change

  • Code change (feature, bug fix, or refactor)
  • Code change with documentation updates
  • Documentation only
  • Contributor tooling or automation
  • CI, build, or test infrastructure

Quality Gates

  • Tests added or updated for changed behavior
  • Existing tests cover changed behavior — justification:
  • Tests not applicable — justification:
  • Documentation updated for user-visible behavior
  • Documentation not applicable — justification:

Verification

  • Pull request title follows the repository's Conventional Commit format
  • Every commit includes an appropriate Signed-off-by: trailer
  • uv run pre-commit run -a passes, or any blocked checks are identified below
  • Targeted tests pass, or tests are marked not applicable above
  • No secrets, API keys, or credentials are included

Targeted validation:

  • uv run --frozen pytest tests/auth_idp/static -v — 101 passed
  • uv run --frozen pytest tests/unit/test_helm_clickhouse.py -v — 6 passed
  • uv run --frozen pytest tests/auth_idp/static/test_envoy_config_validation.py tests/auth_idp/static/test_authentik_kubernetes_demo.py::test_authentik_static_ci_prepares_envoy_validation_inputs -v — 3 passed
  • tools/lint/lint-helm.sh — passed, including rendered Envoy validation
  • uv run --frozen ruff check tests/auth_idp/static/test_envoy_config_validation.py tests/auth_idp/static/test_authentik_kubernetes_demo.py — passed
  • uv run --frozen ruff format --check tests/auth_idp/static/test_envoy_config_validation.py tests/auth_idp/static/test_authentik_kubernetes_demo.py — passed
  • git diff --check — passed
  • uv run pre-commit run -a — passed

CI spot-check after the latest push:

  • Python auth-idp static tests — passed on d065da0626fd950b2ed627c86a6e9b7f8421a0ac
  • Helm lint — passed on d065da0626fd950b2ed627c86a6e9b7f8421a0ac
  • Helm chart verifier — passed on d065da0626fd950b2ed627c86a6e9b7f8421a0ac

@ironcommit
ironcommit requested review from a team as code owners August 5, 2026 18:49
@github-actions github-actions Bot added the fix label Aug 5, 2026
@coderabbitai

coderabbitai Bot commented Aug 5, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • ✅ Review completed - (🔄 Check again to review again)
📝 Walkthrough

Walkthrough

The change adds configurable API keep-alive timeouts and Envoy upstream idle timeouts. CLI, embedded services, platform runner, and Helm deployments propagate the settings. Helm and CI tests validate timeout ordering and rendered Envoy configurations.

Changes

Configurable keep-alive timeouts

Layer / File(s) Summary
Platform timeout contract
packages/nmp_platform_runner/src/nmp/platform_runner/config.py, packages/nmp_platform_runner/tests/test_config.py
Defines the five-second default, validates positive values, and propagates the timeout through resolved run configuration.
Server and service propagation
packages/nmp_platform_runner/src/nmp/platform_runner/{run.py,server.py}, packages/nemo_platform_ext/src/nemo_platform_ext/local/*, packages/nmp_platform_runner/tests/*, packages/nemo_platform_ext/tests/*
Passes the timeout to direct, socket-bound, reload, embedded, and background Uvicorn execution paths.
CLI configuration
packages/nemo_platform_ext/src/nemo_platform_ext/cli/commands/services/cli.py, docs/cli/reference.mdx, packages/nemo_platform_ext/tests/cli/commands/*
Adds timeout options to run, start, and restart. Restart preserves the stored value unless an override is supplied.

Helm and Envoy timeout configuration

Layer / File(s) Summary
Helm timeout contract and Envoy rendering
k8s/helm/{values.yaml,README.md}, k8s/helm/templates/*, contrib/auth/authentik/{gateway/envoy.yaml,helm/*}, tests/unit/test_helm_clickhouse.py, tests/auth_idp/static/test_provider_layout.py
Adds API and Envoy timeout values, validates that Envoy idle timeout is shorter, and renders explicit HTTP/1 options for the nemo cluster.
Envoy validation coverage
.github/workflows/ci.yaml, tests/auth_idp/static/*, tools/lint/lint-helm.sh
Runs rendered Envoy validation in Docker and enables the checks for Helm-related changes.

Sequence Diagram(s)

sequenceDiagram
  participant CLI
  participant PlatformAppConfig
  participant run_platform
  participant Uvicorn
  CLI->>PlatformAppConfig: keep_alive_timeout_seconds
  PlatformAppConfig->>run_platform: resolved timeout
  run_platform->>Uvicorn: timeout_keep_alive
Loading
sequenceDiagram
  participant HelmValues
  participant HelmValidation
  participant EnvoyConfigMap
  participant Envoy
  HelmValues->>HelmValidation: API and upstream idle timeouts
  HelmValidation->>EnvoyConfigMap: validated timeout configuration
  EnvoyConfigMap->>Envoy: rendered Envoy configuration
Loading

Possibly related PRs

Suggested reviewers: tylersbray, mckornfield, mikeknep

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 15.19% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes the primary change: configuring Envoy's upstream idle timeout.
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/ci-job-92312717122

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

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.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@tests/auth_idp/conftest.py`:
- Around line 334-352: The workspace creation flow around sdk.workspaces.create
must pass exist_ok=True so a committed request followed by a 409 ConflictError
is treated as successful and cleanup can proceed. Keep retrying only the
intended transient Envoy failure, but match the complete error signature rather
than checking solely for “connection termination”; preserve immediate
propagation for other errors and exhausted attempts.
🪄 Autofix

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Enterprise

Run ID: dd2d2b03-841a-45fb-9e53-ed70774f9ad7

📥 Commits

Reviewing files that changed from the base of the PR and between 071c81c and 3fb4f53.

📒 Files selected for processing (1)
  • tests/auth_idp/conftest.py

Comment thread tests/auth_idp/conftest.py Outdated
@github-actions

github-actions Bot commented Aug 5, 2026

Copy link
Copy Markdown
Contributor
Suite Lines Covered Line Rate Branch Rate
Unit Tests 31728/40339 78.6% 63.3%
Integration Tests 18444/38269 48.2% 20.9%

@ironcommit
ironcommit force-pushed the fix/ci-job-92312717122 branch from 3fb4f53 to 0bd9a73 Compare August 7, 2026 00:07
@ironcommit ironcommit changed the title fix(auth-idp): retry workspace creation on transient Envoy connection-reset fix(auth): retry workspace creation on transient Envoy connection-reset Aug 7, 2026
@ironcommit ironcommit changed the title fix(auth): retry workspace creation on transient Envoy connection-reset fix: retry workspace creation on transient Envoy connection-reset Aug 7, 2026
@coderabbitai

coderabbitai Bot commented Aug 7, 2026

Copy link
Copy Markdown
Contributor

Note

GitHub couldn't provide a complete incremental comparison for this pull request, so CodeRabbit is performing a full review instead. This review may take a little longer.

@ironcommit ironcommit changed the title fix: retry workspace creation on transient Envoy connection-reset fix: set Envoy upstream idle timeout Aug 7, 2026

@coderabbitai coderabbitai Bot left a comment

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.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@k8s/helm/values.yaml`:
- Around line 1050-1051: Set the Envoy upstream idle timeout to 4s in both
k8s/helm/values.yaml: envoyProxy.timeouts.upstreamIdle, and
contrib/auth/authentik/gateway/envoy.yaml: the static nemo cluster value. Keep
the timeout below Uvicorn’s 5-second keep-alive setting to prevent stale pooled
connections.
🪄 Autofix

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Enterprise

Run ID: 5821541f-7646-464e-912a-2f5ecbb229b2

📥 Commits

Reviewing files that changed from the base of the PR and between c71ca67 and 0bd9a73.

📒 Files selected for processing (8)
  • contrib/auth/authentik/gateway/envoy.yaml
  • contrib/auth/authentik/helm/templates/_envoy-config.tpl
  • k8s/helm/README.md
  • k8s/helm/templates/proxy/envoy-configmap.yaml
  • k8s/helm/values.yaml
  • tests/auth_idp/static/test_authentik_kubernetes_demo.py
  • tests/auth_idp/static/test_provider_layout.py
  • tests/unit/test_helm_clickhouse.py

Comment thread k8s/helm/values.yaml Outdated
@ironcommit
ironcommit force-pushed the fix/ci-job-92312717122 branch from 0bd9a73 to 8547381 Compare August 7, 2026 00:48
@coderabbitai

coderabbitai Bot commented Aug 7, 2026

Copy link
Copy Markdown
Contributor

Note

GitHub couldn't provide a complete incremental comparison for this pull request, so CodeRabbit is performing a full review instead. This review may take a little longer.

Comment thread contrib/auth/authentik/gateway/envoy.yaml Outdated
Comment thread k8s/helm/values.yaml Outdated
@ironcommit
ironcommit enabled auto-merge August 7, 2026 14:57
@ironcommit
ironcommit added this pull request to the merge queue Aug 7, 2026
@ironcommit
ironcommit removed this pull request from the merge queue due to a manual request Aug 7, 2026
@ironcommit
ironcommit force-pushed the fix/ci-job-92312717122 branch from 8547381 to 1027720 Compare August 7, 2026 15:50
@github-actions

github-actions Bot commented Aug 7, 2026

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

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.

Actionable comments posted: 3

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In
`@packages/nemo_platform_ext/src/nemo_platform_ext/cli/commands/services/cli.py`:
- Around line 518-524: Reject non-positive timeout values during CLI parsing for
all three options in
packages/nemo_platform_ext/src/nemo_platform_ext/cli/commands/services/cli.py:214-220,
332-338, and 518-524. Add a minimum-value constraint of 1 or reuse a shared
Typer validator for the timeout option declarations, including
keep_alive_timeout_seconds, so invalid values are rejected before
restart_services calls stop_instance().

In `@packages/nmp_platform_runner/src/nmp/platform_runner/config.py`:
- Around line 115-119: Update validate_keep_alive_timeout_seconds to reject bool
and non-int values before checking positivity, while continuing to accept only
positive integers. Add coverage for -1, 1.5, and True, preserving the existing
ValueError behavior for invalid inputs.

In `@tests/unit/test_envoy_config_validation.py`:
- Line 15: Update _validate_envoy_config to accept the expected Envoy image as a
parameter, or introduce separate image constants, so Helm validation uses
v1.37.0 while static Compose gateway validation uses v1.36.2. Ensure each test
passes the image corresponding to its deployment.
🪄 Autofix

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Enterprise

Run ID: 95bae833-71d4-4f23-96c5-265bbeaae52c

📥 Commits

Reviewing files that changed from the base of the PR and between 8547381 and 1027720.

⛔ Files ignored due to path filters (6)
  • sdk/python/nemo-platform/src/nemo_platform/cli/commands/services/cli.py is excluded by !sdk/**
  • sdk/python/nemo-platform/src/nemo_platform/local/process.py is excluded by !sdk/**
  • sdk/python/nemo-platform/src/nemo_platform/local/services.py is excluded by !sdk/**
  • sdk/python/nemo-platform/tests/vendored/nemo_platform_ext/cli/commands/test_services.py is excluded by !sdk/**
  • sdk/python/nemo-platform/tests/vendored/nemo_platform_ext/cli/commands/test_services_process.py is excluded by !sdk/**
  • sdk/python/nemo-platform/tests/vendored/nemo_platform_ext/local/test_services.py is excluded by !sdk/**
📒 Files selected for processing (25)
  • contrib/auth/authentik/gateway/envoy.yaml
  • contrib/auth/authentik/helm/templates/_envoy-config.tpl
  • contrib/auth/authentik/helm/values.yaml
  • docs/cli/reference.mdx
  • k8s/helm/README.md
  • k8s/helm/templates/_helpers.tpl
  • k8s/helm/templates/api/api-deployment.yaml
  • k8s/helm/templates/proxy/envoy-configmap.yaml
  • k8s/helm/values.yaml
  • packages/nemo_platform_ext/src/nemo_platform_ext/cli/commands/services/cli.py
  • packages/nemo_platform_ext/src/nemo_platform_ext/local/process.py
  • packages/nemo_platform_ext/src/nemo_platform_ext/local/services.py
  • packages/nemo_platform_ext/tests/cli/commands/test_services.py
  • packages/nemo_platform_ext/tests/cli/commands/test_services_process.py
  • packages/nemo_platform_ext/tests/local/test_services.py
  • packages/nmp_platform_runner/src/nmp/platform_runner/config.py
  • packages/nmp_platform_runner/src/nmp/platform_runner/run.py
  • packages/nmp_platform_runner/src/nmp/platform_runner/server.py
  • packages/nmp_platform_runner/tests/test_config.py
  • packages/nmp_platform_runner/tests/test_run.py
  • packages/nmp_platform_runner/tests/test_server.py
  • tests/auth_idp/static/test_authentik_kubernetes_demo.py
  • tests/auth_idp/static/test_provider_layout.py
  • tests/unit/test_envoy_config_validation.py
  • tests/unit/test_helm_clickhouse.py
🚧 Files skipped from review as they are similar to previous changes (3)
  • tests/auth_idp/static/test_authentik_kubernetes_demo.py
  • tests/auth_idp/static/test_provider_layout.py
  • contrib/auth/authentik/helm/templates/_envoy-config.tpl

Comment thread packages/nmp_platform_runner/src/nmp/platform_runner/config.py
Comment thread tests/unit/test_envoy_config_validation.py Outdated
@ironcommit
ironcommit force-pushed the fix/ci-job-92312717122 branch from 1027720 to de351af Compare August 7, 2026 17:03
@ironcommit
ironcommit requested a review from a team as a code owner August 7, 2026 17:03
@ironcommit
ironcommit force-pushed the fix/ci-job-92312717122 branch 3 times, most recently from 1ccaf72 to 9387711 Compare August 7, 2026 20:50
@ironcommit ironcommit changed the title fix: set Envoy upstream idle timeout fix: set envoy upstream idle timeout Aug 7, 2026
@ironcommit
ironcommit force-pushed the fix/ci-job-92312717122 branch from 9387711 to 8601723 Compare August 7, 2026 21:52
Set Envoy's upstream HTTP connection-pool idle timeout to 20s in the base
Helm chart and the Authentik reference Envoy configs.

Envoy defaults this timeout to 1h, which can keep pooled backend API
connections around after the backend has closed its keep-alive socket.
Retiring idle upstream connections sooner reduces stale connection reuse
and addresses the auth-idp Kubernetes failure that surfaced as:

  upstream connect error or disconnect/reset before headers. reset reason:
  connection termination

Add inline Envoy comments, Helm README documentation, and render/static
assertions for the base chart, Authentik chart override, and Authentik
compose gateway.

Signed-off-by: Ryan S <267728323+ironcommit@users.noreply.github.com>
@ironcommit
ironcommit force-pushed the fix/ci-job-92312717122 branch from 8601723 to 5faf1fb Compare August 7, 2026 22:42
@ironcommit
ironcommit enabled auto-merge August 7, 2026 22:54
@ironcommit
ironcommit added this pull request to the merge queue Aug 7, 2026
Merged via the queue into main with commit 018a9f1 Aug 7, 2026
58 checks passed
@ironcommit
ironcommit deleted the fix/ci-job-92312717122 branch August 7, 2026 23:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants