Files
deepseek-harness/docs/rfc/implemented/process/2026-07-04-persistence-log-catalog.md
T
Tianyi Cui 53dc3c8a28 Harden generator against Codex review findings
- A SessionEventMap member that is not a property signature with an
  explicit payload type is now a hard error instead of silently skipped —
  a method-form or type-less member joins keyof SessionEventMap and must
  not escape the catalog.
- A top-level interface SessionEventMap outside @deepseek-ai/dsh-session
  (ownership read from the package manifest) is now a hard error — an
  unrelated same-named local interface was previously catalogued as the
  on-disk vocabulary.
- JSDoc tag detection runs on the trimmed line, so an extra-indented
  '*  @mode' can no longer bypass the forbidden-tag check and leak into
  prose.

Four new spec cases cover these; RFC and module doc updated to describe
the enforced (not just assumed) invariants.
2026-07-04 23:11:42 +08:00

5.6 KiB

RFC: Generated persistence log event catalog

Status: implemented (accepted 2026-07-04)

Context

The session event log is the harness's on-disk contract: every SessionEventMap member is a record a persistence backend writes verbatim and a replay reconstructs from, and adding one that breaks the durability rules is a breaking change to the on-disk format. Yet the vocabulary had no single reference. The declarations are split across three files — the owning interface in @deepseek-ai/dsh-session plus declaration merges in @deepseek-ai/dsh-compact and @deepseek-ai/dsh-hook-protocol — and the doc surfaces covered it with hand-copies: a hook/* payload table in session.md, a compact/* payload table in the compact README, payload bullets in the hook-protocol README, and a name-list in the session README. The name-list's merge note had already drifted (it named the compaction merge and omitted the hook merge entirely), and nothing could catch the next merge going undocumented: a hand-copy only checks the names someone already wrote down. This is the same gap the cordis catalog closed for bus events and the tool catalog closed for model-facing tools — and log events are covered by neither: a SessionEventMap member is not a cordis Events declaration (it reaches listeners via the single session/event emit), so it has no cordis-catalog row by design.

Decision

Generate docs/persistence-catalog/log-events.md from source, with a freshness gate, as the fourth reference surface: the records a persisted session log can contain, complementing the cordis catalog (wiring), core-data-structures (vocabulary), and the tool catalog (tools).

scripts/gen-persistence-catalog.ts is a pure TypeScript-AST pass, like gen-cordis-catalog.ts and unlike the boot-based tool catalog — the right technique because log events ARE statically knowable: every member is a string-literal-named property with a static type annotation, so the AST is the whole truth. The walk collects every interface SessionEventMap declaration under packages/*/*/src — the owning top-level interface and every declare module '@deepseek-ai/dsh-session' merge — so a brand-new event, core or merged, appears in the next regenerate and an un-regenerated file fails --check (verify-persistence-catalog, a doc-sync member, so pre-push and CI both run it). Each entry renders the member's JSDoc prose, its payload (printed through the TypeScript printer, so a newline-separated multi-line type literal still yields a valid one-line fragment), a surface badge, cross-links into core-data-structures, and the declaration's source pointer, grouped by scope.

Specific choices:

  • JSDoc completeness, enforced. Every member must carry description prose — the JSDoc becomes the catalog entry, the same forcing function the cordis catalog applies to bus events. An @mode tag on a member is a hard error: dispatch modes belong to cordis bus events, and a log event has none — the tag would misread as "this fires on the bus with mode X". Violations aggregate into one error listing every offender.
  • The surface badge is derived, not hand-listed. SurfaceEventType — the subset that produces LLM messages and may carry surfaceOp — is parsed from its union declaration in the owning package; a union member naming no declared event is a hard error (a stale union member would otherwise silently badge nothing). Everything else renders log-only.
  • A dedicated fence. Payload blocks use a ```ts persistence-catalog info string that doc-typecheck recognizes and skips, excluded from the opt-out ratio — the same treatment as ts cordis-catalog (a bare payload fragment is not standalone-compilable).
  • Repo scope. The catalog enumerates the packages in this repo, matching the siblings' packages-only scope; a downstream plugin can merge further event types, which are outside the catalog by construction. The walk defends its own assumptions: a top-level interface SessionEventMap outside @deepseek-ai/dsh-session is a hard error (an unrelated same-named local interface cannot be catalogued as the on-disk vocabulary), a member that is not a property signature with an explicit payload type is a hard error (a method-form member would join keyof SessionEventMap yet slip past a silent walk), and a duplicate member across declarations is a hard error.

This supersedes the hand-copies: the session.md hook/* table, the compact README's event table, the hook-protocol README's payload bullets, and the session README's name-list now link the catalog instead of restating payloads (the surrounding semantics prose stays where it was). The two stray @mode emit tags on the hook-protocol merge members are removed — the new gate rejects them as the category error they were.

Consequences

  • The catalog cannot drift: a vocabulary change the committed file doesn't reflect fails verify-persistence-catalog in the pre-push hook and CI, and a new merged event with no JSDoc fails the generator outright — a plugin can no longer add an undocumented on-disk record type.
  • Event prose has a single home, the JSDoc at the declaration; thin JSDoc yields a thin catalog entry, pressuring authors to document at the source.
  • The SurfaceEventType union is now structurally load-bearing for docs: renaming an event without updating the union (or vice versa) fails the generator, not just the compiler.
  • The badge derivation assumes the union stays a closed set of string literals with exactly one owner; a refactor away from that shape must update the generator in the same change.