← Back to AAI for MerusCase

Fix Misfile

The targeted remediation. When an attorney spots a misfiled upload — or a pair that look swapped — this skill re-reads each PDF natively, identifies the correct target case from the bound content, proposes the move + rename + activity re-link, and executes the whole correction as one atomic, rollback-safe sequence. The API binding guard refuses the write if the proposed target doesn’t match the PDF’s applicant.

The upload IDs, case numbers, and filenames in this page are fictitious demonstration data. Your install runs against your real Merus records.

On this page

What it is

At the prompt:

aaicase> fix misfile on upload [UPLOAD-ID]
aaicase> uploads [ID-1] and [ID-2] are swapped
aaicase> upload [UPLOAD-ID] is on the wrong case

The skill re-binds the suspect upload(s) by reading the PDF natively, compares to where they’re currently filed, and shows the diagnosis. The attorney approves; the skill executes the moves as a rollback-safe sequence; everything verifies.

It is the targeted remediation an attorney runs after spotting a specific problem — a filename that doesn’t match the case, a paralegal flagging a confused upload, a report that turned up on a case it doesn’t belong on. Not a firm-wide sweep.

Fix misfile vs. audit case

fix misfileaudit case
Scope1–2 specific uploadsEvery upload on a case
Triggered byAttorney spotted a problemPeriodic file-integrity sweep
Cost~API budget (one or two binding extractions)more for a 50-upload case
Time~3 minutes~5–10 minutes
OutputTargeted move proposalFindings table across all uploads

The relationship: audit case discovers misfiles you didn’t know about; fix-misfile corrects a specific one you already spotted. Either one ends in the same sequencer-based correction flow; they just enter the workflow at different points.

How it runs (under the hood)

  1. Identify the suspect uploads. The attorney provides upload IDs. If they say “swapped” with only one ID, the skill asks which case the other half should be on, then finds the partner upload.
  2. Re-bind each upload from PDF content. aai-bind downloads the PDF to a per-run mktemp -d dir (locked chmod 700), reads it natively with Claude vision, and produces an authoritative {applicant_last, applicant_first, claim_number, doc_date, doc_type} binding. The binding overwrites any prior binding in ~/.aaicase/queue/bindings.json.
  3. Get current filing state. /uploads/view/[ID] returns the upload’s current case_file_id and filename. /caseFiles/view/[CASE-ID] on the current case returns its applicant. Now the skill knows where the upload is vs. where it should be.
  4. Find the correct target case. merus-search on the bound applicant’s last name finds candidate cases. If multiple match, the skill narrows by first name + claim number, then asks the attorney to confirm if ambiguity remains.
  5. Show the diagnosis. See below for the output format.
  6. Wait for approval. The skill never executes without explicit approval.
  7. Execute via aai-sequence.mjs. The move + rename + activity re-link runs as one atomic operation with full rollback support.
  8. Verify. Re-fetch each corrected upload’s state; re-bind to confirm content didn’t drift; show a VERIFY block.
  9. Audit log. One JSON line per correction in ~/.aaicase/audit.log.

Re-bind from PDF content — not from filename

The skill ignores the filename entirely when determining what an upload is. A PDF labeled 2026-05-08-da-letter-qme-panel-strike-roe.pdf might actually be a Doe document with a misleading name. The binding is from PDF content via Claude vision — not text extraction, not filename parsing.

This is the same rule that runs through the rest of AAI — mail processing, audit, audit case — and it’s why fix-misfile works at all. If the skill trusted filenames, it couldn’t correct anything; the misfile would have a misleading filename by definition.

Re-binding always overwrites the cached binding. The skill never uses a stored binding for this correction — it has to know what the PDF says right now, not what it said the last time someone ran a binding.

The diagnosis output

MISFILE DIAGNOSIS
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

Upload #[UPLOAD-1]
  PDF content (re-bound):    DOE, JANE    [doc: 2026-05-06 Subpoena Noncompliance]
  Currently filed on:        ROE #[CASE-ID-2]      ← WRONG
  Current filename:          2026-05-08-da-letter-qme-panel-strike-roe.pdf  ← WRONG NAME
  Should be filed on:        DOE #[CASE-ID-1]

