fix(daemon): add acknowledgment response for heartbeat messages#177
fix(daemon): add acknowledgment response for heartbeat messages#177
Conversation
- Send {"status":"ok"} after processing heartbeat message
- Send {"status":"disabled"} when codeTracking is disabled
- Fixes VS Code extension incorrectly showing "daemon not running"
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Summary of ChangesHello @AnnatarHe, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request addresses a critical communication gap between the daemon and the VS Code extension. Previously, the absence of a response to heartbeat messages led the extension to misinterpret the daemon's operational status. The changes introduce explicit acknowledgment responses, ensuring the extension accurately reflects whether the daemon is running and if codeTracking is enabled or disabled, thereby improving user experience and system reliability. Highlights
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
Codecov Report❌ Patch coverage is
Flags with carried forward coverage won't be shown. Click here to find out more.
... and 2 files with indirect coverage changes 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Code Review
This pull request correctly adds acknowledgment responses for heartbeat messages, which resolves the issue with the VS Code extension. The logic is sound. However, the implementation misses error handling for the JSON encoding operations in both new code blocks. This could lead to silent failures. The provided comments highlight these issues and suggest adding the necessary error checking and logging, which will make the code more robust.
| if p.config.CodeTracking == nil || p.config.CodeTracking.Enabled == nil || !*p.config.CodeTracking.Enabled { | ||
| slog.Debug("Heartbeat message received but codeTracking is disabled, ignoring") | ||
| encoder := json.NewEncoder(conn) | ||
| encoder.Encode(map[string]string{"status": "disabled"}) |
There was a problem hiding this comment.
The error returned by encoder.Encode is not handled. This could lead to silent failures if writing the response to the connection fails. It's important to check for errors and log them to ensure robust operation, similar to how it's handled in the handleStatus function.
if err := encoder.Encode(map[string]string{"status": "disabled"}); err != nil {
slog.Error("Error encoding 'disabled' status response", slog.Any("err", err))
}|
|
||
| // Send acknowledgment to client | ||
| encoder := json.NewEncoder(conn) | ||
| encoder.Encode(map[string]string{"status": "ok"}) |
There was a problem hiding this comment.
Similar to the other change, the error from encoder.Encode is not handled here. Please add error checking and logging to prevent silent failures when sending the acknowledgment.
if err := encoder.Encode(map[string]string{"status": "ok"}); err != nil {
slog.Error("Error encoding 'ok' status response", slog.Any("err", err))
}
Summary
{"status":"ok"}after processing heartbeat message{"status":"disabled"}when codeTracking is disabledProblem
The VS Code extension showed "daemon not running" warning even when the daemon was running. The root cause was that the daemon didn't send any response for heartbeat messages, causing the extension to interpret the empty response as a connection failure.
Solution
Add acknowledgment responses for heartbeat messages:
{"status":"ok"}- heartbeat was received and published to PubSub{"status":"disabled"}- codeTracking is disabled, heartbeat was ignoredTest plan
{"status":"ok"}{"status":"disabled"}🤖 Generated with Claude Code