Skip to content

Persist persona chat in the character workspace - #349

Merged
sparkleMing merged 5 commits into
memex-lab:mainfrom
o-mid:feat/persona-chat-workspace-persistence
Aug 21, 2026
Merged

sparkleMing merged 5 commits into
memex-lab:mainfrom
o-mid:feat/persona-chat-workspace-persistence

Conversation

@o-mid

@o-mid o-mid commented Aug 17, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

  • Make each character workspace the sole runtime source of truth for persona-chat history, following the same file-first direction as the home-page Memex Agent chat.
  • Store one immutable chat message per line in Conversation/messages.jsonl, using a normal message shape with id, role, content blocks, timestamps, origin, and optional turn_id / fact_id.
  • Keep mutable read state, agent processing progress, generation, and rebuildable O(1) summaries in metadata.json instead of writing control records into the message log.
  • Commit multi-bubble character turns with a transient .pending_commit.json write-ahead file. Recovery rewinds to the recorded byte offset and replays the exact message rows, so a crash cannot expose half a turn or duplicate it.
  • Use turn_id in the authoritative message rows for retry idempotency. Metadata only caches the most recent committed turn; older retries fall back to the message log, so there is no receipt directory or second idempotency fact.
  • Import the released SQLite persona-chat rows and reply cursor once through the existing unified MigrationStateService marker. The unreleased episode-based workspace format is intentionally not a migration source or runtime compatibility branch.
  • Rebuild missing durable conversation tasks from workspace processing state at startup, closing the crash window between appending a user message and enqueueing its SQLite task.
  • Load older history and live additions with JSONL byte cursors. The persona chat ViewModel merges incremental pages by message ID instead of repeatedly loading all visible messages.

Workspace layout

character_workspaces/<characterId>/Conversation/
  messages.jsonl         # authoritative immutable message history
  metadata.json          # mutable boundaries + rebuildable summary/cache
  .pending_commit.json   # transient WAL; absent outside an in-flight commit
  .write.lock            # cross-isolate/process writer lock

All workspace paths remain centralized in FileSystemService, and character IDs are validated before becoming path components.

Consistency and performance

  • User-message append is O(1): append one JSONL row and atomically replace the small metadata file. If the process stops between those writes, metadata is repaired from the log.
  • Multi-bubble replies, SQLite snapshot import, and conversation clear use the same crash-recoverable WAL protocol.
  • Writers are serialized by a process path lock plus an OS file lock; tests cover independent storage instances writing concurrently.
  • Message IDs are the single durable ordering identity; byte offsets are ephemeral paging cursors and are not stored on messages.
  • Unread count, latest message, reply progress, and pending-reply discovery normally read metadata without scanning history.
  • Older-turn scans occur only on idempotency fallback; initiative delivery is infrequent, while direct conversation retries use the processed-message boundary to avoid scanning on normal writes.
  • Clearing increments a conversation generation and never reuses message IDs, so stale agent output cannot reappear after reset.

Fixes #347

Test plan

  • Storage tests cover flat message schema, byte-cursor paging, concurrent ID allocation, UTF-8 tail repair, read/processing boundaries, older-turn idempotency, and path safety.
  • Fault injection covers interruption after WAL creation, message append, and metadata replacement, including partial batches, clear, and legacy SQLite import.
  • Migration/recovery tests verify one-way SQLite import, the unified v1 migration marker, runtime independence after SQLite is wiped, and multi-bubble retry idempotency.
  • Character conversation, initiative, startup reconciliation, UI ViewModel, widget, and integration pipeline tests pass.
  • flutter test: 851 passed, 5 skipped live/environment-dependent tests, 0 failed.
  • flutter analyze: no errors or warnings; 158 pre-existing info-level lints remain outside the changed files.

@github-actions

github-actions Bot commented Aug 17, 2026 •

Copy link
Copy Markdown

PR AI Review / PR AI 语义预检

中文

  • 风险等级:高风险
  • 需要人工审核:是
  • 黄金链路影响:可能
  • 置信度:high
  • Workflow run:32455884091

AI 语义预检未得到可解析结果,需要 maintainer 人工审核。

影响范围

  • unknown

黄金链路

  • none
  • 说明:Claude Code Action 未产出结构化 JSON,AI 语义预检结果不可用。

风险项

  • high AI review 结果不可用。证据:Claude Code Action structured_output was empty or invalid.。
    建议:检查 Claude Action 日志和模型网关配置后重新运行 workflow。

测试缺口

  • 未发现新的测试缺口。

English

  • Risk level: HIGH
  • Human review required: YES
  • Golden path impact: POSSIBLE
  • Confidence: high
  • Workflow run: 32455884091

AI semantic review did not return a parseable result; maintainer review is required.

Affected Areas

  • unknown

Golden Path

  • none
  • Rationale: Claude Code Action did not produce structured JSON, so the AI review result is unavailable.

Findings

  • high AI review result unavailable. Evidence: Claude Code Action structured_output was empty or invalid..
    Recommendation: Check Claude Action logs and model gateway configuration, then rerun the workflow.

Test Gaps

  • No new test gap was reported.

AI review is advisory. Maintainers should verify the result before merging.

