Skip to content

JITSU-91: migrate sync/debug/reports HTTP routes onto the shared service classes#1404

Merged
vklimontovich merged 6 commits into
newjitsufrom
refactor/jitsu-91-sync-debug-reports-routes
Jul 21, 2026
Merged

JITSU-91: migrate sync/debug/reports HTTP routes onto the shared service classes#1404
vklimontovich merged 6 commits into
newjitsufrom
refactor/jitsu-91-sync-debug-reports-routes

Conversation

@vklimontovich

@vklimontovich vklimontovich commented Jul 15, 2026

Copy link
Copy Markdown
Contributor

What

Migrate the sync/debug/reports route handlers onto the shared service classes extracted for the MCP server in #1385, so HTTP and MCP share one implementation of workspace scoping, secret unmasking, and syncctl/bulker/functions dispatch instead of two paths that drift. Same play as JITSU-67 (config routes → ConfigObjectsService).

Route Delegates to
sources/run SyncService.runSync (scheduler-bearer special case + logging stay in the route)
sources/cancel cancelSync
sources/tasks GET/POST listSyncTasks / latestSyncTasks (route adds the logs URL)
sources/spec getConnectorSpec
sources/discover discoverStreams
sources/check POST/GET triggerSourceCheck / getSourceCheckResult
sources/state GET/POST getSyncState / resetSyncState + setSyncState
sources/logs findSync (only the ownership lookup moves; gzip streaming stays)
config/[type]/test DebugService.testConnection
function/run DebugService.runFunction
profile-builder/run DebugService.runProfileBuilder
reports/event-stat ReportsService.eventStat (route keeps getWorkspace slug resolution)
reports/sync-stat ReportsService.syncStat (same)

profile-builder/stats.ts from the issue no longer exists — removed in #1195; ReportsService.profileBuilderStats mirrors the dead route, nothing to migrate.

Transport stays in the routes (createRoute schemas, OpenAPI expand metadata, 20mb bodyParser configs, maxDuration). lib/server/route-services.ts provides lazy per-process service instances bound to the db/clickhouse singletons so route files don't repeat the wiring. Net −613 lines.

Service gaps closed for parity

The routes had capabilities the services lacked:

  • SyncService.latestSyncTasks — the tasks POST aggregation (latest non-skipped task per sync)
  • SyncService.setSyncState — the state-editor upsert (state POST with a non-empty body)
  • SyncService.triggerSourceCheck also accepts a caller-supplied unsaved config + client-generated storageKey (service-editor test flow), with secret unmasking; MCP call site updated
  • SyncService.runSync passes taskId; DebugService.runFunction passes functionName
  • ReportsService.eventStat returns srcSize (the client-side Report.parse requires it)

Behavior changes

  • Security: sources/check GET/POST now require the exact ${workspaceId}_ storage-key segment — a bare startsWith(workspaceId) let workspace ws1 poll keys of ws10 (hardened in the service in a1e95e6; the route gets it by delegating). sync-stat counts distinct (fromId, toId) tuples instead of collision-prone string concatenation.
  • sources/cancel returns the service's { ok: true, status } instead of { ok: false, pending: true, startedAt } — the UI only reads .error.
  • sources/discover keeps its historical 200 { ok: false, error } for unknown services via an ApiError adapter in the route (the service 404s).
  • sources/tasks GET without syncId no longer fails spuriously in a workspace with no syncs.
  • sources/tasks GET with taskId builds the logs URL from the returned task's own sync_id, not the request's syncId — a task-only lookup omits syncId, so the old link carried syncId=undefined and the logs endpoint (which requires a real syncId) 404'd. Pre-existing latent bug, hardened here.
  • profile-builder/run now 404s on an unknown profile builder (previously forwarded blindly) and defaults settings/version from the stored builder.
  • reports/event-stat: when end is given without start, start defaults to end − 1 month (was now − 1 month), matching sync-stat.

Testing

New integration tests (testcontainers Postgres/ClickHouse + MSW syncctl): aggregated-tasks scoping, config-mode source check with unmasking, the ws1/ws10 prefix hardening, state upsert, and srcSize in the event-stat wire shape.

JITSU-91

@vklimontovich vklimontovich added the deploy:console Auto-deploy console to beta when this PR merges (JITSU-68) label Jul 15, 2026
@absorbb
absorbb marked this pull request as ready for review July 17, 2026 14:16

@jitsu-code-review jitsu-code-review Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Reviewed the API-route-to-service refactor and associated integration test updates for correctness/security regressions.

I did not find blocking issues in this changeset. The service extraction and handler rewiring appear behaviorally consistent with previous logic in the areas I checked.

absorbb
absorbb previously approved these changes Jul 17, 2026
…ice classes

