: 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 
# Writer memory reduction and unresolved mixed-load gate — ticket20 (2026-11-15)

**Historical writer-only checkpoint: mixed probe failed60MB. Parent20 stays OPEN.**
Superseded for the retained-request fixture by `.scratch/request-retention.md`:
API field/cookie compaction plus large libpq-cache recycling now pass seven
final mixed samples (maximum57020KiB), unchanged pixels/qpdf/capacity. Other
resource overlaps/cardinality/native gates remain open. The failures below are
retained historical evidence, not the latest candidate's measured result.
Earlier source-only transport/parser work: `.scratch/bounded-uploads.md` and
`.scratch/bounded-parsers.md`.
The native writer reduction below is verified; it is not a whole-renderer or
whole-runtime memory certificate. Source-only, uncommitted integration work;
no original checkout, preserved preview, shared-service or production changes.

## Verified native writer improvement

`src/pdfw.c` now uses existing zlib streaming compression into the PDF with
16KiB output chunks and standard indirect stream lengths. PNG colour/alpha and
embedded font data no longer need a whole compressed output buffer next to the
decoded image/loaded font. PNGs without a source alpha channel decode directly
to RGB rather than expanding to RGBA first. RGBA still preserves every alpha
sample, with no separate alpha-plane allocation for an entirely opaque image.
No file/pixel limits, snapshot capacity, render geometry, font fitting, schema,
public interface or dependencies change. Transparency and JPEG passthrough remain.

Retained native regression `sh test/image-memory.sh` creates an actual max4MP
(2048x2048) high-entropy RGB PNG and a valid DejaVuSans with2MiB trailing padding.
The font remains loaded while the image is embedded through the real writer API.
Linux `getrusage(RUSAGE_SELF)` reports native process peak RSS:

- Unmodified ticket21 source: **32728KiB**, fails the fixture's24MiB ceiling.
  `/tmp/signet-image-memory-red.log`.
- Repaired source: **16216KiB**, passes. Same result inside the final full E2E.
  `/tmp/signet-image-memory-green.log` and final E2E log below.

The24MiB ceiling is ONLY a reproducible Linux fixture regression assertion,
not a new product per-process policy or proof for every supported input. It
leaves headroom above the fixture's12MiB RGB +2.85MB font + codec/runtime costs
and catches the old image-sized output overlap. Native writer output is checked
by qpdf; decoded RGB and embedded TTF stream bytes exactly match their inputs;
Unicode text extracts correctly. `/dev/full` output failure is rejected.

`test/image-contract.{c,sh}` also verifies exact decoded pixels/alpha for RGB,
gray, opaque RGBA, transparent RGBA and palette transparency, and that opaque
variants have no soft mask. Existing JPEG and alpha interpolation checks remain.
The native memory regression runs in full E2E and its `image-memory` mode.
The ticket21 fault sweep adapts to16 allocation positions after removing three
compressed-buffer allocations: transient/persistent failures and all targeted
cleanup cases pass. Codec-internal fault injection is still not established.

## Actual mixed-load counterexample — still failing

Retained opt-in **destructive disposable-only** probe:

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

Never run it on a preserved/shared/production stack. It creates private synthetic
records/assets, temporarily stops/restarts ONLY the disposable worker and holds
TWO admitted HTTP document uploads at their INSERTs using an owned PG advisory
lock/trigger. Each body1120212 bytes has a tiny PDF file plus35000 nested ignored
MIME parts. They are admitted sequentially, retained concurrently, then the
worker renders a queued real document independently. This deliberately separates
retained parsed bodies + rendering from simultaneous parser startup. Cleanup
releases the owned holder, removes its trigger/function and temporary DAM assets,
and leaves synthetic records only inside the disposable stack. Proof image/font
bytes are checked independently after qpdf overlay.

The pending document freezes12607295 PNG bytes +2854228 font bytes +757076 audit
font bytes = **16218599 bytes**, within the existing16MiB aggregate snapshot cap.
There are4194304 pixels, within the existing PNG cap. No over-policy input is
needed for this budget counterexample.

