Repository navigation
fix: service socket path errors without a traceback, and no lamport flush panic at python exit - #752
Merged
Merged
Conversation
offline-protocol-service refuses a socket directory other users can read, but the refusal surfaced as a ValueError traceback with no hint. it now raises SocketPathError (a ValueError) with a chmod 700 hint, the cli exits with a one-line --socket error, and paths too long for sun_path are refused before the engine starts.
…the clock drop always wrote the lamport clock through the host storage callback. python often frees the engine at interpreter shutdown, when the callback can no longer run, and uniffi panicked on the unexpected callback error. the flush now skips a value storage already holds, and restoring the clock records the stored value so ticks taken before storage was attached are still written.
bahdotsh
approved these changes
Nov 17, 2026
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 subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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.
Summary
Two fixes for crashes reported against the Python SDK:
offline-protocol-serviceprinted a traceback when it refused its socket directory. It now exits with a one-line error that says how to fix it.UnexpectedUniFFICallbackError ... Python is likely shutting down) is fixed in the core. It was reported as "LAN discovery crashes without the[lan]extra".Context / motivation
Socket directory. The local API server deliberately refuses to put its socket in a directory other users can read, because the socket gives full control of the engine. But the refusal surfaced as a raw
ValueErrortraceback throughasyncio.run. It looked like a crash and gave no hint. A second failure mode: a socket path longer thansun_path(104 bytes on macOS, 108 on Linux) failed only at bind time with an unclear OS error. The macOS pytest temp directory alone is over the limit.Shutdown panic. The missing
[lan]extra is not the cause: on 0.33.0 and main it gives a clean install hint. The crash is inOfflineProtocol::drop, which always wrote the Lamport clock through the host's state-storage callback, even whenstop()had just written the same value. Python often frees the engine during interpreter shutdown, when callbacks can no longer run.MlsStorageErrorhas noFrom<UnexpectedUniFFICallbackError>, so UniFFI panics. LAN-discovery programs hit it most often, which is why it looked LAN-related.Changes
Python local API (
bindings/python/offline_protocol_sdk/local_api/)server.py:SocketPathError(ValueError), raised for a wide directory, a path that is not a socket, and a path too long to bind. Existingexcept ValueErrorstill catches it.chmod 700 <dir>if it is yours to narrow, or put the socket in a directory of its own"._check_socket_path_lengthruns before the directory is prepared or the engine starts.cli.py: catchesSocketPathErrorand exits with--socket: <message>, with no traceback.__init__.py: exportsSocketPathError.Core (
crates/offline-protocol/src/protocol/storage.rs)flush_lamport_clockreturns early when storage already holds the current value. After a normalstop(), drop writes nothing, so no callback runs at shutdown.restore_lamport_clocksetslast_persisted_lamportto what storage actually holds:Without this, the early return would have skipped ticks taken before storage was attached.
Testing
cargo test -p offline-protocol --lib: 2195 passed. New tests:test_a_stopped_protocol_is_dropped_without_writing_the_lamport_clocktest_lamport_ticks_taken_before_storage_was_attached_are_flushedtests/local_api/test_local_api_server.py:SocketPathErrorwith thechmod 700hint, and the error is still aValueError.cargo clippy -p offline-protocol -p offline-protocol-uniffi -- -D warningsis clean.--all-targets, clippy fails inoffline-protocol-transport(unwrap_usedin tests). That crate is untouched and the failure exists on main.Risk and rollout
SocketPathErrorsubclassesValueError, so existing callers are unaffected.Follow-ups / out of scope
OSErrorfrom a host store. The robust fix isFrom<UnexpectedUniFFICallbackError>forMlsStorageError, which needs a new error variant and so regenerating all bindings, the C dispatcher, the C header and the local API table. Left for a separate decision.bindings/python/examples/basic_messaging.pypasses a staleuser_idconfig field.