Skip to content

feat(popup): migrate popup service to Connect-RPC with server-streaming WatchPopup and polymorphic UI registry - #897

Merged
kyasbal merged 3 commits into
GoogleCloudPlatform:mainfrom
kyasbal:push-zonytxtv
Aug 25, 2026
Merged

kyasbal merged 3 commits into
GoogleCloudPlatform:mainfrom
kyasbal:push-zonytxtv

Conversation

@kyasbal

@kyasbal kyasbal commented Aug 25, 2026 •

Copy link
Copy Markdown
Member

Summary

This PR migrates the interactive user popup system in KHI from legacy polling-based REST endpoints to a Connect-RPC service featuring server-streaming WatchPopup and an Open-Closed Principle (OCP) compliant polymorphic UI component registry.

Background & Motivation

  1. Proxy Timeout Resilience & Low Latency: Previously, clients polled the REST endpoint periodically to check for active popups or OAuth completion. The new architecture uses a server-streaming Connect-RPC WatchPopup endpoint with a resilient 30-second server cycle. If an intermediary proxy terminates long-lived streaming connections, the frontend automatically reconnects immediately without stalling or requiring timer polling loops.
  2. Open-Closed Principle (OCP): Adding new popup input types previously required modifying centralized type switches across both backend HTTP handlers and frontend Angular dialog components. Now:
    • Backend: Any popup implements the popup.PopupForm interface, handling its own proto construction, input validation, and answer completion.
    • Frontend: The PopupRegistry service maps oneof proto payloads to dynamic UI content components instantiated via *ngComponentOutlet.
  3. Server-Driven Dismissal: When an OAuth authentication flow completes in the background, the server pushes a dismissal event through WatchPopup, automatically closing the dialog without client-side periodic polling.

API Endpoint Path Changes

Change Protocol / Type HTTP Method Endpoint Path Description
❌ Removed REST (JSON) GET /api/v1/popup Fetches active popup metadata (legacy periodic polling).
❌ Removed REST (JSON) POST /api/v1/popup Submits / validates popup answer (branched via validate_only).
➕ Added Connect-RPC (Streaming) POST /api.v1.PopupService/WatchPopup Real-time popup display & dismissal events (Server-Streaming, 30s auto-reconnect cycle).
➕ Added Connect-RPC (Unary) POST /api.v1.PopupService/ValidatePopupAnswer Validates popup input answer without submitting.
➕ Added Connect-RPC (Unary) POST /api.v1.PopupService/SubmitPopupAnswer Submits popup input answer and completes the interaction.
🔄 Unchanged HTTP (Redirect) GET /api/v1/oauth OAuth authentication redirect callback target.

Key Changes

1. Protobuf (proto/api/v1/popup.proto)

  • Defined PopupService with WatchPopup (server streaming), ValidatePopupAnswer (unary), and SubmitPopupAnswer (unary).
  • Structured polymorphic payloads under PopupForm.payload oneof:
    • TextPopupPayload (text inputs with placeholder and validation).
    • OAuthLoginPopupPayload (OAuth authorization flows with auth_url).

2. Go Backend

  • pkg/server/popup:
    • Defined the polymorphic PopupForm interface (BuildProtoForm, Validate, Answer).
    • Added TextPopupForm implementation.
    • Refactored PopupManager to manage active forms, stream notifications via channels, and delegate validation/submission to the active form.
  • pkg/api/googlecloud/oauth:
    • Implemented popup.PopupForm for oauthTokenPopup, replacing legacy metadata mappings and serving the OAuth authorization URL.
  • pkg/server/api/v1/popup.go:
    • Implemented Connect-RPC PopupServer delegating directly to PopupManager.
    • Removed legacy REST /api/v1/popup handlers and centralized switch statements.

3. Angular Frontend

  • PopupRegistry (popup-registry.service.ts):
    • Implemented dynamic component registry mapping proto payload cases ('text', 'oauthLogin') to child content components.
  • Dynamic Content Components:
    • TextPopupContentComponent: Handles text input forms with real-time validation and submission.
    • OAuthLoginPopupContentComponent: Handles opening the OAuth login window, waiting for server completion, and allowing re-opening.
  • Container Dialog (RequestUserActionPopupComponent):
    • Converted into a host container dynamically loading content components via *ngComponentOutlet="component; inputs: contentInputs()".
  • PopupManagerImpl (popup-manager-impl.ts):
    • Replaced legacy polling with an async generator loop watching the WatchPopup Connect-RPC stream, with automatic reconnect handling.

Verification

  • Backend Unit Tests: go test -v ./pkg/server/... ./pkg/api/googlecloud/oauth/... passed.
  • Frontend Unit Tests: npx ng test --watch=false --browsers=ChromeHeadless passed (741/741 tests).
  • Storybook Stories: TextPopupContentComponent and OAuthLoginPopupContentComponent stories build cleanly (npm run build-storybook).
  • Code Quality & Linter: make lint-go, make lint-web, make format-go, make format-web, and make pre-commit passed with 0 issues.

@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 parallel chunk parsing, direct YAML serialization, trigram indexing with Roaring Bitmaps, and a sparse bitset representation for filter results to optimize performance, alongside migrating the popup system to Connect-RPC. The reviewer identified several critical improvement opportunities: making DirectYAMLSerializer thread-safe by allocating the buffer locally, serializing ShowPopup calls in PopupManager to prevent concurrent state corruption, refining the chunk partitioning logic in filter_log_cel.go and parallel.go to avoid empty chunks and potential nil pointer dereferences, and removing CPU profiling code from the production path of BuildTrigramIndexWithProgress.

Comment thread pkg/server/workbench/filter_log_cel.go Resolved
Comment thread pkg/server/popup/types.go Resolved
Comment thread pkg/server/popup/types.go Resolved
Comment thread pkg/model/khifile/v6/direct_yaml.go Resolved
Comment thread pkg/model/khifile/v6/direct_yaml.go Resolved
Comment thread pkg/common/worker/parallel.go Resolved
Comment thread pkg/server/workbench/index.go Resolved
@kyasbal

kyasbal commented Aug 25, 2026

Copy link
Copy Markdown
Member Author

/gemini review

@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 refactors the popup management system in KHI, migrating the backend popup system from REST endpoints to a Connect-RPC service (PopupService) and updating the frontend to dynamically render popup content components (such as text input and OAuth login) based on the protobuf payload, replacing HTTP polling with a Connect-RPC stream. The code review identified several critical issues, including concurrency bugs in PopupManager.ShowPopup that could leak goroutines, a potential server panic from a non-idempotent unsubscribe function in the subscription logic, a race condition in TextPopupContentComponent where out-of-order validation responses could overwrite newer results, and a UI bug in main.component.ts that prevents a new popup dialog from opening when transitioning directly between popups.

Comment thread pkg/server/popup/types.go Resolved
Comment thread pkg/server/popup/types.go Resolved
Comment thread pkg/server/popup/types.go Resolved
Comment thread pkg/server/api/v1/popup.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 25, 2026
@kyasbal
kyasbal merged commit 14e2233 into GoogleCloudPlatform:main Aug 25, 2026
16 checks passed
@kyasbal
kyasbal deleted the push-zonytxtv branch August 25, 2026 02:32
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