Skip to content

feat(api): add polling fallback APIs for streaming RPCs and transparent interceptor - #912

Merged
kyasbal merged 2 commits into
GoogleCloudPlatform:mainfrom
kyasbal:push-qrqksslkxtqz
Aug 27, 2026
Merged

kyasbal merged 2 commits into
GoogleCloudPlatform:mainfrom
kyasbal:push-qrqksslkxtqz

Conversation

@kyasbal

@kyasbal kyasbal commented Aug 26, 2026

Copy link
Copy Markdown
Member

Description

In hosting environments such as Google App Engine Standard or restricted HTTP proxy environments, persistent HTTP/2 and gRPC server-side streaming connections may be buffered, terminated prematurely, or unsupported.
This PR introduces unary polling counterpart APIs alongside existing Server-Side Streaming RPCs, accompanied by a transparent client-side Connect-RPC interceptor. Frontend callers (UI and services) continue using standard streaming patterns (for await (const res of ...)) without modification, while the interceptor transparently routes calls to unary polling RPCs when legacy polling mode is enabled.

Changes

1. Protobuf Definitions

  • Follow standardized API naming conventions:
    • Watch-style APIs: PullPopup, PullServerStat, PullInspections, PullIndexProgress
    • Job-style APIs: OpenWorkbenchSync / CancelOpenWorkbenchSync, FilterTimelineSync / CancelFilterTimelineSync
  • Remove redundant and unused GetServerStat RPC from ServerStatusService.

2. Backend Implementation

  • pkg/server/streamingutil:
    • StateObserver: Utility for tracking snapshot state updates and broadcasting changes.
    • AsyncJobManager: Lifecycle manager for asynchronous background tasks, supporting job-id tracking, progress caching, 15-second abandonment timeout cancellation, 1-minute TTL cache eviction, and automatic cancellation of superseded jobs on new query requests.
  • Service Handlers:
    • Implement PullPopup, PullServerStat, PullInspections, PullIndexProgress, OpenWorkbenchSync, CancelOpenWorkbenchSync, FilterTimelineSync, and CancelFilterTimelineSync.
    • Handle session cleanup in Workbench.Close.

3. Frontend Implementation

  • Connect Interceptor (legacy-polling.interceptor.ts):
    • Intercepts streaming RPC calls when legacy polling mode is active, converting polling Unary responses into an AsyncIterable<Response>.
    • Safely extracts the first request message using iterator.next() to prevent premature iterator cancellation (TypeError: obj[k] is not a function).
    • Automatically sends cancellation RPCs (CancelXXXSync) when AbortSignal is aborted.
    • Registered in connect-client.service.ts.
  • Mode Toggle:
    • Configurable via usePollingLegacy flag in environment.ts, environment.prod.ts, and environment.dev.ts.
    • Dynamically enabled via the ?pollLegacy=true URL query parameter.

4. Documentation & Guidelines

  • Add .agents/skills/streaming_api/SKILL.md documenting API classification, naming rules, lifecycle management, and interceptor patterns.

5. Tests

  • Added unit tests for backend StateObserver and AsyncJobManager.
  • Added unit tests for Pull* and *Sync RPC endpoints in popup_test.go, server_status_test.go, inspection_test.go, and workbench_test.go.
  • Added unit tests for legacy-polling.interceptor.spec.ts covering all streaming adapters, polling cycles, and abort cancellations.
…nt interceptor

Support non-streaming hosting environments (such as App Engine Standard) by introducing unary polling fallback RPCs and a transparent client-side Connect-RPC interceptor.

- Define paired polling RPCs in Protobuf (PullPopup, PullServerStat, PullInspections, PullIndexProgress, OpenWorkbenchSync, FilterTimelineSync, and associated cancellation RPCs).
- Implement StateObserver and AsyncJobManager in pkg/server/streamingutil for lifecycle management, progress caching, 15s abandonment cancellation, and 1m TTL eviction.
- Implement legacy-polling.interceptor in frontend to transparently adapt streaming RPCs into polling unary calls without modifying caller code.
- Add streaming-api skill documenting API classification, naming rules, and interceptor patterns.
- Remove deprecated and redundant GetServerStat RPC.
@kyasbal kyasbal added type:feature New feature or request area:backend-core Core backend frameworks, DAG task runner, and server API labels Aug 26, 2026

@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 transparent polling fallback mechanism for Server-Side Streaming RPCs to support non-streaming hosting environments. It adds paired unary polling RPCs, implements an AsyncJobManager and state observation utilities on the backend, and introduces a frontend Connect interceptor to map streaming calls to polling unary calls. A review comment identifies a potential data race in pkg/server/streamingutil/async_job.go where prev.isDone is accessed without acquiring the read lock.

Comment thread pkg/server/streamingutil/async_job.go Resolved
…ybook mock

- Acquire prev.mu.RLock() before checking prev.isDone in AsyncJobManager.Poll to prevent a data race with background job completion.
- Add pullPopup method to mockClient in text-popup-content.stories.ts to satisfy Client<typeof PopupService> interface.
@kyasbal
kyasbal merged commit 3192967 into GoogleCloudPlatform:main Aug 27, 2026
2 of 3 checks passed
@kyasbal
kyasbal deleted the push-qrqksslkxtqz branch August 27, 2026 00:22
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