cordis-styling-nitpicking
Cordis Ownership and Lifecycle Audit
This is a focused semantic review of Cordis ownership and lifecycle. Start a repository audit from exported plugin entrypoints (apply or a concrete default export invoked by Cordis), then trace module initialization, registered services, listeners, effects, disposers, and transitive calls reachable from those roots. Exclude unrelated helpers, build tools, CLI paths, and tests as finding targets. Read tests and vendored Cordis to establish behavior; report a generated defect against its owning source. Do not report defects in vendored code under this skill.
Sources of truth
- Repository conventions: Cordis ownership requirements.
- Lifecycle and effects: effect acquisition and disposal.
- Services: dependency tracking and service availability.
- Defensive patterns: quiescent teardown and required completion listeners.
Review workflow
- Locate mutable owners, registrations, resource acquisition, and work admission reachable from the requested plugin roots. For large scopes, use independent directory scans, then consolidate findings involving the same consumer and resource.
- Trace ownership through the actual context: in a traceable service method,
this.ctxis the caller's context. Identify who owns each effect and the disposer that releases it. - Trace cleanup through every await to its last service call, emitted event, acknowledged operation, and durable write. Include indirect event delivery and cleanup performed after abort, kill, or cancellation.
- Compare consumer completion with the time each required listener, registry, writer, connection, domain, or transport becomes unusable. Inspect the current Cordis implementation; reverse start order and dependency registration alone do not establish completion order.
- Establish a legal failing interleaving and observable impact. Check existing cancellation, explicit sequencing, and documented discard semantics before reporting. Use controlled promises for reproduction where feasible, and label source-only findings accurately.
P0: singleton pattern
Flag one process-wide instance or mutable state owner whose identity or lifetime comes from module loading, a static field, a global symbol, a hidden cache, or a getInstance() accessor. Weak keys, size bounds, generation checks, and behavior-preserving memoization do not give a module-level cache Cordis ownership.
Exclude immutable scalar constants, pure frozen tables, stateless functions, and objects allocated inside an explicitly scoped owner. Recommend a Cordis service and declared or otherwise resolved consumer dependencies; use a scoped context or service-owned keyed record for narrower lifetimes.
P0: unreversed side effect
Flag an owner that leaves a live effect behind after disposal: listeners, registrations, timers, watchers, child fibers, processes, connections, temporary files, subscriptions, ambient patches, or asynchronous work. Aborting or killing without awaiting settlement is a violation when cleanup can return before owned work stops.
Correctly owned ctx.on(), ctx.plugin(), and ctx.effect() registrations already provide reversal; callers need not retain their early disposers. Unmanaged resources need an owned effect or explicit awaited cleanup. Do not demand rollback of intentional durable writes or remote mutations; temporary and live resources used by those operations still need owners.
P0: cleanup dependency released before consumer completion
Any service call or event delivery required to finish cleanup is a lifecycle dependency. Keep its actual resources and listeners usable until the consumer has settled, including final result publication and durable writes. A provider's disposal promise finishing after consumers does not prove its resources survived their cleanup.
The current fiber unload starts sibling disposers concurrently. Service withdrawal awaits dependent fibers inside its own disposer, while sibling resource closers can already run. Adding inject, reversing registration order, or retaining a service reference does not fix that race. A listener can also belong to the consumer fiber and auto-unsubscribe alongside an operation's drain.
Require explicit ownership and awaited sequencing: stop admission, settle admitted consumers while their dependencies remain usable, then drain and release the resources. Scope new-admission rejection separately from completion of accepted operations. Use an explicitly composed effect or a resource-owning parent with an awaited consumer/service child; verify the actual captured disposer identities. ctx.effect(function* ...) serializes the disposers it collects, but a wrapper around an independently registered effect does not transfer ownership of the original effect. Top-level plugin generator yields are not a general promise of serial sibling disposal. Check failure paths as well: one cleanup error must not skip required abort, settlement, or resource release.
Current workaround: function plugin with yielded effects
Use a function-style provider plugin with one ctx.effect(function* () { ... }) to compose service publication and resource effects. Yield the exact disposers returned by the registrations so the composed effect takes ownership of them:
- Acquire the resources and
