# API failure logging and development capture — ticket22 (2026-11-16)

**Repaired and verified source-only.** Owner priority is22 →20 →remaining work.
Authoritative source remains `/tmp/signet-roadmap-20261112/integration`, branch
`feat/feature-first-roadmap`, HEAD9876b79 plus uncommitted integrated changes.
Original checkout, preserved previews and production are unchanged.

## Reproduced gaps

Disposable `signet-logging-red`, from the preceding request-retention image:
real400 responses from `/api/docs` and `/pim-api/attrs`, and a404 through a
manually logged dispatch branch, produced no corresponding container output.
Shared `send_err()` never logged; kfcgi's default daemon mode disconnected worker
stderr. The first native LOCAL0 regression failed on the missing docs400 record.
Raw `PQerrorMessage()` and Redis error replies also allowed backend text/DETAIL
(which can repeat private parameters) into application diagnostics.

## Retained implementation

- Existing callers still use `send_err()`. A C99 source-site macro invokes the
  shared `send_err_at()` with `__func__`/`__LINE__`; HTTP response bodies/statuses
  remain unchanged. It emits one request summary before building the response.
  Redundant manual dispatch log calls are removed, including auth/not-found.
- API main loops lend their loaded configuration through `r.arg` after parsing;
  the logger uses the same configurable identity-header reader/validation as
  dispatch, also on pre-dispatch allocation errors. These unmapped
  `khttp_fcgi_init()` calls register no user argument/free callback; inspection
  of kcgi0.13.4 confirms the borrowed request pointer is not freed by request
  destruction. Invalid/missing identity
  becomes `anonymous`, not the original header contents.
- `log_request()` emits method, normalized route, validated actor, HTTP status,
  and source `site=function:line`. Known route words are retained, UUIDs become
  `:id`, all other components become `:other`; query data is omitted and depth
  is bounded. The source site identifies the exact branch without logging its
  possibly private error message. Use the matching source/build when resolving
  line numbers. Method/site are code-owned, not request strings.
- LOCAL0.warning carries4xx; LOCAL0.err carries5xx. stderr includes program and
  PID, matching syslog identity/PID for correlation. Successes are not logged.
  Low-level diagnostics use one bounded512-byte formatted message in both sinks.
- `db.c` logs only operation and SQLSTATE, not SQL/parameters/server message,
  DETAIL, CONTEXT or connection error text. Redis connection/mirror/resync
  diagnostics identify the failed operation without copying reply text.
- Both APIs report configuration/init/parse failures safely. Before a parsed
  request exists, these are process diagnostics, not fabricated actor/HTTP data.
- Dev startup uses documented `kfcgi -d` in background: the shell still owns the
  foreground supervisors, their stderr remains connected, readiness is checked,
  and shutdown stops them. Identity/PIM test restarts preserve that mode and
  route output to PID1's stderr; they wait for supervisors/sockets appropriately.
  Production OpenRC configuration is not changed.

Example stderr (identities below are synthetic):

```
signet-api[123]: request method=POST route=/docs actor=asha status=400 site=h_doc_create:402
pim-api[456]: request method=POST route=/attrs actor=admin status=500 site=h_upsert:149
pim-api[456]: database query failed (SQLSTATE P0001)
```

Sites in this illustration are explanatory, not a promise of fixed line numbers.
No bodies, labels, resolved PIM attributes, raw URLs, query strings, cookies,
authorization tokens, groups or signature data enter the request summary.
Validated actor names intentionally remain visible. Header trust is still a
production boundary requiring ticket14 acceptance.

## Runnable checks

On an explicitly disposable dev container:

```
SIGNET_LOGGING_TEST_DISPOSABLE=yes sh /src/test/e2e.sh logging-contract
```

For the actual container-capture assertion, run where the existing Podman CLI
works (on this Mac, inside `podman machine ssh` with the mounted project path):

```
SIGNET_LOGGING_TEST_DISPOSABLE=yes sh test/logging-dev.sh disposable-container
```

