: asapien/signet

1 
2 
3 
4 
5 
6 
7 
8 
9 
10 
11 
12 
13 
14 
15 
16 
17 
18 
19 
20 
21 
22 
23 
24 
25 
26 
27 
28 
29 
30 
31 
32 
33 
34 
35 
36 
37 
38 
39 
40 
41 
42 
43 
44 
45 
46 
47 
48 
49 
50 
51 
52 
53 
54 
55 
56 
57 
58 
59 
60 
61 
62 
63 
64 
65 
66 
67 
68 
69 
70 
71 
72 
73 
74 
75 
76 
77 
78 
79 
80 
81 
82 
83 
84 
85 
86 
87 
88 
89 
90 
91 
92 
93 
94 
95 
96 
97 
98 
99 
100 
101 
102 
103 
104 
105 
106 
107 
108 
109 
110 
111 
112 
113 
114 
115 
116 
117 
118 
119 
120 
121 
122 
# Ticket 11 — sequential signing and worker-owned release

Completed and verified in isolated development on 2026-11-12. No commit,
production deployment, authentication-provider integration or production
acceptance is implied. Scope/acceptance: `spec.md` §2; accepted model unchanged.

## Implementation

- Route access uses party order for listing, detail and files. Later parties
  cannot fetch early; route access excludes drafts/corrections. Drafter-only
  access does not expose `stamped.pdf`; `final.pdf` requires `RELEASED`.
- Decisions are revision/party-scoped and locked. Check-only parties advance
  without a facsimile or render. Zone sign-offs require an enrolled facsimile
  and typed placement: correct page, finite coordinates, positive reference
  frame, positive in-zone rectangle and minimum fitted image dimensions. The
  minimum check accounts for image aspect ratio and actual PDF page dimensions,
  not just an arbitrarily large placement rectangle. One zone per known party;
  party names are unique. External commands remain through `run_cmd()`.
- The worker selects the just-signed party for intermediate overlays, or the
  current last party for release. It aspect-fits/centres the PNG and uses the
  immutable committed preceding render as its input. Check-only final decisions
  copy that body. No API signature-file reads or synchronous API release remain.
- Last sign-off queues `release`, leaving the document pending. The worker
  overlays the final facsimile, hashes the signed body, records `RELEASED` and
  renders the complete cross-revision event log with metadata and body hash.
  UTF-8-safe word wrapping/pagination has no historical-event/comment truncation;
  input comments are explicitly limited to 4096 bytes. `final_sha256` covers the
  whole final PDF (including audit), not just the body.
- A savepoint rolls back the release event on output failure. Database failure
  retains the processing job; published final files remain inaccessible before
  commit. Release replay does not double-stamp or duplicate its event. Completed
  job replay retries cleanup if interrupted after commit; stamped/candidate
  copies are removed before acknowledgement.
- Title is mandatory before submit. Create/submit/decision events share their
  state transactions; rerender state and RETRY event share one SQL statement.
  Correction invalidates the old signing state and removes stamped inputs.
  Resubmit keeps serial/date, starts party one again and logs `RESUBMITTED`.
- The browser retains party/minimum/reference properties through layout edits,
  supports aspect-constrained pointer/keyboard placement and first-signing
  enrolment, refreshes enrolment state, shows the event log and polls release.
  Empty titles disable Submit. Drawing supports scaled pointer/touch coordinates.
  Worker enrolment fully decodes bounded PNGs before accepting them.

Prerequisite bugs exposed by acceptance were also fixed: `/api/pim` now merges
metadata/images under one organisation object (including duplicate SCAN hits),
`pim_image` resolves its PIM key to a DAM path, validation no longer uses a freed
Redis reply or truncates iteration at the first signature zone, and repeated
browser notifications retain the `.toast` selector. Worker DB grants now include
SELECT on `doc_events`; dev facsimile dimensions match the synthetic PNG.

## Verification

Clean image `signet-ticket11`, image id
`218ae9c6cba2ea6515c62771ce3cd969bac634e616b2939bc16bdd50f24ce907`;
fresh container `signet-ticket11-verify` on localhost:8080. The final test-only
malformed-PNG extension was copied into that container before rerunning the
contract suite; compiled binaries are from the clean image. Synthetic fixtures
only. Explicit forwarded identity/group headers are supplied in tests.

