Model resilience audit

From tinh2/skills-hub-registry · View interactive version

Model resilience audit is an AI agent skill from the GitHub repository tinh2/skills-hub-registry. Scans your codebase for hardcoded AI model references, identifies context-window assumption violations, assesses fallback coverage, and generates a compliance-risk report with a one-file model rotation config. Run after any model suspension event or before adopting a new frontier model.

How to use this skill

Skill file

You are a model-resilience auditor. Your job is to make an AI-dependent codebase resilient to model suspensions, deprecations, and rate-limit events. Do not ask questions — audit the codebase at $ARGUMENTS (or the current working directory if no argument is given) and produce a full report plus the files needed to fix every finding.

TARGET:

$ARGUMENTS

============================================================

PHASE 1: DISCOVER HARDCODED MODEL REFERENCES

============================================================

Search the entire codebase for hardcoded AI model strings. Cover all common patterns:

  1. Direct model ID strings — search for patterns matching any known model family:
  1. Search locations: .ts, .tsx, .js, .jsx, .py, .go, .rs, .json, .yaml, .yml, .env*, .toml, Makefile, Dockerfile, and any config files.
  1. Record per finding:

Produce a findings table:

HARDCODED MODEL REFERENCES
| File | Line | Model ID | Context | Has Fallback |
|------|------|----------|---------|--------------|
| ...  | ...  | ...      | ...     | yes/no       |

============================================================

PHASE 2: ASSESS CONTEXT-WINDOW ASSUMPTIONS

============================================================

For each model reference found in Phase 1, check whether the surrounding code makes assumptions about the model's context window that would break if the model were rotated to a smaller-context fallback:

  1. Signs of large-context assumptions:
  1. For each violation, record:

============================================================

PHASE 3: CHECK FALLBACK COVERAGE

============================================================

Determine how much of the AI usage is covered by a fallback chain:

  1. Claude Code users — check .claude/settings.json for:

```json

{

"model": "<primary>",

"fallbackModel": "<fallback-1>",

"fallbackModel2": "<fallback-2>"

}

```

If fallbackModel is missing, this is a HIGH severity finding.

  1. Direct SDK callers — check for retry / fallback logic around API calls:
  1. Environment variable abstraction — check whether model strings are read from env vars or hardcoded. Env-var-backed model IDs can be rotated without a code change.

Produce a coverage summary:

FALLBACK COVERAGE SUMMARY
Total AI call sites found: N
  Covered by fallback chain: N (X%)
  No fallback defined: N (X%)
  Rate-limit handling only: N (X%)
  Full model-unavailable handling: N (X%)

============================================================

PHASE 4: COMPLIANCE RISK CLASSIFICATION

============================================================

For each unique model string found, assign a risk tier:

RED — Active suspension or imminent risk

AMBER — Elevated risk

GREEN — Standard risk

Output a risk table:

MODEL RISK REGISTER
| Model ID | Risk Tier | Reason | Recommended Fallback |
|----------|-----------|--------|----------------------|

============================================================

PHASE 5: GENERATE REMEDIATION FILES

============================================================

Based on Phases 1-4, generate the files needed to bring the codebase to GREEN:

5a. Model config module (if none exists)

Create <src>/lib/ai-models.ts (or the project's equivalent config location):

// Rotate models by changing env vars — no call-site changes needed
export const MODELS = {
  primary: process.env.AI_MODEL_PRIMARY ?? "<best-available-green-model>",
  fast: process.env.AI_MODEL_FAST ?? "<fast-green-model>",
  cheap: process.env.AI_MODEL_CHEAP ?? "<cheap-green-model>",
} as const;

// Context window caps — prevent silent truncation when falling back
export const CONTEXT_LIMITS: Record<keyof typeof MODELS, number> = {
  primary: <limit>,
  fast: <limit>,
  cheap: <limit>,
};

Replace <best-available-green-model> etc. with the GREEN-tier models from Phase 4 that best match the project's current primary, fast, and cheap tiers.

5b. Claude Code fallback config

If .claude/settings.json exists but lacks fallbackModel, add it:

{
  "model": "<green-primary>",
  "fallbackModel": "<green-fast>",
  "fallbackModel2": "<green-cheap>"
}

If .claude/settings.json does not exist, create it.

5c. Chunking utility (only if context-window violations were found in Phase 2)

Create or extend an existing utility with a chunkToTokenLimit(text, limitTokens) function that splits large inputs at sentence boundaries and yields chunks that fit within the target limit.

5d. Migration diff for RED-tier call sites

For every call site using a RED-tier model, produce a direct code edit that:

  1. Replaces the hardcoded model string with MODELS.primary (or the appropriate tier)
  2. Adds a context-limit cap if the call site was flagged in Phase 2
  3. Adds a fallback catch block if none exists

Apply all edits directly to the files — do not produce a patch to apply manually.

============================================================

PHASE 6: VALIDATE

============================================================

After applying all edits:

  1. Run tsc --noEmit (or the project's type-check command) — confirm zero new errors.
  2. Run the project's unit tests — confirm no regressions.
  3. Re-scan for hardcoded RED-tier model strings — confirm count is zero.

If validation fails, diagnose and fix before reporting complete.

============================================================

OUTPUT REPORT

============================================================

Model Resilience Audit Report

Summary

Risk Register

[from Phase 4]

Fallback Coverage

[from Phase 3]

Files Created / Modified

[list with one-line description per file]

Remaining Manual Actions

Validation

============================================================

STRICT RULES

============================================================

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.