Skip to content

feat(storage): define thread store doctor contract#897

Closed
luoye520ww wants to merge 1 commit into
KunAgent:developfrom
luoye520ww:codex/thread-store-doctor-contract
Closed

feat(storage): define thread store doctor contract#897
luoye520ww wants to merge 1 commit into
KunAgent:developfrom
luoye520ww:codex/thread-store-doctor-contract

Conversation

@luoye520ww

Copy link
Copy Markdown
Collaborator

Problem

Thread persistence currently has no stable diagnostic contract for reporting metadata, event log, SQLite index, and attachment health. Future doctor and repair code would otherwise invent incompatible result shapes.

Root cause

The hybrid store owns several persistence surfaces, but the runtime contracts only describe thread records and storage ports. There is no versioned, bounded result model for read-only health checks.

Scope

This PR adds the versioned ThreadStoreDiagnostic contract only. It does not scan, repair, migrate, or modify any user data.

Changes

  • Add bounded artifact status and diagnostic issue schemas.
  • Add per-thread diagnostic and report schemas with an explicit schema version.
  • Export the contract through kun/contracts.
  • Add schema tests for valid reports, invalid states/timestamps, and unknown fields.

Safety

  • No filesystem or database writes.
  • Diagnostic messages, codes, thread IDs, and issue counts are bounded.
  • Absolute paths, file contents, and secrets are not part of this contract.

Typecheck

npm.cmd --prefix kun run typecheck
npm.cmd run typecheck

Both passed after installing the locked dependencies in this isolated worktree.

Tests

npm.cmd --prefix kun test -- tests/thread-store-diagnostics.test.ts

Result: 1 file, 4 tests passed.

Actual validation

The contract test exercises Zod parsing against a real diagnostic object, an empty report, invalid artifact/timestamp values, and extra fields. npm.cmd --prefix kun run build, npm.cmd run lint, and npm.cmd run build also passed.

Review performed

  • Functional correctness
  • Contract compatibility and schema versioning
  • Data integrity and non-mutating behavior
  • Secret/path exposure
  • Cross-platform timestamp parsing
  • Test quality and PR scope

PR size

Production files: 2
Test files: 1
Production LOC: 48
Total diff: 96 lines

Non-goals

Filesystem scanning, repair, backups, UI, and migration are separate follow-up PRs.

Issue

Part of the Thread Store Doctor work in the full engineering plan.

@luoye520ww

Copy link
Copy Markdown
Collaborator Author

This work is consolidated into #942, which combines the Thread Store Doctor, bounded backups, and schema write guard with one tested scope. Closing the duplicate to keep review focused.

@luoye520ww luoye520ww closed this Jul 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant