kimi-code
kimi-code copied to clipboard
fix(telemetry): make CloudAppender shutdown durable
Summary
Fixes #2246.
Gives CloudAppender durable ownership of flush work across threshold, periodic, and shutdown triggers.
Changes
Serial flush lock
flush()is now serialized through a single in-flight promise. Concurrent callers (periodic timer, threshold trigger, manual flush, shutdown) wait for the current flush to complete before starting a new one, preventing buffer races where two callers swap the buffer simultaneously and lose a batch.
Deadline-bounded shutdown
shutdown(deadlineMs?)provides a deadline-bounded, idempotent close:- Stops the periodic flush timer
- Creates an
AbortControllerwith the remaining deadline budget - Flushes the remaining buffer (in-flight sends observe the abort signal)
- Hands unsent buffered events to durable storage (
saveToDisk) so they survive a restart - Replays recoverable v2 spool data (
retryDiskEvents) before completing - Marks the appender as shut down; subsequent
track()calls are silently ignored
At-least-once delivery
- Stable event IDs (
randomUUID) preserve the server's deduplication key across ambiguous cancellation boundaries. - Legacy spool files remain owned by the legacy pipeline — only the v2
failed_*.jsonlnamespace is touched.
Tests added
- Concurrent flush serialization (no event loss)
- Idempotent shutdown
- Deadline expiry hands events to disk
- Spool replay during shutdown
track()after shutdown is ignored
🦋 Changeset detected
Latest commit: d0764ca6218742f2dc78ed33200eab4561568766
The changes in this PR will be included in the next version bump.
This PR includes changesets to release 1 package
| Name | Type |
|---|---|
| @moonshot-ai/agent-core-v2 | Patch |
Not sure what this means? Click here to learn what changesets are.
Click here if you're a maintainer who wants to add another changeset to this PR