Summed `/proc/*/status` VmRSS includes all signet/signetd/lighttpd UID processes,
kfcgi/kcgi helpers and external tools under those UIDs. Root curl/compiler/test/
sampler, PostgreSQL and Redis are excluded. The helper scans at1ms sleep PLUS
scan time: sampled maxima are not absolute/atomic peak certificates.

- Image-only initial baseline:53736KiB, within for that fixture; did not prove
  mixed safety. The first fixture run had a test identity403 and a corrected
  generator compiler warning before any valid budget conclusion.
- Initial simultaneous-body mixed baseline:68364KiB (old writer).
- Retained-body phased baseline (old writer):**66576KiB**, gate fails.
  `/tmp/signet-image-budget-phased-red.log`.
- Early writer-only streaming prototypes still failed (65608KiB,68064KiB),
  and one warm sample58580KiB barely fell below60MB. This was NOT accepted as
  safety evidence. Subsequent phased samples62704/68904KiB still fail.
- Final exact tested candidate, after full E2E/browser work: held bodies35600KiB,
  parser phase37788KiB, render phase **72240KiB (73973760 bytes)**. Proof RGB/TTF
  byte checks pass; resource probe deliberately exits1 with `budget_result=exceeded`.
  `/tmp/signet-image-memory-final-mixed.log`. No mixed-resource gate is completed.

Existing qpdf facilities were checked before changing product orchestration.
Direct actual overlay of the fixture proof onto the two-page base under BusyBox
`time -v` uses **34028KiB** peak by itself; `--stream-data=preserve` still uses
33752KiB. It is NOT a proven repair, so no qpdf command option was changed.
`/tmp/signet-image-budget-qpdf-options.log`. This is a separate-process peak,
not an exact decomposition of the simultaneous cohort; further process/subphase
correlation, admission/containment and native acceptance remain necessary.

## Final functional verification and safety

Image/container **signet-image-memory-final**, temporary loopback18106;
image/container metadata in the private backup identifies the exact candidate.

- Clean Alpine build (`make clean`, `make -j2`, `make install`), no warnings;
  full `sh /src/test/e2e.sh` ends **all passed** (includes native memory/byte,
  format, allocation, snapshot, signature, PIM, upload and parser regressions).
  `/tmp/signet-image-memory-final-e2e.log`.
- Separate renderer/hang/retry/replay/DB contracts all pass:
  `/tmp/signet-image-memory-final-render.log`.
- Existing Chrome signing flow passes using preinstalled read-only external
  Playwright Core, no package install or new JS automation. Both-page edit,
  proof, stamped and final screenshots plus audit reviewed: fitting, clipping,
  alpha and JPEG placement match; facsimiles appear at the appropriate sign-offs.
  `/tmp/signet-image-memory-browser{.log,/}`; synthetic document
  `f959d7d2-d5ad-4573-b501-65e7f3c36100`.
- `sh -n` on all four added/modified shell scripts, manual POSIX review and
  `git diff --check` pass; actual scripts executed with sh. No production runtime
  or build dependency changes, no ABI/API/install/config change.
- Full native/UI/schema/config/vendor/test source and Makefile/Containerfile
  SHA256 manifests exactly match the tested candidate:
  `/tmp/signet-image-memory-{host,image}.sha256`.
- Owned trigger/holder backend counts are both0 after the mixed probe. All four
  owned investigation containers stopped gracefully/retained; preserved18087
  still responds HTTP200. `/tmp/signet-image-memory-{cleanup,stopped}.log`.

Latest native writer gains must NOT hide the final failing mixed probe.
Remaining20 includes qpdf/API overlap, other metadata/catalog/codec amplification,
resource containment and native representative/coexistence certification. Actual
logging22 and native/proxy/DAM/namespace/backup14 gates are unchanged. No commit,
push or installation on preserved18087; old PIM Resync there remains FLUSHDB.

Private before/after source/evidence backup (not runtime user data):
`/Users/saikrupa/.local/var/signet-feature-backups/image-compression-20261115T014846Z`.