- Home
- Skills
- APIs & Backend
- Workflow State Contract Repair
More screenshots
Works with the AI tools you already use
Workflow State Contract Repair
Workflow State Contract Repair is a bounded ToolForge Labs workflow.
$8.99
Workflow State Contract Repair
Example session with this skill installed
I have a Next.js/TypeScript B2B SaaS with PostgreSQL, Prisma, BullMQ, and React. Customer onboarding, purchase approvals, and support escalations each use status fields, but the UI, API, and workers disagree on allowed transitions. Admin endpoints can jump directly to terminal states, retries can send duplicate side effects, completed records can be reopened by stale jobs, and some flows persist both status and boolean flags that contradict each other. Approval timestamps sometimes precede review timestamps, and a canceled workflow can still receive a late completion callback. Files include models, services, route handlers, workers, permission helpers, event code, tests, fixtures, docs, and runbooks. Repair the workflow-state contract locally. Do not access live data, choose business approval policy, run migrations, or deploy.
- Read your context and instructions
- Compiled the workflow state contract
1. Repair decision
Decision: CROSS-LAYER WORKFLOW STATE DRIFT FOUND — SAFE LOCAL PATCH AVAILABLE; production records and workers remain unverified.
2. Scope and boundary
Reviewed: Prisma models, services, routes, BullMQ workers, permission helpers, React state mapping, tests, fixtures, docs, and runbook.
Not accessed: production databases, Redis, queues, customer records, external systems, or deployment configuration.
The repository contains onboarding, purchase-approval, and support-escalation workflows. The repair can unify mechanics without inventing who may approve, cancel, reopen, or complete them.
3. Workflow-state contract source register
| Source | Current behavior | Status |
|---|---|---|
| models | status plus booleans | Contradiction risk |
| API | transitions differ from services | Drift |
| admin | direct terminal writes | Guard bypass |
| workers | stale jobs advance records | Version gap |
| retries | side effects repeat | Idempotency gap |
| React | separate action map | Parity drift |
| timestamps | lifecycle order conflicts | Chronology gap |
| callbacks | can complete canceled work | Terminal gap |
4. Canonical repository contract
Exact transition graphs are OWNER DECISION REQUIRED where sources disagree.
Safe shared structure
- one typed state set per workflow;
- named transition commands instead of raw status writes;
- current-state, authority, required-data, and version guards;
- explicit terminal-state behavior;
- stable operation identity per transition;
- derived flags from canonical state where practical;
- side effects from the committed result;
- shared transition metadata for UI, API, workers, and bulk tools.
5. Drift findings
F1 — Competing state representations
Records persist status beside flags such as is_closed, approved, or completed.
Repair: make status the candidate source of truth and expose derived predicates. Keep legacy fields behind compatibility code until migration is separately approved.
F2 — Raw terminal-state writes
Admin routes assign terminal values without service guards.
Repair: route writes through commands such as approve, cancel, complete, or reopen. Reject unsupported source/target combinations.
F3 — UI/API disagreement
React and API code maintain independent action lists.
Repair: generate actions from shared transition metadata. Server authorization remains authoritative.
F4 — Stale worker transitions
Queued jobs can advance records after cancellation.
Repair: require expected state or workflow version. A delayed job against newer state returns stale_transition.
F5 — Duplicate side effects
Retries repeat notifications or downstream work.
Repair: use stable operation IDs and record the committed result. Replays return it without repeating the same logical effect.
F6 — Terminal-state regression
Bulk actions and callbacks can move terminal records backward.
Repair: define terminal behavior per workflow. If reopen policy is unclear, return policy_required.
F7 — Timestamp drift
Different layers set lifecycle timestamps independently.
Repair: derive or validate timestamps from committed transitions.
F8 — False completion
A worker result can be treated as completion after state changed.
Repair: apply completion only if current state and version still permit it.
6. Safe patch plan
| Area | Change |
|---|---|
| State | typed states |
| Transitions | named commands/table |
| Guards | state, authority, data, version |
| Legacy flags | derived helpers |
| Workers | state/version checks |
| Retries | operation IDs |
| Side effects | committed-result boundary |
| UI/API | shared transition metadata |
| Tests/docs | parity, replay, stale-job, terminal tests |
No production rewrite, migration, policy invention, or deployment.
7. Deterministic test matrix
- Supported transitions succeed only from approved source states.
- Invalid jumps fail consistently across API and services.
- Patched paths avoid raw terminal writes.
- Derived flags match canonical state.
- A stale BullMQ job cannot advance a canceled record.
- Replaying one transition produces one logical side effect.
- Concurrent approvals converge on one committed transition.
- Terminal records cannot regress without an explicit transition.
- Late completion cannot override a newer canceled state.
- UI actions do not invent server transitions.
- Lifecycle timestamps remain consistent.
- Dashboard groups use canonical state classification.
8. Verification steps
Run repository-supported workflow tests, then typecheck, lint, and build.
Target transition-table, API/service parity, stale-worker, replay, concurrency, terminal-state, legacy-flag, and dashboard tests.
Search for raw status assignments, duplicated transition maps, stale booleans, jobs mutating without expected state/version, and side effects before commit.
9. Production boundary
Unknown issues may include contradictory legacy flags, impossible historical states, stale jobs, duplicate effects already sent, old app versions, and bulk-action histories.
These require separate reconciliation, migration, rollout, monitoring, and rollback.
10. Human approval request
Safe now: state types, transition commands, guards, replay protection, worker version checks, derived predicates, shared metadata, tests, and docs.
Decisions required: workflow-specific graphs, reopen policy, actor authority, prerequisites, legacy migration, historical cleanup, rollout, and rollback.
Status: PATCH READY FOR LOCAL REVIEW — PRODUCTION RECORDS, HISTORICAL INVALID STATES, QUEUED JOBS, AND DEPLOYED POLICY NOT VERIFIED
11. Suggested commit message
fix(workflows): centralize state transitions and replay guards
Connects securely to your tools. The creator never sees your data.
What you get
About this skill
Workflow State Contract Repair is a bounded ToolForge Labs workflow. Repair workflow-state drift in applications using Cursor. Compare statuses, transitions, guards, ownership, retries, concurrency, terminal states, side effects, UI/API/jobs, tests, and docs across orders, onboarding, approvals, tickets, subscriptions, and business flows. Detect invalid jumps, stuck records, duplicate effects, stale transitions, contradictory states, replay bugs, and false completion; prepare bounded patches and tests without data, policy choices, migrations, or deployment. The skill works from supplied repository files or partial evidence, separates verified facts from assumptions, avoids invented execution claims, and provides concrete next steps plus deterministic validation where possible.
How to install
Works the same in every agent - Claude, Cursor, Codex, Copilot and 20+ more.
- 1
Download the ZIP
Free skills download straight away. Paid skills unlock right after purchase.
- 2
Unzip into your skills folder
Every agent reads skills from one folder on your machine. Drop the unzipped folder in there.
- 3
Ask your agent to use it
Restart the agent if it was already running. It picks the skill up automatically - no config needed.
Skills folder by agent
Click the path to copy it. Create the folder if it does not exist yet.
Reviews
No reviews yet
Be one of the first to try it. Every listed skill passes our trust checks below.
Security scanned
Passed our 8-point scan before listing
Fresh listing
Recently published to Agensi
30-day refund
Not a fit? Get your money back
Trust & safety
Security scanned
Verified clean 20 days ago
- Passed all security checks, Safe to install