Upload #[UPLOAD-2]
  PDF content (re-bound):    ROE, MARIA  [doc: 2026-05-08 Defense Panel Strike]
  Currently filed on:        DOE #[CASE-ID-1]       ← WRONG
  Current filename:          2026-05-06-subpoena-noncompliance-second-notice-doe.pdf  ← WRONG NAME
  Should be filed on:        ROE #[CASE-ID-2]

DIAGNOSIS: classic swap — the two uploads have their cases (and filenames) crossed.

PROPOSED FIX:
  1. ⭐ Move upload #[UPLOAD-1] from ROE #[CASE-ID-2] → DOE #[CASE-ID-1]
        + rename to: 2026-05-06-subpoena-noncompliance-sample-copy-doe.pdf
  2. ⭐ Move upload #[UPLOAD-2] from DOE #[CASE-ID-1] → ROE #[CASE-ID-2]
        + rename to: 2026-05-08-da-panel-strike-defense-counsel-roe.pdf
  3. ⭐ Also fix the linked activities (re-link each to the new case)
        Activity [ACT-1] (currently on ROE) → DOE, with right tag
        Activity [ACT-2] (currently on DOE) → ROE, with right tag

  S. SKIP — don't change anything
  Q. QUIT

The diagnosis is descriptive, not prescriptive. The diagnosis tells you what the data says; the proposed fix tells you what AAI is about to do. Both stop and wait for the attorney’s green light.

The proposal — every field editable

Following the canonical approval flow (shared with process mail and process messages), the attorney can edit any field before approving:

After every edit, the proposal is re-shown with the updated values. Nothing writes until the final approval.

Sequencer execution and rollback

A misfile correction is a multi-step write. Moving an upload also means moving the linked activity. If the activity tag is wrong, the activity is soft-deleted and recreated with the right tag. None of these steps is safe to fail halfway through.

Every correction runs through aai-sequence.mjs. Each step has an args and an undo_args. If step 2 fails, the sequencer rolls back step 1. The case never lands in a half-corrected state where the upload moved but the activity didn’t.

For reassignment-style edits (the common case), the undo uses undo_args — the original case_file_id and filename captured before the move, so rollback is a single deterministic write. For delete-and-recreate steps (when the activity tag has to change), the undo uses undo_template — the new activity’s ID is captured from the response and templated into the undo.

aai-sequence prints structured JSON to stdout:

The merus-fetch binding guard

The API layer has the final word. Even with attorney approval, merus-fetch refuses any /uploads/edit write that would move an upload to a case whose applicant doesn’t match the stored binding.

The flow:

  1. Skill proposes: “Move upload #[ID] from ROE #[ID-2] to DOE #[ID-1].”
  2. Attorney approves.
  3. Sequencer issues: POST /uploads/edit/[ID] case_file_id=[DOE-CASE-ID].
  4. merus-fetch checks: does the stored binding for the upload match the applicant on the target case?
  5. If yes (DOE matches DOE): the write proceeds.
  6. If no (the proposed case has a different applicant than the PDF): the write is refused at the API call layer, not just discouraged by a prompt. The sequence fails at this step. No undo needed because nothing was written.

This is the safety property that motivated the skill in the first place: moving a misfiled upload to a case whose applicant doesn’t match would re-misfile it. The guard catches that. The same guard also enforces filename conventions — if the proposed filename doesn’t include the correct applicant’s last name, the write is refused.

Post-fix VERIFY pass

After the sequence completes, the skill verifies in three ways:

  1. Re-fetch the upload. /uploads/view/[ID] — confirm case_file_id now equals the correct target case and description matches the proposed filename.
  2. Re-fetch the activity. /activities/index/[CORRECT-CASE-ID] — confirm the linked activity is on the new case with the right tags.
  3. Re-bind the upload. aai-bind again — confirm the PDF content still maps to the applicant on the (now-correct) case. This catches the rare edge case where moving an upload somehow affected its content.

The verify output:

