You're viewing the readable version of this site. The interactive extras (search, diagrams, read-aloud) need JavaScript and a current browser. Enable JavaScript; if it is already enabled, update your browser.

Learn · Hidden Machines · Part II

budding

Every Child Needs an Owner

Structured concurrency, capabilities, and error kernels.

structured-concurrency, capabilities, supervision, errors, learn

You will recover a task tree from detached work, pass authority explicitly as capabilities, and place failure handling at a supervision boundary that can take meaningful action.

The roster closes before the field trip ends

An HTTP request starts inventory, price, and recommendation queries. Inventory answers, so the handler returns. The other tasks later write to request-owned buffers and log errors no caller can interpret.

Ownership — decide what scope exit promises.

Structured concurrency organizes tasks as a tree. Creation establishes a ownership edge. Scope exit joins children; failure or cancellation follows a declared policy along those edges. The invariant is lifetime containment: a child cannot outlive the scope owning resources it may touch.

Authority is another input

A function that reads global clocks, credentials, configuration, and services has hidden parameters and ambient authority. Pass a narrow environment instead: the clock it may read, the transport it may use, and the cancellation signal owned by the scope. Tests can interpret those capabilities deterministically; production adapters perform the effects.

Explicit environments are not dependency bags. Each capability should retain provenance, freshness, and lifetime. Passing a universal service locator merely launders ambient authority through one parameter.

Failures find the layer that can act

Every intermediate layer catching, logging, and wrapping the same error creates noise and loses causality. A layer handles a failure only when it can retry safely, choose a fallback, compensate, or turn it into a meaningful boundary diagnostic. Otherwise it passes the typed failure upward intact. The small supervision boundary that can act is the error kernel.

Where the model stops

Long-lived daemons and application supervisors intentionally outlive requests; they still need explicit owners. Structured concurrency is not “everything is lexical” so much as “every lifetime edge is owned.” A child must not be canceled merely because a sibling fails unless the scope's policy says their outcomes are coupled.

Lessons

  • Every child task belongs to a lifetime scope.
  • Cancellation is a request; joining proves termination.
  • Capabilities expose authority and nondeterminism as inputs.
  • Failures should be handled by the nearest layer able to act meaningfully.

Practice

  1. Draw the task tree for a request that races two replicas and writes one response.
  2. Separate an explicit capability environment from a service locator.
  3. Transfer the ownership rule to a UI component starting timers and network work.

Owned work still competes for finite resources. The next chapter treats capacity as conserved credit.

References

  1. OpenJDK JEP 525, “Structured Concurrency”.” — task groups as units of lifetime, cancellation, and observability.
  2. Joe Duffy, “15 Years of Concurrency”.” — production context for structured task lifetimes and error propagation.