Skip to content

[codex] Add Codex autostart ensure fallback - #8

Merged
Ingwannu merged 3 commits into
lidge-jun:mainfrom
Ingwannu:codex/auto-start-proxy-port-fallback
Jun 21, 2026
Merged

[codex] Add Codex autostart ensure fallback#8
Ingwannu merged 3 commits into
lidge-jun:mainfrom
Ingwannu:codex/auto-start-proxy-port-fallback

Conversation

@Ingwannu

@Ingwannu Ingwannu commented Jun 21, 2026

Copy link
Copy Markdown
Owner

What changed

  • Adds ocx ensure, which starts the proxy if needed and refreshes Codex config/model cache before Codex runs.
  • Updates the Codex shim to call ocx ensure on every codex launch instead of duplicating start/status/cache logic in shell scripts.
  • Falls back to a random available local port when the configured port is already busy, then persists that port and injects it into Codex.
  • Adds codexAutoStart as an enabled-by-default setting, exposes it through /api/settings, and adds a dashboard toggle to disable it.
  • Makes ocx init offer Codex shim installation by default while still avoiding npm postinstall mutation.
  • Adds ocx uninstall to stop the proxy, remove any installed service, remove the Codex shim, restore native Codex config/catalog/history, and delete ~/.opencodex before package removal.

Why

If the proxy is not already running, Codex CLI/App sessions can start with stale config/cache or fail until the user manually starts opencodex. Centralizing startup in ocx ensure makes CLI/App autostart consistent and lets the proxy recover from port conflicts without requiring users to edit config by hand.

The full uninstall command also makes cleanup explicit: users can restore native Codex and remove opencodex local state before running their package-manager uninstall.

Validation

  • bun test tests
  • bun run typecheck
  • cd gui && bun run build

lidge-jun added a commit that referenced this pull request Jun 21, 2026
Refined review of PR #8 (codex/auto-start-proxy-port-fallback) with
2 must-fix, 2 should-fix, and 1 note. No code changes — review only.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@lidge-jun

Copy link
Copy Markdown
Owner

Code Review — PR #8 Autostart Ensure Fallback

전체 리뷰 결과: devlog/210_pr8-autostart-ensure-review/10_review.md (dev 브랜치)


Must Fix (2)

1. src/server.ts — 불필요한 dynamic import

/api/settings PUT 핸들러에서 saveConfig를 dynamic import로 다시 불러오고 있으나, 파일 상단에 이미 static import 되어 있음:

// 현재 (불필요):
const { saveConfig: save } = await import("./config");
save(config);

// 수정안:
saveConfig(config);

2. src/cli.tshandleEnsure sync 실패 무음 처리

syncModelsToCodex().catch(() => {})가 두 곳에서 에러를 완전히 삼킴. ensure는 프록시 준비를 보장하는 명령어인데 sync 실패 시 Codex가 stale 캐시로 동작할 수 있음:

// 현재:
await syncModelsToCodex(config.port).catch(() => {});

// 수정안 — 최소한 stderr 경고:
await syncModelsToCodex(config.port).catch(e => {
  console.error(`⚠️  Model sync skipped: ${e instanceof Error ? e.message : String(e)}`);
});

Should Fix (2)

3. Dashboard.tsx — 토글 실패 시 에러 미표시
toggleCodexAutoStart의 catch 블록이 토글을 조용히 원복만 하고 사용자에게 알리지 않음. 네트워크 오류 시 원인 파악 불가.

4. tests/uninstall.test.ts — 소스 문자열 매칭 테스트
소스 파일을 텍스트로 읽어서 함수명 포함 여부만 확인하는 패턴. 리팩토링하면 기능은 그대로인데 테스트가 깨짐. ports.test.ts처럼 실제 동작 테스트가 더 견고함.


Note

5. 포트 선점 TOCTOUfindAvailablePort에서 포트 확인 후 서버 닫고 번호 반환하는 사이 경쟁 조건. 본질적 한계이므로 blocking은 아니나, startServer에서 EADDRINUSE 재시도가 있으면 완벽.


Positives

  • shim 스크립트 간소화 (bash 30줄 → ensure 1줄) — 핵심 성과
  • 죽은 PID 자동 정리, waitForProxy의 config 재로드, quiet uninstall helper
  • i18n 3개 언어 업데이트, codexAutoStart !== false 안전한 opt-out 패턴

lidge-jun added a commit that referenced this pull request Jun 21, 2026
Squash of PR #8 — centralizes startup logic into `ocx ensure`,
adds port fallback when busy, `codexAutoStart` dashboard toggle,
and `ocx uninstall` for clean removal.

Co-Authored-By: 이완우 <Ingwannu@users.noreply.github.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
lidge-jun added a commit that referenced this pull request Jun 21, 2026
- server.ts: remove redundant dynamic import of saveConfig, use static import
- cli.ts: log sync failures in handleEnsure instead of silent catch
- Dashboard.tsx: set error state on autostart toggle save failure

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
lidge-jun added a commit that referenced this pull request Jun 21, 2026
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@Ingwannu
Ingwannu marked this pull request as ready for review June 21, 2026 08:44
@Ingwannu
Ingwannu merged commit 1e2eedb into lidge-jun:main Jun 21, 2026
1 of 2 checks passed
@lidge-jun

Copy link
Copy Markdown
Owner

Review Applied ✅

코드 리뷰 완료 후 아래 수정사항을 dev 브랜치에 반영했습니다:

Must Fix (적용 완료)

  1. src/server.ts — 불필요한 dynamic import 제거, 기존 static import saveConfig 직접 사용
  2. src/cli.tssyncModelsToCodex silent catch 제거, stderr 경고 출력으로 변경

Should Fix (적용 완료)
3. Dashboard.tsx — 토글 실패 시 사용자에게 에러 메시지 표시 추가

관련 커밋: 1c2ccfe fix: address PR #8 review — dynamic import, sync logging, toggle error

devmain 머지 시 이 PR은 close 처리됩니다. 기여 감사합니다! 🦈

Ingwannu added a commit that referenced this pull request Jun 21, 2026
Keep Windows CI green after PR #8 by skipping the POSIX execution-only test on Windows while retaining Windows shim assertions.
lidge-jun added a commit that referenced this pull request Jul 12, 2026
…p audit

BLOCKER fixes:
- outbound.ts: detached pump pattern for SSE streaming — frames now reach
  the client as they arrive instead of buffering until upstream EOF; cancel
  calls reader.cancel() instead of the locked stream (#1)
- system-env.ts: transactional launchctl injection with incremental tracking
  and rollback on mid-flight failure (#2)

MAJOR fixes:
- system-env.ts: POSIX single-quote escaping for all user-controlled values
  in the generated shell file, preventing command injection (#3)
- system-env.ts: exported applySystemEnvToggle for runtime ON/OFF lifecycle (#7)
- claude-messages.ts: 120s hard timeout on native passthrough upstream fetch
  using AbortSignal.timeout, returning Anthropic 504 on expiry (#4)
- management-api.ts: reject non-plain-object PUT bodies (null, array, primitive)
  with 400; strict validation for blockedSkills, tierModels, modelMap, and
  autoCompactWindow (integer, range 100k-1M) (#5, #6)
- management-api.ts: call applySystemEnvToggle after systemEnv config toggle (#7)
- cli/claude.ts: override stale loopback ANTHROPIC_BASE_URL with live port;
  warn on gateway-cache and agent-sync failures instead of swallowing (#8, #10)
- gateway-cache.ts: distinguish discovery failure (keep cache) from authoritative
  empty success (write {models:[]}) (#9)

Test fixes: updated assertions for single-quote shell escaping, empty cache
semantics, validation messages, incremental tracking writes, and PUT response
shape.
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.

2 participants