Skip to content

fix(client): clear disconnected hub token on standalone recycle - #5144

Merged
lidge-jun merged 3 commits into
lidge-jun:devfrom
luvs01:fix/standalone-recycle-token
Sep 19, 2026
Merged

lidge-jun merged 3 commits into
lidge-jun:devfrom
luvs01:fix/standalone-recycle-token

Conversation

@luvs01

@luvs01 luvs01 commented Sep 19, 2026 •

Copy link
Copy Markdown
Collaborator

Motivation

After ocx disconnect removes the hub-issued credential, the standalone recycle respawns the proxy with a copy of process.env. A hub token present in OPENCODEX_API_AUTH_TOKEN (or sourced via OCX_API_TOKEN_FILE) would leak into the replacement standalone process even though the hub just revoked it.

Description

  • MachineApiDeps.scheduleStandaloneRecycle now receives the disconnected connection''''''''''''''''''''''''''''''''s tokenFingerprint, and the machine listener forwards it into the runtime.
  • New standaloneRecycleEnv builds the child environment: it deletes OPENCODEX_API_AUTH_TOKEN and OCX_API_TOKEN_FILE only when the env token''''''''''''''''''''''''''''''''s serviceApiTokenFingerprint matches the disconnected fingerprint, so an independently configured operator credential is preserved.
  • The recycle spawn uses the scrubbed environment; supervised mode (OCX_SERVICE=1) is unchanged.

Tests

  • bun test tests/clients/client-machine-listener.test.ts tests/clients/client-runtime.test.ts — 9 pass. The new client-runtime tests cover removing a matching hub token plus its token-file source and preserving a non-matching operator credential; the listener mock now asserts the forwarded fingerprint is the connection''''''''''''''''''''''''''''''''s own.
  • bun x tsc --noEmit — clean.

Review readiness checklist

This PR stays in draft until every box below is ticked. Tick all four boxes once the requirements are met:

  • All CI tests are green on my local testing.

  • I pushed my PR to the latest dev commit.

  • I resolved all correct Codex and CodeRabbit findings.

  • My PR is ready for review.

Summary by CodeRabbit

  • Bug Fixes

    • Standalone machine recycling now preserves token identity and removes disconnected service credentials from the restarted process environment.
    • Independently configured operator credentials remain available during recycling.
    • Token file references are also cleaned up when they point to disconnected credentials.
  • Tests

    • Added coverage for credential filtering across environment variables and token files.
    • Updated machine listener coverage to verify token fingerprints are passed during recycling.

@coderabbitai

coderabbitai Bot commented Sep 19, 2026 •

Copy link
Copy Markdown
Contributor

Review Change StackReview Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository: lidge-jun/opencodex/.coderabbit.yaml

Review profile: ASSERTIVE

Plan: Advanced

Run ID: 68dd6601-f0fc-400a-9e97-1b26a4a91c8e

📥 Commits

Reviewing files that changed from the base of the PR and between c8fb55b and ba8c5ff.

📒 Files selected for processing (1)
  • tests/clients/client-runtime.test.ts

Included review availability: Your plan provides up to 10 included reviews per hour; 6 remain after this review.


📝 Walkthrough

Walkthrough

The standalone recycle flow now receives the disconnected token fingerprint. It removes matching service-token credentials from the respawned process environment while preserving different operator credentials.

Changes

Token-aware standalone recycle

Layer / File(s) Summary
Runtime environment filtering
src/client/runtime.ts, tests/clients/client-runtime.test.ts
standaloneRecycleEnv removes matching OPENCODEX_API_AUTH_TOKEN values and related token-file pointers. It preserves different operator credentials and does not mutate the source environment. scheduleStandaloneRecycle passes the filtered environment to ocx start.
Disconnect fingerprint propagation
src/client/machine-api.ts, src/client/machine-listener.ts, tests/clients/client-machine-listener.test.ts
The disconnect flow passes state.tokenFingerprint through the listener to scheduleStandaloneRecycle. The listener test verifies the fingerprint argument.

Priority: ⬇️ Low

Estimated code review effort: 2 (Simple) | ~15 minutes

Change: Bug fix

Sequence Diagram(s)

