Skip to content

fix(telemetry): make appender shutdown durable - #2254

Open
7Sageer wants to merge 8 commits into
mainfrom
codex/telemetry-durable-shutdown
Open

fix(telemetry): make appender shutdown durable#2254
7Sageer wants to merge 8 commits into
mainfrom
codex/telemetry-durable-shutdown

Conversation

@7Sageer

@7Sageer 7Sageer commented Jul 27, 2026

Copy link
Copy Markdown
Collaborator

Related Issue

Closes #2246

Problem

PR #2230 intentionally limited its scope to wiring cloud telemetry into kap-server. Its server-local close path was bounded and best-effort, but the shared CloudAppender still did not own threshold, periodic, explicit, and shutdown flushes through one lifecycle. A shutdown timeout could therefore stop waiting while remote work continued, without a defined durable handoff or startup recovery path.

What changed

  • Give each CloudAppender one drain owner for queued and in-flight batches, reject new events once shutdown starts, and make concurrent flush/shutdown calls idempotent.
  • Forward one optional signal/deadline budget through ITelemetryService; later shutdown callers can tighten an active lifecycle.
  • Cancel token/network/retry waits at the lifecycle boundary, then persist each unsent batch before shutdown completes. Remote cancellation remains at-least-once and preserves stable event_id values for server-side deduplication.
  • Replay recoverable v2 spool files before new buffered events and isolate them under telemetry-v2, leaving the legacy pipeline's spool untouched.
  • Start appenders when they are registered, clean up retry-sleep listeners, and keep appender failures non-fatal.
  • Pass kap-server's existing deadline into the shared shutdown contract while retaining its outer hard cap for non-cancellable local storage I/O.
domain: telemetry (owning scope: App)
├─ serves
│  ├─ (inject)   business domains @App/Session/Agent — emit through ITelemetryService
│  └─ (accessor) hosts            @App               — register appender destinations
├─ exposes
│  ├─ App       : ITelemetryService — context, fan-out, and lifecycle facade
│  └─ plain     : ITelemetryAppender — host-owned destination contract
└─ depends
   ├─ bootstrap @App direct — read host facts for cloud context
   └─ storage   @App direct — persist and replay durable spool bytes

Verification:

  • agent-core-v2 telemetry tests: 41 passed.
  • kap-server telemetry tests: 10 passed.
  • agent-core-v2 typecheck and domain-layer lint passed; targeted oxlint passed with 0 warnings/errors.
  • Full pnpm test: 15,380 passed; four unrelated 5-second timeouts occurred under full-suite concurrency. The two affected agent-core-v2 files then passed 75/75 in isolation, and the two affected kaos files passed 79/79 with one existing skip.
  • Standards review: 0 findings. Spec review against fix(telemetry): make CloudAppender shutdown durable #2246: 0 findings. Internal-identifier audit passed.

No changeset: this is an internal telemetry lifecycle fix and does not add a user-visible release note. No user documentation update is needed.

Checklist

  • I have read the CONTRIBUTING document.
  • I have linked a related issue, or explained the problem above.
  • I have added tests that prove my feature works.
  • Ran gen-changesets skill, or this PR needs no changeset.
  • Ran gen-docs skill, or this PR needs no doc update.

@changeset-bot

changeset-bot Bot commented Jul 27, 2026

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: 52997f5

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@pkg-pr-new

pkg-pr-new Bot commented Jul 27, 2026

Copy link
Copy Markdown
pnpm dlx https://pkg.pr.new/@moonshot-ai/kimi-code@52997f5
npx https://pkg.pr.new/@moonshot-ai/kimi-code@52997f5

commit: 52997f5

Own queued and in-flight flushes through shutdown cancellation, replay recoverable spool data when appenders start, and forward one lifecycle budget through the telemetry facade.

Refs #2246
@7Sageer
7Sageer force-pushed the codex/telemetry-durable-shutdown branch from 151d9d9 to 2388e1b Compare July 27, 2026 10:32
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.

fix(telemetry): make CloudAppender shutdown durable

1 participant