{"v":{"id":466,"url":"https:\/\/www-s01.apinet.com\/codeforge\/api\/v1\/repos\/apiintl\/hhmanager\/issues\/209","html_url":"https:\/\/www-s01.apinet.com\/codeforge\/apiintl\/hhmanager\/issues\/209","number":209,"user":{"id":1,"login":"charles","login_name":"","source_id":0,"full_name":"Charles Willgren","email":"charles@apinet.com","avatar_url":"https:\/\/www-s01.apinet.com\/codeforge\/avatars\/d3c894f7297c5a18eb3f6ac837c335b11a00aa9cc0961323771632b1e2d61bb2","html_url":"https:\/\/www-s01.apinet.com\/codeforge\/charles","language":"","is_admin":false,"last_login":"0001-01-01T00:00:00Z","created":"2025-12-08T10:03:41-06:00","restricted":false,"active":false,"prohibit_login":false,"location":"","pronouns":"","website":"","description":"","visibility":"public","followers_count":0,"following_count":0,"starred_repos_count":0,"username":"charles"},"original_author":"","original_author_id":0,"title":"Forms V2: keep a list of every form that failed to generate, so we can review them","body":"## Why\n\n#208 reached us only because Cassandra emailed a screenshot. When a visit's form can't be turned into a PDF, the person at the visit sees a red message and a **Try generating again** button, and that's the end of it. Nothing is saved, so we can't tell how often it happens, on which forms or visit types, or whether a fix worked. A failure nobody reports is never seen.\n\nToday every failure goes through one place, `form_v2_artifact_render()` (`code\/form_v2_artifact.inc.php`). It returns `['ok' => false, 'code', 'error', 'refusals']` to the screen and records nothing.\n\n## What a failure looks like\n\n| code | Meaning | Example |\n|---|---|---|\n| `unprinted` | An answer has no place on the paper | #208 |\n| `invalid` | The placement has problems, the blank form doesn't match it, or the placement isn't published | |\n| `render` | The PDF generator itself failed | |\n| `io` | Couldn't make a working directory | |\n| `not_found` | Client not in this agency | (probably not worth keeping: this is a request error, not a form defect) |\n\n## Proposal\n\n1. **Record each failure** in a new table, `form_v2_generation_failure`, written from the one `$fail` point. Each row holds:\n   * agency, visit, form code, release, map hash, template sha\n   * the failure code, and the refusal **field keys \/ map error codes** only\n   * who and when\n   * a count of times seen, plus first and last seen dates\n   \n   Repeats are grouped by (form code, map hash, code, sorted field keys). That way, ten presses of \"Try again\" make one row, not ten.\n2. **No PHI.** Store field keys and error codes, never the answers and never the rendered message text. Pass the generator's error string for `render` through `obs_scrub()` first, or keep only a fixed category. The client is reachable through the visit id; we don't copy their name.\n3. **A review screen** at `\/admin\/form-failures` (Superuser), with one line per group showing the form, what went wrong in plain words, how many times, which visit types, and when last seen. A row can be marked **Fixed**, with a note naming the issue or commit. It reopens if the same group is seen again after being marked fixed, the same rule the flags use (`resolved_by=0 \u21d2 may reopen`).\n4. **Tell someone.** Add a `notify\/FormFailures` subscription (the same pattern as `notify\/PipelineIssues`), sent the first time a new group appears and not on repeats. Alternatively, or as well, send a GlitchTip event tagged with the form code.\n5. **A plainer message at the visit.** \"Correct the form's placement first\" means nothing to a supervisor. It should read: \"This form couldn't be printed. You can carry on with the rest of the visit.\"\n\n## Questions\n\n* Should `invalid` problems with a placement also be recorded when a proof is made from the publishing screens, or only failures at a real visit? I suggest only real visits, since a proof is supposed to find problems.\n* Who gets the notification: just us, or the admins as well?\n\n## Done when\n\n* Every non-`not_found` failure in `form_v2_artifact_render()` writes or updates a row (state test).\n* A pure test confirms the stored row holds no answer values.\n* There is a review screen with Fixed and reopen.\n* Notification goes out on a new group.\n* Docs\/Forms.md, Changelog and UserChangelog are updated.","ref":"","assets":[],"labels":[{"id":33,"name":"action","exclusive":false,"is_archived":false,"color":"d97706","description":"Action item tracked on the Connect dashboard","url":"https:\/\/www-s01.apinet.com\/codeforge\/api\/v1\/repos\/apiintl\/hhmanager\/labels\/33"}],"milestone":null,"assignee":null,"assignees":null,"state":"open","is_locked":false,"comments":1,"created_at":"2026-11-06T10:02:20-06:00","updated_at":"2026-11-09T10:14:04-06:00","closed_at":null,"due_date":null,"pull_request":null,"repository":{"id":27,"name":"hhmanager","owner":"apiintl","full_name":"apiintl\/hhmanager"},"pin_order":0}}