Repository navigation
Fix ChatHistory.load failure atomicity - #292
Conversation
|
Historical draft-stage check: the staged load looked correct. I checked 20 selected tests plus late schema, Message, module and path-normalization failures; prior list/message identities and metadata survived. The later check of |
|
Pushed 93b29ef with test-only changes. Fault construction now uses a path/value parameter table, and the replacement setup and preservation assertions are shared. Changed function complexities are 1–3; an isolated C901 check passes the limit of 10 without the file exemptions. The late normalization regression uses two real image messages: the first path is normalized before the second path fails. It checks exact exception classes/messages for wrapped TypeError and unchanged RuntimeError, alongside late schema, Message and missing-module failures. Prior list/message identities, serialized contents and both metadata fields remain checked. Validation:
The three skips are existing live MiniMax tests without a provider key. Local environments only needed socksio for the configured SOCKS proxy; no project dependency or lockfile changed. Draft status is unchanged. |
|
Historical recheck of This comment was written while the PR was a draft. It is now marked ready, and I still owe the final merge check. Keep the meaningful assertions; no further test reshaping is requested. |
|
I see this is marked ready at |
Eigenwise
left a comment
There was a problem hiding this comment.
Checked 93b29ef7b851596c8d22ddb106122157279d9e05: 25 focused history-load tests passed, no skips. The failure cases preserve the existing history and message identity; the replacement cases load typed content and the expected metadata. All nine touched functions have measured CRAP scores below 6 (1 to 5), with full coverage of each body. Thanks for the fix.
Fixes #290.
ChatHistory.load currently clears the existing messages and assigns replacement metadata before deserialization completes. A failed message can therefore erase the old state or leave a partial replacement.
This change builds the replacement messages and reads metadata in local variables, then updates the instance only after every message has been reconstructed and its multimodal paths processed. Existing exception handling and successful-load behavior stay unchanged. The load docstring now states the failure-atomicity guarantee.
Added regression tests cover malformed JSON, missing metadata, missing or invalid message data, class lookup failure, invalid schema content, failure in a later message, and Message validation failures. They assert that the original message list, message identity, serialized history, max_messages, and current_turn_id survive a failed load. Successful nonempty and empty replacements are covered too.
Validation on Python 3.12.14 with the repository's locked dependencies:
The three skipped tests are existing live MiniMax integration tests; they were not run without a provider key. The local test environment also needed socksio for its SOCKS proxy. No project dependency or lockfile was changed.