mirror of
https://github.com/deepseek-ai/deepseek-harness
synced 2026-08-15 21:04:50 +00:00
Two independent bugs made the ACP server crash the moment an editor (Zed)
connected, despite 178 green unit tests at 100% coverage:
1. `session/new` threw `cannot get property "agents" without inject`. Root
cause: a stray `export default apply` made the cordis Loader's
`unwrapExports` (`exports.default ?? exports`) collapse the module to the
bare `apply` function, discarding the sibling `inject`/`name`/`Config`
named exports. The plugin fiber was built with empty `inject`, so every
`ctx.<service>` read in `apply` threw at load. Fix: remove the default
export so the Loader uses the namespace.
2. `session/load` threw `cannot get property "sessionPersistence" without
inject`. `AgentLoop.resume` read `this.ctx.sessionPersistence` (a service
it deliberately does NOT inject); the property proxy's ancestor-only fiber
walk fails through the bridge's traceable shadow. Fix: read it via
`this.ctx.get('sessionPersistence', false)`, the topology-independent
global-store lookup.
Why the suite missed both: every test mounted the plugin by hand
(`ctx.plugin({name,inject,apply})`), bypassing `unwrapExports` entirely, and
the only test driving these RPCs was key-gated (skipped in CI). Added a no-key
`session/new` e2e that boots the real example through the real Loader — it
fails loudly on bug #1 without an API key. Set `TSX_TSCONFIG_PATH` in the e2e
spawn so the subprocess resolves workspace `paths` from a temp cwd (it was
silently falling back to a stale built `lib/`).
Docs: post-mortem 0001; AGENTS.md "line coverage is not behavior coverage" +
with-key/smoke-test philosophy; packages/AGENTS.md plugin-export-shape and
ctx.get rules; dsh-code-review SKILL checks.
3.8 KiB
3.8 KiB
AGENTS.md — Harness Packages
This directory contains all @deepseek-ai/dsh-* harness packages. When editing code here, follow these conventions:
- Effect-based registrations: every contribution (tool, section, adapter, agent, event listener) goes through
ctx.effect()/ctx.on(), andregister()methods return disposers. Never use bare arrays or manual cleanup. - Declaration merging: services declare their ctx key in
declare module 'cordis' { interface Context { } }and their events ininterface Events. Merge-extensible maps (ContentBlockMap,MessageSourceMap,FinishReasonMap,TurnTriggerMap,TurnEndReasonMap,SessionEventMap) are how plugins add new variants. - Waterfall semantics:
ctx.waterfalllisteners receive(...args, next); callnext()to delegate, or return without it to short-circuit (veto). Never callnext()after returning. - Plugin export shape — namespace OR default, never both. A service package exports the service class as
export default(the Loader instantiates it). A function/namespace plugin exportsname/inject/Config/applyas separate named exports and must NOT addexport default— the cordis Loader'sunwrapExportsdoesexports.default ?? exports, so a stray default export collapses the module to the bareapplyfunction and silently discards theinject/name/Confignamespace, leaving the plugin with no injected services (it then throwscannot get property … without injectat load). See docs/postmortem/0001. - Read an optional (non-injected) service via
ctx.get(name, false), notctx.<name>. For a service a plugin reads opportunistically but deliberately leaves out ofstatic inject(e.g.AgentLoopreadingsessionPersistence), thectx.<name>property proxy resolves by an ancestor-only fiber walk that throws when the call arrives through a foreign traceable shadow (the service lives on a sibling fiber).ctx.get(name, false)is the topology-independent global-store lookup (falseskips the active-state check). Services that ARE instatic injectresolve fine viactx.<name>. See docs/postmortem/0001. - Tests: vitest in
packages/<name>/tests/*.spec.ts. Every registry needs an HMR-safety test (register a plugin, dispose its fiber, assert cleanup). Err on the side of more tests — edge cases, error paths, event ordering, races. A plugin shipped viacordis.ymlalso needs at least one test that drives it through the REAL Loader/export path (hand-builtctx.plugin({...})mounts bypassunwrapExportsand cannot catch a broken export shape) — see AGENTS.md § Defensive patterns "Line coverage is not behavior coverage". Real-API (with-key) e2e tests are cheap here (we are DeepSeek) and welcome — write many, especially smoke tests; see AGENTS.md § Secrets / .env.
Naming notes:
- A service
src/index.tsexports the service class asexport default+ all public types; a function/namespace pluginsrc/index.tsexportsname/inject/Config/applyas named exports and NO default (see the plugin-export-shape rule above) src/types.tscontain only types — no runtime code- Tests live at package level under
tests/, notsrc/__tests__/ - A package's README and module/JSDoc comments are part of the change: when you alter behavior (config keys, defaults, error codes, wire fields), update them in the same commit. CI runs
pnpm run doc-sync, which typechecks fencedtsblocks inpackages/*/README.mdand verifies the event-taxonomy table — but it does NOT cover this file or prose drift (config keys, defaults, error codes), so those stay on the author.
Read the per-package README.md for package-specific details: service API, events, extension points, TODOs.