# Ticket20: unpruned request delivery overlaps qpdf (2026-11-17)

**2026-11-18 follow-up:** parent parse/prune admission was experimentally
implemented, then REJECTED and selectively reverted. Request-first exclusion
passed, but reverse worker-first order still reached59136/59296KiB because kcgi
children buffer before parent readiness. Current47 product inputs still match
final22; baseline replay remains red63112KiB. Read `.scratch/parser-coordination.md`
before retrying a gate; it records both schedules and the private candidate.

**New reproducible budget counterexample; NOT repaired. Ticket20 stays OPEN.**
Production source remains byte-identical to the final ticket22 checkpoint.
This slice adds only opt-in diagnostic instrumentation and sampler reporting.
No admission limit, role, render geometry, data format or signing behavior changed.

## Source recovery first

The old `/tmp/signet-roadmap-20261112/integration` lost `.git` and source files.
The authoritative worktree is now:
`/Users/saikrupa/.local/var/signet-work/integration-recovery-nQvIoiCL`.
Branch `feat/feature-first-roadmap`, HEAD9876b79 plus uncommitted work.

Recovered final22 `after/source.tar` into a NEW durable directory, preserving the
old partial tree. All105 surviving product/doc files and61 tool files matched;
all91 runtime-input hashes and the complete Git status matched the saved final22
checkpoint before new work. All19 surviving symlink targets and surviving-file
executable bits also match. Excluded clean tool metadata was recovered from the
same Git revision and compared with surviving files. Native `git worktree repair`
reconnected registration, without checkout/reset/commit. Durable pointer:
`~/.local/var/signet-work/current-integration`. Partial-source/registration
archives and recovery comparisons are in that parent. Do not reuse the old
incomplete `/tmp` tree or replace this source with an older feature worktree.

## Replay setup from the host

Use `podman machine ssh` for native VM-side Podman operations; the host CLI's
known_hosts error is not repaired. Create a NEW, unused, unpublished container
from existing image `signet-logging-final-r2` (no `-p`); stop on any setup error.
The old three measurement stacks remain stopped evidence, not candidate builds.
Wait for normal development initialization (the tested loop used six seconds).
Copy these THREE files from the durable worktree into its `/src/test/`:

- `test/resource-image-probe.sh`
- `test/resource-rss.c`
- `test/resource-parse-gate.c`

Use `podman cp` inside the VM; `/Users` is mounted there. Example for one file,
with `name` set to the newly created owned container and `root` read from the
durable pointer on the HOST:

```sh
podman machine ssh "podman cp '$root/test/resource-parse-gate.c' '$name:/src/test/'" </dev/null
```

The `/dev/null` redirection matters when SSH is invoked from a shell heredoc:
otherwise it can consume later commands from the caller's stdin. The baseline
image's47 product inputs are unchanged in this diagnostic slice. Copying these
tests does NOT update product binaries; any future C repair needs a rebuild
from the canonical tree/private staging and a fresh candidate source manifest.

## Tight loop

Only inside that explicitly disposable Alpine development stack with these tests:

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

The test retains the existing4MP high-entropy PNG, padded loaded font and exact
proof RGB/font validation. It admits one1120212-byte multipart PIM request with
35001 parsed fields. There are NO retained document-upload requests, dense query
or cookies in the minimized case. Its eventual response is the expected404 for
an unknown route, not a pre-parser413 or forced input rejection.

`test/resource-parse-gate.c` is a disposable LD_PRELOAD library, compiled only by
this opt-in mode, never linked/installed into the product. It calls the real
`khttp_fcgi_parse()`, publishes only PID/field count atomically in a private gate
directory and stops its own PIM parent before the application can prune fields.
The root fixture verifies that process is stopped before starting the worker,
keeps it stopped through proof completion, then resumes it and verifies404.
It holds the real library allocations without copying the request. This models
an otherwise permitted scheduling pause at that call boundary; it is NOT a
claim that ordinary traffic naturally holds that window this long, nor a
measurement of every earlier child-parser phase.

