Human overview · for understanding
The deal-FSM refactor + a 5-layer spec that keeps code and intent in lockstep · 2026-07-01
The deal-FSM refactor + a 5-layer spec that keeps code and intent in lockstep
Master summary — the gist in 30 seconds
Input: deal logic scattered across ~28 places (which caused a card to jump to 'Negative' 1 second after a rep logged a call, and cards routing to different columns depending on which copy of the code ran). Output: one authority (deal_fsm.py) that every path asks, plus a 5-layer written spec with an automatic guard that blocks the code from drifting from the spec. Test suite grew 1206 → 1415, all green; the two named bug-fixes still hold; nothing that sends to a lead was touched.
flowchart LR Scatter["~28 scattered<br/>decision points"] --> FSM["deal_fsm.py<br/>ONE authority"] FSM --> Spec["5-layer spec<br/>+ drift-gate"] Spec --> Trust["code & intent<br/>stay in lockstep"]
Input: three separate messes — how a deal's board COLUMN is computed (T1, which existed in two copies, one stale), how a NEGATIVE reply is recorded (T2, ad-hoc in 6 places), and how a deal's STAGE is changed (T3, with a bypass that skipped the audit trail). Output: deal_fsm.py owns all three — derive_column (T1), set/dispose/clear_negative (T2), transition (T3) — and the old callers now just ask it.
flowchart TD
subgraph Before
A1["board_view.deal_col"] -.->|copy drift| A2["dash._deal_col<br/>(STALE)"]
A3["neg_reply set in<br/>6 places"]
A4["stage set 2 ways"]
end
subgraph After
F["deal_fsm.py"]
F --> C["derive_column"]
F --> N["set / dispose / clear_negative"]
F --> S["transition"]
end
Before ==> After
Input: a rep logs a call on a deal, then an automated email-classifier sees an inbound reply ~1 second later and wants to mark it 'Negative'. Output: the FSM refuses the automatic mark when a human has already acted (a logged call or a set follow-up) — but a human can still mark it negative anytime. Before, this rule lived as a fragile check inside one function; now it's the authority's own law.
flowchart TD
Call["Rep logs a call"] --> Human{"Human already<br/>decided?"}
Email["Auto classifier:<br/>'looks negative'"] --> Ask["set_negative(auto)"]
Ask --> Human
Human -->|yes| Reject["REJECTED —<br/>card stays put"]
Human -->|no| Allow["marked Negative"]
HumanMark["Human clicks 'negative'"] --> Always["ALWAYS allowed"]
Input: a codebase where the 'rules' lived only in the code and people's heads. Output: five linked layers (00-vocabulary → L0 FSM → L1 EBO answer-key → L2 event-log → L3 Gherkin → L4 SPEC) all speaking one frozen vocabulary, plus scripts/spec_drift_gate.py — a hook that blocks a commit if the code's public contract diverges from the written SPEC. We proved it fires: aligned = pass, tampered = blocked, reverted = pass.
flowchart LR V["Vocabulary<br/>(frozen)"] --> L0["L0 FSM<br/>state map"] L0 --> L1["L1 EBO<br/>answer-key"] L1 --> L3["L3 Gherkin<br/>scenarios"] L0 --> L2["L2 event-log<br/>replayable"] L0 --> L4["L4 SPEC<br/>+ drift-gate"] L4 -->|blocks drift| Code["deal_fsm.py"] Code -->|checked against| L4