The host-side check invokes real API requests and reads `podman logs`, rather
than trusting that writing stderr implies capture. It checks only newly appended
records, exact per-component summary counts, and private-marker/success absence.

`test/logging-contract.sh` exercises:
- Both APIs' validation400, missing/invalid identity401, CSRF/role403, Signet
  unknown/file404, both APIs' injected database500, and PIM Redis503.
- A temporary existing-BusyBox syslog receiver selecting only LOCAL0.warning
  and above. Other facilities and LOCAL0.info markers must stay out. The test
  refuses to replace an existing `/dev/log`, stops its receiver and removes its
  own socket. Final requests prove stderr still works with no receiver.
- Private sentinel values in bodies/PIM values, raw paths/queries, cookies,
  Authorization, invalid identity, config paths and backend message/DETAIL.
- Native `test/log-request.c`: control characters, invalid actors,4096-byte path,
  query/UUID redaction, bounded output and success silence.
- Both APIs' missing-configuration diagnostics without leaking its path.

The full E2E includes the native logging check. The existing snapshot/render
failure tests formerly depended on leaking PostgreSQL message text; they now
inject distinct SQLSTATE P2210/P2211/P2212 and retain all transaction, cached
proof, queue, hash and replay assertions. This is not a weakened failure test.

## Verified final checkpoint

Image/container `signet-logging-final-r2`, no host port or implicit preview.
Clean build/install has no compiler/make warnings. Full E2E ends `all passed`;
standalone render/hang/retry/replay/DB contracts pass. Real `podman logs`
assertions pass both after the full suite's API-pool replacements and after a
full graceful container restart. Each run checks13 representative HTTP errors;
startup/low-level diagnostics are additional, not duplicate request summaries.
All91 source/build/UI/schema/config/vendor/test files hash-match the final image;
installed API/PIM/worker binaries match their build outputs. Eight changed shell
scripts each pass `sh -n`; runtime checks cover Alpine scripts and the host
Podman-capture wrapper. Fixtures intentionally use Alpine/Linux facilities,
not a cross-platform runtime promise. Modified portable
C also passes the Mac syntax/warning check; `git diff --check` passes.

All four owned logging stacks were checked for zero logging SQL fixtures/saved
Redis keys, restored registry shape and no temporary syslog/socket, then stopped
with exit0. Preserved18087/18090 return200. Preserved8080 is still the old
`signet-ticket11-verify` (started2026-11-12, PID1 lighttpd); both host and internal
HTTP checks timed out. No restart/repair was attempted there. Do not claim that
stack healthy or infer a new cause from this logging work.

Private backup:
`/Users/saikrupa/.local/var/signet-feature-backups/api-logging-20261116T170748Z`.
Logs `/tmp/signet-logging-{red,green,contract-green,final-tests,final-retest,final-r2}.log`.
The first full test run correctly failed its old raw-server-message assertion;
that historical failure is retained alongside the successful updated contracts.
No Python, new dependency, persistent logging service, schema/config migration,
commit, push, original-checkout edit, shared-service change or deployment.

## Scope and remaining gates

This verifies errors emitted by the parsed APIs and generic startup/parse
failure diagnostics. Rejections generated before API dispatch by lighttpd,
kcgi or a proxy are not fabricated as API responses. Client disconnects or
failures after a200 stream starts are not turned into retrospective HTTP500s.
Do not claim all web/proxy/server/backend diagnostics are sanitized by this work.
PostgreSQL's own protected server log is separately administered.

Persistent native LOCAL0 capture, log permissions/rotation/retention, disk
pressure and deployed OpenRC/proxy behavior still require owner-approved
native acceptance (ticket14). Production needs its existing system logger;
application stderr cannot substitute for verified persistent storage. No per-app
daemon/rate limiter was added. Ticket20 resource/cardinality/overlap/native gates
remain OPEN and are next; no production RSS or logging-delivery certificate.
