fix: Use the connected key for the rest of the run - #64
Open
chmaltsp wants to merge 1 commit into
Open
Conversation
The analyze step re-read the key with findExistingApiKey, which returns process.env.SEAM_API_KEY ahead of any dotenv file. A run that connected through the browser or a pasted key therefore planned the integration with whatever SEAM_API_KEY the shell happened to export, not the key it had just verified. When those keys belong to different workspaces the run does not fail: it reports the workspace it connected to and then works against the other one. It only surfaces as an error when the exported key is invalid, as "Couldn't start the AI session". Carry the verified key through settleOn instead. The browser and pasted paths called setWorkspace and advanceAfterAuth directly, bypassing the one place that records a connection, which is why the 'browser' and 'pasted' members of its source union were unreachable. Routing them through settleOn fixes the key selection and records those runs. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
The
analyzestep re-read the API key from disk instead of using the one the run had just authenticated with:findExistingApiKeyreturnsprocess.env.SEAM_API_KEYahead of any dotenv file (src/lib/env-file.ts), while the browser handoff and the pasted-key path write the chosen key to.env.So when
SEAM_API_KEYis exported in the shell, a run that connects through the browser to workspace B mints its wizard session with workspace A's key.The failure is quiet. The UI prints
Connected · workspace Bfromresult.workspace, then plans and writes the integration against workspace A. It only becomes a visible error when the exported key is invalid or points at an unreachable endpoint, and then only as the genericCouldn't start the AI session.A second shadowing path exists even with no environment variable set:
ENV_FILE_NAMESprefers.env.localover.env, but both auth paths write to.env, so a stale.env.localalso wins.Fix
Carry the verified key through the run rather than re-deriving it:
connectViaWebandverifyAndSaveKeynow return the key they verified alongside the workspace.settleOnrecords it inapiKeyRef, andanalyzeprefers that over re-reading the environment (the existing lookup stays as a fallback).The browser and pasted paths called
setWorkspace+advanceAfterAuthdirectly, bypassingsettleOn— the one place that callssaveConnection. That is why the'browser'and'pasted'members ofsettleOn'ssourceunion were unreachable. Routing both throughsettleOnfixes the key selection and, as a side effect, records connections for runs that previously left none — so the "Set up here before" drift check now works for them too.Verification
src/lib/steps/authenticate.test.ts. Both cases fail against the unfixedauthenticate.ts(expected undefined to be 'seam_pasted_key') and pass with it.npm test— 172 passed, 20 files.npm run typecheckandnpm run lint— clean.Note: the wiring in
app.tsxis not covered directly.test/app.test.tsxstates that a full interactive run cannot be exercised headlessly, so it asserts only the first frame; I did not try to extend that harness here.Not addressed
The
.env.localprecedence remains: a key written to.envis still shadowed by an existing.env.localon the next run. Worth a follow-up on whethersaveProjectApiKeyshould write to the file the key was found in, or whether the wizard should warn on the conflict.🤖 Generated with Claude Code