agentleFS
MicrosoftKnown publishermicrosoft/duroxide-pg/.agents/skills/fail-closed-database-state-review/SKILL.md

fail-closed-database-state-review

Skill45 starsChanged 42 days agoMITView on GitHub

Review database-backed provider and migration changes for errors that are converted into absent, empty, zero, or success-shaped state and can permit writes, replay, or destructive repair.

The file

We split this skill into the rules it gives an agent

7 rules. About 0 are common, 6 are distinctive, and 1 is very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈6

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 1

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    Use this skill for changes that read PostgreSQL catalog state, migration history, stored-procedure results, durable history, queue state, …

    line 8
  2. Distinctive:

    Do not convert a failed database query or decode into:

    line 16
  3. Distinctive:

    Search production Rust and SQL for success-shaped fallbacks:

    line 36
  4. Distinctive:

    delete or rewrite migration records.

    line 45
  5. Distinctive:

    every entry is decoded strictly.

    line 60
  6. Very specific:

    Use a fresh CARGO_TARGET_DIR keyed by the source and diff digest so embedded migrations and SQL-only changes cannot reuse a stale binary.

    line 85
  7. Distinctive:

    Do not approve while a database or decode error can become absent state on a write, migration, acknowledgement, pruning, or replay path …

    line 102

≈ “Common” is an estimate: at least 1 in 5 of the 408,460 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

Fail-Closed Database State Review

Use this skill for changes that read PostgreSQL catalog state, migration history, stored-procedure results, durable history, queue state, or serialized provider payloads.

Required Invariant

An error is not evidence that state is absent.

Do not convert a failed database query or decode into:

  • false, None, an empty collection, or a zero count;
  • a missing migration, table, queue item, history entry, or KV entry;
  • permission to create, delete, re-apply, repair, acknowledge, prune, or replay;
  • a successful provider result.

Return the original error with operation and state context. If the database result is structurally invalid, return a permanent provider error that identifies the invalid field or key.

One exception: in fetch_orchestration_item, an undecodable durable payload (history or KV snapshot) is returned as Ok(Some(item)) with history_error set, so the runtime counts the attempt and poisons the instance after max_attempts. Returning Err there hides the item from the poison check: the attempt count climbs on every lock expiry but is never read, so the instance retries forever.

Review Procedure

  1. Search production Rust and SQL for success-shaped fallbacks:

    rg -n 'unwrap_or\(false\)|unwrap_or_default\(\)|unwrap_or\(0|unwrap_or\(\(0|filter_map\(|\.ok\(\)|let _ = ' src migrations
    rg -n 'fetch_optional|row\.and_then|history_error|check_.*await|DELETE FROM .*_duroxide_migrations|re-?apply' src migrations
  2. Trace each fallback to its next side effect. Flag it when the fallback can:
    • enter a create or repair path;
    • delete or rewrite migration records;
    • execute DDL or replace stored procedures;
    • acknowledge, delete, or prune durable state;
    • return replay input after dropping malformed data.
  3. For migrations, require all of these:
    • catalog query errors propagate;
    • applied versions are an ordered prefix of bundled migrations;
    • unknown versions, interior holes, and missing core tables stop before DDL;
    • required objects are verified as base-table relation kinds, not by name alone;
    • the runner never deletes applied migration rows to trigger a re-run;
    • repair is explicit and separate from normal startup.
  4. For serialized provider state, require all of these:
    • the root JSON type is checked;
    • every entry is decoded strictly;
    • required fields and their types are enforced;
    • one malformed entry fails the whole operation;
    • errors identify the operation and affected key or field.
  5. Inspect cleanup and lock-release code separately. A deliberately best-effort action must explain why suppressing its error cannot retain a lock, return a poisoned connection to a pool, or report a successful write.

Regression Proof

Require the same test code to show red before the fix and green after it. Each affected path needs:

  • a positive control with valid state;
  • a malformed, missing, or error-producing input;
  • an assertion on the returned error;
  • a before/after snapshot of every ledger or durable object that must not change;
  • a behavior assertion, not only a log or string check.

For migration safety, compare _duroxide_migrations rows and pg_get_functiondef() before and after the rejected startup. For provider payloads, prove malformed input does not become empty successful state.

Use a fresh CARGO_TARGET_DIR keyed by the source and diff digest so embedded migrations and SQL-only changes cannot reuse a stale binary. Run the targeted regressions before the full repository suite.

Review Output

Report each finding with:

FieldRequired content
LocationFile and line
FallbackThe exact error-to-state conversion
Side effectThe write, replay, or success result it enables
SeverityBlocker, high, medium, or low
ProofRed test and immutable before/after state
FixError propagation or explicit validation

Do not approve while a database or decode error can become absent state on a write, migration, acknowledgement, pruning, or replay path introduced or changed by the candidate. Record pre-existing matches as follow-up debt with the same evidence, but do not silently expand a scoped patch unless they share the candidate's execution path or make its safety claim false.

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.