Skip to content

fix(kap-server): make boot and telemetry shutdown lifecycle complete #2247

Description

@7Sageer

Context

PR #2230 added a deliberately local, 3-second best-effort telemetry close path to kap-server. The review also exposed broader server lifecycle gaps that were kept out of that PR.

Problem

  • The server must quiesce asynchronous engine telemetry producers before the final telemetry flush; otherwise events can be emitted after the flush boundary.
  • If startServer fails after partially initializing scopes, routes, or telemetry, boot needs one complete rollback path rather than ad hoc cleanup at individual call sites.

These are server lifecycle invariants, not part of wiring a new telemetry appender.

Scope

  • Define and enforce shutdown ordering: stop intake, quiesce producers, perform bounded telemetry shutdown, then dispose remaining scopes/resources.
  • Preserve the invariant that telemetry failure never blocks core/instance cleanup.
  • Make partially completed startServer initialization unwind every acquired resource exactly once.
  • Avoid changing public CLI shutdown policy in this issue.

Acceptance criteria

  • No telemetry event can be produced after the final flush boundary.
  • Cleanup continues when telemetry flush rejects or reaches its deadline.
  • Failure injection at each meaningful boot stage leaves no live server, timer, appender, or scope.
  • Normal close and partial-boot rollback are idempotent and covered by tests.

Follow-up to #2230.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions