mirror of
https://github.com/deepseek-ai/deepseek-harness
synced 2026-08-15 21:04:50 +00:00
Introduce HarnessError in dsh-llm (the leaf package): a stable machine-routable
code distinct from the message, cause chaining, name from the subclass, plus
isHarnessError. LlmError, ToolArgsError, and InvariantError now extend it.
Tool failures carry the structure end-to-end: ToolExecutionResult gains
error: { name, code } (populated from a thrown HarnessError), and the loop
forwards it onto the tool/result session event (which gained the same optional
field) for retry/sandbox plugins and replay. The loop's toError wraps non-Error
throws in a HarnessError(code: UNKNOWN, cause) instead of a bare Error.
Landed last and in isolation so it's a pure upgrade over the plain Error+code
the earlier PRs used — independently revertible. Graduates RFC 005 pt 2 ->
ADR 0015; RFC 005 now fully implemented.
2.7 KiB
2.7 KiB
RFC 005: Runtime validation at the model boundary, error taxonomy, dev-mode invariants
Status: implemented — part 1 (arg validation) → ADR 0011; part 3 (dev invariants) → ADR 0012; part 2 (error taxonomy) → ADR 0015
Problem
Three gaps where compile-time guarantees stop:
- Tool args are model-generated JSON —
defineTool'sInferArgs<S>claim is only as true as the model's output. Today a malformed call reachesexecuteuntyped-in-practice. - Tool errors flatten to a text block; name/code/stack are lost, so future sandbox/retry plugins can't distinguish ENOENT from EACCES, and the model gets less actionable feedback than it could.
- Loop ordering invariants (seq monotonicity, step/turn event nesting, turn-number continuity) are asserted only where tests look.
Proposal
- Schema validation in defineTool: before
execute, validate parsed args against the SchemaSpec (the converter already encodes the structure — a small interpreter walks it: presence of required keys, primitive type checks, enum membership, recursion into objects/arrays). On mismatch, return anisErrorToolExecutionResult describing the violation — the model can self-correct. Raw-registered tools (MCP) keep validating their own input. - Structured error taxonomy: per-package error classes extending a common
HarnessError(name,code,causechaining).ToolExecutionResultgains optionalerror: { name, code }alongside the model-facing text. The loop'serrorDataconsumes it; sessionerrorevents carry the code. This also properly fixes the non-Error-throw message degradation found in review. - Dev-mode invariants: a
dsh-invariantsdebug plugin (everything is a plugin — it's just listeners) asserting, when enabled: session seq strictly increases;step/startprecedes its chunks;turn/start/turn/endpair and nest; tool/call has a matching tool/result; status transitions are legal. Enabled in tests and the demo; off in production. Doubles as executable documentation of the event contract. (As implemented, the tool rule is one-directional — atool/resultrequires a priortool/call, but NOT the converse: a throwingtools/executewaterfall ends a step with no result. See ADR 0012.)
Plan
2 first (taxonomy is a dependency of 1's error shape), then 1, then 3. Property tests (RFC 001) then close the loop: generated args ↔ validator ↔ InferArgs agreement.
Risks
Validator/InferArgs drift — covered by the RFC 001 composition property. Validation cost per call is negligible next to a model call.