Skip to content

fix: detect and replace stale playground instances on target port#55

Closed
heimanba wants to merge 3 commits into
mainfrom
fix/playground-stale-instance-replacement
Closed

fix: detect and replace stale playground instances on target port#55
heimanba wants to merge 3 commits into
mainfrom
fix/playground-stale-instance-replacement

Conversation

@heimanba

Copy link
Copy Markdown
Contributor

Problem

When upgrading @openagentpack/cli (e.g. from @latest to @beta), a previously-started playground process may still occupy port 4848. The new instance silently binds to 4849, but the browser opens 4848 — leaving the user stuck on a stale UI with missing features (e.g. no deployment/schedule UI).

Root Cause

  • agents playground spawns a playground subprocess that auto-increments the port when the preferred one is busy
  • There was no mechanism to detect what was occupying the port
  • The old playground /health endpoint only returned { "status": "ok" } with no version or identity information

Solution

1. Enriched /health endpoint (packages/playground/src/server.ts)

GET /health → { "status": "ok", "playground": { "version": "0.3.0-beta-xxx", "pid": 12345 } }

Registered before the server routes so it takes precedence over the generic health check from apps/server.

2. Pre-launch probe + auto-replace (packages/cli/src/commands/playground.ts)

Before spawning a new playground, the CLI now probes the target port:

Port state Behavior
Free Normal startup
Same-version playground running Reuse it — open browser, skip spawn
Different-version playground running SIGTERM → wait for port release → start new version
Non-playground process / no /health Proceed normally (playground auto-increments port)
Old playground without version in /health Same as non-playground (backward-compatible)

3. Cache-Control for static assets

Added Cache-Control: no-cache middleware for /assets/* — filenames are stable (not content-hashed) due to console embed constraints, so browsers must revalidate on every navigation to avoid serving stale JS/CSS after an upgrade.

heimanba added 3 commits July 21, 2026 20:23
- 新增 scenario/git-repo.yaml,包含 BYOC 测试环境、身份、通道、环境、隧道、vault、agent 等配置
- 支持 Qoder BYOC 内网接入验证,集成 GitHub 仓库资源端到端测试和 Alibaba BYOC 助手代理
- 设计配置引用真实 environment_id、tunnel_id,token 通过环境变量注入,保证安全性
- 在 scenario/pr.md 中添加 OpenAgentPack 正式开源说明,阐述 CMA 团队远程同事价值与应用场景
- 说明通过 Git 和 YAML 管理 CMA,实现远程 Agent 的共享、审查、迭代和持续运行
- 介绍 CMA 的自动化管理流程,包括同步、校验、计划及应用,支持多平台迁移与自动运行

Change-Id: I8b178fbb412b10dc2bc58b668a281388725f627d
Co-developed-by: Qoder <noreply@qoder.com>
- 删除了byoc identity及相关配置,简化身份管理
- 移除byoc-dingtalk频道配置,减少无用渠道定义
- 去除内存存储相关注释及配置,避免冗余说明
- 精简agents中github-session-agent配置,保持核心测试逻辑
- 精简delivery配置,去除forward类型定义,明确当前配置结构

Change-Id: I4bbbe17522e6e39c63555a80fb8441807112e5cf
Co-developed-by: Qoder <noreply@qoder.com>
When upgrading the CLI (e.g. from stable to beta), a previously-started
playground process may still occupy the default port. The new instance
silently binds to the next port, but the browser opens the old one —
leaving the user stuck on a stale UI.

Changes:

- playground /health now returns { playground: { version, pid } } so the
  CLI can identify what is running on the port
- CLI probes the target port before spawning a new playground:
  - same version → reuse the existing instance, open browser, exit
  - different version → SIGTERM the old process, wait for port release,
    then start the new version
  - non-playground / no response → proceed normally (backward-compatible)
- Add Cache-Control: no-cache to static assets served by the playground
  to prevent browsers caching stale JS/CSS across upgrades (filenames
  are stable, not content-hashed, due to console embed constraints)

Change-Id: Ida50d15b60802fc8b56e13d2d9318c2cc077ad46
Co-developed-by: OpenCode <noreply@opencode.ai>
@heimanba heimanba closed this Jul 22, 2026
@heimanba
heimanba deleted the fix/playground-stale-instance-replacement branch July 22, 2026 03:16
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.

1 participant