Skip to content

feat: GitHub-token heartbeat + real-CLI e2e (fixes 2 Codex /responses bugs) - #7

Merged
wangcansunking merged 7 commits into
masterfrom
worktree-github-token-heartbeat
Jun 28, 2026
Merged

wangcansunking merged 7 commits into
masterfrom
worktree-github-token-heartbeat

Conversation

@wangcansunking

Copy link
Copy Markdown
Owner

Summary

Two themes on this branch:

  1. GitHub-token heartbeat — the supervisor now re-checks every ~60s whether the stored GitHub login still works, and the TUI footer shows a live github ✓ / ✗ /login badge, so an expired/revoked login surfaces within ~60s instead of only on the next failed request or a manual /status.
  2. Real-CLI e2e — a true black-box Docker test driving the actual claude and codex CLIs against the real daemon. It caught (and this PR fixes) two Codex /responses bugs that curl and unit tests missed.

Heartbeat

  • probeGithubAuth classifies a definitive 401/403 (→ expired) vs a transient timeout/5xx/network error (→ keep last-known-good), so a single GitHub hiccup never flips the badge to "expired". nextGithubStatus is a pure, sticky reducer. signed-out (no token) stays distinct from expired.
  • New optional github field on /api/status (absent until the first probe → existing consumers unaffected); the TUI's existing 2s poll drives the badge. /status does a live check; HUD footer restructured to github · daemon / web · claude · codex.
  • Addresses the /code-review findings: /status is authoritative again (was reading a stale cache), isCopilotTokenValid delegates to probeGithubAuth, /doctor shares the signed-out message, start() is idempotent. The unbounded-stickiness / 403 / boot-pending tradeoffs are documented in-code rather than half-fixed.

Codex /responses bug fixes (found via the real codex CLI)

  1. Tool-translation 400. Codex sends custom (apply_patch) and tool_search tools; the inbound translator forwarded every non-function tool as a bare {type} with no name → Copilot 400 "Missing required parameter: tools[N].name" → surfaced to Codex as "stream closed before response.completed". Fix: keep custom tools as named tools; allow-list only the nameless hosted tools Copilot accepts (web_search); drop unknown nameless tools.
  2. Empty terminal events. ResponsesSSE sent output_text.done / content_part.done / output_item.done with empty text, so Codex completed the turn but rendered nothing. Fix: replay the accumulated text in all three done events and populate response.completed.response.output.

Tests

  • npm test → 394 passed (56 files), tsc build clean. Adds: heartbeat unit tests, 12 hermetic in-process Codex /responses cases (EP-27…EP-38), probeGithubAuth cases, regression tests for both Codex fixes.
  • Real Linux container e2e (e2e/docker/): the heartbeat (Dockerfile + heartbeat-e2e.mjs) and the real CLIs (Dockerfile.cli + cli-e2e.sh) — node:22, installs @anthropic-ai/claude-code + @openai/codex, mounts a real token, asserts codex exec → CODEX_OK, claude -p → CLAUDE_OK, and claude gateway web search → a grounded answer. Writes a markdown report after each run. All passed.

Security

No secrets committed — the only key in any file is the placeholder copilot-reverse-local; the real GitHub token / WebIQ key mount at runtime via -v, and .gitignore now guards creds.json / webiq.json / report artifacts.

Test plan

  • npm test green; npm run build clean.
  • HUD shows github ✓ on a valid login; flips to ✗ /login within ~60s of revoking the token.
  • docker build -f e2e/docker/Dockerfile.cli … then run with a mounted token → codex + claude + web-search checks all pass; report.md written.
  • Codex (codex exec) completes a turn against the daemon and renders text (regression for both /responses fixes).

🤖 Generated with Claude Code

wangcansunking and others added 7 commits June 28, 2026 17:49
Periodically (every 60s, plus once ~2s after boot) re-check whether the
stored GitHub token still exchanges for a Copilot token, so an expired or
revoked login surfaces within ~60s instead of only on the next failed
request or a manual /status.

- probeGithubAuth classifies a definitive 401/403 (→ expired) vs a transient
  timeout/5xx/network error (→ keep last-known-good), so a single GitHub
  hiccup never flips the UI to "expired".
- GithubHeartbeat (supervisor-side) caches a GithubStatus via the pure,
  sticky nextGithubStatus reducer; exposed through a new optional `github`
  field on /api/status (absent until the first probe → existing consumers
  unaffected).
- The TUI's existing 2s status poll drives a live footer badge
  (github ✓ / ✗ /login); /status reads the cached value (no redundant check).
  signed-out (no token) stays distinct from expired.

Verified in-process against the real token: connected / signed-out /
expired / sticky-on-transient all correct.

Co-Authored-By: Claude <noreply@anthropic.com>
Boots the real control API + a real GithubHeartbeat.start() inside a Docker
(node:20) container, listens on a real port, and drives it over real HTTP
(GET /api/status) against the real GitHub API. All four states pass:
connected (real token → real Copilot token exchange, mounted read-only),
signed-out (creds removed), expired (bad token → a real GitHub 401), and
HTTP delivery of the github field.

The container's own network namespace sidesteps the host's port-7890
conflict; only the probe interval is shortened for the test, which required
making GithubHeartbeat's interval/initial-delay injectable (prod still
defaults to 60s/2s).

Adds e2e/docker/{Dockerfile,heartbeat-e2e.mjs,README.md} + .dockerignore.

Co-Authored-By: Claude <noreply@anthropic.com>
The login badge now reads "登录" and sits right after the model name (before
daemon/web), making the login state the first status the eye lands on.

Co-Authored-By: Claude <noreply@anthropic.com>
Row 1 now shows "github" login state and daemon; row 2 shows web search and
the claude/codex client badges. Drop the model name from the footer (it still
drives the model picker and chat). Revert the badge label to English.

Co-Authored-By: Claude <noreply@anthropic.com>
- /status now does the live githubStatus() check first (the cached heartbeat
  can be up to ~60s stale after a revoke), restoring the on-demand authority
  that the cache-first ordering had turned into dead code.
- isCopilotTokenValid delegates to probeGithubAuth — one token-exchange path.
- Share SIGNED_OUT_DETAIL so /doctor and the HUD show the same "run /login"
  hint for the signed-out state (they had diverged).
- start() is now idempotent (guard against leaking a second timer).
- Comments on probeGithubAuth / nextGithubStatus now state the real
  limitations instead of over-promising: the transient stickiness is
  UNBOUNDED (a sustained non-401/403 fault never surfaces), 403 is treated as
  definitive despite GitHub using it for some rate-limits, and a boot-time
  transient leaves the badge pending/absent.

Full suite green (379), build clean.

Co-Authored-By: Claude <noreply@anthropic.com>
Driving the real codex CLI against the daemon surfaced two bugs that curl and
unit tests missed:

1. Tool translation 400. Codex sends `custom` (apply_patch) and `tool_search`
   tools; the inbound translator forwarded every non-function tool as a bare
   {type} with no name, so Copilot rejected the request with 400 "Missing
   required parameter: tools[N].name" and the stream errored — surfacing to
   Codex as "stream closed before response.completed". Fix: keep `custom`
   tools as named tools, and allow-list only the nameless hosted tools Copilot
   accepts (web_search); drop unknown nameless tools instead of forwarding a
   malformed one. (tool_search is excluded — Copilot needs a deferred tool.)

2. Empty terminal events. ResponsesSSE sent output_text.done / content_part.done
   / output_item.done with empty text, so Codex completed the turn but rendered
   no assistant text (it reconstructs the message from the done events, not just
   the deltas). Fix: accumulate the streamed text and replay it in all three
   done events, and populate response.completed.response.output.

Adds 12 hermetic in-process /responses cases (EP-27..EP-38) as fast regression
and extends wired() to forward a gateway runner.

Co-Authored-By: Claude <noreply@anthropic.com>
A true black-box e2e: the actual `claude` (Claude Code) and `codex` CLIs run
inside a node:22 container against the real worker daemon, with a real GitHub
token (+ optional WebIQ key) mounted read-only. Asserts codex exec round-trips
/openai/responses (CODEX_OK), claude -p round-trips /anthropic (CLAUDE_OK), and
claude's gateway web_search returns a grounded answer. Writes a markdown report
after each run (mount -v <dir>:/out to capture it).

No secrets committed: the only key in any file is the placeholder
copilot-reverse-local; real creds/keys mount at runtime. Hardens .gitignore
against creds.json / webiq.json / report artifacts.

Adds Dockerfile.cli + cli-e2e.sh; documents both in e2e/docker/README.md and
e2e/cases.md.

Co-Authored-By: Claude <noreply@anthropic.com>
@wangcansunking
wangcansunking merged commit dcac836 into master Jun 28, 2026
4 checks passed
wangcansunking added a commit that referenced this pull request Jun 29, 2026
…plate, config, banner (#15)

* feat(tui): scope+model status, chat-setup confirmation, parity, report template, config, banner

- #6 /status + HUD show each client's scope AND pinned model, not a bare check
- #5 chat setup_claude/codex require scope+model (ask first, never assume)
- #7 add recent_errors + metrics chat tools to match slash commands
- #4 /report body follows the #5 template (Summary/Environment/Repro)
- #3 GitHub heartbeat interval/delay now configurable via AppConfig
- #1 versioned "what's new" banner, shown ~3 launches then suppressed
- #2 README reflects guards, runaway reporting, scope+model, config knobs

Co-Authored-By: Claude <noreply@anthropic.com>

* feat(report): add #5-style issue template; banner = major changes only

- .github/ISSUE_TEMPLATE/bug.yml (Summary/Environment/Repro/Diagnostics/fixes) so manual
  issues match the rich #5 shape; /report still auto-fills the same sections.
- what's-new banner trimmed to major changes only (the freeze fix); minor polish dropped.

Co-Authored-By: Claude <noreply@anthropic.com>

---------

Co-authored-by: Claude <noreply@anthropic.com>
@wangcansunking
wangcansunking deleted the worktree-github-token-heartbeat branch July 1, 2026 07:53
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