The sampler's opt-in `--qpdf` additionally records maximum aggregate app RSS on
scans containing a live, nonzero-RSS qpdf process of a Signet cohort UID. Default
sampler/`--once` output stays compatible. Since the PIM parent is verified stopped
through the render, this establishes coexistence with its unpruned allocations,
not just separate peaks added by hand. Scans remain non-atomic and1ms plus scan
time; successful samples still cannot certify a universal/native ceiling.

Matched preload control (same library/pool replacement but no large PIM request):

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

Omit `SIGNET_RESOURCE_PARSE_WINDOW` for the ORIGINAL retained-upload fixture:
two densely populated admitted document uploads held at INSERTs after pruning.
That existing case was not replaced or waived.

## Measurements

| Scenario | Sampled app peak KiB | Bytes | Verdict |
| --- | ---: | ---: | --- |
| First exploratory window, two retained uploads plus query/cookies |63028|64540672|exceeded|
| Minimized window, no retained uploads/query/cookies |62716|64221184|exceeded|
| Fresh minimized repeat |62352|63848448|exceeded|
| Fresh preload-only control |53688|54976512|within for fixture|
| Original retained-upload fixture |56404|57757696|within for fixture|
| Final hardened probe, preload-only control after restart |54252|55554048|within for fixture|
| Final hardened probe, minimized window after restart |60992|62455808|exceeded|

Every row validates exact decoded RGB and loaded font bytes. Window rows require
35001 fields held and an admitted404 after resume (first exploratory row36001).
The final hardened probe atomically publishes readiness and includes scoped
cleanup for an interrupted/stopped PIM process. Budget is strictly less than
60000000 bytes; exit1 with `budget_result=exceeded` is an actual diagnostic red,
not a build/HTTP/check failure. Root test clients, compiler, PostgreSQL and Redis
are excluded from app RSS; Signet/lighttpd UIDs and their helpers are included.

The approximately6.6–8.5MiB contrast with matched preload controls supports actual
parsed request storage as the cause, not the tiny hook/library itself. Repeats also
separate this from one ordinary qpdf peak crossing the budget: both controls and
the existing retained fixture pass, while every measured unpruned window fails.
Neither controls nor these forced schedules certify other traffic or native
coexistence on the target1vCPU/1GB machine.

## Why the earlier repair is insufficient

`http_keep_fields()` correctly discards unnecessary fields immediately AFTER
`khttp_fcgi_parse()` returns. It cannot eliminate the library's earlier peak or
prevent a scheduler from pausing at that boundary. In kcgi0.13.4 `parent.c`,
`kpair_expand()` grows storage for every received field before mapping known
keys. Supplying a key registry alone does not skip unknown fields. The previous
retained-request/libpq repair is still valid; `.scratch/request-retention.md`.
This is a DIFFERENT live-memory window, not a reverted allocation repair.

Next repair should address overlap before materialization, not add another
post-parse free or lower accepted capacities. A native coordination/admission
approach must be checked against kcgi's public polling API, already-buffering
child processes, idle waits, database/queue lock ordering, interruption/crash
cleanup, permissions and starvation. `khttp_fcgi_getfd()` permits polling only;
do not manipulate its control protocol. A lock held while an idle FastCGI call
waits forever would block useful worker progress. No such gate has been shipped
or claimed correct here; no third-party fork/filter was introduced.

The diagnostic intentionally waits for proof completion while holding the
window. A real admission repair may instead block the worker: adapt the gate
handshake to verify that exclusion and release the parser safely, retaining the
same request/assets and RSS/content assertions. A timeout or an unobserved qpdf
phase is NOT a green result. Do not silently disable the window to obtain a pass.

## Upstream source used for the diagnosis

Selected surviving kcgi0.13.4 investigation sources/manuals are copied verbatim
into the private phase archive under `evidence/kcgi-0.13.4/`, with `SHA256`:
`parent.c`, `child.c`, `fcgi.c`, `kcgi.c`, `extern.h`, `kcgi.h`, `man/kfcgi.8`
and `man/khttp_fcgi_getfd.3`. Read `parent.c` around182/321 for field growth,
`fcgi.c` around636/642 for the poll-only control descriptor and parse entry,
and the getfd manual for supported readiness use. This is selected read-only
evidence, not a new vendored dependency, buildable checkout or claim that every
upstream file remains present. The old `/tmp` investigation cannot be relied on
for recovery (its previously referenced `man/kreq.3` is now absent).

## Checks, safety and evidence

- 47 non-test source/build/UI/schema/config/vendor inputs hash-match final22;
 product binaries are unchanged. Three test files form this slice.
- Full E2E after the hardened window/cleanup ends `all passed`, including actual
 logging contracts and pool replacement. Earlier full E2E plus standalone
 parser probe also pass; parser-only sampled peak47612KiB is limited evidence.
- `sh -n` on the changed shell fixture, host portable-C sampler syntax/warnings,
 Alpine `-Wall -Wextra` compilation of sampler/hook and `git diff --check` pass.
 No new dependency, Python/Node helper, container/image publication, commit,
 deployment or preserved-preview replacement.
- Dedicated stacks: `signet-parser-window`, `signet-parser-window-control`,
 `signet-parser-window-repeat`, all based on `signet-logging-final-r2`, no host
 port. Only the diagnostic files were copied into these owned containers.
 PIM replacement is restored to normal foreground capture on all exits; the
 temporary preload/gate files are removed. SQL triggers/holders in default mode
 remain owned and cleaned. These are destructive disposable tests, never for
 preserved18087 (old PIM Resync still FLUSHDB),18090,8080 or production.

Logs and recovery evidence are initially under `~/.local/var/signet-work/`:
`parser-window-{first,minimized,fresh-repeat,preload-control,original-fixture,
regressions,final-control,final-red,final-e2e}.log` and product SHA checks.
Restricted source/evidence archive (UTC timestamp):
`/Users/saikrupa/.local/var/signet-feature-backups/parser-window-20261116T193934Z`.
All three owned stacks are instrumentation/holder-free, queues empty, normal
PIM pool restored, no stopped processes or temporary syslog left; then stopped
exit0. Preserved18087/18090 return200; other preserved services are untouched.
For a new replay, retain output before cleanup. The fixture restores its scoped
PIM replacement on exit; independently verify owned trigger/function/holder
counts, normal PIM process count, stopped processes and queue lengths, then stop
ONLY that owned container and record its exit status. The private
`evidence/parser-window-cleanup.sh` shows the actual read-only checks for the
three historical names; adapt the name deliberately rather than checking old
stacks as evidence for a new candidate. Do not run whole-container logging or
resync tests against preserved services.

Latest evidence mapping:

| File in private `evidence/` | Meaning |
| --- | --- |
| `parser-window-final-red.log` | Hardened final window, expected exit1/exceeded |
| `parser-window-final-control.log` | Same loaded hook, no held request |
| `parser-window-original-fixture.log` | Original two retained uploads still exercised |
| `parser-window-final-e2e.log` | Full suite after hardened window, all passed |
| `parser-window-regressions.log` | Earlier full suite and standalone parser probe |
| `parser-window-product.sha256`, `product-unchanged-final.log` |47 final22 non-test inputs unchanged |
| `parser-window-cleanup.log`, `parser-window-stopped.log` | All three owned stacks clean, then exit0 |
| `signet-parser-window*-capture.log`, `*-inspect.json` | Original container logs and identities |

A replay is red ONLY when it reaches the held-field/RGB/font/resumed404/qpdf
checks AND reports `budget_result=exceeded`; a generic exit1 is insufficient.
Native trust/DAM/OpenRC/backups and other ticket20 metadata/catalogue/codec/
history/arbitrary-PDF resource gates remain open. Do not deploy this integration.