sequenceDiagram
  participant MachineApi
  participant MachineListener
  participant Runtime
  participant ocx_start
  MachineApi->>MachineListener: disconnect with state.tokenFingerprint
  MachineListener->>Runtime: scheduleStandaloneRecycle(tokenFingerprint)
  Runtime->>Runtime: standaloneRecycleEnv(process.env, tokenFingerprint)
  Runtime->>ocx_start: spawn ocx start with filtered environment
Loading
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 5 functions across 5 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes the main change: removing a disconnected hub token during standalone recycle. It matches the runtime, listener, and test changes.
  • Fix all pre-merge checks with AI
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create a new PR

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@github-actions

Copy link
Copy Markdown
Contributor

✅ Deterministic PR hygiene checks passed.

@github-actions github-actions Bot added bug Something isn't working review-ready labels Sep 19, 2026
@github-actions

github-actions Bot commented Sep 19, 2026 •

Copy link
Copy Markdown
Contributor

⏳ DRAFT

  • review readiness checklist open (3/4 boxes ticked).

What to do

  • Tick all four boxes in the PR description once you're done (currently 3/4).

Review readiness checklist

  • ✅ All CI tests are green on my local testing.
  • ⬜ I pushed my PR to the latest dev commit.
  • ✅ I resolved all correct Codex and CodeRabbit findings.
  • ✅ My PR is ready for review.

3/4 boxes ticked.

Automatic draft conversion failed. Please convert this pull request to a draft manually until every box above is ticked.

@lidge-jun

Copy link
Copy Markdown
Owner

리뷰 · 우선순위 66 / 80

ocx disconnect가 허브가 준 키를 지운 다음, 이 컴퓨터의 프록시를 다시 띄워요. 다시 띄울 때 예전에는 지금 프로세스의 환경변수를 그대로 복사했어요. 방금 끊긴 키가 OPENCODEX_API_AUTH_TOKEN에 남아 있으면 새 프로세스로 넘어갔어요.

이 PR은 끊긴 연결의 지문을 넘겨요. 지문은 키를 SHA-256으로 줄인 64글자예요. 환경변수에 있는 키의 지문이 그것과 같으면 그 키와 OCX_API_TOKEN_FILE을 지우고 새 프로세스를 띄워요. 지문이 다르면 운영자가 따로 넣은 키는 남겨요. 서비스로 돌 때(OCX_SERVICE=1)는 자식을 만들지 않고, 예전처럼 종료 코드 1로 나가요. 베이스는 dev예요. 같은 주제로 열린 다른 PR은 없어요.

standaloneRecycleEnv (src/client/runtime.ts 27행) - OPENCODEX_API_AUTH_TOKEN이 비어 있으면 아무 칸도 안 지워요. OCX_API_TOKEN_FILE만 있으면 그 경로가 새 프로세스에 남아요. ocx start는 환경변수 키가 없을 때 그 파일에서 키를 다시 읽어요 (src/cli/index.ts의 startupDataPlaneToken). disconnect가 설치 경로의 파일을 이미 지웠으면 읽기는 실패해요. 그 변수가 다른 파일을 가리키면 허브 키가 남아요. 테스트는 환경변수에 키가 있는 경우만 봐요.

standaloneRecycleEnv (src/client/runtime.ts 29행) - 환경변수 지문이 맞으면 OCX_API_TOKEN_FILE도 같이 지워요. 파일 안 키의 지문은 안 봐요. 환경변수는 허브 키인데 파일은 운영자 키면, 운영자 키 경로까지 빠져요. "운영자 키를 남긴다" 테스트는 환경변수 지문이 다를 때만 맞아요.

메인테이너의 판단이 필요한 지점

OCX_API_TOKEN_FILE을 환경변수와 한 번에 지울지, 파일 내용의 지문이 끊긴 키와 같을 때만 지울지 정해 주세요. 서비스가 띄울 때는 보통 둘이 같은 키예요. 둘이 다를 수 있으면 지금 조건은 넓어요.

감독되는 서비스(OCX_SERVICE=1)를 그대로 두는 건 맞아요. 그 환경은 이 프로세스가 아니라 슈퍼바이저가 다시 넣어요.

너의 추천

파일도 읽어서 지문을 비교해라. 환경변수 키와 파일 키가 각각 끊긴 지문과 같을 때만 그 칸을 지워라. 파일이 없거나 못 읽으면 경로는 둬라. 키만 파일에 있는 경우와, 환경변수와 파일이 다른 키인 경우를 테스트에 넣어라.

