Skip to content

fix(happy-cli,happy-server): avoid false vendor token timeouts during connect#986

Open
wang-kaopu wants to merge 2 commits intoslopus:mainfrom
wang-kaopu:fix-983-register-timeout
Open

fix(happy-cli,happy-server): avoid false vendor token timeouts during connect#986
wang-kaopu wants to merge 2 commits intoslopus:mainfrom
wang-kaopu:fix-983-register-timeout

Conversation

@wang-kaopu
Copy link
Copy Markdown
Contributor

Fixes #983.

Summary

happy connect codex could fail with timeout of 5000ms exceeded even when vendor token registration was still progressing normally. The old flow treated registration as a single synchronous HTTP call with a hardcoded 5s client timeout, so it could not distinguish a slow-but-active request from a genuinely stalled one.

This change converts vendor token registration into a small long-task handshake for the connect register path. The server now accepts the work, tracks task stage and heartbeat in memory, and exposes task status for polling. The CLI waits on observable progress instead of a fixed request timeout, and reports task stages while waiting.

What Changed

  • switched registerVendorToken() to an activity-aware long-task wait loop in the CLI
  • changed POST /v1/connect/:vendor/register to return 202 Accepted with task metadata
  • added GET /v1/tasks/:taskId for task status polling
  • added an in-memory long-task store for registration state, stage, and heartbeat tracking
  • added CLI progress output for accepted/encrypting/persisting/succeeded stages
  • updated API documentation for the new contract
  • added regression tests for progress, stall, failure, and heartbeat behavior

Validation

  • dynamic tests passed:
    • CLI: 14 passing
    • Server: 4 passing
  • type diagnostics passed for happy-cli and happy-server

Known Limitation

The long-task store is intentionally in-memory for this first rollout. That keeps the registration path lightweight for a single-process foreground wait flow, but tasks do not survive server restarts and are not shared across multiple server instances yet.

… connect (slopus#983)

* switch vendor token registration to a long-task handshake with task polling and heartbeats

* add CLI and server regression coverage for progress, stall, and failure paths
Copilot AI review requested due to automatic review settings April 4, 2026 07:53
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR updates the vendor token registration flow used by happy connect to avoid client-side timeouts by switching from a single blocking request to a server-tracked long-task handshake that the CLI can poll and display progress for.

Changes:

  • Server: change POST /v1/connect/:vendor/register to return 202 Accepted with task metadata and add GET /v1/tasks/:taskId for polling task status.
  • Server: introduce an in-memory long-task store with stage/state tracking and heartbeat updates during persistence.
  • CLI: update registerVendorToken() to poll task status with idle/absolute timeouts and surface stage progress output; add regression tests and API docs updates.

Reviewed changes

Copilot reviewed 8 out of 8 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
packages/happy-server/sources/app/api/routes/connectRoutes.ts Converts vendor token registration into an async long-task + adds task status polling route.
packages/happy-server/sources/app/api/routes/connectRoutes.test.ts Adds tests for accepted→running→succeeded flow, heartbeat updates, and failure surfacing.
packages/happy-server/sources/app/api/longTaskStore.ts Adds in-memory task store, TTL pruning, and heartbeat helper.
packages/happy-cli/src/commands/connect.ts Adds CLI progress output and passes onProgress callback into registration call.
packages/happy-cli/src/commands/connect.test.ts Tests progress callback wiring and de-duplication of stage output.
packages/happy-cli/src/api/api.ts Implements long-task polling logic for vendor registration (202 handling, progress, stall detection).
packages/happy-cli/src/api/api.test.ts Adds tests for long-task completion, stalling, and failure behavior.
docs/api.md Documents the new 202 + task polling contract.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@wang-kaopu wang-kaopu force-pushed the fix-983-register-timeout branch from e9300d8 to 1a7a53f Compare April 4, 2026 08:56
Copy link
Copy Markdown
Contributor Author

Follow-up update after addressing Copilot robustness feedback.

Additional changes on top of the original long-task flow:

  • defer connect register task execution with setImmediate() so the route can return 202 Accepted before synchronous work starts
  • sanitize task failure payloads behind a stable errorCode instead of returning raw backend error messages
  • handle /v1/tasks/:taskId 404 in the CLI with a clearer retry message when the in-memory task record is lost
  • update the older happy-app consumer to support both legacy { success: true } responses and the new long-task polling contract

Validation run locally:

  • passed: cd packages/happy-server && node ../../node_modules/vitest/vitest.mjs run sources/app/api/routes/connectRoutes.test.ts
  • passed: cd packages/happy-cli && node ../../node_modules/vitest/vitest.mjs run src/api/api.test.ts
  • passed: cd packages/happy-app && node ../../node_modules/vitest/vitest.mjs run sources/sync/apiServices.spec.ts
  • tsc --noEmit still fails in happy-server, happy-cli, and happy-app, but the failures are pre-existing repo-wide issues (@slopus/happy-wire resolution, Prisma exports, and unrelated existing type errors), not from these follow-up changes

Current head:

  • 1a7a53fe fix(happy-cli,happy-server,happy-app): harden connect register task flow

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.

happy connect codex fails with "timeout of 5000ms exceeded" when registering vendor token

2 participants