@github-actions github-actions Bot added ai: high risk AI review classified the PR as high risk golden path impact AI review found possible impact to a core user flow needs human review AI review or policy signals require maintainer review labels Aug 17, 2026
@o-mid

o-mid commented Aug 18, 2026

Copy link
Copy Markdown
Collaborator Author

@whbzju this is the implementation for #347. Ready for review when you have time.

The ai: high risk / golden path impact labels are from the AI precheck failing to parse JSON (structured_output was empty), not from a finding in the diff. Happy to walk through storage or migration if useful.

@github-actions github-actions Bot added ai: high risk AI review classified the PR as high risk golden path impact AI review found possible impact to a core user flow needs human review AI review or policy signals require maintainer review and removed ai: high risk AI review classified the PR as high risk needs human review AI review or policy signals require maintainer review golden path impact AI review found possible impact to a core user flow labels Aug 20, 2026
@github-actions

github-actions Bot commented Aug 20, 2026 •

Copy link
Copy Markdown

PR Preflight Summary / PR 预检汇总

中文

  • 统一结论:低风险:两个预检均已完成,质量预检通过,可走普通手动合并流程。
  • Policy preflight:低风险。未命中打回或高风险规则。
  • Flutter quality:通过。Analyzer 和 test baseline 均未发现新增问题。
  • PR head:90558f895f6a6b7691cba4a4db0c66caa884106d
  • Policy run:32455884210
  • Flutter run:32455890002

English

  • Combined result: Low risk: both preflights completed and quality passed; use the normal manual merge flow.
  • Policy preflight: LOW RISK. No blocking or high-risk policy signal was found.
  • Flutter quality: PASS. Analyzer and test baselines found no newly introduced issue.
  • PR head: 90558f895f6a6b7691cba4a4db0c66caa884106d
  • Policy run: 32455884210
  • Flutter run: 32455890002
PR Policy Preflight / PR 规则预检

PR Policy Preflight / PR 规则预检

中文

  • 判定:低风险
  • 变更文件数:30
  • 变更行数:4232
  • Diff 是否截断:false

未发现确定性规则问题。

English

  • Decision: LOW RISK
  • Changed files: 30
  • Changed lines: 4232
  • Diff truncated: false

No deterministic policy findings.

PR Flutter Quality / Flutter 质量预检

PR Flutter Quality / Flutter 质量预检

中文

  • 总体:通过
  • Analyzer baseline:通过
  • Test baseline:通过

English

  • Overall: PASS
  • Analyzer baseline: PASS
  • Test baseline: PASS

Flutter Analyzer Baseline

  • Base issues: 162
  • PR issues: 162
  • New issues: 0

No new analyzer issues introduced by this PR.

Flutter Test Baseline

  • Base failures: 0
  • PR failures: 0
  • New failures: 0

No new Flutter test failures introduced by this PR.

o-mid and others added 2 commits August 21, 2026 10:25
Private-chat history and reply cursors lived only in SQLite, so restoring a workspace did not restore the conversation. Keep messages.jsonl and state.json as the durable store and rebuild the SQLite projection from them.
@sparkleMing
sparkleMing force-pushed the feat/persona-chat-workspace-persistence branch from a4c8900 to 0cd46fb Compare August 21, 2026 02:27
@github-actions github-actions Bot added ai: high risk AI review classified the PR as high risk golden path impact AI review found possible impact to a core user flow needs human review AI review or policy signals require maintainer review and removed ai: high risk AI review classified the PR as high risk needs human review AI review or policy signals require maintainer review golden path impact AI review found possible impact to a core user flow labels Aug 21, 2026
@sparkleMing
sparkleMing force-pushed the feat/persona-chat-workspace-persistence branch from 0cd46fb to c8760d3 Compare August 21, 2026 02:33
@github-actions github-actions Bot added ai: high risk AI review classified the PR as high risk golden path impact AI review found possible impact to a core user flow needs human review AI review or policy signals require maintainer review and removed ai: high risk AI review classified the PR as high risk needs human review AI review or policy signals require maintainer review golden path impact AI review found possible impact to a core user flow labels Aug 21, 2026
@github-actions github-actions Bot added ai: high risk AI review classified the PR as high risk golden path impact AI review found possible impact to a core user flow needs human review AI review or policy signals require maintainer review and removed ai: high risk AI review classified the PR as high risk needs human review AI review or policy signals require maintainer review golden path impact AI review found possible impact to a core user flow labels Aug 21, 2026
@github-actions github-actions Bot added ai: high risk AI review classified the PR as high risk golden path impact AI review found possible impact to a core user flow needs human review AI review or policy signals require maintainer review and removed ai: high risk AI review classified the PR as high risk needs human review AI review or policy signals require maintainer review golden path impact AI review found possible impact to a core user flow labels Aug 21, 2026
@sparkleMing
sparkleMing merged commit ce9b6a5 into memex-lab:main Aug 21, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ai: high risk AI review classified the PR as high risk golden path impact AI review found possible impact to a core user flow needs human review AI review or policy signals require maintainer review

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Persist persona chat history in character workspace and rebuild SQLite as a projection

2 participants