adminandClaude Opus 4.8 e6d3101501 fix: 17 confirmed bugs from full-repo audit (edge + Python engine) (#5)
* docs: correct stale quality-check-service.ts comment references

Two source comments still cited src/services/quality-check-service.ts as an
existing precedent. It doesn't exist anywhere in this repo's history (git
log --all: zero commits, any branch, ever) -- confirmed during the earlier
full-doc-corpus accuracy pass. Points each comment at the real precedent
instead (document-extraction-service.ts / iceberg-write-service.ts).

Applied from task_05ec36aa, spun off during that pass.

* fix: 17 confirmed bugs from full-repo audit (edge + Python engine)

Found by an 8-finder bug hunt across app/api, src/services, src/clients,
frontend, the Python engine, the data layer, config/infra, and tests, then
independently adversarially verified per finding (32 raw findings -> 27
confirmed real bugs; 5 refuted). This commit applies the 17 confirmed as
safe, mechanical fixes -- no architecture/design decision required. The
other 10 need a decision and are reported separately, not touched here.

Most consequential, app/api/payments/[order_id]/deposit/route.ts:
the client-supplied Origin request header was trusted unsanitized both as
a server-side fetch target (SSRF) and as Stripe Checkout success/cancel
redirect URLs (open redirect tied to a real payment flow), and a failed
order lookup silently fell through to a hardcoded deposit amount instead
of 404. Fixed by reading the order directly via lib/orders-store.ts
(mirroring the sibling release/route.ts, which already did this correctly)
instead of both trusting the Origin header and self-issuing an HTTP fetch.

Also fixed:
- 5 routes (orders, orders/[id], estimates, subscriptions, ai/parse) that
  500'd instead of 400ing on a literal JSON `null` body, since req.json()
  resolves (not rejects) for that input and bypasses the try/catch guard.
- app/api/0pt/lakehouse/mappings/{,[mappingId]/{,writes/}}route.ts each
  instantiated their own private service instances, so a mapping created
  via POST was invisible to the sibling GET and writes routes even before
  the separately-tracked dataset-registration gap. Extracted a shared
  singleton module, src/services/lakehouse-mapping-registry.ts.
- app/api/0pt/documents/[documentId]/extraction/route.ts collapsed every
  error (not-configured, policy-denied, policy-approval-required,
  not-found) into a blanket 400; now status-mapped like the sibling
  sources/[sourceId]/query route.
- app/api/vehicles/route.ts: plate query param wasn't URL-encoded before
  being concatenated into the outbound RDW request, allowing extra query
  parameters to be injected; added a strict allowlist + encodeURIComponent.
- app/api/uploads/route.ts: POST returned a fake 200 success with
  put_url: null even when "configured", instead of continuing to report
  501 until presign generation is actually implemented.
- src/adapters/document-intelligence-adapter.ts: the result-polling loop
  never checked response.ok, so a non-2xx poll response (auth expiry,
  429, 5xx) was silently retried until a generic timeout masked the real
  error.
- app/order/[id]/page.tsx: finish() never cleared the production-simulation
  setInterval, so it kept firing (and re-rendering) forever after delivery.
- app/admin/page.tsx: the metrics fetch had no response/shape validation
  (unlike the adjacent orders fetch), rendering literal "undefined" stat
  tiles on a malformed response instead of falling back to <ErrorState/>.
- services/api/workers/pipeline.py: `config.get("seeds") or DEMO_SEEDS`
  used truthy-or, so an explicit empty seeds dict was silently replaced
  with hardcoded demo org numbers instead of being respected as empty.
- services/api/workers/resolve.py: corroboration (confidence/agreed_sources
  bump) no longer fires for two hits from the same source under fuzzy
  match -- only a genuinely independent source now counts, per docs/06's
  own ">=2 independent sources agree" definition -- and a merged record's
  provenance array now actually includes the corroborating source's
  fields instead of only a bare source-name string.
- services/api/orchestrator/main.py: create_order's int(...) on
  unvalidated client volume/confidence fields raised on any
  decimal-formatted input (int("92.5") -> ValueError); now coerced via
  float() first with a safe default. /vehicles/{plate} and /screen also
  now catch connector exceptions and degrade gracefully, matching
  pipeline.py's existing pattern for the same connectors.
- lib/orders-store.ts: postgres.js (pinned v3.4.9) returns bigint/numeric
  columns as strings by default; getOrder/listOrders/setStatus were
  silently handing callers stringified money fields. Added a narrow
  per-row coercion instead of touching the shared client's global type
  map (which would affect unrelated tables' bigint/numeric columns too).
- lib/subscriptions-store.ts: the in-memory fallback returned
  oldest-first while the Postgres branch explicitly orders newest-first;
  now consistent, mirroring the identical fix already in orders-store.ts.
- app/api/auth/login/route.ts: DEV_LOGIN_KEY was compared with a plain
  !==, a non-constant-time comparison; replaced with crypto.timingSafeEqual.

Verified before commit: tsc --noEmit clean; vitest run 88 passed, 1 todo,
0 failures (13 files, unchanged from before this commit -- no existing
test's assertions needed to change). services/api/workers/resolve.py's
source-novelty and provenance-merge logic additionally verified by direct
execution against synthetic same-source/cross-source inputs (no Python
test suite exists in this repo to add to). services/api/workers/pipeline.py
and services/api/orchestrator/main.py verified with python -m py_compile
(no httpx/fastapi installed in this environment to run them directly).

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>

* fix(engine): treat explicit seeds:null as missing to avoid 500 in run_job

Four-eyes follow-up to this PR's own seeds change. Switching from
`config.get('seeds') or DEMO_SEEDS` to `config['seeds'] if 'seeds' in config`
correctly stopped an explicit empty {} from being backfilled with DEMO_SEEDS,
but regressed on client-controlled `{"seeds": null}`: seeds became None and
the downstream `seeds.get(market, [])` raised AttributeError -> 500. That path
is reachable (POST /orders stores raw body.config; POST /orders/{id}/run passes
it straight to run_job). Using `config.get('seeds') is not None` keeps the
intended behaviour (explicit {} honoured, never silently seeded with demo data)
while restoring the None-tolerance the old idiom had.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>

---------

Co-authored-by: Claude Sonnet 5 <noreply@anthropic.com>
2026-07-22 18:52:19 +02:00
2026-06-24 14:47:12 +00:00
2026-06-24 14:47:12 +00:00
2026-06-24 14:47:12 +00:00
2026-06-24 14:47:12 +00:00
2026-06-24 14:47:12 +00:00
2026-06-24 14:51:57 +00:00

0pt — your data

Data services on demand for the Nordics + Europe. Compose a data job, pay 50 % to start, watch production live, validate with full provenance, deliver anywhere. Owned by SIAX Technology AB. Honest accuracy is the moat: every field carries source, freshness and confidence; nothing is guessed.

Live: https://0pt.app · Contract: CLAUDE.md + docs/

Two planes (see docs/02-architecture.md)

  • Edge (Vercel, this app) — marketing, catalog, the order lifecycle, customer portal, admin portal, and the API route handlers. Defers to the data engine when ENGINE_URL is set.
  • Engine (services/api, runs on a VPS) — FastAPI orchestrator + worker pipeline doing the compliant sourcing (official API → bulk → authorized web → licensed → else level 0). Never on Vercel (long jobs). Bypass/stealth/proxy-rotation/fake-account paths are excluded by design (CLAUDE.md §1).

Routes

Area Routes
Marketing / (hero, filosofi, katalog, motorn, visualiseringar, täckning, editorial, bevis, priser, footer)
Catalog /katalog, /katalog/[id]
Sourcing map /kallor
Order lifecycle /bestall → /bestall/beskriv → /bestall/forskott → /order/[id] → /order/[id]/validera
Customer portal /portal, /portal/subscriptions, /portal/files, /portal/integrationer, /portal/settings
Admin portal /admin, /admin/sources, /admin/jobs, /admin/customers, /admin/verktyg
API /api/{health,estimates,catalog,sources,vehicles,screen,orders,orders/[id],subscriptions,admin/metrics,uploads,auth/*,ai/parse,payments/*,webhooks/stripe,connections/db-grant}
Data platform (P0) /api/0pt, /api/0pt/documents/capture, /api/0pt/documents/[documentId]/extraction, /api/0pt/lakehouse/mappings[/[mappingId]/writes], /api/0pt/sources/[sourceId]/query, /api/0pt/sources/rate-policies[/[id]] — ⚠ these read tenant_id/project_id from the request body or query string, not a server session. See Known issues below.

Design system

Mono/editorial, light, radius 0, Inter + JetBrains Mono, single red #e40014, animated grain, scroll-reveal motion. No photography — imagery is rendered data (DataArtifact). Every fact shows a provenance square (ProvenanceBadge). Full spec: docs/05-design-system.md.

Run locally

pnpm install
pnpm dev                       # Next.js on http://localhost:3000

# data engine (separate, optional)
cd services/api && pip install -r requirements.txt && uvicorn orchestrator.main:app --reload

Deploy

  • Frontend → Vercel (project 0pt, scope Simon Axelsson's projects), domain 0pt.app.
  • Engine + DB + embeds → one VPS via infra/docker-compose.yml (Postgres+pgvector, Redis, api, worker, NocoDB, Metabase, Caddy).
  • Env inventory: .env.example — not on main yet. It exists on branch/PR feature/0pt-env-example (github.com/sax3l/0pt PR #3, unmerged as of this pass), added after discovering .gitignore's blanket .env* rule had silently kept it out of every commit despite docs/09-build-plan.md Phase 0 requiring it. Until that PR merges, use docs/08-infrastructure.md as the source of truth for env var names.

Status

Frontend (marketing, catalog, order lifecycle UI, customer + admin portals) and the edge API route handlers build and typecheck green. That is a statement about the code compiling and running, not about the platform being production-ready — read Known issues below before relying on any of this against real tenants or real money.

Integrations are env-guarded and activate when their keys/DB are provided:

  1. Database — Vercel → Storage → Postgres (sets POSTGRES_URL) → durable persistence (schema in sql/001_init.sql). Without it, orders fall back to an in-memory, non-durable store (lib/orders-store.ts).
  2. Stripe keys → payments (app/api/payments/*, app/api/webhooks/stripe) — this is wired code, not just a plan. Resend is documented as the email provider (docs/08-infrastructure.md) but has no call site anywhere in this repo yet — treat "+ email" as not-yet-implemented, not merely unconfigured.
  3. VPS for the engine (services/api) → set ENGINE_URL so edge routes defer to it (lib/engine.ts). Unset, several routes (/api/screen, /api/vehicles, /api/ai/parse) fall back to calling public sources directly or computing locally instead.
  4. AUTH_SECRET + DEV_LOGIN_KEY → a guarded dev-only login (app/api/auth/login/route.ts): an HMAC-signed session cookie (lib/auth.ts), not a real auth system. Full OAuth via Auth.js is Phase 3 of docs/09-build-plan.md and has not been built — see Known issues.

Known issues

Blunt on purpose, per CLAUDE.md's own house rule ("flag conflicts ... and propose the reconciliation rather than guessing"). These are open, real gaps as of this pass — not silently patched, not guessed at.

  1. No authentication or tenant scoping is wired anywhere in this repo. The only thing that exists is the DEV_LOGIN_KEY dev gate described above. There is no session-to-org/tenant binding at all — app/api/orders/route.ts's own GET handler carries the literal comment // GET /api/orders — list (org scoping added with auth)., i.e. not yet. As a direct consequence, the newer P0 data-platform routes read tenant_id/project_id from the client-supplied request body or query string instead of a server-bound session:

    • app/api/0pt/lakehouse/mappings/route.ts and .../[mappingId]/writes/route.ts
    • app/api/0pt/sources/rate-policies/route.ts and .../[sourceRatePolicyId]/route.ts
    • app/api/0pt/sources/[sourceId]/query/route.ts
    • src/services/document-capture-service.ts (called from app/api/0pt/documents/capture/route.ts)

    This violates the platform-wide hard rule that tenant_id must be server-bound to an authenticated session and never read from client input. It is not a deliberate two-tier design — it exists because no auth/session system has been built yet. Do not expose these routes to untrusted callers before Phase 3 (docs/09-build-plan.md) lands.

  2. The CL0UD/N0D/AUD0/ST0RE platform clients are real code, but mock-only. src/clients/{cl0ud,n0d,aud0,st0re,st0re-lakehouse}-client.ts are genuine, typechecked TypeScript with real tests — but every one of them runs against an in-memory mock today. Corrected this pass: CL0UD_URL/N0D_URL/AUD0_URL/ST0RE_URL are never read via process.env anywhere in this repo — verified by grepping the whole tree; the only hits are a code comment and a TODO/it.todo in tests/p0/iceberg-write-service.test.ts describing ST0RE_URL as future work, not an actual read. Every client only accepts an optional constructor baseUrl (st0reBaseUrl, cl0udBaseUrl, n0dBaseUrl, aud0BaseUrl), and every service that instantiates one (src/services/*.ts) is called from its route handler with no options, so all of them resolve to the in-memory mock today. Read this as "real code, mock-only, not live-verified, no env wiring at all yet" wherever it comes up — not "integrated" or "connected."

  3. 0pt's data-quality/QA enforcement code does not exist in this repo. src/services/quality-check-service.ts, src/services/quality-report-service.ts, src/types/quality-check.ts, src/types/quality-report.ts, src/data-platform/services/catalog-service.ts, sql/002_p0_dataset_quality.sql, and sql/003_*.sql were at one point described, in docs/ICEBERG_WRITE_BOUNDARY.md, docs/11-lakehouse-write-plan.md, and docs/P0_QUERY_SOURCE_FLOW.md, as if they were already built and tested. git log --all for every one of those paths returns zero commits, on any branch, ever — they have never existed in this repository; the sql/ directory today holds only 001_init.sql and 004_iceberg_write_boundary.sql. 0pt's QA/quality-check stage is spec/target only right now. Corrected as of this pass: all three of the docs above, plus docs/12-edge-capability-api.md, now consistently state this — each carries its own "fabricated, not built" callout, and docs/P0_DATASET_QUALITY_FLOW.md (added by an earlier parallel pass) is the explicit, clearly-labeled target-spec doc for what this stage should look like once built. Treat any other doc that asserts the QA stage already exists as wrong until it actually lands.

  4. Two diverged git remotes both claim to be "the 0pt repo." origin in this checkout is github.com/sax3l/0pt. A separate Gitea remote, git.siax.io/sax3l/0pt, shares at least part of the same history — services/api/workers/adaptive_router.py is byte-for-byte identical between GitHub's current main and a Gitea post-fix PR branch — but Gitea's main independently accumulated three 2026-07-13 commits adding a real WAF-bypass/proxy-rotation/fake-identity scraper stack (services/scrapers/*, since removed via a Gitea PR) that never touched GitHub's main. Which remote is authoritative, which is deployed to 0pt.app, and whether the two should be kept in sync is unresolved — Simon's decision, not something this pass or any doc should silently assume.

  5. 0pt is registered as API-only in the platform's six-surface capability model, not "api/cli/mcp/ui/job/sdk" across the board. 14 0pt.* capabilities are registered in cl0ud's packages/capability-registry/src/registry.ts today (verified by name: query_source, document_ocr, write_external_record, lakehouse_mapping_manage, lakehouse_write, source_rate_policy_manage, screen_sanctions, estimate_compute, vehicle_lookup, catalog_list, source_registry_list, order_create, order_payment, write_iceberg_table). None has cliEnabled/mcpEnabled true. Surfaces, checked per-entry: 11 have ['api'] only, lakehouse_write and write_iceberg_table have ['api', 'job'], and write_external_record has ['job'] only (no api surface at all) — so it is not quite "api everywhere plus job for the two heaviest," one capability is job-only. If any doc anywhere describes a live siax 0pt ... CLI or an 0pt MCP tool, it is describing a target, not current reality.

  6. No evidence a "t_0pt" dedicated-node N0D auth pattern is built. sax3l/n0d was searched in full (all branches, all commits, all files) — zero references to t_0pt exist anywhere in that repo. Treat any claim that this is already built/tested as unconfirmed.

© 2026 SIAX Technology AB. Not affiliated with Protosell.

S
Description
No description provided
Readme
26 MiB
Languages
TypeScript 90.4%
Python 5.4%
JavaScript 2.1%
PLpgSQL 1.4%
Shell 0.3%
Other 0.4%