Route handlers delegate to SyncService/DebugService/ReportsService (extracted
for the MCP server in #1385) so HTTP and MCP share one implementation of
workspace scoping, secret unmasking and syncctl/bulker/functions dispatch.
Transport stays in the routes: createRoute schemas, OpenAPI metadata, the
scheduler-bearer special case in sources/run and the gzip streaming in
sources/logs.

Service gaps closed for parity: latestSyncTasks (tasks POST aggregation),
setSyncState (state editor upsert), triggerSourceCheck accepts an unsaved
config with a caller-generated storageKey, runSync taskId and runFunction
functionName passthrough, eventStat returns srcSize.

Security fixes picked up by delegating: sources/check requires the exact
workspaceId_ storage-key segment (ws1 no longer accepts ws10 keys), sync-stat
counts distinct (fromId, toId) tuples instead of string concatenation.

profile-builder/stats.ts from the issue no longer exists (removed in #1195).

JITSU-91
@vklimontovich
vklimontovich force-pushed the refactor/jitsu-91-sync-debug-reports-routes branch from e45d310 to bbc35d6 Compare July 20, 2026 12:31
jitsu-code-review[bot]
jitsu-code-review Bot previously approved these changes Jul 20, 2026

@jitsu-code-review jitsu-code-review Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Reviewed the service extraction and route rewiring in this PR, focusing on sync/report/debug API behavior and workspace scoping. I found one user-visible correctness regression (details inline) around the task logs URL generation when syncId is omitted. Everything else I checked in this range looked consistent with previous behavior.

Comment thread webapps/console/pages/api/[workspaceId]/sources/tasks.ts Outdated
"Mirrors" read as a duplicated copy to keep in sync; the routes delegate to
these methods, so there is a single implementation.

JITSU-91

@jitsu-code-review jitsu-code-review Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Reviewed the route→service migration across sync/debug/reports handlers and related integration coverage. I focused on workspace scoping, secret handling, and request/response behavior parity with prior routes.

No new actionable bugs/regressions found beyond the already-open thread on logs URL construction when only is provided.

jitsu-code-review[bot]
jitsu-code-review Bot previously approved these changes Jul 20, 2026

@jitsu-code-review jitsu-code-review Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Reviewed the route-to-service migration across sync/debug/reports handlers and related integration coverage. I focused on workspace scoping, secret handling, and request/response behavior parity with prior routes.

No new actionable bugs/regressions found beyond the already-open thread on sources/tasks logs URL construction when only taskId is provided.

…task model

The query column list and the route zod schema were two hand-maintained copies of
the same shape. Derive one latestSyncTaskSchema from source_taskDbModel, select *
and let it trim the result, and reuse it as the route response schema.

JITSU-91

@jitsu-code-review jitsu-code-review Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Reviewed the service extraction for sync/debug/reports routes and spot-checked the behavior-sensitive changes around workspace scoping, source check dispatch, and report payload shapes.\n\nI did not find new actionable correctness/security regressions beyond the already-open thread on the logs URL when is provided without .

jitsu-code-review[bot]
jitsu-code-review Bot previously approved these changes Jul 20, 2026

@jitsu-code-review jitsu-code-review Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Reviewed the service extraction for sync/debug/reports routes and spot-checked the behavior-sensitive changes around workspace scoping, source check dispatch, and report payload shapes.

I did not find new actionable correctness/security regressions beyond the already-open thread on the sources/tasks logs URL when taskId is provided without syncId.

A taskId-only GET /sources/tasks lookup omits syncId, so the logs link
carried syncId=undefined. Use the returned task's own sync_id instead.

JITSU-91

@jitsu-code-review jitsu-code-review Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Reviewed the service/route refactor across sources/check/discover/spec/run/state/tasks plus reports/debug endpoints, and validated the key behavior changes in and . I did not find any new correctness, security, or user-visible regression issues beyond the already-resolved thread.

@jitsu-code-review jitsu-code-review Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Reviewed the service/route refactor across sources/check/discover/spec/run/state/tasks plus reports/debug endpoints, and validated key behavior changes in sync-service and reports-service. I did not find any new correctness, security, or user-visible regression issues beyond the already-resolved thread.

@vklimontovich
vklimontovich requested a review from absorbb July 20, 2026 18:25
@vklimontovich
vklimontovich merged commit 4b66799 into newjitsu Jul 21, 2026
6 checks passed
@vklimontovich
vklimontovich deleted the refactor/jitsu-91-sync-debug-reports-routes branch July 21, 2026 06:19
@github-actions

Copy link
Copy Markdown
Contributor

🚀 deploy:console label detected — triggered a beta console deployment to jitsu-cloud-infra. Track it in the deploy runs (newest at top): https://github.com/jitsucom/jitsu-cloud-infra/actions/workflows/deploy.yaml?query=event%3Aworkflow_dispatch

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

deploy:console Auto-deploy console to beta when this PR merges (JITSU-68)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants