Repository navigation
fix(tui): run built-in login in-process so a same-session auth resumes - #201770
wangmiao0668000666 wants to merge 3 commits into
Conversation
An in-process local login persists the credential behind the running runtime's back. The published auth generation still predates it, and a same-process write need not produce a file event on every platform, so the next turn reported the reference as unmaterialized until restart. Rebuild the generation from the persisted store at the login boundary, clearing it first so a dropped observer still republishes. Fixes openclaw#201751
|
🦞👀 Pull request received. I will update this pull request when review starts. ClawSweeper review completeClawSweeper finished reviewing this revision. The review result is being finalized. |
|
|
Codex review: needs real behavior proof before merge. What this changesThis PR runs built-in local TUI login in-process and republishes saved credentials before chat resumes. Example: Sign in to GitHub Copilot from an existing local TUI session, then send “test”.
Review scores
ProductKind: Bug fix · Worth it: Yes · Fix scope: Complete Merge readiness⛔ Blocked before merge - 4 items remain Keep open: the same-session login repair is useful, but both previously reported blockers remain in this head. Priority: P2 Before merge
Findings
Tests
Agent review detailsHow this fits togetherThe local TUI invokes shared provider login, which persists credentials and refreshes the secrets snapshot consumed by embedded model requests. flowchart LR
A[Local TUI auth command] --> B[Shared provider login]
B --> C[Credential store]
B --> D[Post-login refresh]
C --> E[Secrets runtime snapshot]
D --> E
E --> F[Next embedded model request]
Technical reviewBest possible solution: Keep in-process login and existing shutdown ownership, call the secrets refresh owner directly, and preserve the working Codex child invocation. Do we have a high-confidence way to reproduce the issue? Source shows the child-process login and stale SecretRef publication boundaries, while the related PR records matching failures; no target code was executed during this review. Is this the best way to solve the issue? In-process login addresses state ownership, but the existing post-login callback can invoke the authoritative secrets refresh directly without another registration mechanism. Full review comments:
Overall correctness: patch is incorrect AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 87e11d6259e9. Provenance checked
TestingProof path: in-process harness. SecurityNone. EvidenceWhat I checked:
Likely related people:
PR surfaceSource +79, Tests +92. Total +171 across 18 files. Added test files: 0. View PR surface stats
Preflight sourceSource unknown. Source comparison at the observed PR snapshot only. Completion is self-reported; body, policy, tests, execution, and report bytes are not verified. LabelsLabel changes: No label changes. Label justifications:
Rating scale6/6 🦀 challenger crab · 5/6 🦞 diamond lobster · 4/6 🐚 platinum hermit · 3/6 🦐 gold shrimp · 2/6 🦪 silver shellfish · 1/6 🧂 unranked krab. Overall follows the weaker of proof and patch quality; ✨ marks media proof (a screenshot, video, or linked artifact) that directly shows the changed behavior. WorkflowClawSweeper edits this one comment on every review. Comment HistoryReview history (3 earlier review cycles)
Reviewed November 19, 2026, 8:06 PM ET / November 20, 2026, 01:06 UTC (Revision 4). |
ClawSweeper found the refresh hook was only bound inside the external-file refresh callback, so a fresh process that never fired a file event could not republish a same-session login credential. Move the binding to module scope so it exists before any event. The regression now exercises production registration: with no file event fired, the post-login refresh must republish through the hook the secrets runtime bound at load time. Red on the old binding placement, green here.
|
@clawsweeper re-review |
|
🦞👀 Re-review progress:
|
The child-process login could not acquire gateway state ownership while the TUI held it, so /auth failed before the post-login refresh ever ran. Run the login in-process through the TUI's own state owner (sharing the embedded runtime), matching the approved openclaw#200605 shape. The post-login republish still goes through the module-scoped secrets-layer binding (refreshRuntimeAuthProfileStoreAfterLogin), so the persisted store is re-observed and republished into the active runtime generation without relying on an external file event. The prepared-model-runtime lifetimes key is exposed so CLI cleanup releases model generations backed by native workers, letting the TUI exit on SIGTERM while an auth prompt is open. Regression: the built-CLI PTY scenario now exercises cancellation, retry, credential entry, and a resumed request carrying the new credential for both an inline API key and a store-backed token. Co-Authored-By: nebulacoder-v8.0 <[email protected]>
|
@clawsweeper re-review |
|
🦞👀 Re-review progress:
|
|
@clawsweeper re-review — PR body updated to the in-process implementation with real-PTY e2e evidence for both credential shapes (inline API key and store-backed token). |
|
🦞👀 Re-review progress:
|
|
Closing in favor of #200605, which fixes the same reported bug (#201751) plus #200558 with a broader, better-evidenced change: it runs built-in login in-process under the TUI's state owner, republishes the provider snapshot for a warm session, and ships real-PTY proof for both inline-key and store-backed-token logins. That PR is already at Branch |
What Problem This Solves
A local TUI
/authlogin saves the credential and reportsauth flow finished for <provider>, then the very next turn in that same session fails withSecret owner account:[...,github-copilot:github] is configured but unavailable (secret reference was not materialized by the active runtime). A freshopenclawprocess using the same saved credential chats fine. The TUI only works again after a restart.Fixes #201751
Why This Change Was Made
Two compounding defects:
The login ran as a child process.
tui.tsspawned a separateopenclaw models auth loginprocess. That child could not acquire the gateway state ownership the TUI already holds, so it failed withOpenClaw state database is busy... holder <tui-pid>, and the login could not publish its credential into the running session at all. A same-session auth could therefore never resume — only a restart worked.Even when the credential was persisted, nothing republished it.
oauth.tspublishedrequires the stored profile to be present ingetRuntimeAuthProfileStoreSnapshotCore(agentDir). For a profile saved after the session's snapshot was prepared, that snapshot is the pre-login generation, sopublishedis false and the resolver throwsSecretSurfaceUnavailableErrorwith reasonsecret reference was not materialized by the active runtime— the reported message. The old code cleared the published generation and hoped a retained runtime would rebuild it, but nothing triggered the rebuild when the write happened in the same process tree rather than through an observed file event.The fix runs the built-in login in-process (sharing the TUI's state owner and embedded runtime) and rebuilds the published auth generation at the login boundary:
runLocalProviderLogin()insrc/tui/tui-auth-invocation.tscallsmodelsAuthLoginCommandwithcreateNonExitingRuntime()— in-process, no child process, so no state-ownership conflict.refreshAfterLogincallsrefreshRuntimeAuthProfileStoreAfterLogin()(insrc/agents/auth-profiles.ts): it re-observes the persisted auth store (refreshAuthProfileFileState) and republishes through the secrets runtime'srefreshActiveProviderAuthRuntimeSnapshothook.src/secrets/runtime.tsbindsrefreshActiveProviderAuthRuntimeSnapshotas the post-login republish hook at module scope (where it already registers the auth-store external-refresh hook). Binding at load time — not inside the external-file callback — is what lets a fresh process that has never fired a file event republish a same-session login.tui.tsrunAuthFlowkeeps the Codex child branch; for the built-in local path it suspends the TUI (withTuiSuspended), runs the login in-process on the TUI's own abort signal, and records the completion so the next turn waits for it.tui.tsis grandfathered over its line cap, so the new sequence lives intui-auth-invocation.tsandauth-login.types.ts(types moved out of the oversizedauth.ts);tui.tsitself does not grow.modelsAuthLoginCommandgainsrefreshAfterLogin; when it is set and the login did not refresh, it raisesProviderCredentialsSavedError("Sign-in was saved, but this session could not refresh... Restart the local TUI and retry") instead of silently claiming success.PREPARED_MODEL_RUNTIME_LIFETIMES_KEYis hoisted to a shared constant (prepared-model-runtime.{lifecycle,types}.ts), andruntime-cleanup-scope.tsreleases the native-worker-backed model generation on CLI cleanup, so a SIGTERM with an auth prompt open still exits.Behavior is unchanged for Codex-backed logins (Codex owns its own store and keeps its child branch) and for profiles already present in the published generation.
User Impact
Signing in from the local TUI now lets the same session send its next message, instead of requiring a restart. Users who already restart lose nothing; the stale-generation window that produced the misleading error is closed.
Evidence
Discriminating unit regression (fresh-process binding, no file event)
src/secrets/runtime-file-observation.test.tsgainsrepublishes the persisted store through the production-bound refresh hook without a file event. It activates a real secrets snapshot, then callsrefreshRuntimeAuthProfileStoreAfterLogin()with no external-file event having fired, and asserts the post-login refresh republishes through the hook the secrets runtime bound at module scope. This is the exact fresh-process shape: with the binding inside the external-file callback (base) a process that never fired a file event has no hook and reports no republish; with the binding at module scope (head) it republishes.Command:
node scripts/run-vitest.mjs run src/secrets/runtime-file-observation.test.ts --maxWorkers=1.src/agents/auth-profiles/oauth.test.tskeeps a fresh-process contract —does not fabricate a published generation when no secrets runtime bound the republish hookasserts an unbound process reports no republish (rather than inventing a generation). 15/15 on head. Neighbouring owners stay green on head:tui.test.ts,runtime-file-invalidation.test.ts,file-state.test.ts— 50 + 23 tests passed.End-to-end: real built CLI + PTY, both credential shapes
src/tui/tui-pty-local.e2e.test.ts's existing local-auth case is now a parameterized, in-process, real-PTY run against a built CLI and a mock Gateway (itWithBuiltCli.for(["inline API key", "store-backed token"])), reusing the new helpersprepareLocalAuthProviderFixture,signInToLocalPtyProviderandreadLocalPtyAuthProfileintui-pty-local-test-support.ts. Both variants pass on head.Each variant drives
/auth tui-pty-mockthrough the real TTY, completes the provider's prompt with a sentinel value, and asserts that a message in the same session reaches the mock Gateway with the new credential:Enter T05 local auth API key), one follow-up request;authorization === "Bearer <sentinel>",body.model === "gpt-5.5", persisted profile istype: api_keywith the sentinel key.kind: device_code, warm session already active):requestslength is 2 — the warm-session request plus the post-login request with the newBearer <sentinel>— and the persisted profile istype: tokenwithtokenRef.source === "store"and no inlined token, proving the login refreshed the active session rather than just writing storage.Both variants also prove the lifecycle regression fix: after re-opening the auth prompt, the TUI is SIGTERMed and exits with code 0 and no signal (the TUI shutdown handlers run and release the native-worker-backed model generation), then the persisted profile is asserted on disk.
The prior child-process version of this test passed the message-turn assertion only because it reloaded the store from outside the TUI process; the in-process run exercises the actual same-session path, which is the reported scenario.
Honest scope of the proof
The e2e runs a real TTY and a built CLI, but the provider is a local mock provider, not the reported GitHub Copilot device flow (a network device-auth flow this environment cannot drive). The decision boundary that produced the reported error — the post-login republish in a process that never fired a file event — is covered directly by the unit regression above; the e2e covers the full same-session resume path with a real credential of both shapes.
Verification
node scripts/run-vitest.mjs run src/secrets/runtime-file-observation.test.ts --maxWorkers=1— 6/6 on head; the added case failsexpected false to be trueon base.node scripts/run-vitest.mjs run src/agents/auth-profiles/oauth.test.ts --maxWorkers=1— 15/15.node scripts/run-vitest.mjs run src/tui/tui.test.ts src/agents/auth-profiles/runtime-file-invalidation.test.ts src/agents/auth-profiles/file-state.test.ts --maxWorkers=1— 50 + 23 tests passed.tui-pty-local.e2e.test.ts— both credential cases pass against a built CLI on a real PTY (mock Gateway).node scripts/check-line-cap-ratchet.mts --base origin/main --no-merge-base— OK (changed source files;tui.tsdoes not grow).node scripts/check-test-lines-ratchet.mts --base origin/main --no-merge-base— OK.oxfmt --checkandoxlint --tsconfig config/tsconfig/oxlint.core.jsonon the changed files — clean.git diff --check— clean.Scope and risk
oauth.ts+24,runtime-file-observation.ts+13,secrets/runtime.ts+5,tui-auth-invocation.ts+20,auth.ts−33 (types moved toauth-login.types.ts+49),prepared-model-runtime.lifecycle.ts+5/−4,prepared-model-runtime.types.ts+4,runtime-cleanup-scope.ts+3,tui.ts+26/−34 (net −8), plustui-command-context.ts,tui-command-handlers.tsand barrel export. No new config, option, schema, migration, or persistence policy.refreshAuthProfileFileState(persisted-store observer),refreshActiveProviderAuthRuntimeSnapshot(secrets-owned refresh, already registered for auth-store refresh) and thePREPARED_MODEL_RUNTIME_LIFETIMES_KEYconstant; no new resolution primitive.runtime-snapshots/auth-profiles/oauth/runtime-degraded-stateall clear).