Skip to content

fix(cli): share telemetry shutdown deadline - #2333

Open
ousamabenyounes wants to merge 6 commits into
MoonshotAI:mainfrom
ousamabenyounes:fix/issue-2248
Open

ousamabenyounes wants to merge 6 commits into
MoonshotAI:mainfrom
ousamabenyounes:fix/issue-2248

Conversation

@ousamabenyounes

@ousamabenyounes ousamabenyounes commented Jul 29, 2026 •

Copy link
Copy Markdown

Requirement or Bug

Resolve #2248. CLI shutdown previously gave each telemetry owner a separate timeout, so a stalled engine pipeline followed by a stalled host pipeline could delay exit beyond the configured budget. The same budget must also cover cleanup after web startup fails.

Bug Reproduction Steps

The regression tests run two stalled telemetry pipelines under fake time. Before this change, their cumulative shutdown time exceeded one budget; the startup-failure cleanup path had the same problem. See apps/kimi-code/test/cli/telemetry.test.ts, apps/kimi-code/test/cli/web/web.test.ts, and packages/kap-server/test/boot.test.ts.

Root Cause

The print and web entrypoints passed a fresh timeout to each independently owned telemetry pipeline. RunningServer.close() had no way to receive the absolute deadline from the web host, and the web onReady rejection path bypassed the normal shutdown policy. This is a shared-deadline fix, not a change to telemetry transport or stored data.

Code Changes

One absolute deadline is created at each CLI shutdown boundary. Each pipeline receives only the remaining time, and the caller also bounds the await so a stalled token lookup cannot outlive the deadline. A rejection or timeout is reported without blocking the next owner. Web startup failure now uses the same close helper as normal shutdown.

print/headless exit
  CLI deadline → engine telemetry → host telemetry
web exit or startup failure
  CLI deadline → RunningServer.close(deadline) → engine telemetry
               → host telemetry

The server-close error boundary remains distinct from telemetry failures, and print exit results are preserved. Start with apps/kimi-code/src/cli/telemetry-shutdown.ts, then the print/web call sites and packages/kap-server/src/start.ts.

Behavior Changes and Affected Users

Behavior Before After Who relies on the old behavior Escape hatch
Telemetry flush on print/headless CLI exit Each pipeline could use a full timeout, extending exit latency All pipelines share one absolute budget; failures are reported and later cleanup is still attempted Headless CLI users, scripts that parse print output or exit status No output format, exit code, flag, or telemetry setting changes; the existing telemetry toggle still applies
Telemetry flush on kimi web exit or startup failure Engine and host flushes could each wait a full timeout, including after onReady failed Both use the remaining shared budget; server close errors remain visible Code-app web/desktop hosts and remote-control clients using the local server No REST, WebSocket, remote-control protocol, auth, or persisted session shape changes

Previous-release clients and data remain compatible: this PR changes shutdown timing and warning behavior only. Existing CLI arguments, printed result formats, exit outcomes, REST/WebSocket contracts, remote-control messages, and stored sessions remain readable and unchanged. A stalled telemetry owner may receive less time than before because it shares the process exit budget; the configured budget itself and the telemetry setting stay the same.

Affected modules and evidence: print lifecycle tests cover failure, reporter failure, expired budget, and preserved exit result; web lifecycle tests cover normal shutdown, startup failure, and server-close error; kap-server tests cover the propagated deadline. On the rebased branch, 128 focused tests pass across four suites (including a RED → GREEN stalled-host-lookup regression), apps/kimi-code and packages/kap-server typecheck, and the CLI production build passes. Full Vitest matrix was not rerun for this rebase.

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.
  • The behavior-change table above is complete, and every removed behavior or flipped default is named in the changeset and either has an escape hatch or was explicitly approved by a maintainer in this PR.
  • Ran gen-changesets skill; added a patch changeset for the CLI package.
  • Ran gen-docs skill; no documentation update is needed for this internal shutdown policy.

@changeset-bot

changeset-bot Bot commented Jul 29, 2026 •

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 94cc62f

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/kimi-code 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

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 19, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-02T00:26:28.235915Z 94cc62f New commits
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 1604d213b9

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread apps/kimi-code/src/cli/sub/web/run.ts Resolved

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 01e851e8a1

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread .changeset/calm-ravens-share.md Resolved
@ousamabenyounes

Copy link
Copy Markdown
Author

Rebased onto current main, resolved the conflicts, restored the separate server-close error boundary, and rewrote the changeset around the observable shutdown-delay fix. The focused web suite passes 68/68, and full local CI is iso-or-better with 100% changed-line coverage.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 1b00403e55

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread .changeset/calm-ravens-share.md Resolved
@ousamabenyounes

Copy link
Copy Markdown
Author

Rebased this PR onto current main and resolved the run.ts / run-v2-print.ts import conflicts while retaining the upstream host-identity split. GitHub now reports the PR as mergeable on 94cc62f1.

Addressed the two open review threads: startup-failure cleanup uses the shared deadline (existing follow-up 99d6c7c9, now with a bounded await in 94cc62f1), and the PR description names the affected print/headless, web/desktop, and remote-control consumers plus previous-release compatibility. I replied in both threads and verified both are marked resolved.

Validation on the rebased head: stalled-host-lookup regression RED before / GREEN after the new bound, 128/128 focused tests, both affected package typechecks, CLI production build, and lint for modified files pass. GitHub currently shows no status checks for this fork PR, so the remote CI result is not yet independently available; the remaining BLOCKED merge state is review policy, not a merge conflict.

This branch has not been deployed

No deployments
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(cli): share one deadline across telemetry shutdown pipelines

1 participant