Patch ui/src/main.tsx in the Dockerfile build to add basename="/app"
to BrowserRouter. With this, React Router strips the /app prefix
client-side before matching routes — /app/ becomes /, /app/ABC/issues
becomes /ABC/issues — so the company-prefix extractor never sees "app".
Health server:
- / → HuggingClip dashboard (restored)
- /app/* → proxy to Paperclip with /app prefix stripped
- /api/* → proxy pass-through
- /* catch-all → proxy pass-through (assets, sw.js, etc.)
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
- Move dashboard to /_status, proxy / root directly to Paperclip
(fixes "Company not found APP" — SPA no longer sees /app/ prefix)
- Hardcode PAPERCLIP_HOST to 127.0.0.1 instead of reading HOST env
(fixes ECONNREFUSED 0.0.0.0:3100 — 0.0.0.0 is bind-only)
- Remove CLOUDFLARE_ACCOUNT_ID requirement from setup condition
(setup script already auto-discovers account ID)
- Source CF proxy env file after setup so CLOUDFLARE_PROXY_URL/SECRET
reach the Node process
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
set -euo pipefail kills the script when the bootstrap-ceo grep
pipeline returns no match (admin already exists). Previous fix
covered bootstrap-ceo itself but not the grep pipeline. Add
|| true at the end of the pipeline so empty INVITE_URL is fine.
Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
Build failed silently. Add: file existence check, simpler sed
pattern (just seen.has(current.id) → wrapped form), grep-verify
the patch landed, dump file context if not for debugging.
Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
Patch Paperclip source to cap recovery chain depth at 500
Found the actual bug. Confirmed via @paperclipai/server npm tarball:
firstBlockedChainFinding does proper cycle detection via Set.has,
but the chain in user data is genuinely 1000+ deep (created by a
runaway recovery-issue loop). Each recursive call also clones the
Set into new Set(seen), so memory blows up too.
Fix: sed-patch the if-check to also bail when seen.size > 500.
This short-circuits deep linear chains without affecting normal
graphs. Patch runs in the builder stage before pnpm build.
Reverted SQL purge and --unhandled-rejections=none from start.sh —
neither addressed the root cause.
Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
Purge orphaned heartbeat run UUID from all tables before launch
The orphaned run 1fc2bf0e... triggers Paperclip's startup recovery
which overflows the stack via firstBlockedChainFinding. Even when
caught, downstream periodic checks crash Paperclip. Solution:
delete the UUID from every UUID column across every public table
before launch, so recovery has nothing to do.
Foreign-key constraint failures are swallowed per-row.
Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
Prevent crash from unhandled RangeError in periodic heartbeat
The startup heartbeat recovery catches the stack overflow and logs it.
But the periodic heartbeat (30s) fires the same firstBlockedChainFinding
recursion in an async context with no try/catch → unhandled rejection
→ process.exit(1). --unhandled-rejections=none silences these instead
of crashing the process.
Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
Revert --stack-size=65536; stack overflow was harmless
With larger stack, recovery code completes and triggers a crash in
Paperclip's issue-graph traversal result handling (exit code 1).
The RangeError was caught internally and the app continued fine.
Reverting lets the stack overflow remain caught-and-logged, which
is the working state.
Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
Increase Node.js stack size to fix startup recovery overflow
Deep issue dependency chains from stalled CEO tasks cause
RangeError in firstBlockedChainFinding recursive DFS.
--stack-size=65536 (64MB vs 1MB default) handles any realistic depth.
Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
Reset stale agent runs before startup to prevent stack overflow
Paperclip's startup recovery does recursive DFS on the issue graph.
Deeply nested stalled-task chains cause RangeError on restart.
Marking orphaned running runs as failed before launch prevents the
recovery code from firing entirely.
Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
Simplify logs to match Hugging8n style; fix Agent JWT missing
- Proxy WebSocket upgrades (events/ws) through to Paperclip using raw
net.connect — fixes persistent 403 reconnect spam in logs
- Skip morgan logging for /events/ws paths
- Switch from app.listen to http.createServer so upgrade events attach
Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
- morgan: skip /health, /sw.js, /assets/*, /favicon.ico
- morgan: switch from "combined" to "tiny" format (no UA/referrer noise)
- Dashboard: poll every 30s instead of 5s
Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
Install gemini CLI in Docker image for gemini-local adapter
Paperclip's gemini-local adapter spawns 'gemini' as a subprocess.
Add @google/gemini-cli globally so it resolves in PATH. Also export
GEMINI_API_KEY, ANTHROPIC_API_KEY, OPENAI_API_KEY explicitly so all
adapters and sub-processes inherit them from HF Space secrets.
Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
Auto-create Paperclip instance config.json on first boot
bootstrap-ceo exits early with "No config found" when config.json is absent.
Generate a minimal valid config at PAPERCLIP_CONFIG before launching Paperclip,
using env vars for DB URL, public URL, and deployment mode. Skipped when config
was already restored from HF Dataset backup.
Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
Fix admin invite URL extraction and add setup banner to dashboard
- grep for 'Invite URL:' line specifically instead of any 'http' match,
which was capturing corepack's npm registry download URL
- Strip ANSI escape codes before extracting URL
- Save invite URL to /tmp/invite-url.txt for dashboard to read
- Add prominent orange setup banner on dashboard when invite URL exists
- Expose setupUrl in /health JSON response
Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
fix: bootstrap-ceo wait loop and missing PAPERCLIP_CONFIG env var
- Use 127.0.0.1 not localhost in curl health check (IPv6 resolution issue)
- Remove file-existence check from wait condition (was always false)
- Add PAPERCLIP_CONFIG env var from official Paperclip Dockerfile
- bootstrap-ceo now runs when API is ready regardless of config file path
Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
fix: bootstrap-ceo after Paperclip init, better startup error messages
- Start Paperclip in background, wait for config.json + /api/health (max 90s)
- Run bootstrap-ceo after server is ready (config exists), not before
- Print boxed admin invite URL to logs when bootstrap generates one
- Proxy shows "starting up" message instead of generic error during boot
- Cleanup handler now kills PAPERCLIP_PID on SIGTERM
Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
fix: 503 health check, backup dataset creation, auto bootstrap-ceo
- Use PAPERCLIP_ALLOWED_HOSTNAMES env var (no CLI/config.json required)
- Set PAPERCLIP_PUBLIC_URL from SPACE_HOST for Better Auth base URL
- Remove broken CLI-based allowed-hostname calls from step 7
- sync_from_hf returns None for no-backup (first boot) vs False for errors
- First boot restore: write db_status=connected, not error
Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
fix: dashboard display bugs (Invalid Date, DB status, backup status)
- Add startTime to /health response (was missing, caused Invalid Date)
- Show DB as green when status is unknown (pre-sync state is fine)
- Backup status: show Disabled when no HF_TOKEN, Pending before first sync
Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
fix: allowlist hostnames and add missing Paperclip env vars
- corepack enable uses correct pnpm version from packageManager field
- add @paperclipai/plugin-sdk build (matches official Paperclip Dockerfile)
Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
- Remove HfFolder import (removed in huggingface_hub >= 0.20)
- Build only ui + server packages (match official Paperclip Dockerfile)
- Launch server with tsx loader so workspace .ts packages resolve at runtime
Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
feat: auto-generate BETTER_AUTH_SECRET on first boot
If not set via HF Space secrets:
- First boot: generate with openssl rand -base64 32, save to /paperclip/.auth-secret
- Subsequent restarts: reload from saved file (stable across restarts)
- User-set secret always wins (checked before file lookup)
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
fix: three runtime errors after PostgreSQL startup
- PostgreSQL: use su -postgres for ALTER USER / CREATE DATABASE
(peer auth blocks root from connecting as postgres)
- Health server: hardcode port 7861 — was reading PORT=3100
(Paperclip's port env var, caused conflict)
- Paperclip launch: pnpm --filter @paperclipai/server start
(root package has no start script, server package does)
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
fix: initialize PostgreSQL cluster before starting
Use pg_createcluster + pg_ctlcluster (Debian way) instead of
raw postgres -D. Auto-detect installed PG version. Initialize
data dir on first boot, start cluster on every restart.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>