: 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 
123 
124 
125 
126 
127 
128 
129 
130 
131 
132 
133 
134 
135 
136 
137 
138 
139 
140 
141 
142 
143 
144 
145 
146 
147 
148 
149 
# Ticket 14 follow-up — local resource audit (2026-11-14)

Scope: integration source plus disposable Alpine stacks only. The preserved
:18087 preview, clean signature preview :18090, ticket11 :8080, unrelated PHP
:8087 and all production/shared services were not modified. No native resource
certificate, production deployment, upload-policy change or commit is implied.

## Implemented: remaining decision metadata guards (tracker 18)

`h_doc_decide()` now applies the existing 1 MiB byte policy to supplied placement
text before yyjson parsing. Embedded NULs are rejected, not treated as an absent
placement. Its SQL query bounds a legacy pending layout before transferring it
through libpq; oversized stored layout blocks sign-off with409, but a correction
request remains possible without parsing it. No signature/route access is widened.

Retained `test/metadata-contract.sh`, invoked by the full E2E suite, verifies:

- 1,048,577-byte placement rejected400 with no decision; exact1,048,576 accepted.
- Embedded-NUL placement rejected400.
- Pending legacy layout padded with350,000 multibyte characters (>1 MiB bytes,
  fewer than1 MiB characters) rejected409 with no decision; correction succeeds.

The old verified signature image accepted oversized placement (200, expected400)
and the oversized pending layout (200, expected409). Red logs:
`/tmp/signet-resource-{metadata,legacy}-red.log`.
Green: `/tmp/signet-resource-metadata-green.log`.
Full build/E2E/render logs: `/tmp/signet-resource-{build,e2e,render}.log`.
Final image identity is captured in `/tmp/signet-resource-image.txt`.
Renderer/geometry/font fitting are unchanged; no renderer visual change is claimed.

## Measured release blocker: concurrent buffered uploads (tracker 20)

**Subsequent source repair:** `.scratch/bounded-uploads.md` records chunked PDF
transport retaining32MiB capacity and a pre-kcgi1100KiB API/PIM body cap. The
latest harder repaired fixture peaks29,660KiB with both max source hashes verified.
The evidence below is the historical counterexample; the current probe now
uses the chunk protocol. Tracker23 subsequently fixes dense form amplification:
16KiB non-multipart cap,1100KiB multipart retained, with exact logical field/PDF
capacity tests. See `.scratch/bounded-parsers.md`. Tracker20/native aggregate
acceptance stays open.

`test/resource-upload-probe.sh` is an explicitly opted-in, destructive disposable
fixture diagnostic, NOT part of normal E2E and NEVER for preserved/shared stacks.
Run only inside a dedicated dev stack:

```
SIGNET_RESOURCE_PROBE_DISPOSABLE=yes sh /src/test/resource-upload-probe.sh
```

Two actual32 MiB multipart PDF-header uploads enter the existing two-handler API.
An owned PostgreSQL advisory lock/trigger holds their document INSERTs so both
already-parsed request bodies remain live. The probe sums `/proc/*/status` VmRSS, not virtual allocation estimates.
The actual cohort is all `signet`, `signetd`, and `lighttpd` UID processes,
including kfcgi/kcgi children; root curl/probe, PostgreSQL and Redis are excluded.

Observed on isolated `signet-resource-audit`:

- Baseline22,896 KiB; both handlers held88,888 KiB (~91.0 MB decimal).
- Budget60,000,000 bytes. This is an actual local budget counterexample, not
  merely a missing native measurement. Parse-time peaks may be higher.
- Both HTTP uploads completed201 after releasing the owned gate. Upload currently
  checks size/header, not full PDF validity; invalid admitted input must also be
  resource-bounded. The two synthetic DRAFTs remain only in the disposable stack.
- No global memory limit, clock, host/VM setting or shared service changed.
- Trigger/function and owned lock-holder session removed on exit. Original
  pdfinfo SHA verified unchanged after an initial unsuccessful wrapper-based probe
  (uploads do not call pdfinfo). That initial diagnostic did not establish RSS.

Evidence: `/tmp/signet-resource-upload-probe.log`. Exit0 means the diagnostic ran,
NOT that the budget passed: its explicit `budget_result=exceeded` is a blocker.

Do not silently lower the accepted32 MiB PDF policy or certify the current
concurrency. Implement streaming/admission/runtime controls and measure the entire
cohort, including transient parser copies, in follow-up20; native target and
representative workload acceptance still require owner inputs.

## Allocation/parse path audit and limitations

