LAYER 04 · Understand safety and durability

Cancellation, timeouts, and defensive invariants

Production reliability comes from every boundary reporting truthful state, not from hoping errors do not happen

18 min3 source anchorsupstream@47f9438
request stop ≠ fully stopped
The question this chapter resolves

Why can a timeout not simply Promise.race and forget the still-running work?

Build intuition

A fire alarm announcing evacuation does not mean the building is empty. The system must distinguish request issued, evacuation in progress, and verified clearance.

MECHANISM

Mechanism

DeepSeek Harness uses structured error codes, AbortSignal, deadlines, and holder-owned disposal to separate stop requests from resource release.

The invariants service lets each package register verifiable conditions. Dispatchers isolate observer exceptions and report orthogonal outcomes independently so notification failure cannot falsify the primary operation.

Step 1 of 5

Create deadline

Child operations share remaining budget instead of resetting timeout.

INVARIANTS

What extensions must preserve

  • Cancellation cause is first-wins
  • Completed dispose means resources are truly released
  • Observer failure cannot revoke an authoritative committed operation
FAILURE MODES

The tempting wrong turns

  • ×Restarting a full timeout at every layer
  • ×Catching every error and returning plain text
  • ×Following a symlink outside the boundary before unlink
VERIFY IN SOURCE

Do not trust the conclusion—verify it

These anchors are pinned to official deepseek-harness@47f9438; account for later breaking changes when reading current upstream.

KNOWLEDGE CHECK

Pause for ten seconds before revealing

Why must observer failure not make Session.append() fail?

Why the next chapter follows

The reliable single-agent spine is complete. Next we add replayable collaboration state: goals, plans, and todos.

Learn DeepSeek Harness

An independent learning project. Explanations derive from source; upstream remains authoritative.