mirror of
https://github.com/paperclipai/paperclip.git
synced 2026-11-01 06:42:06 +01:00
## Thinking Path > - Paperclip is the open source app people use to manage AI agents for work. > - Companies use several agent harnesses and execution environments. > - Operators need one place to select where native agent logs and traces go. > - An inference proxy would add a dependency to the agent request path. > - This pull request supplies native OpenTelemetry settings to managed Codex and Claude Code processes. > - Company secrets protect destination credentials. Export failure does not change the task result. ## Linked Issues or Issue Description **Subsystem affected** Company settings, shared contracts, database, server, adapters, and runner. **Problem or motivation** An operator cannot configure a company destination for native agent logs and traces. Manual harness configuration is hard to apply across local and remote execution. **Proposed solution** Add one company destination: Braintrust or a custom OTLP HTTP/protobuf endpoint. Apply a transient snapshot when execution preparation starts. Keep credentials out of API reads, task environment manifests, recovery files, and command arguments. Replace a warm process when its export settings change and preserve its conversation. **Alternatives considered** Multiple destinations can use a user-operated collector for fan-out. This change does not add a collector, an inference proxy, or transcript scraping. **Roadmap alignment** This extends company settings, secret management, and support for multiple harnesses. The maintainer requested this implementation. Searches for observability and Braintrust found no duplicate company destination feature. Related infrastructure tracing work in #16236 has a separate content-free contract. ## What Changed - Add strict schemas, revision checks, encrypted secret storage, activity records, and board-only settings routes. - Add explicit synthetic logs and traces tests with a bounded HTTP request and sanitized results. - Supply native Codex configuration and Claude Code environment values through local and remote launch paths. - Preserve Codex login refresh through the existing managed credential link. Retain unsaved drafts across background reads. Require complete custom header re-entry when the endpoint origin changes. - Separate process export compatibility from conversation identity. Isolate generated Codex configuration and preserve resumable sessions, including remote home refresh after export changes. - Advance the immutable Pi/Copilot source attestations for shared environment and sidecar code changes. Keep their provider payloads unchanged and retain prior identities for decoding. - Redact destination credentials throughout launch diagnostics and HTTP logs. - Add the production settings form, Storybook states and journey, documentation, and feature/access map entries. ## Verification - Real managed local Codex 0.160.0 and Claude Code 2.1.286 tasks exported to Braintrust. API readback and the Braintrust UI showed the test records. A real remote Daytona Codex task exported through the legacy `exec` path. - Live tests exercised content capture off, export disabled, warm conversation reuse, and a destination that accepted connections but never replied. Agent work succeeded and export requests stopped at the configured three-second timeout. The UI connection test returned “Test payload accepted”; the saved API key stayed masked after reload. - All current-head CI test lanes, typechecks, packaging/build checks, and required aggregates passed on `71e994b2be9c8fb6d6e938a4ad7cf4c95fdafe31` ([CI run](https://github.com/paperclipai/paperclip/actions/runs/39319194318)). Greptile completed on that exact commit at 5/5, with zero unresolved review threads. The additional optional Paperclip Review check remains queued waiting for its assigned agent. - Local workspace typecheck and build passed. Focused verification included 239 combined runner tests, 789 API/native-session tests, 107 Codex home/ACP/sandbox-site tests, 204 feature/privacy tests, and the affected Rust suites. Migration, token, map, Storybook catalog, and Storybook build checks passed during acceptance. These checks ran at the relevant implementation or merge boundary; the current-head CI is the complete final gate. - Managed AI credential projections now receive enabled and disabled company export settings; genuine caller-owned Codex homes remain untouched. Two regressions reproduced the skip before the repair. All 276 engine/lifecycle tests and adapter-utils typecheck pass afterward. The launched TOML retains provider/MCP settings, credential continuity, and redaction. - Settings saves, removal, and the real company-deletion owner acquire secret mutation ownership before database locks. PostgreSQL NOWAIT probes cover all three paths; concurrent save/rotation/removal/deletion requests settle correctly. The affected suites passed 137 tests, followed by all 32 service/connection cases after expanded deletion coverage. Server and Codex adapter typechecks pass. - Codex source profiles use the effective CLI argument list. A spawned fixture CLI reproduced both ignored-argument failures; all three precedence/fallback cases now pass. - Real tar staging reproduced remote conversation loss in both API-key and subscription modes before the repair. Both now pass: changing managed settings preserves sessions, archives, native indexes, and refreshed subscription credentials. A corrupt upload preserves the prior config and conversation. - Preserved failure evidence: initial CI caught stale Pi/Copilot source attestations, a missing test-harness helper, and packaging fixture/probe mismatches; those were corrected and covered by focused checks. Superseded heads had intermittent attachment-composer timeouts despite successful uploads; [the original trace and screenshot remain available](https://github.com/paperclipai/paperclip/actions/runs/39309701089/artifacts/12215109203). The same attachment case passed on the final head: [25/25 tests in shard 3](https://github.com/paperclipai/paperclip/actions/runs/39319194318/job/118288637051). - A connection-fault fixture also exposed a stale pooled socket after its hang case; closing fixture responses isolated scenarios and the full affected suite passed. - The broad local test run was not clean: database resource failures, timeouts, an older cached module graph, and a stale optional-resource manifest assumption were recorded. Focused checks passed after the documented fixes. This does not establish a clean full local pass. - Native remote Codex, remote Claude, and the full ACPX Codex bridge remain unqualified. The direct Codex resume test does not establish full bridge acceptance. ## Risks - Native exporters perform network requests from each execution environment. A server connection test does not prove remote reachability. - Prompts, assistant responses, and tool content are enabled by default when supported. Native caps and harness-specific controls still apply. - Caller-owned Codex homes are unsupported for automatic configuration and remain untouched. - Native harnesses and their tool processes can inspect export credentials. The settings form and documentation advise using ingestion-scoped credentials. Retained headers remain bound to their saved scheme, host, and port; changing origin requires fresh values or removal. - Migration 0357 adds a company-scoped row and secret reference. It is safe to reapply. Secret removal and company deletion use the existing secret lifecycle. - Slow or unavailable destinations must not block task settlement. Export settings take effect at the next execution preparation boundary. ## Model Used OpenAI Codex, GPT-6, with reasoning, tool use, code execution, and browser verification. The exact serving model ID and context window size are not exposed in 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>
145 lines
5.9 KiB
TypeScript
145 lines
5.9 KiB
TypeScript
const SILENCED_SUCCESS_METHODS = new Set(["GET", "HEAD"]);
|
|
|
|
const SILENCED_SUCCESS_API_PATHS = [
|
|
/^\/api\/muse\/v1\/signal$/i,
|
|
/^\/api\/health(?:\/|$)/,
|
|
/^\/api\/companies\/[^/]+\/activity(?:\/|$)/,
|
|
/^\/api\/companies\/[^/]+\/dashboard(?:\/|$)/,
|
|
/^\/api\/companies\/[^/]+\/heartbeat-runs(?:\/|$)/,
|
|
/^\/api\/companies\/[^/]+\/issues(?:\/|$)/,
|
|
/^\/api\/companies\/[^/]+\/live-runs(?:\/|$)/,
|
|
/^\/api\/companies\/[^/]+\/sidebar-badges(?:\/|$)/,
|
|
/^\/api\/heartbeat-runs\/[^/]+\/log(?:\/|$)/,
|
|
];
|
|
|
|
const SILENCED_SUCCESS_STATIC_PREFIXES = [
|
|
"/@fs/",
|
|
"/@id/",
|
|
"/@react-refresh",
|
|
"/@vite/",
|
|
"/_plugins/",
|
|
"/assets/",
|
|
"/node_modules/",
|
|
"/src/",
|
|
];
|
|
|
|
const SILENCED_SUCCESS_STATIC_PATHS = new Set([
|
|
"/",
|
|
"/index.html",
|
|
"/favicon.ico",
|
|
"/site.webmanifest",
|
|
"/sw.js",
|
|
]);
|
|
|
|
function normalizePath(url: string): string {
|
|
const trimmed = url.trim();
|
|
if (trimmed.length === 0) return "/";
|
|
const pathname = trimmed.split("?")[0]?.trim() ?? "/";
|
|
return pathname.length > 0 ? pathname : "/";
|
|
}
|
|
|
|
const SECRET_SENSITIVE_HTTP_PATHS = [
|
|
/^\/api\/companies\/[^/]+\/voice-sessions(?:\/|$)/,
|
|
/^\/mcp\/(?:oauth|paperclip)(?:\/|$)/,
|
|
/^\/api\/mcp(?:\/|$)/,
|
|
/^\/api\/chat-endpoints\/[^/]+\/setup(?:-secret)?(?:\/|$)/,
|
|
];
|
|
const SECRET_SENSITIVE_HTTP_METHODS = new Set(["POST", "PUT", "PATCH"]);
|
|
|
|
/** Free-form agent feedback must never be copied into HTTP diagnostics. */
|
|
export function isPrivateAgentCommentaryHttpRequest(url: string | undefined): boolean {
|
|
if (!url) return false;
|
|
// Express routes are case-insensitive and also accept absolute-form URLs.
|
|
const pathname = normalizePath(url).replace(/^https?:\/\/[^/]*/i, "");
|
|
return /^\/api\/companies\/[^/]+\/agent-commentary(?:\/|$)/i.test(pathname);
|
|
}
|
|
|
|
/** Destination credentials stay private even on malformed settings requests. */
|
|
export function isPrivateAgentObservabilityHttpRequest(url: string | undefined): boolean {
|
|
if (!url) return false;
|
|
const pathname = normalizePath(url).replace(/^https?:\/\/[^/]*/i, "");
|
|
return /^\/api\/companies\/[^/]+\/observability(?:\/|$)/i.test(pathname);
|
|
}
|
|
|
|
/** Muse OAuth and worker payloads stay private even on malformed/rejected paths. */
|
|
export function isPrivateMuseHttpRequest(url:string|undefined):boolean {
|
|
if(!url)return false;
|
|
let pathname=normalizePath(url).replace(/^https?:\/\/[^/]*/i, "");
|
|
for(let depth=0;depth<4;depth++) {
|
|
if(/^\/api\/muse(?:\/|$)/i.test(pathname) || /^\/api\/companies\/[^/]+\/(?:muse-invitations|agents\/[^/]+\/muse-binding)(?:\/|$)/i.test(pathname))return true;
|
|
try {const decoded=decodeURIComponent(pathname);if(decoded===pathname)break;pathname=decoded;} catch {break;}
|
|
}
|
|
return false;
|
|
}
|
|
|
|
/** Provider payloads are private even when a method/signature is rejected. */
|
|
export function isPrivateWebhookHttpRequest(
|
|
method: string | undefined,
|
|
url: string | undefined,
|
|
): boolean {
|
|
if (!method || !url) return false;
|
|
let pathname = normalizePath(url);
|
|
if (/^https?:\/\//i.test(pathname)) {
|
|
// Do not let URL dot-segment normalization erase an explicitly supplied
|
|
// ingress namespace on a malformed absolute-form callback.
|
|
const rawPath = pathname.replace(/^https?:\/\/[^/]*/i, "");
|
|
if (/^\/api\/(?:chat-webhooks|voice-webhooks|routine-triggers\/public)(?:\/|$)/i.test(rawPath)) return true;
|
|
try {
|
|
pathname = new URL(url).pathname;
|
|
} catch {
|
|
return false;
|
|
}
|
|
}
|
|
// This namespace is reserved for provider ingress, including malformed or
|
|
// unknown callback paths. Rejecting a route must not make its payload public.
|
|
return /^\/api\/(?:chat-webhooks|voice-webhooks|routine-triggers\/public)(?:\/|$)/i.test(pathname);
|
|
}
|
|
|
|
/**
|
|
* These routes accept or create one-time connector credentials. A provider or
|
|
* validation error can echo credential material in its message even after the
|
|
* structured request body has been redacted, so HTTP failure logs use generic
|
|
* error metadata for the whole route. Webhook failures also use generic error
|
|
* metadata: raw provider text/files/credentials cannot be named-field redacted.
|
|
*/
|
|
export function isSecretSensitiveHttpRequest(
|
|
method: string | undefined,
|
|
url: string | undefined,
|
|
): boolean {
|
|
if (isPrivateWebhookHttpRequest(method, url) || isPrivateMuseHttpRequest(url)) return true;
|
|
if (url && normalizePath(url).startsWith("/mcp/files/")) return true;
|
|
if (isPrivateAgentCommentaryHttpRequest(url)) return true;
|
|
// Custom OTLP header values are arbitrary credentials, including on rejected
|
|
// methods or malformed subpaths. Named-field redaction cannot identify them.
|
|
if (isPrivateAgentObservabilityHttpRequest(url)) return true;
|
|
// Avatar uploads and dedicated Dot MCP calls may contain private image bytes.
|
|
if (url && /^(?:\/mcp\/runner(?:\/|$)|\/api\/companies\/[^/]+\/agents\/[^/]+\/avatar(?:\/|$))/i.test(normalizePath(url).replace(/^https?:\/\/[^/]*/i, ""))) return true;
|
|
if (!method || !url) return false;
|
|
if (/^\/api\/chat-slack\/(?:managed\/)?oauth(?:\/|$)/i.test(normalizePath(url).replace(/^https?:\/\/[^/]*/i, ""))) return true;
|
|
if (/^\/api\/chat-endpoints\/[^/]+\/slack(?:\/|$)/i.test(normalizePath(url).replace(/^https?:\/\/[^/]*/i, ""))) return true;
|
|
if (!SECRET_SENSITIVE_HTTP_METHODS.has(method.toUpperCase())) return false;
|
|
const pathname = normalizePath(url);
|
|
return SECRET_SENSITIVE_HTTP_PATHS.some((pattern) => pattern.test(pathname));
|
|
}
|
|
|
|
export function shouldSilenceHttpSuccessLog(
|
|
method: string | undefined,
|
|
url: string | undefined,
|
|
statusCode: number,
|
|
): boolean {
|
|
if (statusCode >= 400) return false;
|
|
if (statusCode === 304) return true;
|
|
if (!method || !url) return false;
|
|
if (!SILENCED_SUCCESS_METHODS.has(method.toUpperCase())) return false;
|
|
|
|
const pathname = normalizePath(url);
|
|
if (SILENCED_SUCCESS_STATIC_PATHS.has(pathname)) return true;
|
|
if (
|
|
SILENCED_SUCCESS_STATIC_PREFIXES.some((prefix) =>
|
|
pathname.startsWith(prefix),
|
|
)
|
|
)
|
|
return true;
|
|
return SILENCED_SUCCESS_API_PATHS.some((pattern) => pattern.test(pathname));
|
|
}
|