Files
PaperClipAI/server
DottaandPaperclip 6ce0909db4 fix(agents): skip runtime probes for unchanged connections (#18016)
## Thinking Path

> - Paperclip manages AI agents and their runtime settings.
> - Operators save identity, model, connection, and run-policy settings
from the agent page.
> - PostgreSQL stores connection bindings as JSONB and can return keys
in a different order.
> - The save route compared JSON strings and treated an unchanged
binding as a new connection.
> - That false change started a remote runtime and credential probe
during ordinary saves.
> - This pull request compares binding values and checks real execution
selection changes separately.
> - Ordinary edits save without a probe. New connections and execution
selections retain validation.

## Linked Issues or Issue Description

Fixes #14518.

Related work: #17760 also addresses prospective environment resolution.
#14027 also adds explicit connection removal. This change is limited to
the save validation gate and its regressions.

**What happened?**

A title-only save took 9.8–16.0 seconds in a hosted reproduction. JSONB
key order made the unchanged AI connection look different. The route
then waited for a remote runtime probe.

**Expected behavior**

Identity, thinking-effort, and run-policy edits skip the probe when the
connection and execution selection stay the same. A changed connection,
harness, model, provider, engine, or environment still validates
adoption.

**Steps to reproduce**

1. Save an agent with a managed AI connection in PostgreSQL.
2. Edit its title or thinking effort without changing the connection or
execution selection.
3. Observe that the old route starts the adapter environment test. The
fixed route saves without that test.

## What Changed

- Use value equality for the stored and validated AI connection
bindings.
- Compare the effective execution selection separately. Preserve runtime
probes for real selection changes and existing Copilot checks.
- Add PostgreSQL route regressions for shared, delegated, default-user,
and pooled bindings. Cover failed connection, model, engine,
environment, and harness changes.
- Keep the existing credential rejection and reconnect tests. Document
the save behavior.

## Verification

- `pnpm -r typecheck` passed on the rebased implementation.
- Focused PostgreSQL 17 route selection: 21 passed, 58 excluded by the
name filter. This covers ordinary saves, selection-change rejection, and
credential health.
- Full PostgreSQL 17 connection suite: 79 passed, zero skipped. Final
`pnpm build` passed at `8fde75fa1a8fe63c71b05a3db149edf289295672`.
- Before the fix, the PostgreSQL regression reached the unintended probe
and failed for unchanged shared, delegated, and default-user bindings.
The pool control passed.
- An early controlled HTTP comparison of the binding fix used a
synthetic 500 ms provider probe: five measured saves had a median of 798
ms before and 56 ms after. Probe count fell from five to zero. This is
local supporting evidence, not a hosted latency result.
- Earlier adjacent-route run: 159 of 160 tests passed. One existing
roster-edit case exceeded its 15-second timeout. That case passed alone
with the normal timeout. The cause of the earlier timeout remains
unproven.
- Local full-repository tests were not run. Native PostgreSQL startup
fails because the host has exhausted System V semaphores. The focused
tests use an isolated PostgreSQL 17 Docker fixture.
- `git diff --check` passed. Hosted improvement remains unverified until
deployment.
- Greptile and Ponytail Paperclip Review both rated the exact head
`8fde75fa1a8fe63c71b05a3db149edf289295672` 5/5, with no actionable
defects.
- CI attempt 1 passed 51 checks. Three self-hosted runners lost
communication, interrupting the chat shard, serialized server shard, and
canary dry run. GitHub annotations identify the runner communication
failures; the serialized shard log also records a shutdown signal. Only
those failed jobs were retried, once, on the unchanged commit. The [full
CI
workflow](https://github.com/paperclipai/paperclip/actions/runs/40692641103/attempts/2)
then passed on attempt 2 at the same commit. All 55 passing checks and
the legacy Snyk status are green; no checks remain pending.

## Risks

This changes when connection adoption validation runs. Separate
selection checks preserve validation for real runtime changes.
Regression tests verify that rejected selections do not replace the
saved configuration. Company access, connection authorization, activity
records, and Copilot checks retain their existing paths. There is no
schema or migration change.

## Model Used

OpenAI Codex, configured model `gpt-6.1-sol` with ultra reasoning. Work
used source inspection, shell tools, browser network timing, and
PostgreSQL route tests. The context window size is not exposed by this
session.

## 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
- [x] 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
- [x] 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-10-28 08:25:27 -05:00
..