8 min readPost 35
Replacing 25 Docker checks with one provider contract—and the two bugs review caught after
When Docker container branches spread to 25+ call sites across four packages, every future resource gets locked out by hardcoding. On 29 November we unified obit doctor, proposal views, and background discovery behind a stdlib-only 6-method extres.Provider plus optional Doctor and Discoverer traits—and independent read-only review caught two sharp bugs before merge: volume.go crossing 500 lines with a decorator purge trap, and auto discovery missing zero CreatedAt and relative Project paths.

On this page
Obituary started by attaching countdowns to local files and folders and moving expired items into a restorable graveyard. Later, because developer disks fill up fastest from containers and volumes, we added Docker container lifespans and explicit Docker volume archival.
At first, dropping if item.Kind == KindContainer into a function or two felt fast and harmless. By late November, that shortcut had multiplied into more than 25 hardcoded Docker checks spread across the ledger, lifecycle engine, auto-registration, app views, and obit doctor.
The cost showed up right away on Docker volumes: four separate cleanup and registration paths broke because someone checked for containers and forgot volumes. Adding a second runtime like Podman under that setup would mean hunting through every switch in the repo and hoping none got missed.
On 29 November we finished unifying external-resource dispatch (5bbee23, 5125530, 2135cbe, e684c40) behind a standard-library-only contract—and then ran independent read-only review that caught two concrete bugs before the branch hit main.

