DeepSeek Harness

DeepSeek Harness: Plugin Scopes and Cleanup

· 7 min read · 中文版

In DeepSeek Harness, a registration scope can tie visibility to a specific agent and tie the registration's lifetime to Cordis cleanup. Service isolation and plugin-fiber effects are related but distinct mechanisms, so identify the owner and disposer for each resource.

DeepSeek Harness: Which kinds of scope are involved?

The scoped registration reference describes a library primitive for per-agent visibility and shared lifetime ownership. It is not itself a Cordis service. A ScopeKey is an opaque object identity; the shipped loop uses the live Agent object as its key, while the primitive does not inspect that object. A scoped registration context carries both visibility and Cordis effect ownership.

The Cordis Context reference describes a separate service-isolation operation, ctx.isolate(name, label?). It creates a child context where reads and writes of that named service resolve against another label. These uses of “scope” solve different problems: an agent-specific registry overlay is not automatically a separate service implementation.

Identify the owner, register the effect, then await scope or fiber cleanup

DeepSeek Harness: What owns cleanup?

A Scope provides ctx for owned registrations, rawDispose for the exact Cordis disposer needed in an ordered composite effect, and dispose() as the public shared quiescence boundary. Racing calls to dispose() await the same completion. That contract matters when two parts of a lifecycle try to close the same scope: awaiting disposal means waiting for scope-owned registrations to be disposed, rather than merely requesting their removal.

At the plugin level, a fiber represents one loaded plugin instance and its effects. The fiber reference says ctx.effect() runs its body immediately, collects the disposers it produces, and runs them in reverse order when its returned disposer is invoked or the fiber unloads, whichever happens first. Calling that disposer twice is a no-op. fiber.dispose() settles after cleanup finishes.

MechanismControlsCleanup or lifetime detail
ScopeKeyExact identity used by scoped routingIdentity alone is not a disposer
Scope.ctxContext for scope-owned registrationScope.dispose() awaits shared cleanup
ctx.effect()Effects owned by the current fiberDisposers run in reverse order
ctx.provide()Service visible to dependents in an isolation scopeReturned disposer or fiber unload unregisters it
ctx.isolate()Resolution of a named service in a child contextDifferent labels define service scopes

ctx.provide() returns a disposer and unregisters the service when that disposer runs or the fiber unloads. It throws if the service name is already provided in that scope or declared as an accessor. This is a concrete cleanup contract; simply creating a child context with metadata does not, by itself, establish a cleanup action.

DeepSeek Harness: How should a plugin author reason about a resource?

  1. Identify the resource and its intended owner: a plugin instance, an agent-specific registration, or a named service scope. State when the resource should stop being visible and when its work should finish.
  2. Register through the context that owns the relevant lifetime. For a scoped registry, use its registration context so that visibility and effect ownership agree. For a service, inspect its isolation label and the provide contract.
  3. Retain and use the returned disposer where early removal is required. For a resource managed by ctx.effect(), provide the appropriate cleanup through the effect contract and await disposal where asynchronous cleanup is involved.
  4. Exercise both explicit removal and owner teardown. Check that a second disposal is handled according to the relevant contract and that dependent work has settled before reusing the resource.
  5. Check unrelated owners and global registrations separately. Removing one agent's contribution should be evaluated against the registry's exact-scope and global merge behavior, rather than assumed from a display name.

This sequence is a review method, not a claim that every API returns the same kind of disposer. Consult the owning API for the precise return type and whether its cleanup is asynchronous. Resources created outside the tracked effect or registration require their own lifecycle handling; these references do not promise automatic cleanup of arbitrary external work.

DeepSeek Harness: How do global and scoped registrations interact?

ScopedLayers owns an eager global layer and lazily created exact-scope layers. Reads do not create layers: peek(undefined) means no overlay. merge() materializes global named entries in insertion order followed by scoped shadows. An exact-scope contribution can therefore shadow a global named entry in the merged view; it is not a change to the global entry itself.

A ScopeLayer represents a registry's complete contribution for a global or exact scope and may aggregate multiple tables. Reclamation happens only when the complete layer is empty, preventing one emptied table from discarding a sibling table. Registrations collect one synchronous undo before optional notification and return Cordis's exact disposer. NamedEntries supplies named lookup, while AnonymousEntries gives each append a unique identity so equal values remain independent; their exact-entry undos are idempotent.

These details make removal more precise than “delete everything with this value.” If two anonymous registrations happen to contain equal values, each has its own identity and undo. When reviewing a registry, distinguish removing an individual contribution from tearing down the entire scope and from changing the global layer.

Cleanup order deserves review when one resource depends on another. The fiber effect contract runs its collected disposers in reverse order, so arrange the owned effects with their dependencies in mind. Do not assume a separately owned resource participates in that order. Also distinguish a registration becoming invisible from the associated asynchronous work becoming quiescent: whether a disposer waits for the latter depends on the specific API. The scope's shared dispose() boundary is documented; equivalent behavior must be checked separately for other resources.

DeepSeek Harness: What are the limits and safety boundaries?

A scope is a lifecycle and visibility mechanism; the cited contracts do not establish a sandbox, network isolation, or a general authorization boundary. Do not treat a scoped registration or successful disposal as proof that arbitrary plugin code is safe. Check each resource's contract, especially external processes or asynchronous operations that the plugin itself starts.

ctx.extend() creates a child with metadata that shadows inherited properties without mutating the parent. ctx.isolate() redirects a named service to an independent label; passing the same label can join two isolation scopes. Neither should be confused with the agent ScopeKey or with cleanup ownership. Using a new context without recording who owns its effects can make later teardown difficult to reason about.

DeepSeek Harness: What do these terms mean?

  • Fiber: one loaded plugin instance with lifecycle state and effects.
  • Disposer: a function that removes or cleans up a registered contribution.
  • Quiescence: completion of the cleanup awaited by the relevant disposal contract.
  • Scoped layer: a registry's contribution for a particular identity or the global layer.
  • Isolation label: a label used to resolve a named Cordis service in a child context.

Frequently asked questions

Is an agent scope the same as service isolation?

No. Scoped registry visibility and named service resolution are distinct mechanisms.

What does Scope.dispose() wait for?

Racing callers await the same scope-owned registration cleanup.

Does scope guarantee arbitrary resources are cleaned up?

No. Each resource must be owned and cleaned up according to its contract.

Sources

Every claim in this article was checked against the sources below. Community discussions are user reports, not official behavior.

  1. Scoped registration
  2. Cordis Context
  3. Cordis Fiber

This is an independent community article, not official DeepSeek documentation. Listing a plugin in the registry is not a security review.

← Back to all articles

DeepSeek Harness: Plugin Scopes and Cleanup