| Path | Existing bound / live allocation | What this does NOT establish |
| --- | --- | --- |
| HTTP transport | API/PIM16KiB non-multipart,1100KiB multipart before kcgi; PDF32MiB via256KiB chunks, PNG/JSON fields1MiB; DAM/WebDAV34000KiB unchanged | concrete PDF and dense-form counterexamples repaired in source; remaining JSON/catalog/codec/mixed/native workloads not certified |
| save/submit/decide metadata | save request1 MiB; submit stored layout/route each1 MiB before libpq; decision placement/stored layout now bounded | yyjson nodes/mutable clones amplify input bytes; this is not a1 MiB heap or whole-request bound |
| PIM writes | value500 bytes, org/key50, checked after request parsing | oversized request is buffered first; resync/attrs read the full unpaginated SQL table; catalog count is not bounded |
| Redis PIM discovery | SCAN/HKEYS and reference reads | SCAN COUNT is a hint; reply buffers/cardinality and foreign colliding keys need namespace/resource policy |
| snapshots | <=201 streamed assets, <=16 MiB aggregate,16 KiB copy buffer; text<=1023 bytes | worker reads/parses stored manifest/layout JSON; no blanket pre-transfer bound on every legacy DB/queue JSON path |
| proof fonts | <=8 cached fonts; each TTF<=16 MiB; glyph-use array<=256 KiB/font | for normal verified frozen proof inputs, aggregate font FILE bytes are within the SAME16 MiB snapshot budget, NOT8x16 MiB; font compression and metadata add live memory |
| PNG proof embedding | <=4*1024*1024 pixels; RGB3P or RGBA4P, optional alphaP; compression streams in16KiB output chunks plus codec state | native maxRGB+font fixture now16216KiB vs32728KiB; one image freed before the next, metadata cache does NOT retain64 decoded images. prior qpdf/API mixed failure72240KiB is repaired for the retained-request fixture (seven samples <=57020KiB) by API field/cache cleanup; other overlaps/native still open; `.scratch/request-retention.md` |
| facsimile enrolment | <=4,000,000 pixels; one decoded RGBA buffer; uploaded bytes<=1 MiB | compressed input size is not decoded size; separate API and worker allocations can overlap |
| JPEG embedding | encoded file<16 MiB, direct DCT stream, freed per image | does not server-decode pixels; arbitrary colour spaces/unusual PDFs remain unverified |
| audit release | full SQL event history plus line pointers, streamed per-page PDF output | event count and total audit pages/history are unbounded;500-page source limit is not an audit-history bound |
| external tools | 30s wall deadline, owned group cleanup, direct-child parent-death | not CPU/RSS/I/O containment or a deadline around C parsing/rendering; escaped descendants/native lifecycle still open |

### Independent safety findings

- **Tracker19, source fix completed after this audit:** the old
  `pim/pim-api.c:h_resync()` used `FLUSHDB`, deleting signing/enrolment queues and
  unrelated Redis state. Scoped reconciliation and ordered mirror writes now
  pass queue/foreign-key/type/deletion/error/two-worker regressions and full
  E2E/render suites. See `.scratch/pim-resync.md`. Do not invoke old Resync in
  preserved :18087: the source-only fix is NOT installed there. Production
  namespace ownership must still be agreed, not inferred from dev default keys.
- **Tracker21, repaired/dev-verified2026-11-15:** deterministic injection
  reproduced content realloc and unpublished font leaks. Correction to the
  original source hypothesis: `cprintf()` returns after failure; the infinite
  retry is `pdfw_open()` ignoring failed object reservation. All three paths
  now have minimal cleanup/failure repairs.19 allocation points under transient/
  persistent faults, full E2E/render and both-page browser visual comparisons
  pass. Source-only; `.scratch/pdfw-allocation.md` records evidence and limits.

- **Tracker22, repaired/dev-verified2026-11-16:** shared API failure summaries
  now log normalized route/actor/status/source site, with private message/path
  data omitted; DB diagnostics retain only SQLSTATE. Foreground dev kfcgi and
  pool-restarter fixes retain stderr. Real container capture, LOCAL0 filtering,
  privacy/success-silence tests and restart/full E2E/render checks pass. See
  `.scratch/api-logging.md`. Pre-dispatch web/proxy failures and persistent
  native LOCAL0 capture/rotation remain separate administrator gates.

### Subsequent writer slice and actual mixed-load blocker (2026-11-15)

Streaming image/font compression and direct RGB decoding halve the native writer
fixture peak32728→16216KiB without reducing capacity. Exact RGB/alpha/font bytes,
Unicode, fault tests and full E2E/render/browser visuals pass. That writer-only
checkpoint still failed aggregate20 at72240KiB. Subsequent request compaction
and libpq large-I/O cache recycling repair the retained-body fixture without
changing pixels/qpdf/capacity: seven final samples <=57020KiB. Compaction alone
still failed59100KiB; the strip-rendering prototype changed visuals and was
rejected/reverted. The unchanged opt-in probe is retained, not waived. See
`.scratch/request-retention.md` for final evidence and operational implications;
`.scratch/image-memory.md` preserves the earlier failure. Active dense parsing
plus qpdf and other metadata/catalog/codec/native combinations remain unverified.
No production/preserved stack is changed.

### New scheduling-window counterexample (2026-11-17)

The post-parse cleanup does not bound the earlier live array: one admitted
35001-field PIM request paused after real kcgi parsing but before pruning, with
NO retained API uploads/query/cookies, overlaps qpdf at60992–62716KiB, exceeding
60000000 bytes. Matched loaded-hook/no-request controls peak53688/54252KiB;
the original retained-upload probe still passes56404KiB. Exact decoded RGB/font
bytes and eventual PIM404 pass. All47 non-test inputs remain final22-identical;
only disposable diagnostic tests changed. Full E2E after cleanup passes.
This forced scheduling diagnostic is a new technical blocker, NOT a repair or
proof of every running-parser phase. `.scratch/parser-window.md` gives exact
invocations, limits and next admission-repair requirements. Do not lower caps
or treat an unobserved/blocked qpdf phase as a green budget result.

The native/proxy/DAM/shared-service/backup gates in ticket14 remain open. Local
technical work20 is unfinished;22 is source-only complete. Owner questions
are not the sole remaining blocker.