Files
PaperClipAI/doc/performance
DottaandPaperclip dd02595390 fix(db): retain hosted census construction callers (#18725)
## Thinking Path

> - Paperclip is the open source app people use to manage AI agents for
work.
> - Operators use a bounded database census to find expensive read
paths.
> - The hosted server combines application code and capture wrappers in
generated files.
> - Generic HTTP owners suppressed caller capture. Generated paths also
failed the caller allowlist.
> - This PR retains trusted query construction locations without source
maps.
> - Operators can distinguish application query sites while exact
owners, privacy limits and capture bounds stay intact.

## Linked Issues or Issue Description

Refs #17522, #17564.

**What happened?**

A real map-free bundle with two application query sites produces one
callerless census group. This affects unowned queries and queries under
the generic `http.request` owner.

**Expected behavior**

The census should distinguish trusted query construction sites. It must
keep unknown calls unknown and preserve specific semantic owners without
stack capture.

**Steps to reproduce**

Run the committed bundle test and pinned comparison helper. The helper
bundles the actual capture module and real Drizzle, with a fake
postgres-js client. It does not assign a fake path to an isolated mock
caller.

**Paperclip version or commit**

Control: `09162fe893b464dd2ccdafd14bd3ef1611202a86`. The branch is
rebased onto `1e3ab690b072bbf6a1c1f1d0454ea49315b2074c`; neither
intervening commit changes this owner.

## What Changed

- Keep the exact generic HTTP owner and add bounded caller capture only
during the active census window.
- Exclude capture wrapper frames with a local V8 stack boundary. Keep
one static generated construction anchor for trusted root builders.
- Keep unscoped bundled driver and relational paths unknown. Their first
frame can belong to the ORM.
- Cover exact application lines, alternate parameters, prepared
builders, transactions, nested savepoints, privacy and inactive windows
in a real bundled scaffold.
- Add a portable pinned comparison helper and retained measurements.
Existing group, page, byte, expiry and output-rate caps remain in force.

## Verification

- PASS: 54 focused unit, real-bundle, existing runtime bundler and
real-PostgreSQL tests.
- PASS: database TypeScript check.
- PASS at final head `b270b92821`: full local `pnpm -r typecheck` and
`pnpm build`.
- The first local `pnpm test:run` was stopped after two chat partitions
passed (668 cases), because source changed during the run. This is
partial evidence only. The fresh final-head full local command passed
all six chat partitions (1,829 cases). Its general phase reported one
failure in the unchanged workspace port-conflict test. The exact case
then passed alone (1 pass, 178 skipped), and the unchanged full file
passed 179/179. The original failure did not reproduce; its cause is
unknown. The general phase was stopped after its remaining serial queue
was measured at roughly three hours. Cancellation did not print the
original assertion diff. The full command is failed/incomplete, not
passed. Remaining general files, workspace-project phases and 164
serialized files were not reached. Fresh final-head CI passes all
partitions.
- Final-head code CI passes. Greptile is 5/5 with its thread resolved.
Paperclip Review is delayed by an external review workspace recovery
failure; it has not completed on this head.
- Five serial alternating rounds per mode, 1,000 queries per sample, 40
retained samples, Node v24.22.2. Generic and unowned attribution rises
from 0/1,000 to 1,000/1,000 across two exact application anchors.
Specific owners stay stack-free.
- HTTP median wall cost is 10.528 → 15.169 µs/query; process CPU is
15.461 → 17.662 µs/query, with noisy overlapping ranges. This is census
overhead, not a product speedup.
- Review failure retained: the existing runtime bundler test first
failed because the public parser accepted arbitrary generated frames.
The fix restores default rejection and permits generated frames only
from the trusted builder boundary. The unchanged existing test now
passes.
- Full ranges, raw samples, proof boundaries and reproduction commands:
https://github.com/paperclipai/paperclip/blob/b270b92821ae47c456a1b61d78c1593c5348ede7/doc/performance/2026-11-03-db-capture-hosted-callers.md

## Risks

- Active generic HTTP census now captures stacks. More groups can reach
the existing 2,048-group cap sooner.
- Anchors identify construction sites in one exact generated build. They
do not identify later async consumers, TypeScript lines or CPU owners.
- Unscoped driver calls can remain unknown. This is intentional.
- The no-network local fixture excludes deployed Sentry/OTel stack
formatting and traffic effects. It does not establish exact hosted
overhead.
- Wrappers remain installed after expiry. Disabled, future and expired
windows do not capture stacks. No schema, authorization, provider, or
query behavior changes.

## Model Used

OpenAI GPT-6.1 Sol (`gpt-6.1-sol`) with reasoning, code execution and
repository tools. The host does not expose the context-window size.
Independent review used the same model family.

## Checklist

- [x] I have included a thinking path that traces from project context
to this change
- [x] I have specified the model used (with version and capability
details)
- [x] I have checked ROADMAP.md and confirmed this PR does not duplicate
planned core work
- [x] I have searched GitHub for duplicate or related PRs and linked
them above
- [x] I have either (a) linked existing issues with `Fixes: #` / `Closes
#` / `Refs #` OR (b) described the issue in-PR following the relevant
issue template
- [x] I have not referenced internal/instance-local Paperclip issues or
links (only public GitHub `#NNN` / `github.com/paperclipai/paperclip`
URLs)
- [x] My branch name describes the change (e.g. `docs/...`, `fix/...`)
and contains no internal Paperclip ticket id or instance-derived details
- [ ] I have run tests locally and they pass
- [x] I have added or updated tests where applicable
- [x] I have updated relevant documentation to reflect my changes
- [x] I have considered and documented any risks above
- [ ] All Paperclip CI gates are green
- [x] Greptile is 5/5 with no open P2s, recommendations, or follow-ups
- [x] I will address all Greptile and reviewer comments before
requesting merge

---------

Co-authored-by: Paperclip <noreply@paperclip.ing>
2026-11-03 06:04:42 -06:00
..