FIX VERIFIED
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
  ✓ Upload #[ID-1] now on DOE #[CASE-ID-1] (was ROE)
        Filename: "2026-05-06-subpoena-noncompliance-sample-copy-doe.pdf"
        Re-bind:  DOE (still matches)
  ✓ Activity #[ACT-1] reassigned to DOE #[CASE-ID-1] with tag [27960 Subpoena]

  ✓ Upload #[ID-2] now on ROE #[CASE-ID-2] (was DOE)
        Filename: "2026-05-08-da-panel-strike-defense-counsel-roe.pdf"
        Re-bind:  ROE (still matches)
  ✓ Activity #[ACT-2] reassigned to ROE #[CASE-ID-2] with tag [47955 DA Letter]

If verify fails on any step, the skill stops and shows expected vs. actual — the attorney decides whether to retry, accept, or quit.

Never delete — only reassign

Fix-misfile never deletes an upload to “fix” a misfile. Reassignment via /uploads/edit moves the upload without re-uploading. The PDF stays in Merus.

The reasoning is the same as audit case: a deleted upload is gone; a reassigned upload is restored to its correct home. Reassignment is reversible (the audit log records where it used to be); deletion is not. Integrity is restored by moving the record, not by erasing it.

This applies even when the misfiled upload looks like a clear duplicate. Reassign to the correct case; the attorney decides whether to use the Merus UI to clean up the duplicate outside AAI.

Edge cases

Upload binding returns “UNKNOWN”

aai-bind couldn’t determine the applicant — rare, but happens with cover sheets, blank pages, heavily redacted documents. The skill stops and tells the attorney; they can supply the right case manually with an explicit override (logged loudly in the audit), or open the upload directly via read upload [id] and decide.

Upload is already on the correct case

The re-bind matches the current case’s applicant. The skill responds: “Upload #X is already correctly filed on [case]. Nothing to fix.” The attorney may have suspected a misfile that isn’t there — common, and the skill confirms the file is clean rather than inventing a correction.

Three-way swap or more complex tangle

The skill does them one upload at a time. Each fix is independent and runs through its own sequence. A three-way swap is three separate runs, not one nested operation — this keeps each correction atomic and rollback-safe.

Upload was filed on a case that doesn’t exist anymore

The current_case_file_id resolves to a deleted/archived case. The skill flags this and offers to move to the right case via the standard reassignment write. The orphan reference is the “wrong” side; the binding tells you the “right” side.

Activity has multiple tags, some right some wrong

The skill prefers an in-place tag edit over the delete-and-recreate flow when most tags are correct. If all the tags need to change, the delete-and-recreate sequence runs; if just one or two are wrong among many, the activity is edited in place.

Troubleshooting

“Binding refused by guard”

The merus-fetch binding guard rejected the proposed move because the target case’s applicant doesn’t match the upload’s bound applicant. This is the guard doing its job. Re-check the diagnosis — usually the proposed target case is the wrong case (the skill suggested one, the attorney edited it, the edit was wrong). Re-run the search by the bound applicant’s name to find the right case.

The sequence rolled back

A later step in the sequence failed, so the earlier step was undone. The case is back in the state it was before. The skill tells you which step failed and why — usually a transient API issue (re-run) or a permissions issue (the API token doesn’t allow the specific edit). Check the audit log for details.

The upload moved but the activity didn’t

That shouldn’t happen — the sequencer either commits both or rolls back both. If you see this state, run aai-undo with the sequence label to fully revert, then re-run the fix.

The wrong activity got moved

The skill found the wrong linked activity (an upload can have multiple activities referencing it). Stop, run aai-undo to revert, and re-run the fix with the specific activity ID instead of letting the skill pick.

Re-bind during VERIFY returned a different applicant

Unlikely but theoretically possible — the upload’s content somehow changed between the initial bind and verify. The skill stops and surfaces both bindings. If the verify-bind looks correct, the initial bind was wrong; if the verify-bind looks wrong, you may have a deeper Merus data issue. Either way, don’t accept the fix without understanding what changed.

Part of AAI for MerusCase — code-guarded AI case intelligence for California Workers’ Comp attorneys.