Skip to content

Eng#1: Backend sync reconciliation, metrics, OpenAPI#3

Merged
shayancoin merged 1 commit intomainfrom
feat/sync-reconcile-metrics-openapi
Oct 15, 2025
Merged

Eng#1: Backend sync reconciliation, metrics, OpenAPI#3
shayancoin merged 1 commit intomainfrom
feat/sync-reconcile-metrics-openapi

Conversation

@shayancoin
Copy link
Owner

@shayancoin shayancoin commented Oct 15, 2025

Eng#1 — Backend sync & operability

PR checklist

  • Webhook: validator (2 MB/413) + DB dedup (event_id/body_sha) + 202 + background + JSON log.
  • Counters: sync_success_total, sync_failure_total, sync_records_upserted_total{type}; /metrics exposes them.
  • Pull: accepts type|sync_type, validates page_size, unified envelope, increments counters.
  • Tests: webhook dedup/log/counters, pull alias/page_size, manifest coverage (skips if no manifest).
  • OpenAPI regenerated (docs/API_SPEC.md).
  • No changes to Eng#2/3 surfaces (viewer/assets/CI wiring untouched).

Notes

  • Admin: after Eng#3 assets PR merges, mark assets workflow as Required on main.

Summary by CodeRabbit

  • Documentation
    • Replaced legacy textual API docs with a complete OpenAPI 3.1 specification.
    • Documented comprehensive endpoints (e.g., examples, materials, modules, quote generation, CNC export, sync, root, healthcheck, metrics).
    • Added standardized request/response schemas, error formats, and security schemes.
    • Improves clarity, consistency, and compatibility with tooling (e.g., client generation, validation).
    • No runtime behavior changes.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Oct 15, 2025

Note

Currently processing new changes in this PR. This may take a few minutes, please wait...

📥 Commits

Reviewing files that changed from the base of the PR and between 9848a04 and c18ee4b.

📒 Files selected for processing (1)
  • docs/API_SPEC.md (1 hunks)
 __________________________________________________________________________________
< Controlling complexity is the essence of computer programming. - Brian Kernighan >
 ----------------------------------------------------------------------------------
  \
   \   (\__/)
       (•ㅅ•)
       /   づ
✨ Finishing touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch feat/sync-reconcile-metrics-openapi

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting

Comment on lines +591 to +603
"/api/sync/hygraph": {
"post": {
"tags": [
"sync"
],
"summary": "Hygraph Webhook",
"description": "Webhook receiver:\n- HMAC validated (dependency)\n- Single size guard (2MB) already enforced by dependency; body/raw set on request.state\n- DB dedup via SyncEvent(event_id, body_sha256 unique)\n- 202 fast-ack with background processing (pull_all)\n- Structured JSON log line and Prometheus counters",
"operationId": "hygraph_webhook_api_sync_hygraph_post",
"responses": {
"202": {
"description": "Successful Response",
"content": {
"application/json": {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Hygraph webhook advertises 202 while implementation returns 200

The specification for POST /api/sync/hygraph describes a 202 success response and “fast-ack with background processing”. The actual handler (backend/api/routes_sync.py) simply returns a dict without setting status_code=202, so FastAPI responds with 200. This mismatch will cause clients following the spec to treat the 200 responses as unexpected and breaks monitoring dashboards that rely on a 202 acknowledgement. Either change the code to return 202 or update the spec to document the 200 behaviour.

Useful? React with 👍 / 👎.

Comment on lines +615 to +647
"/api/sync/hygraph/pull": {
"post": {
"tags": [
"sync"
],
"summary": "Hygraph Pull",
"description": "Admin pull:\n- Auth via Bearer token (constant-time compare)\n- Accepts \"type\" or \"sync_type\" + optional \"page_size\"\n- Validates positive page_size and caps inside service (\u2264200)",
"operationId": "hygraph_pull_api_sync_hygraph_pull_post",
"requestBody": {
"content": {
"application/json": {
"schema": {
"additionalProperties": true,
"type": "object",
"title": "Body"
}
}
},
"required": true
},
"responses": {
"200": {
"description": "Successful Response",
"content": {
"application/json": {
"schema": {
"additionalProperties": true,
"type": "object",
"title": "Response Hygraph Pull Api Sync Hygraph Pull Post"
}
}
}
},

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge OpenAPI lists /api/sync/hygraph/pull although no such route exists

The spec introduces a secured POST /api/sync/hygraph/pull endpoint, but there is no implementation anywhere in the backend (rg "hygraph/pull" backend yields nothing). Publishing a non-existent admin sync endpoint will lead operators to 404s and erodes trust in the spec. Either add the pull route or remove it from the OpenAPI document.

Useful? React with 👍 / 👎.

Comment on lines +712 to +722
"/metrics": {
"get": {
"summary": "Metrics",
"operationId": "metrics_metrics_get",
"responses": {
"200": {
"description": "Successful Response",
"content": {
"application/json": {
"schema": {}
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge /metrics path documented without an implemented Prometheus endpoint

The new OpenAPI document exposes a GET /metrics path returning JSON, but the backend codebase contains no route or instrumentation for /metrics (rg "metrics" backend finds nothing). Requests to this path will return 404 and monitoring tooling configured from the spec will fail. Either instrument the app with a metrics endpoint or remove the path from the spec.

Useful? React with 👍 / 👎.

@shayancoin shayancoin merged commit b683750 into main Oct 15, 2025
1 of 6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant