All posts

6 min readPost 12

When a product story became a requirement: grave notices and Docker containers

While describing how Obituary works, we pictured an agent touching a buried file and immediately learning how to resurrect it—then checked the code and realized it couldn't. That same night produced both 25ms-budgeted grave notices and full-ID, out-of-lock Docker container lifespans.

On this page
  1. Gap one: once a file was buried, the agent just hit ENOENT
  2. Grave notices: inform without blocking, under a 25 ms lock budget
  3. Gap two: stopping expired Docker containers without touching images or volumes

Writing a product story often exposes gaps faster than a spec does: you describe an interaction that feels completely obvious, check the implementation, and realize the code cannot actually do it. Instead of softening the story, we turned those gaps into real features.

In the early hours of 11 November, that happened twice back-to-back—yielding grave notices for missing files and Docker container lifespans.

Gap one: once a file was buried, the agent just hit ENOENT ​

Obituary moves expired AI-agent files into a local graveyard where they stay restorable for 7 days. Describing that flow, we naturally wrote: if you aren't sure whether a scratch file is still needed, bury it—if an agent tries to use it during the next week, Obituary tells the agent where it went so it can resurrect it.

Checking our code revealed a blind spot. Agents only saw a summary at session start; once a file sat in the graveyard, any later tool call targeting that path simply failed with No such file or directory, leaving the agent assuming the file had never existed.

Grave notices: inform without blocking, under a 25 ms lock budget ​

We added a lightweight notice hook. Whenever an agent's tool call references a path that does not exist on disk yet matches a restorable grave (either the buried path itself or a child inside a buried folder), Obituary attaches additionalContext stating four facts:

  • The grave ID
  • When it was buried
  • How long it remains restorable
  • The exact command: obit resurrect <id>

The hook only informs—it never denies or mutates the tool call, and fires at most once per grave per session. Hosts that accept pre-tool context receive it on the spot; other hosts deliver it on the next context-capable event, as documented in the capability table.

Here is an isolated run: burying notes.md and feeding a PreToolUse file-read payload into obit hook claude:

Terminal output burying notes.md then sending a PreToolUse read payload to obit hook claude: additionalContext reports grave ID 1, restorable deadline, and obit resurrect 1 without denying the call
Real grave notice output: reading a buried path injects the grave ID, burial timestamp, restore deadline, and resurrect command while letting the tool call proceed.

Keeping PreToolUse fast ​

PreToolUse runs on every file and shell action and previously never touched the ledger. Four constraints keep grave notices cheap:

  • Zero ledger reads when the path exists: checks trigger only when the referenced path is actually missing.
  • Fast path-only index: every ledger commit rebuilds a compact path index used purely as a negative filter; only a hit reads the ledger to verify.
  • Hard 25 ms shared-lock budget: if the ledger lock is busy for more than 25 ms, the hook skips the notice rather than stalling the agent.
  • Exact-case matching: we prefer an occasional missed notice over expensive directory walks.

That same evening we also switched the session-start summary of recently buried files to off by default to save agent context tokens (re-enableable via [hooks] session_summary or Settings).

Gap two: stopping expired Docker containers without touching images or volumes ​

A second everyday annoyance landed the same night: agents routinely run docker run and docker compose up during debugging, leaving behind orphaned containers nobody remembers a few days later.

Version one drew a strict perimeter: containers only—never images, networks, or volumes. (Later volume support remained strictly opt-in via --docker-volume, and burying a container still never deletes its volumes.)

Containers enter either explicitly via obit docker add <container> <lifespan> or—when auto-proposals are enabled—as pending proposals for containers created during a session. Their lifecycle mirrors files cleanly:

StageDocker actionSafety rule
Expiry burialdocker stopKeeps container and writable layer intact
Resurrectdocker startRestores container with writable layer untouched
Post-retention purgedocker rmNever passes -v (volumes) or -f (force-kill running)

Three invariants hold across every step:

  • Every command passes the full 64-character container ID (names are display-only), re-inspecting ID and creation timestamp right before acting.
  • If a container is running at purge time, someone started it again—Obituary treats it as resurrected and never removes it.
  • Containers started with --rm (AutoRemove) vanish automatically when stopped, making burial irreversible, so Obituary refuses to register them.

A subtle Docker hazard: renaming another container to a full 64-char ID ​

Docker resolves container references in order: full ID, then exact name, then ID prefix. If the original container disappears and a different container gets renamed to that exact 64-character hex string, docker rm <fullID> matches the unrelated container by exact name!

Before every stop, start, or rm, Obituary runs docker ps to confirm no container's name collides with the target's full ID, refusing to proceed if one does.

Testing against our fake Docker CLI captures every call made during a full add → expire → resurrect cycle, showing the ps collision checks before stop and start plus 9 total inspect calls:

Terminal output registering web-api for 5s, burying on expiry, and resurrecting via fake Docker CLI: logs show ps collision checks before stop and start, full 64-char container IDs, 9 inspects, and no -f or -v flags
Recorded commands from a fake Docker CLI run: stop on expiry, start on resurrect, full 64-character IDs everywhere, pre-action ps collision checks, and never -f or -v.

Out-of-lock execution with durable intents ​

docker stop often waits ten seconds or more for graceful shutdown, so it can never run inside a hook or while holding store.lock. Every mutation follows a three-step protocol:

  1. Under store.lock, verify the entry and persist a durable container intent (binding a unique token alongside Docker context, endpoint, and DaemonID).
  2. Release store.lock and invoke the docker CLI explicitly against that pinned endpoint; if the daemon ID drifted, refuse.
  3. Reacquire store.lock, verify the intent token still matches, commit the outcome, and clear the intent.

Crash recovery only observes state rather than blindly replaying destructive commands: a running container is never marked buried, a confirmed removal finishes purge bookkeeping, and an unsent intent clears to retry on schedule. Two days later we tightened session container proposals further to require concrete compose working-directory or project bind-mount evidence—never guessing ownership from timestamp overlap alone.

All posts