fix(client): survive handshake from a protocol-incompatible daemon - #238
Merged
Conversation
Fixes #237. Upgrading 0.2.37 → 0.2.38 bricked every ccc command with "ValidationError: Object missing required field `pid`": 0.2.38 added a required `pid` field to HandshakeResponse, so the reply of a still-running pre-upgrade daemon no longer decoded — before the client could see the `ok=False` version mismatch and restart it. The same uncaught error also broke `ccc daemon stop`, the recovery path. Three layers: - `HandshakeResponse.pid` gets a default (None), with a comment stating the wire-compat rule: handshake fields added after a release must have defaults, since the handshake is the one message exchanged between mismatched versions. - An undecodable handshake reply now raises `DaemonProtocolError` instead of escaping as a raw decode error; `_connect_and_handshake` treats it like a version mismatch (restart on first contact, fail fast once a matching daemon was ensured). This protects against any future wire drift, not just this field. - `stop_daemon` tolerates the decode failure and falls through to its SIGTERM/SIGKILL escalation, so `ccc daemon stop` always works. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #237.
Summary
Upgrading 0.2.37 → 0.2.38 bricked every
ccccommand withValidationError: Object missing required field 'pid'. Root cause: 0.2.38 (#214) added a requiredpidfield toHandshakeResponse, so the reply of a still-running pre-upgrade daemon no longer decoded — the decode error fired before the client could see theok=Falseversion mismatch and restart the daemon. The same uncaught error also brokeccc daemon stop, i.e. the recovery path itself.Three layers of fix:
HandshakeResponse.pidgets a default (None), with a comment stating the rule — handshake fields added after a release must have defaults, since the handshake is the one message exchanged between mismatched client/daemon versions. With this alone, a stale 0.2.37 daemon's reply decodes,ok=Falseis seen, and the normal restart path fires.DaemonProtocolErrorinstead of escaping as a rawmsgspecerror;_connect_and_handshaketreats it like a version mismatch (restart on first contact, fail fast once a matching daemon was already ensured). This protects against any future wire drift, not just this field.stop_daemontolerates the handshake failure and falls through to its SIGTERM/SIGKILL escalation, soccc daemon stopalways works against an incompatible daemon.Workaround for users hitting this on 0.2.38 today:
pkill -f cocoindex_code.daemon(or kill the PID from~/.cocoindex_code/daemon.pid), then rerun anyccccommand.Test plan
pidfield) decodes (test_decode_handshake_response_from_pre_0_2_38_daemon)test_connect_restarts_daemon_on_undecodable_handshake)test_connect_fails_fast_on_undecodable_handshake_after_ensured)stop_daemonreaches the kill escalation instead of crashing (test_stop_daemon_escalates_past_undecodable_handshake)🤖 Generated with Claude Code