Skip to content

fix(ai): write chat history atomically - #2843

Open
HandSonic wants to merge 1 commit into
OtterMind:mainfrom
HandSonic:fix/ai-history-atomic-write
Open

fix(ai): write chat history atomically#2843
HandSonic wants to merge 1 commit into
OtterMind:mainfrom
HandSonic:fix/ai-history-atomic-write

Conversation

@HandSonic

@HandSonic HandSonic commented Aug 31, 2026

Copy link
Copy Markdown
Contributor

Related issue

N/A - no matching issue was found.

Summary

AI session and message histories were written directly to their final JSON files. Jackson truncates a File target before serialization, so a mid-write failure destroyed the last valid history and made subsequent reads fail. This change writes to a same-directory temporary file, atomically replaces the target when supported, cleans failed temporary writes, and constrains message paths to canonical UUIDs inside the normalized history directory.

Affected surfaces

  • Frontend / Web
  • Backend / API / Storage
  • Database plugin / Driver
  • JCEF / Desktop packaging
  • CI / Build / Release
  • Documentation only

Verification

  • Commands and results:
    • Red serializers truncated valid session/message files to 27 bytes and made them unreadable.
    • Atomic history, path-safety, compatibility, and locking tests: 7 passed.
    • AI history/config related tests: 38 passed.
    • Domain-core reactor: 226 tests passed.
    • Backend package and fork code/CodeQL checks: passed.
    • Merge-tree with history deletion rollback: passed.
  • Manual verification: N/A - custom serializers flush a partial prefix before throwing and verify final bytes/readability/temp cleanup.
  • UI evidence: N/A

Risk and compatibility

  • Public API or stored data: Existing JSON schemas and paths are unchanged.
  • Database or driver compatibility: N/A.
  • Network, privacy, or security: Canonical UUID validation and strict parent checks prevent history paths from escaping the configured directory.
  • Community / Local / Pro boundary: Shared Community AI history service.
  • Backward compatibility: Successful writes preserve pretty JSON; unsupported atomic moves fall back to replacement.

Reviewer map

  • Start here: AiChatHistoryServiceImpl.writeAtomically and AiChatHistoryAtomicWriteTest.
  • Failure condition: a failed serializer changes the final file or leaves a temporary file.
  • Rollback or disable path: Revert commit 23f7627f50e9b2745c4c53a2e83982e6354fd32e; no migration is required.

Contributor declaration

  • I linked the Issue that defines this change.
  • I tested the affected behavior and reported the actual results above.
  • I did not include credentials, private data, or generated build output.
  • I disclosed substantial AI assistance below, or this PR contains no substantial AI-generated code.

AI assistance: OpenAI Codex assisted with diagnosis, implementation, deterministic tests, verification, and adversarial review.

Latest-main revalidation (2026-09-04)

  • Rebased onto upstream 144a04e; current head 23f7627.
  • Full domain-core module: 233/233 passed.

@openai0229 openai0229 moved this to In Review in Chat2DB Community Aug 31, 2026
@HandSonic
HandSonic marked this pull request as draft August 31, 2026 03:59
@openai0229 openai0229 moved this from In Review to In Progress in Chat2DB Community Aug 31, 2026
@HandSonic
HandSonic force-pushed the fix/ai-history-atomic-write branch 2 times, most recently from 783cbff to cc5f04f Compare August 31, 2026 04:32
@HandSonic
HandSonic marked this pull request as ready for review August 31, 2026 05:05
@HandSonic
HandSonic force-pushed the fix/ai-history-atomic-write branch from cc5f04f to d5ed154 Compare August 31, 2026 05:10
@openai0229 openai0229 moved this from In Progress to In Review in Chat2DB Community Aug 31, 2026
@HandSonic
HandSonic force-pushed the fix/ai-history-atomic-write branch from d5ed154 to 1e37182 Compare September 3, 2026 08:08
@HandSonic
HandSonic force-pushed the fix/ai-history-atomic-write branch from 1e37182 to 23f7627 Compare September 3, 2026 21:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: In Review

Development

Successfully merging this pull request may close these issues.

3 participants