6 Runtime View¶
FeeCheck's runtime is told in the terms of CMMN, the case management notation of the case model
(spec 15 (docs/specs/15-workflow-module.md)), which runs on the Flowable CMMN engine. One contract
PDF is one case; the case runs in stages; a stage holds tasks, each of a CMMN type. One
task following another inside the case is a Sentry of the engine, not an event on a queue. A
stage's work is handed out by domain event: the case sends a request, the stage module does
the work and answers with a reply, and a timer bounds the wait (6.1.2).
Facts that leave or enter a case are domain events as well (8.16). A
step is a technical interaction inside one task's implementation and appears only in the step
tables of 6.2.1, 6.2.2 and 6.4. The terms are defined in the glossary.
Legend. Every CMMN diagram of this chapter uses the notation and the legend of 8.18.1: the shape and the stereotype say what an element is, the colour whether it is built. In the sequence diagrams a green box holds built participants, a blue one planned and a grey one external ones.
6.1 The FeeCheck case¶
One FeeCheck case per business document — a main document and its attachments, each an uploaded
file; what the main document holds is a fee agreement. The overview draws each stage as a black box — CMMN's collapsed stage, marked ⊞ — with
the results it writes into the case file and the milestones it reaches; the tasks inside the
stages are drawn in 6.2 and
6.3. The upload, or DocumentReceived from another channel,
opens the case at the head of the stage Contract intake; the stage Invoice intake captures a fee
statement; the child case Fee reconciliation, run by the same engine, compares the fee agreement
against the master data and puts the findings in front of a person. A further child case is one
more CaseTask beside it; a customer-specific flow is another model under the same case key
(spec 15 W-8).
flowchart LR
p["«person»<br/>Person"]
evIn((("«event listener»<br/>DocumentReceived")))
subgraph fc["«case» FeeCheck case"]
direction LR
subgraph ci["«stage» Contract intake"]
direction LR
pdf[("«case file item»<br/>Contract PDF")]
dp["«stage» ⊞<br/>Document preparation"]
rend[("«case file item»<br/>Rendition")]
conv(["«milestone»<br/>Converted"])
dc["«stage» ⊞<br/>Data capture"]
res[("«case file item»<br/>Extraction result")]
crec[("«case file item»<br/>Contract record")]
recd(["«milestone»<br/>Contract recorded"])
end
ii["«stage» ⊞<br/>Invoice intake"]
irec[("«case file item»<br/>Invoice record")]
fr[["«case task» ⊞<br/>Fee reconciliation"]]
find[("«case file item»<br/>Findings")]
rel(["«milestone»<br/>Released"])
end
p -- "upload" --> pdf
evIn -.-> pdf
pdf --> dp
dp --> rend
dp --> conv
conv --> dc
rend --> dc
p -- "starts" --> dc
dc --> res
dc -.-> crec
dc -.-> recd
recd -.-> fr
crec -.-> fr
ii -.-> irec
irec -.-> fr
fr -.-> find
fr -.-> rel
classDef person fill:#ffe8b0,stroke:#9a6b00,color:#000
classDef built fill:#b7e4c7,stroke:#2d6a4f,color:#000
classDef planned fill:#c6dcff,stroke:#1168bd,stroke-dasharray:4 3,color:#000
classDef external fill:#e6e6e6,stroke:#6b6b6b,color:#000
class p person
class pdf,dp,rend,conv,dc,res built
class evIn,crec,recd,ii,irec,fr,find,rel planned
style fc fill:none,stroke:#666
style ci fill:none,stroke:#666
| Element | CMMN type | Domain event in / out | Status |
|---|---|---|---|
| FeeCheck case | case, one per business document, run by the Flowable CMMN engine; its child cases in the same engine | the upload or DocumentReceived opens it / ContractRecorded, FindingsPublished |
built as the case the upload opens, with the business states of 6.1.1; the case model on Flowable planned (spec 15 (docs/specs/15-workflow-module.md) and its CMMN models) |
| Person | — (a person, not a CMMN element) | uploads the contract PDF, which opens the case; starts Data capture's extraction (manual activation) | built |
| DocumentReceived | event listener: a document from a channel other than the upload — SharePoint, a DMS, an archive — opens the case | DocumentReceived / — |
planned |
| Contract intake | stage, holding Document preparation and Data capture | — / ContractRecorded |
built in part (6.2); spec 15's stage Document, named Contract intake here — spec 15 is unchanged |
| Document preparation | stage, collapsed: check, classify, confirm the type, release a blocked case, convert (6.2) | the upload or DocumentReceived / DocumentConverted, which reaches Converted |
built for the conversion: started by the upload in its call or as a conversion job on the queue's case ID (6.2.1); the rest planned |
| Contract PDF | CaseFileItem: the uploaded files — the main document and its attachments — in the document store, kept for as long as the case exists and removed when its conversion fails or the case is deleted (8.3) | the upload / — | built, in the backend, on a developer machine and on Google Cloud, where the bucket has no lifecycle rule |
| Rendition | CaseFileItem: the converter's markdown, page by page with page anchors | — | built (held by the case) |
| Converted | milestone | DocumentConverted / — |
built as the business state converted |
| Data capture | stage, collapsed: extract, normalise and map the attributes, record the contract (6.2); its extraction waits for a person (manual activation) | Converted, and a person's start / ContractRecorded, which reaches Contract recorded |
built for the extraction of the two contract partners and the contract ID, on the web app's request (6.2.2); the rest planned |
| Extraction result | CaseFileItem: the extracted values, each with its passage, page and derived confidence | — | built (held by the case) |
| Contract record | CaseFileItem: the canonical contract record, with the PDF and the markdown | — | planned |
| Contract recorded | milestone | ContractRecorded / — |
planned |
| Invoice intake | stage, collapsed: receive a fee statement — a PDF, XML, CSV or e-invoice, or a document Confirm document type redirects — check it, read its line items, normalise them, check the references, map them to the invoice model and record the invoice; its tasks are drawn with its spec | a statement received / InvoiceRecorded |
planned, not in the PoC; not modelled in spec 15 |
| Invoice record | CaseFileItem: the invoice record the child case reads | — | planned, not in the PoC |
| Fee reconciliation | CaseTask, starting the child case in the same engine, drawn collapsed (6.3) | Contract recorded / the child case's completion completes it | planned; the child case, not a stage (spec 15 §7's first question); spec 15's model starts it when the stage Document completes |
| Findings | CaseFileItem of the child case: per attribute confirmed, deviating, low confidence, not verifiable or no comparison source, each with evidence | — | planned; domain data of the reconciliation, not tasks (spec 15 §2) |
| Released | milestone | FindingsPublished / — |
planned; nothing is released without a person (W-3, 8.2 Guardrails) |
A CaseFileItem in the engine is a case variable holding a reference to where the result is stored; the results themselves stay in the case database and the document store (8.3), and no contract content is in an event (8.16.3).
6.1.1 Case lifecycle¶
Two levels, as CMMN has them. Every plan item has the engine's own lifecycle — available, enabled or disabled, active, then completed, terminated or failed (8.18). A rejection or a missed reply deadline ends a stage task through its exit criterion, and the business state records Failed with the cause. Above it, the case's business state says where a case stands for the person and the screen. It is FeeCheck's own record beside the engine's plan items, kept by a plan-item lifecycle listener in the engine's transaction, so the screen reads one row and never the engine's tables; the audit trail stays FeeCheck's own append-only record (spec 15 §2). A retry re-activates the plan item that failed, not its stage's start (W-4).
stateDiagram-v2
direction LR
[*] --> Preparing : DocumentReceived
Preparing --> Blocked : DocumentBlocked
Blocked --> Preparing : CaseReleased
Preparing --> AwaitingTypeConfirmation : DocumentClassified [type uncertain]
AwaitingTypeConfirmation --> Preparing : DocumentTypeConfirmed
AwaitingTypeConfirmation --> Discarded : DocumentDiscarded
AwaitingTypeConfirmation --> Redirected : DocumentRedirected
Preparing --> Converted : DocumentConverted
Converted --> Capturing : ExtractionRequested
Capturing --> Reconciling : ContractRecorded
Reconciling --> Completed : FindingsPublished
Preparing --> Failed : TaskFailed
Capturing --> Failed : TaskFailed
Reconciling --> Failed : TaskFailed
Failed --> Preparing : TaskRetried [failed in preparation]
Failed --> Capturing : TaskRetried [failed in data capture]
Failed --> Reconciling : TaskRetried [failed in reconciliation]
Completed --> [*]
Discarded --> [*]
Redirected --> [*]
classDef built fill:#b7e4c7,stroke:#2d6a4f,color:#000
classDef planned fill:#c6dcff,stroke:#1168bd,stroke-dasharray:4 3,color:#000
class Preparing,Blocked,Converted,Capturing,Failed built
class AwaitingTypeConfirmation,Discarded,Redirected,Reconciling,Completed planned
| State | Meaning | Left by | Status |
|---|---|---|---|
| Preparing | stage Document preparation active: check, OCR, classify, convert | DocumentConverted; DocumentBlocked; DocumentClassified type uncertain; TaskFailed |
built for the conversion, as queued and converting |
| Blocked | the document was blocked: over the page limit, or hard-blocked by the contract gate as not a contract (6.2.1); the PDF is kept | CaseReleased — the HumanTask Release blocked case, the person recorded |
built for the page limit (spec 360 (docs/specs/360-pdf-upload-limits.md)) and for not a contract (spec 367 (docs/specs/367-contract-gate.md)); the release decided, planned |
| AwaitingTypeConfirmation | HumanTask Confirm document type open | confirmed, discarded, or redirected to Invoice intake (6.1) | planned |
| Converted | the rendition is there, with the contract gate's verdict and the document's language (6.2.1); Extract attributes is enabled and waits for a person | ExtractionRequested, once a person starts it (manual activation) |
built |
| Capturing | stage Data capture active: extract, normalise, map, record | ContractRecorded; TaskFailed |
built for the extraction, as extracting and extracted |
| Reconciling | child case Fee reconciliation active, its HumanTasks included | FindingsPublished; TaskFailed |
planned |
| Failed | a task ended for good: its stage rejected it, no reply came within the deadline, or a permanent fault; the task and the cause are kept | TaskRetried — a person's command, only for a retryable cause |
built for conversion and extraction failures |
| Completed | terminal: the findings are published | — | planned |
| Discarded | terminal: a person discarded the document | — | planned |
| Redirected | terminal: the document went to Invoice intake | — | planned, not in the PoC |
A file that is not a PDF opens no case (spec 339 (docs/specs/339-case-api.md) R-9) and never
reaches this machine. A model that fails is not a failed task: the extraction answers with its
defined fallback, an incomplete result, and the case goes on to human review
(8.7). A transient fault changes no state; the delivery is retried.
6.1.2 Stage work by event¶
How a stage's work is handed to a stage module, drawn once. In 6.2 and 6.3 each stage task is one parallelogram; it stands for the sub-stage below. The form is standard CMMN: the send event task completes when it has sent the request; an event listener inside the sub-stage waits for the reply, and the rejection and the reply deadline end the sub-stage through its exit criteria. A listener inside a stage hears its event only while that stage is active, so a late reply finds nothing to complete.
flowchart LR
p["«person»<br/>Person"]
subgraph fc["«case» FeeCheck case"]
direction LR
prev("«plan item»<br/>Previous plan item")
subgraph st["«stage» Stage task"]
direction TB
send[/"«send event task»<br/>Send the request<br/>…Requested"/]
reply((("«event listener»<br/>the reply")))
done(["«milestone»<br/>Answered"])
rejected((("«event listener»<br/>…Rejected")))
timer{{"«timer event listener»<br/>Reply deadline"}}
exitc{"«exit criterion»<br/>the stage task ends"}
end
item[("«case file item»<br/>Result")]
next("«plan item»<br/>Next plan item")
end
work("«module»<br/>The stage's work")
prev -.-> send
p -. "starts, where manual" .-> send
send -. "request" .-> work
work -. "reply" .-> reply
work -. "rejection" .-> rejected
reply -.-> done
done -.-> item
done -.-> next
rejected -. "rejected" .-> exitc
timer -. "no reply in time" .-> exitc
classDef person fill:#ffe8b0,stroke:#9a6b00,color:#000
classDef built fill:#b7e4c7,stroke:#2d6a4f,color:#000
classDef planned fill:#c6dcff,stroke:#1168bd,stroke-dasharray:4 3,color:#000
classDef external fill:#e6e6e6,stroke:#6b6b6b,color:#000
class p person
class work built
class prev,send,reply,done,rejected,timer,exitc,item,next planned
style fc fill:none,stroke:#666
style st fill:none,stroke:#666
| Element | CMMN type | Domain event in / out | Status |
|---|---|---|---|
| Person | — (a person) | starts the stage task where the model sets manual activation | built (the web app's extraction request) |
| Previous plan item | whatever the model puts before the stage task; its completion is the stage task's entry criterion | — | planned |
| Stage task | stage, one per piece of stage work, completing when its milestone Answered is reached; manual activation where the model says so | the previous plan item's completion, and a person where manual / — | planned |
| Send the request | send event task: sends …Requested with the case ID and a new request ID, and completes |
— / …Requested |
planned |
| The stage's work | not a CMMN element: the stage module's listener on the request, outside the engine's transaction; it claims the request ID before the long work (8.16.3) | …Requested / the reply, or …Rejected |
built for the conversion (intake) and the extraction (extraction), called directly; as a request listener planned |
| the reply | event listener, correlated by case ID and request ID; its occurrence reaches the milestone | the reply, e.g. AttributesExtracted / — |
planned |
| Answered | milestone, required by its stage | — | planned |
| …Rejected | event listener; its Sentry is the stage's exit criterion | …Rejected / — |
planned; the stage is terminated and the business state records Failed with the cause (6.1.1) |
| Reply deadline | timer event listener, started with the stage; its Sentry is the stage's exit criterion | — | planned; one default, overridden in the model where a stage needs longer |
| the stage task ends | exit criterion of the stage task, drawn as the rhombus CMMN draws on the stage's border: the rejection or the deadline terminates the stage task | — | planned |
| Result | CaseFileItem: the case holds a reference to the result the stage module stored | — | planned as a reference; the case holds the rendition and the extraction result itself |
| Next plan item | whatever the model puts next; its entry criterion is the milestone Answered | — | planned |
A retry starts the failed stage task again through the engine's change of plan-item state, behind the case port's retry a task (8.16.3); its new request carries a new request ID. An external worker task — a job the stage module's worker acquires from the engine — is the exception for a stage that needs the engine's lock, retry and dead letter more than the event's decoupling; no stage uses it.
6.2 Stage Contract intake¶
From the upload of a contract PDF, through the page-anchored markdown, to the canonical contract record. The stage holds two stages: Document preparation makes the contract PDF readable and sure of its type; Data capture reads, normalises and records the fee agreement's attributes. Every stage task here is answered as 6.1.2 draws it. One stage task is one request to one stage module and covers every step that follows in that module until a person or another module is next; the steps inside a request are the module's business, not the case's.
%%{init: {"flowchart": {"nodeSpacing": 30, "rankSpacing": 40}}}%%
flowchart TB
p["«person»<br/>Person"]
subgraph ci["«stage» Contract intake"]
direction TB
subgraph dp["«stage» Document preparation"]
direction LR
receive("«case start»<br/>Receive document")
pdf[("«case file item»<br/>Contract PDF")]
check[/"«send event task»<br/>Check document<br/>DocumentCheckRequested"/]
unblock("«human task»<br/>Release blocked case")
classify[/"«send event task»<br/>Classify document<br/>ClassificationRequested"/]
confirm("«human task»<br/>Confirm document type")
convert[/"«send event task»<br/>Convert document<br/>ConversionRequested"/]
rend[("«case file item»<br/>Rendition")]
conv(["«milestone»<br/>Converted"])
end
subgraph dc["«stage» Data capture"]
direction LR
extract[/"«send event task»<br/>Extract attributes<br/>ExtractionRequested"/]
res[("«case file item»<br/>Extraction result")]
record[/"«send event task»<br/>Record contract<br/>ContractRecorded"/]
crec[("«case file item»<br/>Contract record")]
recd(["«milestone»<br/>Contract recorded"])
end
end
p -- "upload" --> receive
receive --> pdf --> convert
receive -.-> check
check -. "checked" .-> classify
check -. "blocked" .-> unblock
classify -. "not a contract" .-> unblock
classify -. "type uncertain" .-> confirm -.-> convert
classify -. "fee agreement" .-> convert
unblock -.-> convert
convert --> rend
convert --> conv
conv --> extract
p -- "starts" --> extract
rend --> extract
extract --> res
extract -.-> crec
extract -.-> record
record -.-> recd
classDef person fill:#ffe8b0,stroke:#9a6b00,color:#000
classDef built fill:#b7e4c7,stroke:#2d6a4f,color:#000
classDef planned fill:#c6dcff,stroke:#1168bd,stroke-dasharray:4 3,color:#000
classDef external fill:#e6e6e6,stroke:#6b6b6b,color:#000
class p person
class receive,pdf,convert,rend,conv,extract,res built
class check,unblock,classify,confirm,record,crec,recd planned
style ci fill:none,stroke:#666
style dp fill:none,stroke:#666
style dc fill:none,stroke:#666
| Task | Type | Input | Output | Domain event on completion | Status |
|---|---|---|---|---|---|
| Person | — (a person) | — | uploads the contract PDF; starts Extract attributes | — | built |
| Contract intake, Document preparation, Data capture | stages, the frames | — | — | — | built in part |
| Receive document | the case's start (not a plan item, 6.1) | the contract PDF from the web app, SharePoint, a DMS or an archive | the case; the contract PDF, a CaseFileItem | DocumentReceived, when it comes from a channel other than the upload |
built for the upload, which opens the case and refuses a file that is not a PDF or is over the size limit — no case is opened; the other channels planned |
| Check document | stage task, a request to intake, deterministic and AI-supported: the integrity check — format, encryption, active content, embedded files, page limit, document hash — and, when the document has no text layer, the first page read by OCR for the classification |
the contract PDF | the check's verdict; the first page's text where OCR was needed; the rest is read only once the type is confirmed | DocumentChecked, or DocumentBlocked when the document is blocked |
planned; the PDF header and the page limit are checked in Receive document, and a PDF over the page limit is recorded blocked with its PDF kept (spec 360 (docs/specs/360-pdf-upload-limits.md)); OCR of every page without a text layer runs inside Convert document |
| Release blocked case | HumanTask, candidate group supervisor | DocumentBlocked, or DocumentClassified not a contract |
the release, recorded with the person and the time; the case goes on as if it had not been blocked | CaseReleased |
planned; where a released case re-enters is open (open.md) |
| Classify document | stage task, a request to intake, AI classification: a model call |
DocumentChecked |
the document type with its confidence, and any signs of embedded instructions | DocumentClassified — fee agreement, type uncertain or not a contract |
planned; how it relates to the contract gate in Convert document (6.2.1) is open (open.md) |
| Confirm document type | HumanTask; the candidate group is open | DocumentClassified type uncertain |
the person confirms, redirects (to Invoice intake, 6.1) or discards | DocumentTypeConfirmed |
planned; a fee agreement reliably recognised passes without it |
| Convert document | stage task, a request to intake, AI-supported (layout, OCR) |
DocumentTypeConfirmed, DocumentClassified fee agreement, or CaseReleased; the contract PDF |
the rendition, a CaseFileItem: markdown page by page, structure and tables kept, page anchors for locations, with the contract gate's verdict and the document's language | DocumentConverted, which reaches the milestone Converted; DocumentBlocked when the contract gate hard-blocks the document |
built (6.2.1), started by the upload, with the contract gate (spec 367 (docs/specs/367-contract-gate.md)) and the language recognition (spec 377 (docs/specs/377-document-language.md)); the request and reply events planned |
| Extract attributes | stage task, a request to extraction, AI-supported, manual activation: the extraction, then the normalisation — units, currencies, date formats; the canonical key = category + attribute name + master-data reference — and the mapping to the FinDatEx EMT / EET fields where a standard format matches, otherwise to the canonical internal model |
Converted, and a person's start; the rendition | the extraction result, a CaseFileItem: evidence passages with attribute value, page and derived confidence per attribute; the contract record, a CaseFileItem | AttributesExtracted |
built for the two contract partners and the contract ID (6.2.2), started by the web app's request; the further attributes, the normalisation, the mapping and the events planned |
| Record contract | send event task; its payload references the contract record the extraction stored | AttributesExtracted |
— | ContractRecorded, a fact out of the case, which reaches the milestone Contract recorded |
planned |
| Contract PDF | CaseFileItem | the upload | — | — | built |
| Rendition | CaseFileItem | Convert document | — | — | built (held by the case) |
| Converted | milestone | DocumentConverted |
— | — | built |
| Extraction result | CaseFileItem | Extract attributes | — | — | built (held by the case) |
| Contract record | CaseFileItem | Extract attributes (the mapping) | — | — | planned |
| Contract recorded | milestone | ContractRecorded |
— | — | planned |
6.2.1 Convert document¶
From spec 7 (docs/specs/7-docling-intake.md), spec 263 (docs/specs/263-intake-job.md),
spec 264 (docs/specs/264-google-case-adapters.md), spec 367 (docs/specs/367-contract-gate.md) (the contract gate),
spec 377 (docs/specs/377-document-language.md) (the language), spec 368 (docs/specs/368-translation-port.md) (the translation) and ADR-0004 (docs/adr/adr-0004-document-conversion-docling.md),
ADR-0009 (docs/adr/adr-0009-async-intake-pubsub-bucket-firestore.md); the containers are in
7.1.2.2, and the building blocks behind the
steps in 8.15.4. The case ID
is the job ID; no contract content goes into a message, its attributes or a log (NFR-4).
Conversion in the upload's call — the default, with no queue configured.
sequenceDiagram
autonumber
actor P as Person
box rgb(183,228,199) Built
participant UI as Web app
participant BE as Backend
participant DS as docling-serve
end
box rgb(230,230,230) External
participant M as LLM provider
end
P->>UI: upload contract PDF
UI->>BE: POST /api/cases
BE->>BE: check the PDF header
BE->>DS: probe /health
DS-->>BE: up
BE->>DS: convert the first pages
DS-->>BE: markdown and document structure, or failure
BE->>BE: lay the markdown onto the pages
BE->>M: classify the first two pages
M-->>BE: label and indicators, each with its passage
BE->>BE: check each passage, derive the verdict
alt hard block
BE-->>UI: 422 not-a-contract with the blocked case
else pass, soft block, failed or unchecked
BE->>BE: recognise the language
opt neither English nor unrecognised
BE->>M: translate, page by page
M-->>BE: English pages
end
BE-->>UI: 201 with the case and its pages, or 422 / 503
end
| Step | From → To | What | Status |
|---|---|---|---|
| 1–2 | Person → Web app → Backend | The intake screen sends the PDF to the case's upload endpoint. An upload over the size limit is answered 413 before anything else runs. |
built |
| 3 | Backend | The upload must start with the PDF header; otherwise it is answered 415 not-pdf and no case is opened. Its pages are then counted on the machine, before the converter is called; a PDF over the intake's page limit is never converted or cut: it is recorded as a blocked case with its PDF kept and answered 422 over-page-limit (spec 360 (docs/specs/360-pdf-upload-limits.md)). |
built |
| 4–5 | Backend → docling-serve | The docling adapter probes the service first and sends the PDF only once the probe answers, repeating the probe through a cold start and a few short retries while a failure is transient (429, 502 or 503, a refused connection or a connect timeout; a read timeout is final, and so is a 504, a conversion still running: only the probe repeats it). |
built |
| 6–7 | Backend → docling-serve | The whole document is converted; docling-serve recognises layout, reading order and tables and applies OCR where a page has no text layer, and answers with markdown and the document structure. | built |
| 8 | Backend | The markdown is laid onto the pages the structure reports. A page without body content stays an empty page, so no page number shifts; only a complete conversion counts — a page docling could not read, or markdown that does not line up with the pages, fails the conversion rather than drop or shift a page. The rendition joins the pages with <!-- page N --> anchors and escapes any comment opener in the text, so a document cannot forge an anchor. |
built |
| 9–11 | Backend → LLM provider | The contract gate: the first two pages (the one page of a one-page document) go to the model as data between markers a document cannot forge, and the model answers a label — contract, invoice, other or unsure — and the indicators it found, each with the passage it was read from. Every passage is checked against exactly those pages by the extraction's citation rule (8.7), and the verdict is derived from the confirmed indicators and the label alone; the model is never asked how sure it is. Which model answers is configuration, and the stub gate asks none (8.13.1); the deployed service runs Mistral Medium (7.1.2). | built |
| 12 | Backend → Web app | A hard block is recorded as the table below says and answered 422 not-a-contract with the case and a reason that names the file; no page of it goes further. |
built |
| 13 | Backend | Every other verdict goes on, and the document's language is recognised on the machine, with no model and no network (below). | built |
| 14–15 | Backend → LLM provider | A document whose language is neither English nor unrecognised is translated into English once, page by page; the case keeps the translation beside the original, and a translation that fails is none — the original is read alone. Which model translates is configuration, and the stub translates nothing (8.13.1). | built |
| 16 | Backend → Web app | The case is recorded converted, with the gate's verdict and the language, and answered 201 with its pages. A document the converter cannot read is 422 conversion-failed, a converter still unreachable after the retries 503 converter-unreachable, each with the ID of the case that records the failure. The reason is one a person can act on, never document content. The temporary copy of the PDF is deleted whatever the outcome. |
built |
The contract gate and the language. The table gives the gate's five verdicts — the rules that
derive them are spec 367 (docs/specs/367-contract-gate.md) R-4 and R-5 — and what a person sees of
each; the screens are specified in spec 204 (docs/specs/204-contract-intake.md) ST-8,
spec 568 (docs/specs/568-case-screen.md) CV-13 to CV-16 and spec 566 (docs/specs/566-cases-dashboard.md)
CD-12. The case API answers the verdict with the pages, and a blocked case's verdict too (spec 367 (docs/specs/367-contract-gate.md)
R-7, R-12); the gate's log line carries nothing of the document (spec 367 (docs/specs/367-contract-gate.md) R-9, NFR-4).
| Verdict | When | The case | What a person sees | Status |
|---|---|---|---|---|
| pass | clear evidence of a contract, none of an invoice | converted | the classification step passed; passed on the case screen | built |
| soft block | evidence not conclusive either way | converted, and goes on | the step marked unclear, and a notice to confirm that the document is a contract, and the chip check unclear in Cases; starting the extraction is that confirmation, recorded with who and when (spec 339 (docs/specs/339-case-api.md) R-11) |
built |
| hard block | no confirmed evidence of a contract, and either confirmed evidence of an invoice or the model's label other | blocked with the cause not a contract; its PDF and the verdict kept, its pages not | the refusal with its reason, which names the file; a reviewer may report the case as wrongly classified, with a reason (spec 339 (docs/specs/339-case-api.md) R-12) |
built; the release planned |
| failed | the check could not run: an unreadable answer, a failed call, first pages without text | converted, as after a soft block: a failing gate never blocks and never throws | a failed classification step — the classification could not run — the same notice to confirm that it is a contract, and the chip check failed in Cases | built |
| unchecked | the stub gate asked no model; or the case was stored before the gate | converted | no classification step on the intake screen; not run on the case screen | built |
The language detector weighs the text's passages by their letters and names the dominant language
and whether the text is mixed; the supported languages are configuration
(spec 377 (docs/specs/377-document-language.md)). A language never blocks a document: the case API
answers its code, whether it is mixed, and the warning beside the pages.
| Warning | When | Status |
|---|---|---|
| none | the dominant language is English | built |
| not English | another supported language (German, French, Italian by default) | built; shown on the intake screen planned |
| not supported | any other language, and a document whose language cannot be recognised — empty, numbers only | built; shown on the intake screen planned |
Conversion job — with a queue configured. Convert document runs as a conversion job: the upload stores the PDF and the case, and Pub/Sub pushes the case ID back to the backend.
sequenceDiagram
autonumber
actor P as Person
box rgb(183,228,199) Built
participant UI as Web app
participant BE as Backend
participant FS as Case database
end
box rgb(198,220,255) Planned
participant B as Document store
participant Q as Event broker
end
box rgb(183,228,199) Built
participant DS as docling-serve
end
P->>UI: upload contract PDF
UI->>BE: POST /api/cases
BE->>B: store PDF
BE->>FS: case = queued
BE->>Q: publish case ID
alt publish fails
BE->>FS: case = failed
BE-->>UI: 503 with the failed case
else published
BE-->>UI: 202 with the case
end
Q->>BE: push case ID (OIDC token)
BE->>FS: claim in a transaction: queued → converting, with a lease
alt case already converted or failed
BE-->>Q: 204, acknowledged, skipped
else converting under a live lease
BE-->>Q: 409, redelivered later
else claimed
BE->>B: read PDF
BE->>DS: convert, as in the call
alt docling-serve unreachable after the retries
DS-->>BE: 429 or timeout
BE->>FS: release the claim: case = queued
BE-->>Q: 503, redelivered with a backoff
else converted, or the document cannot be read
DS-->>BE: rendition or failure
BE->>BE: gate, language and translation, as in the call
BE->>FS: pages, case = converted, blocked or failed
opt failed
BE->>B: delete PDF
end
BE-->>Q: 204, acknowledged
end
end
opt after the last delivery attempt
Q->>BE: push to the dead-letter endpoint
BE->>FS: case = failed
end
loop meanwhile, every few seconds until done
UI->>BE: GET /api/cases/{id}
BE->>FS: read case
BE-->>UI: queued · converting · converted with pages · blocked · failed
end
| Step | From → To | What | Status |
|---|---|---|---|
| 1–2 | Person → Web app → Backend | As in the call: size limit and PDF header first; a refused upload opens no case. | built |
| 3–5 | Backend → Document store, Case database, Event broker | The PDF goes into the private bucket, the case is recorded queued, and its case ID is published, marked as a conversion. | built: the store, case-store and queue adapters and the bucket on Google Cloud; the queue's cloud resources planned (7.1.2), locally the emulators |
| 6–7 | Backend → Case database, Web app | A publish that fails marks the case failed and deletes the PDF; the upload is answered 503 with the failed case. |
built |
| 8 | Backend → Web app | Published: the upload is answered 202 Accepted with the case, and Location where it is read. |
built |
| 9 | Event broker → Backend | Pub/Sub pushes the case ID to the backend's push endpoint, with an OIDC token on Cloud Run. A message whose data is not a case ID is refused 400. |
built; the subscription and its token planned |
| 10 | Backend → Case database | Pub/Sub delivers at least once, so the case is claimed in a transaction — queued → converting, with a lease longer than the push acknowledgement deadline. | built |
| 11–12 | Backend → Event broker | A case already converted or failed is acknowledged and skipped; one converting under a live lease is a duplicate, answered 409 and redelivered later. An expired lease — a restart mid-conversion — may be claimed again. |
built |
| 13–14 | Backend → Document store, docling-serve | The PDF is read and converted as in the call, steps 4 to 8 above. | built |
| 15–17 | docling-serve → Backend → Case database, Event broker | A converter still unreachable after the adapter's retries releases the claim, and the push is answered 503: the event broker retries with a backoff (spec 263 (docs/specs/263-intake-job.md)). |
built |
| 18–22 | Backend → Case database, Document store, Event broker | The contract gate, the language recognition and the translation run as in the call, steps 9 to 15 above. A converted case gets its pages, and its PDF stays kept until the case is deleted (spec 339 (docs/specs/339-case-api.md) §5.2). A hard block is recorded blocked, as the table above says. A document that cannot be read is failed, and its PDF is deleted. The push is answered 204, which acknowledges it. |
built |
| 23–24 | Event broker → Backend → Case database | After the last delivery attempt (spec 263 (docs/specs/263-intake-job.md)) the message moves to the dead-letter topic, whose subscription pushes it to the dead-letter endpoint; a case whose conversion still waits is marked failed, one already done is left as it is. |
built; the dead-letter topic and subscription planned |
| 25–27 | Web app → Backend → Case database | The screen polls the case every few seconds until it is done, and reads the pages at GET /api/cases/{id}/pages. A case still queued with no delivery after the queued timeout (spec 263 (docs/specs/263-intake-job.md)) — a crash between recording and publishing — is reported failed. A case is kept until it is deleted, and its PDF with it (8.3). |
built in the backend, on a developer machine and on Google Cloud, where the bucket has no lifecycle rule |
The case database is PostgreSQL under the database profiles; the Cloud Run case profile names no case store, so the database profile selects it (5.1).
6.2.2 Extract attributes¶
What is read: the two contract partners — the distribution partner and the
AssetCo entity, each with name, partner number, e-mail and address —
and the contract ID, every datum a field graded on its own. From
ADR-0012 (docs/adr/adr-0012-model-provider-and-extraction-shape.md) (option S3, the agent loop with
read-only lookup tools), spec 383 (docs/specs/383-extraction-agent-loop.md) and
spec 8 (docs/specs/8-intake-into-extraction.md); the rules are 8.7,
and the extraction guide (docs/guides/structured-llm-response.md) gives the full account, with the
building blocks and the cases the tests pin.
sequenceDiagram
autonumber
box rgb(183,228,199) Built
participant UI as Web app
participant BE as Backend
end
box rgb(230,230,230) External
participant M as LLM provider
end
UI->>BE: POST /api/cases/{id}/extraction
BE->>M: prompt with the anchored markdown, two lookup tools
loop until the model answers, within the caps
M-->>BE: call: find passages or read page
BE->>M: lines or page from the rendition only
end
M-->>BE: answer as JSON text
BE->>BE: validate against the schema, ask again on error
BE->>BE: collapse candidates, check each citation
opt a field unsupported or not found
BE->>M: re-ask once, naming each such field
M-->>BE: new answer, validated and checked
end
BE-->>UI: 201 with the extraction result
| Step | From → To | What | Status |
|---|---|---|---|
| 1 | Web app → Backend | The screen requests the extraction of a converted case. A case without pages is 409 not-ready, one whose extraction runs 409 running. With a queue configured, the request is answered 202 with the case extracting, and the extraction runs as an extraction job through the same push endpoint, claim and lease as 6.2.1. |
built |
| 2 | Backend → LLM provider | The configured extractor — the stub, Mistral, or Gemini on Vertex AI in an EU location — gets the structured prompt with the rendition's anchored markdown and two read-only tools over the same rendition: find passages (the lines that contain a query) and read page (one page). The stub plays a prepared script of tool calls and a prepared answer inside the same loop, with no network. | built |
| 3–4 | Model ↔ Backend | The model decides whether to look anything up before it answers. The tools refuse an argument outside the document themselves. The loop is capped: 5 calls per tool, 8 tool calls in total, 12 model turns and 100,000 tokens per case. | built |
| 5–6 | LLM provider → Backend | The answer is validated against the schema of what the model may claim; on a violation the concrete error goes back and the model is asked again, three times over. A spent loop returns the last answer; nothing here throws. | built |
| 7 | Backend | The answer is parsed as text: empty, non-JSON or non-object answers become the defined fallback — every field empty, incomplete. Candidates are collapsed by value and each is checked against the document, punctuation-blind, at most 300 characters. Confirmed candidates win; more than one survivor leaves the field empty and AMBIGUOUS. A single candidate that fails the check is kept as UNSUPPORTED; several that all fail are AMBIGUOUS as well. |
built |
| 8–9 | Backend ↔ Model | One re-ask after the citation check, and only one (spec 383 §8, which supersedes ADR-0012 §3's "nothing feeds a failed citation or an empty field back to the model"): each field UNSUPPORTED or NOT_FOUND is named with its finding. The new answer runs through the same validation and citation check, under the same caps and budget, and only the re-asked fields are taken from it. A re-ask the budget does not admit ends in the fallback. An empty list stays a correct answer, and a grounded or ambiguous field is never asked about again. |
built |
| 10 | Backend → Web app | The result — each value with its derived confidence, a GROUNDED value with its page and passage, and a derived complete — is stored on the case and answered 201; GET on the same path reads it again. A spent cap or budget, a timeout or a rejected key has ended in the fallback before this step, recorded with its reason. Every model call runs under one retry policy, whichever provider answers it (spec 210 (docs/specs/210-spring-retry.md) §7): an outage — a 5xx, a 408, a call that got no answer — is retried up to two times, one second apart and then two, and a quota hit (429) or any other failure is called once; a retried call is one turn of the loop. Under Vertex AI the Google client retries a 408, 429 or 5xx on its own as well, inside each of those calls. |
built |
Nothing read out of the document, a tool result or the answer is logged, at any level (NFR-4); every line names the extraction by an internal ID — one per model call and tool call, one per retry of a model call, one for a stopped loop, one for the re-ask and one with the outcome as verdict counts, repeated by the case under its case ID (G-5, G-6 in 8.2).
6.3 Child case Fee reconciliation¶
Compares the recorded fee agreement against the master data. Not verifiable is an outcome of its
own, not the same as deviating; no comparison source is something different again. The child
case runs in the same engine as the FeeCheck case, with the case's ID as its business key; its
machine work is requested from the reconciliation module, a case-agnostic stage module, and its
human tasks belong to the case. Every stage task here is answered as
6.1.2 draws it, one request per module until a person is next. The
task names of spec 15 (docs/specs/15-workflow-module.md) and its
CMMN model (docs/specs/15-fee-reconciliation.cmmn) are kept.
%%{init: {"flowchart": {"nodeSpacing": 30, "rankSpacing": 40}}}%%
flowchart TB
start[["«case task»<br/>Fee reconciliation"]]
subgraph frc["«case» Child case: Fee reconciliation"]
direction TB
reconcile[/"«send event task»<br/>Reconcile against master data<br/>ReconciliationRequested"/]
find[("«case file item»<br/>Findings")]
assess[/"«send event task»<br/>Assess findings<br/>AssessmentRequested"/]
review("«human task»<br/>Review findings")
release("«human task»<br/>Release findings")
publish[/"«send event task»<br/>Publish released findings<br/>FindingsPublished"/]
released(["«milestone»<br/>Released"])
end
report("«module»<br/>Export module")
start -.-> reconcile
reconcile -.-> find
reconcile -.-> assess -.-> review
review -.-> release -.-> publish -.-> released
publish -. "FindingsPublished" .-> report
classDef person fill:#ffe8b0,stroke:#9a6b00,color:#000
classDef built fill:#b7e4c7,stroke:#2d6a4f,color:#000
classDef planned fill:#c6dcff,stroke:#1168bd,stroke-dasharray:4 3,color:#000
classDef external fill:#e6e6e6,stroke:#6b6b6b,color:#000
class start,reconcile,find,assess,review,release,publish,released,report planned
style frc fill:none,stroke:#666
| Task | Type | Input | Output | Domain event on completion | Status |
|---|---|---|---|---|---|
| Fee reconciliation | CaseTask in the FeeCheck case, starting this child case in the same engine | the milestone Contract recorded | the child case, one per contract PDF | — | planned; the child case, not a stage; spec 15 starts it when the stage Document completes (W-1) |
| Reconcile against master data | stage task, a request to reconciliation, deterministic: assign the contract via AssetCo unit and distribution partner, and below that per product, share class and period; reconcile per attribute against the master-data value, with tolerance and code lists, and recalculate the amount only with the invoice record of Invoice intake; cross-check ISIN, legal entity, UID / VAT, IBAN and BIC, and the NAV per valuation date only with Invoice intake; create the findings |
the child case's start; the contract record | the findings, a CaseFileItem: per attribute confirmed, deviating, low confidence, not verifiable or no comparison source — each with evidence | FindingsCreated |
planned; when the master data does not answer, the request's delivery is retried and the reply deadline bounds the whole (6.1.2); a failed stage task waits as Failed and is resumed without repeating convert or extract (W-4). Spec 15's three engine retries give way to this, and W-4 is revised with spec 15. Spec 15 models the findings as domain data of the reconciliation, not as tasks |
| Assess findings | stage task, a request for two model calls, both advisory: classify each match to a rubric level, with score and cause class, measurable against real decisions; and comment where the differences are and where they might come from, written from level, cause class and evidence — score and comment are context, not criterion | FindingsCreated |
the findings classified and commented | FindingsCommented |
planned; not modelled in spec 15; the module that makes the model calls is open |
| Review findings | HumanTask, candidate group reviewer | FindingsCommented |
the findings reviewed in a split screen of evidence passage against master-data value; correction in the app, an Excel round-trip as optional adapter. Completing it is refused while a finding is open | FindingsReviewed, a case step |
planned; runs on every case, as spec 15 models it (§2, W-2). Which role reviews is open (OQ-10) |
| Release findings | HumanTask, candidate group approver | FindingsReviewed |
the decision with justification, four-eyes when needed; completed by a named person in the candidate group, whose identity is recorded (W-7) | FindingsReleased, a case step |
planned |
| Publish released findings | send event task | FindingsReleased — only after a person completed Release findings (W-3) |
a snapshot of all evidence in the audit trail; both case instances complete (W-5) | FindingsPublished, a fact out of the case, externalized to Pub/Sub for downstream processing (8.16.3); it reaches the milestone Released |
planned; nothing is released without a person (8.2 Guardrails) |
| Findings | CaseFileItem of the child case | Reconcile against master data | per attribute confirmed, deviating, low confidence, not verifiable or no comparison source, each with evidence | — | planned |
| Released | milestone of the child case | FindingsPublished |
— | — | planned; spec 15's milestone |
| Export module | no CMMN element: the export module of the backend's planned components, listening for FindingsPublished |
FindingsPublished |
the comparison report, viewed and downloaded in the web app; an export API for Power BI and downstream systems | — | planned; not modelled in spec 15 |
A provider timeout anywhere in the case resumes from the last persisted task without paying again for finished contracts (QS-10).
6.4 Sign-in and an API call through the gateway¶
As ADR-0010 (docs/adr/adr-0010-api-gateway-and-api-contract.md) decides it; not part of the case.
The diagram says the person's token: which of Google's tokens is relayed, and how the two tokens
share a request, is open.
sequenceDiagram
autonumber
actor P as Person (browser)
box rgb(198,220,255) Planned
participant G as gateway
end
box rgb(230,230,230) External
participant O as Google (OIDC)
end
box rgb(183,228,199) Built
participant B as backend
end
P->>G: GET /intake (no session)
G-->>P: 302 to Google's sign-in
P->>O: sign in, consent
O-->>P: 302 to the gateway's redirect URI, with a code
P->>G: GET /login/oauth2/code/google?code=…
G->>O: exchange the code for the tokens
O-->>G: ID token, access token
G->>G: account on the allowlist? keep the tokens in the session
G-->>P: 302 to /intake, Set-Cookie (HttpOnly session)
P->>G: POST /api/cases (session cookie, PDF)
G->>B: the same request, with both tokens
B->>B: validate the token (issuer, audience, expiry)
B-->>G: 201 or 202 with the case, or 413 / 415 / 422 / 503
G-->>P: the answer, unchanged
| Step | From → To | What | Status |
|---|---|---|---|
| 1–7 | Person → gateway → Google | The browser asks the gateway for a page or /api/** without a session; the gateway sends it to Google's sign-in (OIDC code flow) and exchanges the code for the tokens. |
planned; today the backend runs the same code flow itself (8.8) |
| 8 | gateway | The account is checked against the allowlist, and the person's tokens are kept in the gateway's session. An account not on the allowlist is refused here and never reaches the backend. | planned; today the backend's sign-in checks the allowlist |
| 9 | gateway → Person | The browser holds only an HttpOnly session cookie with the gateway — no token. |
planned |
| 10–11 | Person → gateway → backend | Every call to the backend carries the person's token and, on Cloud Run, the gateway's own service-account ID token for the IAM check; which token is relayed and in which header is open. | planned |
| 12 | backend | As a resource server, the backend accepts the call only with a valid token; a request without one is answered 401. |
planned: the backend's resource-server role |
| 13–14 | backend → gateway → Person | The backend answers as it does without the gateway; the gateway passes the answer back unchanged. | planned |