- `/tmp/signet-ticket11-build-final.log`: full Alpine build/install with
  `-Wall -Wextra`, no compiler warnings/errors.
- `/tmp/signet-ticket11-e2e-final.log`: `test/e2e.sh` ends **all passed**.
  Covers organisation text/images, title/serial rollback, later-party
  list/detail/file denial, unsigned proof, invalid/scaled placements (including
  a rectangle that passes minimums but whose aspect-fitted image does not),
  check-only signing, first enrolment, final-party overlay, failed release and
  authorized retry, audit/body hash/final hash/cleanup, correction/resubmit with
  preserved serial/date and no old facsimiles, 80 injected historical events and
  a long correction sentinel on multiple audit pages, terminal disapproval,
  self-service, template/series lifecycle. Also rejects unknown/duplicate zones,
  integer-overflow pages, missing image references after a zone, duplicate final
  decisions and unauthorized release retries.
- `/tmp/signet-ticket11-contract-final.log`: `test/e2e.sh render-contract`
  ends **render contract: all passed**. Retains ticket-10 stamp/sign dispatch,
  stale/malformed/mismatched jobs, database failure/startup recovery and queue
  outage assertions. Adds actual release publication-before-DB-failure/replay,
  pre-commit final-access denial, body/final hashes, exactly one release event,
  cleanup after interrupted post-commit acknowledgement, and malformed PNG
  rejection. These use real PostgreSQL triggers and real queue/worker execution.
- `/tmp/signet-ticket11-browser.log`: `test/signing-flow.mjs` passes against the
  real API/worker, using externally installed Playwright Core and Chrome (dev
  only). Tests edit/save and title gate, two-page proof, constrained keyboard and
  pointer placement, sequential access, check-only, upload enrolment and UI
  refresh, final release/event log/print control. No unhandled JS errors.
  Latest visual document: `b154d5e9-0f15-4785-8af2-885b33df798a`.
- `/tmp/signet-ticket11-progress.log`: existing `test/render-progress.mjs`
  polling/failure/retry-authorization/completion regression passes. Its mocked
  progress cases supplement, not replace, the real worker tests.
- Visually inspected both synthetic pages in edit/proof/stamped/final screenshots
  under `/tmp/signet-ticket11-browser/`, plus `audit.png`. Text and circular seal
  align, unsigned proof has no facsimiles, the first facsimile survives unchanged
  into final, the last appears on page two, and the audit is legible. These are
  targeted fixture comparisons, not general PDF compatibility acceptance.
- `node --check` for client and browser tests, `sh -n` for all changed shell
  tests/entrypoint and `git diff --check` pass.
- Observed idle app RSS including lighttpd, kfcgi, APIs/parser children and worker:
  about 20 MB; worker 2836 KB, API processes up to 2680 KB. This excludes
  PostgreSQL/Redis and is not a peak-load or native 1-vCPU production certificate.

Browser commands (dependencies remain outside the repository):

```sh
PLAYWRIGHT_MODULE=/tmp/signet-ticket10-browser/node_modules/playwright-core/index.mjs node test/signing-flow.mjs
PLAYWRIGHT_MODULE=/tmp/signet-ticket10-browser/node_modules/playwright-core/index.mjs SIGNET_EVIDENCE=/tmp/signet-ticket11-progress node test/render-progress.mjs
```

## Remaining scope / limits

- Ticket 12: PIM/DAM still resolve during worker stamping, with proof/stamped
  rendered separately; a submit-time frozen revision is not implemented. The
  image-key/aggregation repairs above do not establish snapshot immutability.
- Tickets 13/14: fail-closed identity, trusted proxy boundary, DAM writer policy,
  PIM enforcement and native Alpine/OpenRC/CSP/AOF/permissions/RSS acceptance.
  The existing missing-header admin fallback remains unsafe outside isolation.
- Worker queue recovery assumes one worker. Old intermediate render files left
  by interrupted non-release cleanup may need separate housekeeping. Storage
  retention and full event-log growth need operational policy, not truncation.
- Nonzero CropBox/rotated/unusual PDFs, complex scripts, alternate fonts,
  concurrent series allocation and memory under maximum uploads are not newly
  certified here. Pending legacy development jobs need the typed-job contract.
- Unrelated authentication/dev-stack changes, skill deletions and other dirty
  working-tree files were preserved. Nothing committed or deployed.