Skip to content

feat(api,web): introduce Connect-RPC and chunked .khi file import workflow - #891

Merged
kyasbal merged 6 commits into
GoogleCloudPlatform:mainfrom
kyasbal:push-xzwqxqouptms
Aug 19, 2026
Merged

kyasbal merged 6 commits into
GoogleCloudPlatform:mainfrom
kyasbal:push-xzwqxqouptms

Conversation

@kyasbal

@kyasbal kyasbal commented Aug 19, 2026

Copy link
Copy Markdown
Member

Summary

Introduces Connect-RPC (proto-based RPC framework) to KHI and implements ImportInspectionService for chunked .khi inspection file uploads and imports across backend and frontend.
Also includes refactored API basePath resolution utilities and a bug fix preventing NaN division in progress metadata when handling imported inspections.


Key Changes

1. Proto Management & Connect-RPC Integration

  • Buf / Connect-RPC Setup:
    • Configured buf.gen.yaml and Makefile for Connect-RPC code generation for both Go (connect-go) and Web (@connectrpc/connect-web).
  • Common Route Mounting Utility:
    • Added RegisterConnectServiceHandler to mount Connect-RPC handlers on Gin while transparently stripping subpath prefixes (basePath).

2. Frontend API Base Path Resolution Refactoring

  • Added APIPathUtil.resolveApiPath to unify path resolution across relative paths, absolute paths, and custom base paths for both REST and Connect-RPC endpoints.

3. Backend: Chunked Inspection File Import Service

  • Protobuf Definition (proto/api/v1/import_inspection.proto):
    • StartImportInspection: Initializes an upload session, generates an upload token, and returns recommended chunk size.
    • UploadInspectionChunk: Handles binary chunk uploads with offset validation.
    • CompleteImportInspection: Validates complete byte range coverage, extracts KHI v6 binary metadata, and registers the imported inspection into InspectionTaskServer.
    • AbortImportInspection: Cleans up abandoned sessions and temporary files.
  • ImportSessionManager:
    • Supports concurrent, out-of-order chunk writes (WriteAt protected by mutex).
    • Validates full byte coverage without gaps or overlaps before finalization.
    • Includes a background SessionCleaner to automatically purge expired sessions.
  • Initializer Integration (khi.default/import-inspection):
    • Added ImportInspectionInitializer to the DAG initialization pipeline to register Connect-RPC routes during server boot.
  • ImportedInspectionRunner:
    • Registers imported .khi files as pre-computed completed results in InspectionTaskServer, keeping full compatibility with task listing and existing result download endpoints.

4. Frontend: Parallel Chunk Upload & UI Integration

  • ImportInspectionClientService:
    • Implemented client using @connectrpc/connect-web with parallel worker pool (maxConcurrency, default: 4) for high-speed chunk uploads.
    • Handles immediate cancellation via AbortController and remote session abortion on failure.
  • InspectionDataLoaderService & Startup Dialog:
    • Migrated the "Open .khi file" action into an import workflow (uploads to the backend and reloads the task list).
    • Keeps the startup dialog open so users can review the imported inspection in the list.
  • Progress Metadata Zero-Division (NaN) Fix:
    • Fixed Progress.updateTotalTaskProgress() generating 0 / 0 = NaN when totalTaskCount is 0 (as in pre-computed imported inspections), which caused json.Marshal on GET /api/v3/inspection to fail with HTTP 500.

Included Revisions

  • wpmvzvov: feat(api): introduce proto-based API management with Connect-RPC
  • wvqrvvyl: feat(api): add a common utility function to register a new connect rpc service
  • ryptzyqy: Refactored API base path management logic
  • qtyknlqz: feat(api): add ImportInspectionService for chunked inspection file upload and import
  • xzwqxqou: feat(web): implement ImportInspectionClientService and update data loader
  • ttuvsqzn: fix(core): prevent NaN percentage when total task count is zero on imported inspections

Verification

  • Go Tests & Linting:
    • make test-go : All tests passing (including table-driven unit tests for ImportSessionManager, ValidateAndExtractMetadata, ImportInspectionInitializer, and ProgressMetadata).
    • make lint-go : 0 issues.
    • make format-go : Formatted.
  • Frontend Tests & Linting:
    • make test-web : 741 / 741 tests passing (ImportInspectionClientService, APIPathUtil, InspectionDataLoaderService, etc.).
    • make lint-web : 0 issues.
    • make build-storybook : Build successful.
    • make pre-commit : All pre-commit checks passed.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Code Review

This pull request introduces a new chunked file import mechanism for inspection files, including a new Connect-RPC service, backend session management with automatic cleanup, and a corresponding frontend client service. The changes also include necessary updates to build and lint configurations, as well as new utility functions for path resolution. I have reviewed the feedback provided and kept all comments as they offer actionable improvements for code robustness and style consistency.

Comment thread pkg/server/importinspection/session.go Resolved
@kyasbal kyasbal added type:feature New feature or request area:backend-core Core backend frameworks, DAG task runner, and server API labels Aug 19, 2026
@kyasbal
kyasbal merged commit 2e353ac into GoogleCloudPlatform:main Aug 19, 2026
15 of 16 checks passed
@kyasbal
kyasbal deleted the push-xzwqxqouptms branch August 19, 2026 09:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:backend-core Core backend frameworks, DAG task runner, and server API type:feature New feature or request

1 participant