Six methods, zero Docker imports, and opt-in capabilities
The usual trap when abstracting external resources is inventing a bloated CRUD interface—or letting the contract package import Docker types, which guarantees import cycles the moment another runtime arrives.
internal/core/extres imports only four Go standard-library packages (context, encoding/json, io, time) and splits the contract into a tiny core plus opt-in traits:
- A 6-method
Provider(plusKind()):Validate,Inspect,Verify,Bury,Resurrect, andPurge. The methods mirror Obituary's safety state machine directly: external calls outside ledger locks, durable pre-send intents, and read-back verification.Validateis explicitly restricted to pure in-memory checks because lifecycle calls it inside astore.locktransaction, where blocking I/O or subprocesses are forbidden. - Three opt-in capability interfaces:
RetentionPolicy(retention and recycle-mode rules),Doctor(live availability and diagnostics), andDiscoverer(session-end auto-discovery).
Making Discoverer opt-in lets the Go type system enforce a product safety boundary. docker.ContainerProvider implements Provider + RetentionPolicy + Doctor + Discoverer, while docker.VolumeProvider intentionally does not implement Discoverer. Docker volumes stay explicit --docker-volume opt-in forever; TestVolumeProviderDoctorDiagnoseAndNoDiscoverer asserts that VolumeProvider never satisfies extres.Discoverer, turning any accidental wiring into an immediate test failure.
Moving the last three Docker-only callers onto extres.Registry
An interface only earns its keep once the callers stop knowing which concrete runtime sits behind it:
app.ProposalViewsdrops direct Docker probes: Previously, proposal view rendering checked specifically for container candidates and probed Docker directly.internal/app/proposals.gonow filters onc.IsExternal(), looks up anextres.Doctorfrom the service's registry, caches results per(kind, target), and callsAvailable(ctx)to populateBlocked.TestProposalViewsDispatchesCustomNonDockerDoctorProviderregisters a syntheticpodman-containerprovider and getspodman-unavailableback without changing a single line of app code.obit doctorreads ledger state through a read-only projection:internal/cli/doctorused to pass rawledger.Stateinto Docker-specific availability, legacy v14 target, and volume-recovery checks. Nowlifecycle.ExternalResourceRecords(st)projects items, burials, proposals, and intents into stdlib-onlyextres.ResourceRecordsnapshots.doctorwalks registeredextres.Doctorproviders in deterministic sorted order and localizes structuredSummary+Datafields at the CLI edge. One subtle regression surfaced immediately (5125530): moving volume-recovery scanning intoVolumeProvider.Diagnosebroke the existingvolume-recoverymutation anchor that targeted the path constant ininternal/cli/doctor/volume.go. WiringVolumeDirexplicitly throughDiagnoseRequestfromvolumeArchiveRelDir()kept unified dispatch intact while preserving mutation coverage.auto.Engine.Finishdispatches across registeredDiscoverers: Background finish (ExternalLeftovers) now loops through every registeredextres.Discovererwith aSessionWindowcarryingStarted,Ended, and project lookup callbacks. Foreground hook entry points still write only their timestamp and never invoke external engines.
Five edge cases got tightened in the same sweep:
VolumeProvider.Resurrectforbids rawos.Open(grave.Path): It now requireshooks.OpenGrave, keeping every restore confined insideos.Rooteven when wrapped by a decorator.VolumeProvider.Purgerejects a nilBeforeSendhook and validates burial volume identity before writingPurgeIntent, so invalid metadata never leaves a half-written intent behind.- Mixed Docker overrides suppress stale default volume providers: When a caller or test overrides
Service.Dockerwith a container-only stub,adaptOverriddenDockerProvidertreats only zero-valuedocker.CLI{}as the default placeholder and drops the defaultVolumeProviderinstead of falling through to the hostdockerbinary (TestAdaptOverriddenDockerProviderMixedOverrides). - Recycle-mode policy runs before
dryRun:settleDockerVolumechecksExcludeFromRecycleMode()ahead ofdryRunso dry runs match real execution. - Error-free
Verifyverdicts still gate approval:ApproveContainermapsVerdictNotFound,VerdictIdentity, andVerdictUnavailableeven when a provider returnserr == nil(TestApproveContainerMapsVerdictWithoutError).
Two bugs independent review caught before merge
All tests were green after the refactor, yet an independent read-only review before merging into main uncovered two real defects (2135cbe).
Catch 1: auto's secondary guard let zero CreatedAt and relative Project paths through
Even when a Discoverer promises to enforce session windows and absolute project roots, externalCandidate in internal/auto/container.go is the core's second line of defense against a buggy future provider.
Review read two quiet lines in the initial patch and built working bypasses for both:
if cand.Project == "" || cand.Reason == "" {
return "", ledger.Candidate{}, false
}
if !cand.CreatedAt.IsZero() && (cand.CreatedAt.Before(window.Started) || cand.CreatedAt.After(window.Ended)) {
return "", ledger.Candidate{}, false
}Both checks had real holes:
- Relative
Project: "."sailed pastcand.Project == "":pathutil.LongAbs(".")then resolved"."against whatever working directory the background process happened to be running in, attaching a container to an unrelated project. - A zero
CreatedAtbypassed the time window completely: If a provider omittedCandidate.CreatedAt, an old container whose encodedid.Createdpredated the session by two hours—or a candidate where both timestamps were zero—skipped the window check and slipped straight into a proposal.
Before touching the implementation, we added three probe candidates to TestFinishDispatchesCustomDiscovererAndRequiresEvidence—zeroCreatedAtOldID (zero outer timestamp, 2-hour-old credential), bothZeroID (both timestamps zero), and relProjectID (Project: ".")—and watched the test fail on the exact bypasses. Then we hardened externalCandidate:
- Require
filepath.IsAbs(cand.Project)up front so relative paths are rejected outright. - Decode the credential first and fall back from a zero
cand.CreatedAttoid.Created. - Route the final timestamp through
withinExternalWindow, which rejects zero timestamps and anything outside[window.Started, window.Ended].
Catch 2: volume.go hit 505 lines and hid a decorator purge trap
The second review catch paired a structural guardrail breach with a subtle state-machine failure:
- Past the 500-line ceiling: Wiring provider dispatch pushed
internal/core/lifecycle/volume.goto 505 lines, crossing our ~500-line per-file split limit. - Plain
extres.Providerdecorators got stuck onPurgeIntent: TracingpurgeDockerVolumerevealed what happened if a caller wrappeddocker.VolumeProviderin a plain 6-method decorator (for logging or metrics) without forwarding the unexportedUsesLocalGraveArchive()method. The oldusesLocalGraveArchivereturnedfalse, routing the burial intopurgeCustomVolumeProvider. That path persistedPurgeIntent, calledVolumeProvider.Purgewith an emptyMutateHooks{}, and immediately errored becauseBeforeSendwas nil—leaving a stuckPurgeIntenton disk that permanently blockedobit resurrectas well.
We fixed both cleanly in one pass:
- Extracted volume purging into
internal/core/lifecycle/volume_purge.go(105 lines), bringingvolume.goback down to 407 lines. - Flipped
usesLocalGraveArchiveto default totrueforKindDockerVolumeunless a provider explicitly opts out withfalse. Any plain decorator around a Docker volume provider now keepsos.Root-confined resurrection and purge by default and never strands aPurgeIntent(TestWrappedVolumeProviderKeepsRootedResurrectAndPurge).

Existing Docker containers, local volumes, v14–v18 ledgers, and mutation anchors kept their exact behavior. The difference is that doctor, auto, and proposal views no longer know any container engine by name—bringing in the next external runtime now means writing one adapter, not chasing 25 branches across the repo.