이 댓글은 grok-bot이 작성했습니다

@lidge-jun
lidge-jun force-pushed the fix/standalone-recycle-token branch from edd1f17 to c8fb55b Compare September 19, 2026 12:40
@lidge-jun

Copy link
Copy Markdown
Owner

추가 리뷰 · 우선순위 76 / 80

지난 리뷰 다음 커밋 edd1f17이 파일을 열어요. 파일 안의 키를 끊긴 키와 비교해요.

환경변수 OPENCODEX_API_AUTH_TOKEN이 끊긴 키와 같으면 그 칸을 지워요. 그다음 OCX_API_TOKEN_FILE을 읽어요. 파일이 없거나 안이 끊긴 키면 경로도 지워요. 안이 다른 키면 경로는 남겨요. 환경변수 키가 끊긴 키와 다르면 파일을 안 보고 둘 다 남겨요. 키가 파일에만 있는 경우와, 환경변수는 허브 키인데 파일은 다른 키인 경우를 테스트가 봐요.

tests/clients/client-runtime.test.ts 13행 - 첫 테스트의 경로는 /tmp/hub-service-token이에요. 테스트가 그 파일을 만들지 않아요. 지금 코드는 파일을 못 읽으면 경로를 지워요. 그래서 이 테스트는 파일 안이 허브 키라서가 아니라, 그 자리에 파일이 없어서 통과해요. 그 경로에 다른 키 파일이 있으면 실패해요.

메인테이너의 판단이 필요한 지점

환경변수 키가 끊긴 키와 다르면 파일을 안 봐요 (src/client/runtime.ts 27행). 파일에 허브 키가 남아 있으면 그 경로가 새 프로세스에 남아요. 키 값은 안 넘어가요. ocx start는 환경변수에 키가 있으면 파일을 읽지 않아요 (src/lib/service-secrets.ts의 loadServiceTokenFromFile, startupDataPlaneToken). 경로까지 지우려면 이 경우에도 파일을 읽으면 돼요. 안 지워도, 끊긴 키가 환경변수로 복사되던 문제는 없어요.

못 읽는 파일 경로는 지우세요. 지난 추천은 남기라는 쪽이었어요. disconnect가 파일을 이미 지워서 못 읽는 경우가 많아요. 그때 경로를 남기면 그 파일이 허브 키일 수 있어요.

너의 추천

첫 테스트만 고치세요. /tmp/hub-service-token 대신 임시 파일을 만들고, 그 안에 허브 키를 쓰세요. 경로가 지워지는지 확인하면 돼요. 지우는 로직은 더 손대지 마세요.

이 댓글은 grok-bot이 작성했습니다

@luvs01
luvs01 marked this pull request as ready for review September 19, 2026 12:55
@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.
To continue using code reviews, add credits to your account and enable them for code reviews in your settings.

@github-actions
github-actions Bot marked this pull request as draft September 19, 2026 13:02
@luvs01

luvs01 commented Sep 19, 2026

Copy link
Copy Markdown
Collaborator Author

Author follow-up: the token-file test now creates a real temp file containing the hub token and asserts the pointer is dropped (ba8c5ff). Removal logic unchanged per review.

@luvs01
luvs01 marked this pull request as ready for review September 19, 2026 16:26
@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.
To continue using code reviews, add credits to your account and enable them for code reviews in your settings.

@github-actions
github-actions Bot marked this pull request as draft September 19, 2026 16:35
@luvs01
luvs01 marked this pull request as ready for review September 19, 2026 17:58
@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.
To continue using code reviews, add credits to your account and enable them for code reviews in your settings.

@github-actions
github-actions Bot marked this pull request as draft September 19, 2026 18:18
@luvs01
luvs01 marked this pull request as ready for review September 19, 2026 19:03
@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.
To continue using code reviews, add credits to your account and enable them for code reviews in your settings.

@github-actions
github-actions Bot marked this pull request as draft September 19, 2026 19:19
@luvs01
luvs01 marked this pull request as ready for review September 19, 2026 19:23
@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.
To continue using code reviews, add credits to your account and enable them for code reviews in your settings.

@github-actions
github-actions Bot marked this pull request as draft September 19, 2026 19:26
@luvs01
luvs01 marked this pull request as ready for review September 19, 2026 19:48
@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.
To continue using code reviews, add credits to your account and enable them for code reviews in your settings.

@github-actions
github-actions Bot marked this pull request as draft September 19, 2026 19:48
@luvs01
luvs01 marked this pull request as ready for review September 19, 2026 20:36
@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.
To continue using code reviews, add credits to your account and enable them for code reviews in your settings.

@github-actions
github-actions Bot marked this pull request as draft September 19, 2026 20:36
@lidge-jun
lidge-jun marked this pull request as ready for review September 19, 2026 21:04
@lidge-jun
lidge-jun merged commit d764bb4 into lidge-jun:dev Sep 19, 2026
44 of 45 checks passed
lidge-jun added a commit that referenced this pull request Sep 19, 2026
tests/clients/client-runtime.test.ts arrived with #5144 and was recorded
in neither scripts/test-layout/layout.json explicit nor
tests/fixtures/test-layout-expected.json, so the layout guards fail for
every branch whose merge ref includes current dev.

The file already sits in the domain directory its name implies, so the
registration is the whole fix: clients in both inventories, matching the
other tests/clients entries. No guard was relaxed and no seed regex was
widened to make the file resolve implicitly.

Reported by the contract-campaign task, which verified the omission by
static blob lookup on dev before raising it.

No local suite, focused test, typecheck or build was run. Exact-head
hosted CI is the execution evidence.
lidge-jun added a commit that referenced this pull request Sep 19, 2026
* refactor(oauth): move in-flight login state into its own module

src/oauth/index.ts reached 2009 lines after #5090 and is not in the
file-size baseline, so it tripped NEW_OVERSIZED at the 2000-line
threshold and failed the gate for every branch whose merge ref includes
current dev.

Raising the cap is not available: updateBaseline only lowers, and
tests/ci-workflows/file-size-ratchet.test.ts asserts it. Trimming the
comments that #5090 added to explain why a raw paste carrying an
explicit state suffix is state-bearing would have fit the budget and is
the wrong trade.

src/oauth/login-flow-state.ts takes the bookkeeping for a login that has
started and not yet settled: the per-provider state, abort and manual
paste maps, the slot helpers, the flow-state reconciliation, and
submitManualLoginCode. The cut follows a seam rather than a line count.
Nothing moved reads or writes a stored credential, and nothing left
behind touches an in-flight slot. index.ts re-exports
reconcileOAuthFlowState and submitManualLoginCode, so the management
routes and the Codex login flow that import them are unchanged.

The raw code#state validation from #5090 moves with submitManualLoginCode
unchanged, comments included.

index.ts ends at 1894 lines.

No local suite, focused test, typecheck or build was run. Exact-head
hosted CI is the execution evidence.

* fix(adapters): keep the bounded image decode inside the file's size cap

src/adapters/openai-chat.ts reached 823 lines against a committed cap of
822 after #5208, so the ratchet reports GREW and the gate fails for every
branch whose merge ref includes current dev.

The overage is one line out of a six-line addition, which does not justify
extracting a module. Naming the options object instead of spreading it
across three lines expresses the same call with the same arguments and
leaves the file at 821, one line under the cap. No comment was removed and
no behaviour changed: normalizeOpenAIChatImages receives the same
tierBias and abortSignal, and the rejection handler still rethrows on a
real abort and otherwise finishes.

No local suite, focused test, typecheck or build was run. Exact-head
hosted CI is the execution evidence.

* test(layout): register the client runtime test in both inventories

tests/clients/client-runtime.test.ts arrived with #5144 and was recorded
in neither scripts/test-layout/layout.json explicit nor
tests/fixtures/test-layout-expected.json, so the layout guards fail for
every branch whose merge ref includes current dev.

The file already sits in the domain directory its name implies, so the
registration is the whole fix: clients in both inventories, matching the
other tests/clients entries. No guard was relaxed and no seed regex was
widened to make the file resolve implicitly.

Reported by the contract-campaign task, which verified the omission by
static blob lookup on dev before raising it.

No local suite, focused test, typecheck or build was run. Exact-head
hosted CI is the execution evidence.

---------

Co-authored-by: lidge-jun <[email protected]>
@luvs01
luvs01 deleted the fix/standalone-recycle-token branch September 19, 2026 21:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants