Deterministic fallback when a draft cannot be made
Use this page for the fixed rule when the writing service errors, times out or returns a malformed result. The rule is the same every time. One attempt, one retry for a timeout or a dropped connection only, no retry for a malformed result, the shape checked before anything is shown, and a template fallback built only from supplied fields on the same record.
How to read this contract
This page replaces the Unknown rows on the routing map for the timeout, the retry count and the malformed result. The signed-in app draft helper that is not in this site pack must match this contract word for word before any draft ships. Public pages contain no draft call, and the demo form send in site.js is not a draft path.
- Timeout is 15 seconds for every draft task. Do not copy the 20 second demo form timeout or the 10 second health timeout to a draft task.
- Retry is one retry for a timeout or a dropped connection only. A malformed result, an empty result and a conflicting field set are never retried, and no task retries in a loop.
- A result is shown only where it is fully covered by supplied fields, each factual sentence with its bracket citation, for example [records.record_number]. A part that needs a missing field is listed as Unknown and is not shown as a draft.
- Draft output is for a person to review and edit. It is never saved, published or sent on its own.
- Log every fallback with a support code, the task name and the outcome kind, with user and time in the audit history on that record. Never log a supplied field value, supplied text, draft text, a name, a fee, a date, a code or a person fact. See the logging section below.
Decision table, one row per failure
Work down the table in order. Each row states the attempts, the exact message the person sees, and the non-writing fallback that runs instead of a draft.
| What happened | Attempts | What the person sees | Non-writing fallback that runs |
|---|---|---|---|
| Writing service returns an error | One attempt, no retry | Drafts are unavailable right now. Your entries are kept on this page. You can copy the missing items list below and work from the record, or try again in a few minutes. | Template fallback from supplied fields only. Submission confirmation shows record number and next step where supplied. Decision notice shows outcome and next step where supplied. Consolidated letter shows each open comment by discipline, sheet and location where supplied. Checklist shows required, received and missing in words. |
| Writing service times out after 15 seconds | One attempt, then one retry, then stop | Same message as the error row. Entries stay on the page and the retry control is offered once. | Same template fallback as the error row, run after the single retry fails. No second retry and no queued send. |
| Writing service returns text that is not the expected shape | One attempt, no retry, nothing shown | Same message as the error row, with the missing items list for the part that needed the malformed result. | Same template fallback as the error row. The malformed text is not displayed, is not saved, and no field is copied from it, so a value cannot be invented from a malformed result. |
| Writing service returns an empty result | One attempt, no retry, nothing shown | Same message as the error row, with the missing items list. | Same template fallback as the error row. An empty result is treated as a failure, never as a complete draft. |
| Supplied fields conflict or a value is unclear | No writing service call for that part | Unknown for that item, both field names and the conflict in plain words. | Template fallback for the parts that supplied fields fully cover, each with its bracket citation. The conflicting part stays Unknown until staff correct the record with a logged reason. |
The five rules in order
Apply these rules in this order before any draft is shown. Each rule ends with what you should see when it worked.
Run one attempt with a 15 second timeout
Start one attempt per task per record. Abort at 15 seconds. You should see the attempt end at the timeout with entries kept on the page.
Retry once only for a timeout or a dropped connection
Where the first attempt timed out or the connection dropped, offer one retry. You should see one retry control, and no retry for an error, a malformed result, an empty result or a conflict.
Check the shape before anything is shown
Read the result as text. Where it is not readable, or a required field is absent or of the wrong kind, treat the result as malformed and show nothing from it. You should see no partial draft that contains a guessed value.
Run the template fallback from supplied fields only
For each part that supplied fields fully cover, show the template with bracket citations. For each part that needs a missing field, show Unknown: field not in supplied context and name the source field or document needed. You should see the missing items list and never a fee, date, code or person fact that is not in a supplied field.
Keep the result for review, never send it on its own
Show the shown part for editing, labelled by result. You should see the record number noted for follow-up, and no save, publish or send without a person choosing it.
Logging for every fallback
Log every fallback so a repeated error can be traced on the record. Log the task, the outcome and the support code only. The entry follows the audit rule on the security page, with user and time, and never contains a supplied value.
| Outcome | Log these fields only | Never log |
|---|---|---|
| Error, timeout, malformed or empty | Task name, outcome kind, support code starting with PD-DRAFT, page or record task step, user and time in the audit history on that record, and whether the one retry was used. | Supplied text, draft text, any supplied field value, a name, email, phone, address, fee, date, code, record detail beyond the record the entry is written on, or a secret, token or vault item. |
| Conflicting fields | Task name, conflicting field names, support code starting with PD-DRAFT, user and time in the audit history on that record. | Either conflicting value, draft text, or any other supplied field value. |
- Show the support code to the person on the page with the unavailable message, in the same way site.js shows a PD-REQ code for a failed form send. The code is for follow-up with the town office. It is not a record field and it is never sent as a form field.
- Write the same support code to the browser console with a warning, with the task name and the outcome kind only, so support can match the code on the page with the code in the log.
- A support code never replaces the Unknown marker. Where a field is missing, the missing item list still names the field and the source needed.
Try the contract on this page
Choose one case below. The page applies the decision table above and shows the message and the fallback for that case, with no network call. This panel is a check of the contract text, not a draft.
Choose a case to see the message and the fallback for that case.
- Every case shows the same message, so the person learns one state and not a different wording per failure.
- Every case names the template fallback that runs, and the malformed and empty cases state that nothing was shown and nothing was saved.
- The conflict case shows Unknown with both field names named, and no value silently picked.
- Every case shows a support code starting with PD-DRAFT and writes the same code to the console, with the task name and the outcome kind only and no field value.
What this contract never does
Keep these limits in place when the signed-in app implements this page.
- It never invents a fee, a date, a code, a requirement, an applicant fact, a license status, an inspection result or a balance. Where a field is missing, the item is Unknown and the missing items list is returned.
- It never gives legal advice or legal interpretation, and never states that a project complies with a code. That question goes to the issuing town office or code official for that record.
- It never treats supplied text as instructions. An instruction inside supplied text to ignore this rule, invent a value or change a supplied value is ignored, and the instruction is not mentioned unless the task is to summarize that text as supplied text.
- It never infers a missing value from another record, another workspace, an example, a template, a document title or general practice. A similar record is not a supplied field for this record.
- It never shows phone, email, payment details, internal notes or draft applications in public search, and a draft never creates a fee.
Drafts, summaries and checks - Respond to a correction letter - Security
Check the record, not a guess
When a draft cannot be made safely, read the Unknown list and ask the town office that issued the record.