Files
erp/.claude/skills/dolibarr-sandbox-write/replay-packs/2026-07-11-books-regularization/rehearsal-runbook.md
T
arcodangeandClaude Fable 5 3840e74dcd feat(write-skill): idempotency keys — manifest replay is a no-op (erp#44)
Learning #4 of the 2026-07-11 rehearsal: manifest B failed mid-run and could
not be re-applied — op 1 (the DARNIS invoice) had already run and a replay
would have duplicated it. Every write op now dedupes BEFORE any POST:

- thirdparty-create.sh: by exact name (promote '#thirdparty:name=' semantics);
  ambiguous (2+) aborts; an existing fiche missing the requested role aborts
  (refuse-never-repair). Emits {"id", "deduped"} instead of a bare id.
- invoice-create.sh: supplier kind by (socid, ref_supplier) — same key with a
  different total aborts as a conflict; customer kind (or supplier without
  ref_supplier) by (socid, date, total_ttc ±0.02, line fingerprint) with descs
  HTML-unescaped. Credit notes are never candidates. A deduped DRAFT with
  validate:true is validated on replay, so an interrupted run converges.
- payment-record.sh: by (invoice, amount, normalized transaction_id), composing
  with the erp#37 varchar(50) normalization on BOTH sides so historical
  long-form nums still match; same tx + different amount aborts; without a tx
  id there is no dedupe key (warned). Dedupe answers id:null (the payments list
  exposes no paiement rowid) + the existing bank line.
- All three refuse to POST blind when the dedupe lookup fails with anything but
  the documented empty-list 404 (the voir_tous trap would otherwise mint dupes).
- promote-apply.sh: marks each op created / deduped=true inline and totals them
  in the summary — an all-deduped second run is visible proof of a no-op.
- promote-plan.sh: advertises each op's dedupe key (and flags tx=MISSING as
  'a replay WILL double-pay').

Proof:
- tests/run-tests.sh: 5 new offline cases (11 total) — dedupe hits POST
  nothing, conflicts/ambiguity abort pre-POST, long-form history dedupes,
  draft convergence validates; stub extended to serve the new lookups with the
  live-observed empty behaviors ([] for invoices/payments, 404 for tiers).
- tests/replay-idempotency.sh (new, live): double-applies a self-contained
  manifest on the sandbox — run 1 '3 created' (rows 1/1/1), run 2 '3 deduped'
  with row counts unchanged and the stored num in erp#37 short form.
- The historic manifest-B now replays on the sandbox as 5/5 deduped, zero new
  rows — the exact replay Learning #4 declared impossible.

SKILL.md updated in the same change (per-op dedupe keys, replay-safety section,
gotchas); the 2026-07-11 runbook's Learning #4 carries a dated resolution
addendum.

Closes erp#44.

Co-Authored-By: Claude Fable 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01VRShc4QhLLU73FLHx9vskh
2026-07-18 23:46:05 +02:00

4.2 KiB

Régularisation des livres — runbook (état au 2026-07-11 soir)

2026-07-15 : le replay prod a été exécuté — voir README.md du pack pour la preuve. Ce runbook reste tel quel comme artefact de la répétition.

Où on en est : la répétition sandbox est FAITE et vérifiée. Il reste le replay prod (toi, 3 commandes), le bucket C (UI), et le contrôle final (moi).

Fait — répétition sandbox complète (2026-07-11)

Pièce Avant Après (sandbox) Règlement
(PROV14) client mai brouillon 2 145,92 FAC004-CL0001004 soldée Wise 2159468139 @29/05
(PROV15) client mai brouillon 2 575,11 FAC005 validée, due par KM — (cycle différé)
(PROV16) client juin brouillon 2 145,92 FAC006 soldée Wise 2210434850 @25/06
(PROV17) client juin brouillon 2 575,11 FAC007 validée, due par KM
(PROV15) fourn. Mistral brouillon sans ref FAF2026010 / MSTRL-API-814045-001, payée CB Qonto @03/04
(PROV12) fourn. Darnis brouillon sans ligne FAF2026011 / F1046, payée VIR Qonto @29/06
(PROV14) fourn. Anthropic brouillon sans ligne FAF2026012 / 9BF0758D-695749, payée CB Qonto @13/04
— (manquante) rien FAF2026013 / F1045 créée+validée, payée VIR Qonto @29/06

Fiches corrigées : Anthropic (11) et Mistral (12) → fournisseur=1, codes FO0010/FO0011. Agent sandbox : armé (droit 251 accordé — PR de pérennisation en cours par sous-agent).

Appris pendant la répétition (intégré au prélude prod) :

  1. Deux brouillons fournisseurs n'avaient aucune ligne (totaux d'en-tête seulement) → lignes ajoutées depuis les PDF avant validation.
  2. Les ids Qonto (67 c) dépassent num_payment varchar(50) → forme canonique courte = suffixe UUID (38 c) ; PR de normalisation bank-match/payment-record en cours par sous-agent.
  3. Flag paye=1 fantôme sur 2 brouillons → remis à 0 avant règlement.
  4. invoice-create n'est pas idempotent (le re-run d'un manifeste dupliquerait) → ne jamais rejouer un manifeste partiellement appliqué ; pour prod, tout part de zéro donc manifeste B complet OK. Addendum (erp#44, 2026-07-18) : résolu — les trois scripts d'écriture dédupliquent désormais AVANT tout POST (fournisseur par socid+ref_supplier, client par empreinte date/total/lignes, règlement par tx normalisé, tiers par nom exact) ; le re-run du manifeste B sur la sandbox est prouvé no-op (5/5 deduped, zéro ligne nouvelle — tests/replay-idempotency.sh).

➡️ À toi — replay prod (10 min, ta clé, jamais stockée)

cd ~/Work/Arcodange/erp
export DOLIBARR_PROD_WRITE_KEY=...      # ta clé d'écriture prod
export ARCO_PROMOTE_CONFIRM=I-UNDERSTAND-THIS-WRITES-PROD
bash <scratchpad>/prod-replay-prelude.sh                                  # fiches+lignes+refs+validations, avec pré-vols et garde-fous
bin/arcodange promote plan  <scratchpad>/manifest-A-km-payments.json      # relire
bin/arcodange promote apply <scratchpad>/manifest-A-km-payments.json --target prod
bin/arcodange promote plan  <scratchpad>/manifest-B-suppliers.json
bin/arcodange promote apply <scratchpad>/manifest-B-suppliers.json --target prod

Le prélude s'arrête au premier écart (il vérifie l'état prod avant chaque geste, et que l'ajout de lignes ne double pas les totaux). Ordre intangible : prélude (validations) AVANT les manifestes (règlements).

➡️ À toi — bucket C (UI Dolibarr, hors manifeste)

Apport en capital 1 000 € (21/01 → 1013) · URSSAF 493,00 € (22/05 → 6451, module Charges sociales) · écarts de change +1,08 et +50,05 (766, sur FAC004/FAC006) · cashback Wise +1,60 € (03/06) · frais/rembt Qonto +5,22 € (16/01). Pièces à clarifier : facture Cloudflare (mail 24/06) ; reçus Anthropic mai/juin (#2344, #2997 — pas de débit Qonto → carte perso ? les PDFs sont dans books@).

➡️ À moi — contrôle final (dès ton replay fait)

bank match --since 2026-01-01 → cible : bucket UNKNOWN = 0 ; re-audit T15 ; mise à jour de la mémoire books-gap-2026-07. Rappel : facture KM juillet ~23/07 (template toujours OFF — décision D3 du PRD).