Skip to content

feat(worker): make the graceful-shutdown timeout configurable - #3092

Open
ai-ag2026 wants to merge 1 commit into
vectorize-io:mainfrom
ai-ag2026:pr/shutdown-grace-env
Open

feat(worker): make the graceful-shutdown timeout configurable#3092
ai-ag2026 wants to merge 1 commit into
vectorize-io:mainfrom
ai-ag2026:pr/shutdown-grace-env

Conversation

@ai-ag2026

Copy link
Copy Markdown
Contributor

Summary

The worker poller's graceful-shutdown timeout is hardcoded to 30.0 in both
shutdown paths (worker/main.py, and the API-embedded poller in
api/http.py). An in-flight retain is an LLM call that may legitimately run
for minutes — HINDSIGHT_API_LLM_TIMEOUT defaults far above 30s — so every
service stop cancels it mid-flight and loses the operation.

This adds HINDSIGHT_API_SHUTDOWN_GRACE (default 30.0, behaviour
unchanged unless set), wired through HindsightConfig like the other
operational knobs, and used at both call sites.

Why

Running Hindsight under systemd, we size this together with
TimeoutStopSec so the supervisor never SIGKILLs the process mid-cleanup:
grace comfortably under the supervisor timeout, both above the realistic
LLM-call duration. In production since 2026-07-16; restarts stopped eating
in-flight retains.

Changes

  • config.py: ENV_SHUTDOWN_GRACE + DEFAULT_SHUTDOWN_GRACE +
    HindsightConfig.shutdown_grace + from_env parsing
  • worker/main.py, api/http.py: shutdown_graceful(timeout=get_config().shutdown_grace)
  • .env.example documented

Validation

tests/test_shutdown_grace_config.py: default-is-30 and env override, in
the pattern of the neighbouring config-wiring test files (2 passed).

The worker poller's graceful-shutdown timeout is hardcoded to 30s in both
shutdown paths (worker/main.py and the API-embedded poller in api/http.py).
An in-flight retain is an LLM call that may legitimately run for minutes —
HINDSIGHT_API_LLM_TIMEOUT defaults far above 30s — so every service stop
cancels it mid-flight and the operation is lost.

Add HINDSIGHT_API_SHUTDOWN_GRACE (default 30.0 = unchanged behaviour),
wired through HindsightConfig like the other operational knobs, and use it
at both call sites. Deployments size it together with their supervisor stop
timeout (e.g. systemd TimeoutStopSec) so the supervisor never SIGKILLs
mid-cleanup.

Tests: config default + env parsing, in the pattern of the neighbouring
config-wiring test files.

@nicoloboschi nicoloboschi left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

please add the new field to the docs

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants