Repository navigation
Conversation
|
| return None; | ||
| } | ||
| }; | ||
| *credentials.write().await = next; |
There was a problem hiding this comment.
When a stream rotates after an authentication or quota failure, this replaces the shared runtime credentials but leaves the selected account label unchanged. Nothing restores the original credentials when the stream ends, so later requests and prewarms can use the alternate account while the UI and usage reporting still identify the original account.
Knowledge Base Used:
Prompt To Fix With AI
This is a comment left during a code review.
Path: crates/jcode-provider-openai-runtime/src/openai_provider_impl.rs
Line: 58
Comment:
**Restore rotated credentials**
When a stream rotates after an authentication or quota failure, this replaces the shared runtime credentials but leaves the selected account label unchanged. Nothing restores the original credentials when the stream ends, so later requests and prewarms can use the alternate account while the UI and usage reporting still identify the original account.
**Knowledge Base Used:**
- [Authentication and account management](https://app.greptile.com/solo-systems/-/custom-context/knowledge-base/1jehuang/jcode/-/docs/authentication-and-account-management.md)
- [Provider selection and runtime adapters](https://app.greptile.com/solo-systems/-/custom-context/knowledge-base/1jehuang/jcode/-/docs/provider-selection-and-runtime-adapters.md)
---
For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.| } | ||
|
|
||
| fn write_unlocked(provider: &str, file: &AccountFile) -> Result<()> { | ||
| let persisted = PersistedAccountFile::from_managed(provider, file)?; |
There was a problem hiding this comment.
Credential values are written to native storage before the metadata file is published, with no rollback if metadata publication fails. For example, a disk-full or permission error while updating an existing account can leave the old metadata pointing at newly replaced credentials; a new account can instead leave orphaned secrets. Stage or reconcile both stores so a failed save cannot partially update an account.
Knowledge Base Used: Authentication and account management
Prompt To Fix With AI
This is a comment left during a code review.
Path: crates/jcode-base/src/auth/provider_pool.rs
Line: 521
Comment:
**Make credential writes atomic**
Credential values are written to native storage before the metadata file is published, with no rollback if metadata publication fails. For example, a disk-full or permission error while updating an existing account can leave the old metadata pointing at newly replaced credentials; a new account can instead leave orphaned secrets. Stage or reconcile both stores so a failed save cannot partially update an account.
**Knowledge Base Used:** [Authentication and account management](https://app.greptile.com/solo-systems/-/custom-context/knowledge-base/1jehuang/jcode/-/docs/authentication-and-account-management.md)
---
For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.| let item = self.inner.as_mut().poll_next(context); | ||
| if matches!(item, Poll::Ready(None)) { | ||
| self.account_lease = None; | ||
| } | ||
| item |
There was a problem hiding this comment.
The wrapper forwards Some(Err(_)) without invoking account or provider failover, while Cursor starts its network operation only after returning an event stream. Cursor transport, authentication, and quota failures therefore bypass the new same-provider failover path, and the user receives the original error without trying another pooled account.
Knowledge Base Used:
Prompt To Fix With AI
This is a comment left during a code review.
Path: crates/jcode-base/src/provider/dispatch.rs
Line: 44-48
Comment:
**Handle streamed failures**
The wrapper forwards `Some(Err(_))` without invoking account or provider failover, while Cursor starts its network operation only after returning an event stream. Cursor transport, authentication, and quota failures therefore bypass the new same-provider failover path, and the user receives the original error without trying another pooled account.
**Knowledge Base Used:**
- [Model provider integration](https://app.greptile.com/solo-systems/-/custom-context/knowledge-base/1jehuang/jcode/-/docs/provider-integration.md)
- [Provider selection and runtime adapters](https://app.greptile.com/solo-systems/-/custom-context/knowledge-base/1jehuang/jcode/-/docs/provider-selection-and-runtime-adapters.md)
---
For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.0656752 to
c84657c
Compare
|
Want your agent to iterate on Greptile's feedback? Try greploops. |
…l-account-management-upstream # Conflicts: # Cargo.lock # crates/jcode-base/src/auth/codex_tests.rs # crates/jcode-base/src/auth/cursor.rs # crates/jcode-base/src/provider/account_failover.rs # crates/jcode-base/src/provider/tests/catalog_subscription.rs # crates/jcode-base/src/usage.rs # crates/jcode-base/src/usage/provider_fetch.rs # crates/jcode-provider-core/src/retry_after.rs # crates/jcode-provider-cursor-runtime/src/agent_transport.rs # crates/jcode-provider-cursor-runtime/src/lib.rs # crates/jcode-provider-openai-runtime/src/lib.rs # crates/jcode-provider-openai-runtime/src/openai_provider_impl.rs Co-authored-by: SB Yoon <[email protected]>
Refresh inactive Antigravity quotas on the selected account, restore OpenAI credentials and labels after a stream rotation, and lock account files on every platform. Cursor startup failures now return before the stream so same-provider failover can run, and pooled Cursor or Antigravity accounts can be removed. Co-authored-by: SB Yoon <[email protected]>
Rustfmt the module and import order current stable rustfmt requires, keep the companion listener mutable only on Windows, and compile the niri Deserialize import only where those types exist. Upgrade quinn-proto to 0.11.19 so the current RustSec advisories clear. Co-authored-by: SB Yoon <[email protected]>
Replace the newline write, the infallible lock match, and the nested device and capture checks that stable clippy denies. Co-authored-by: SB Yoon <[email protected]>
The native credential helper imports Mutex on every platform, so the Windows-only import collided with it and the Windows build stopped. Co-authored-by: SB Yoon <[email protected]>
| if key.is_empty() || key.len() > 256 || key.chars().any(|ch| ch.is_control()) { | ||
| anyhow::bail!("invalid native credential key"); | ||
| } | ||
| keyring::Entry::new(NATIVE_CREDENTIAL_SERVICE, key) |
There was a problem hiding this comment.
Separate homes share credentials
Production uses the same native service and raw key for every JCODE_HOME; only tests add the home to the key. Saving Cursor or Antigravity credentials in an isolated home can overwrite the normal home's credentials. Removing an imported account can also delete credentials another home still uses. Scope production keys to the resolved home.
Knowledge Base Used: Authentication and account management
Artifacts
- Compiles revision-specific application source and runs separate-process persistence checks with an isolated file-backed backend, making the reproduction repeatable without Cargo builds.
- Contains the generated Rust used for the base standalone save/read comparison, showing the exact executed control code.
- Contains the generated Rust with production managed-account persistence code and the controlled credential backend, showing the exact executed reproduction.
- Captures the rustc command compiling storage source from the specified base revision and exit zero, establishing successful control compilation.
- Captures the rustc command linking the base persistence harness and exit zero, establishing successful control executable creation.
- Captures the rustc command compiling head storage source with the keyring-core backend substitution and exit zero, documenting the precise execution boundary.
- Captures the rustc command linking the head persistence harness and exit zero, establishing successful reproduction executable creation.
- Runs saves and reads in separate processes under two homes at the specified base revision, showing that each home retains its own tokens.
- Runs standalone and managed-account saves, reads, and removal across two homes at head, showing cross-home token overwrite and credential deletion.
- Captures numbered application and keyring source excerpts plus a clean diff for the relevant tracked files, showing the missing production home namespace and unchanged reviewed source.
Ran code and verified through T-Rex
Prompt To Fix With AI
This is a comment left during a code review.
Path: crates/jcode-storage/src/lib.rs
Line: 566
Comment:
**Separate homes share credentials**
Production uses the same native service and raw key for every `JCODE_HOME`; only tests add the home to the key. Saving Cursor or Antigravity credentials in an isolated home can overwrite the normal home's credentials. Removing an imported account can also delete credentials another home still uses. Scope production keys to the resolved home.
**Knowledge Base Used:** [Authentication and account management](https://app.greptile.com/solo-systems/-/custom-context/knowledge-base/1jehuang/jcode/-/docs/authentication-and-account-management.md)
---
For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.| if is_account_rotation_error(&error) | ||
| && account_attempt < MAX_ACCOUNT_ROTATIONS | ||
| && let Some(account) = try_rotate_openai_account( | ||
| &credentials, | ||
| &mut attempted_accounts, | ||
| &mut account_restore, | ||
| ) | ||
| .await |
There was a problem hiding this comment.
Disabled account rotation still runs
OpenAI stream rotation and Antigravity runtime failover can try another account after an auth or quota error even when same_provider_account_failover is disabled. Antigravity also reads all saved accounts instead of honoring AccountPool exclusions. Apply the existing setting and allowed-account selection before retrying so requests respect the user's account choices.
Knowledge Base Used: Authentication and account management
Prompt To Fix With AI
This is a comment left during a code review.
Path: crates/jcode-provider-openai-runtime/src/openai_provider_impl.rs
Line: 721-728
Comment:
**Disabled account rotation still runs**
OpenAI stream rotation and Antigravity runtime failover can try another account after an auth or quota error even when `same_provider_account_failover` is disabled. Antigravity also reads all saved accounts instead of honoring `AccountPool` exclusions. Apply the existing setting and allowed-account selection before retrying so requests respect the user's account choices.
**Knowledge Base Used:** [Authentication and account management](https://app.greptile.com/solo-systems/-/custom-context/knowledge-base/1jehuang/jcode/-/docs/authentication-and-account-management.md)
---
For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.| let next = match jcode_base::auth::codex::load_credentials_for_account(&candidate) { | ||
| Ok(next) => next, | ||
| Err(error) => { | ||
| jcode_base::logging::info(&format!( | ||
| "OpenAI stream account rotation could not load '{}': {}", | ||
| candidate, error | ||
| )); | ||
| return None; | ||
| } | ||
| }; | ||
| *credentials.write().await = next; | ||
| restore.note(&candidate); |
There was a problem hiding this comment.
After an API-key auth or quota error, try_rotate_openai_account can load saved OAuth credentials without checking credential_mode_snapshot(). It replaces the shared credentials, and the next attempt chooses its endpoint from those credentials. An explicitly selected openai-api request can therefore move to ChatGPT/Codex under another login. Keep API-key mode pinned during retries.
Knowledge Base Used: Provider selection and runtime adapters
Prompt To Fix With AI
This is a comment left during a code review.
Path: crates/jcode-provider-openai-runtime/src/openai_provider_impl.rs
Line: 88-99
Comment:
**API-key requests change login**
After an API-key auth or quota error, `try_rotate_openai_account` can load saved OAuth credentials without checking `credential_mode_snapshot()`. It replaces the shared credentials, and the next attempt chooses its endpoint from those credentials. An explicitly selected `openai-api` request can therefore move to ChatGPT/Codex under another login. Keep API-key mode pinned during retries.
**Knowledge Base Used:** [Provider selection and runtime adapters](https://app.greptile.com/solo-systems/-/custom-context/knowledge-base/1jehuang/jcode/-/docs/provider-selection-and-runtime-adapters.md)
---
For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.| let current = jcode_base::auth::codex::active_account_label()?; | ||
| let candidate = jcode_base::provider::MultiProvider::preferred_openai_account_label()?; | ||
| if candidate == current || !attempted_accounts.insert(candidate.clone()) { | ||
| return None; |
There was a problem hiding this comment.
attempted_accounts starts empty, and each rotation checks only the first preferred candidate. With saved order A, B, C and no usable quota snapshot, failures can produce A → B → A. Both rotations are spent without trying healthy C. Seed the set with the starting account and choose the first untried account from the full candidate list.
Artifacts
- The executed Python driver installs each original implementation temporarily, runs the same harness sequentially, captures command output, and restores the source.
- The executed Rust test saves three synthetic accounts and sends real provider requests to a loopback endpoint, demonstrating the automatic sequence and a successful C control.
- The base implementation was executed against the synthetic endpoint and captured A returning 401 Unauthorized followed by the direct C control returning 200 OK.
- The head implementation was executed against the same endpoint and captured A → B → A returning 401 Unauthorized while the direct C control returned 200 OK, confirming the missed working account.
- The base implementation is preserved with its temporary harness include, identifying the underlying source used for the before capture.
- The head implementation is preserved with its temporary harness include, identifying the underlying source used for the confirmed A → B → A capture.
- Executed Git source extraction and comparison captured the selection logic and verified that the tested provider source was restored byte-for-byte.
Ran code and verified through T-Rex
Prompt To Fix With AI
This is a comment left during a code review.
Path: crates/jcode-provider-openai-runtime/src/openai_provider_impl.rs
Line: 78-81
Comment:
**Healthy accounts go untried**
`attempted_accounts` starts empty, and each rotation checks only the first preferred candidate. With saved order A, B, C and no usable quota snapshot, failures can produce A → B → A. Both rotations are spent without trying healthy C. Seed the set with the starting account and choose the first untried account from the full candidate list.
---
For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.| let safe = safe.trim_matches('-'); | ||
| if safe.is_empty() { | ||
| crate::auth::account_store::canonical_account_label(provider, index + 1) | ||
| } else { | ||
| format!("{provider}-{safe}") |
There was a problem hiding this comment.
Imported account labels collide
Aliases Work Email and Work-Email both become cursor-Work-Email. upsert_account accepts both accounts because it checks IDs, but loading and switching find the first account by label. The second account cannot be selected; importing it as active selects the first account's credentials. Make labels unique within each provider.
Ran code and verified through T-Rex
Prompt To Fix With AI
This is a comment left during a code review.
Path: crates/jcode-base/src/auth/provider_pool.rs
Line: 1110-1114
Comment:
**Imported account labels collide**
Aliases `Work Email` and `Work-Email` both become `cursor-Work-Email`. `upsert_account` accepts both accounts because it checks IDs, but loading and switching find the first account by label. The second account cannot be selected; importing it as active selects the first account's credentials. Make labels unique within each provider.
---
For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.| if let Some((used, limit)) = pair(object) { | ||
| return Some(((used / limit) * 100.0).clamp(0.0, MAX_PERCENT) as f32); | ||
| } | ||
| } | ||
| aliases.iter().find_map(|alias| { | ||
| let value = find_value(root, &[alias], 0); |
There was a problem hiding this comment.
A monthly-only planUsage response containing spend and limit produces identical Monthly, Auto, and API windows because percent_from_object applies pair(object) to the monthly object for all three scopes. The fallback parser also fills absent scopes from generic percentages elsewhere in the response. These values are saved as account quota observations. This is non-blocking, but users see Auto/API usage the provider did not report, and later account comparisons use those invented observations. Read each window only from its own fields and leave missing quota unknown.
Ran code and verified through T-Rex
Prompt To Fix With AI
This is a comment left during a code review.
Path: crates/jcode-base/src/usage/cursor.rs
Line: 243-248
Comment:
**Missing quotas get invented**
A monthly-only `planUsage` response containing spend and limit produces identical Monthly, Auto, and API windows because `percent_from_object` applies `pair(object)` to the monthly object for all three scopes. The fallback parser also fills absent scopes from generic percentages elsewhere in the response. These values are saved as account quota observations. This is non-blocking, but users see Auto/API usage the provider did not report, and later account comparisons use those invented observations. Read each window only from its own fields and leave missing quota unknown.
---
For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.| if let Some(account) = crate::auth::provider_pool::active_account("antigravity") | ||
| .ok() | ||
| .flatten() | ||
| { |
There was a problem hiding this comment.
Quota follows the wrong account
Antigravity reads the active label after the network request. Switching from account A to B while polling waits therefore saves quota fetched with A's credentials under B. The executed switch succeeded and replaced B's 900-milli remaining quota with A's 100-milli response. This is non-blocking, but it misreports B's capacity and gives later account ranking the wrong data. Capture the account before fetching and use its account-specific credentials and label throughout.
Knowledge Base Used: Authentication and account management
Ran code and verified through T-Rex
Prompt To Fix With AI
This is a comment left during a code review.
Path: crates/jcode-base/src/usage/provider_fetch.rs
Line: 482-485
Comment:
**Quota follows the wrong account**
Antigravity reads the active label after the network request. Switching from account A to B while polling waits therefore saves quota fetched with A's credentials under B. The executed switch succeeded and replaced B's 900-milli remaining quota with A's 100-milli response. This is non-blocking, but it misreports B's capacity and gives later account ranking the wrong data. Capture the account before fetching and use its account-specific credentials and label throughout.
**Knowledge Base Used:** [Authentication and account management](https://app.greptile.com/solo-systems/-/custom-context/knowledge-base/1jehuang/jcode/-/docs/authentication-and-account-management.md)
---
For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.| for account in alternatives { | ||
| jcode_base::auth::provider_pool::mark_account_cooldown( | ||
| "antigravity", | ||
| &original, | ||
| cooldown, | ||
| ); | ||
| match self | ||
| .generate_content_for_account( |
There was a problem hiding this comment.
Antigravity's runtime failover sends an alternate-account request without acquiring its AccountLease. After a primary HTTP 429, the executed retry used an alternate whose lease was still held by another process. This is non-blocking, but concurrent processes can send retries through an account that shared failover would skip, defeating the pool's busy-account admission behavior. Acquire and hold an AccountLease for each alternate attempt.
Ran code and verified through T-Rex
Prompt To Fix With AI
This is a comment left during a code review.
Path: crates/jcode-provider-antigravity-runtime/src/lib.rs
Line: 112-119
Comment:
**Retries share a busy account**
Antigravity's runtime failover sends an alternate-account request without acquiring its `AccountLease`. After a primary HTTP 429, the executed retry used an alternate whose lease was still held by another process. This is non-blocking, but concurrent processes can send retries through an account that shared failover would skip, defeating the pool's busy-account admission behavior. Acquire and hold an `AccountLease` for each alternate attempt.
---
For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.| match self { | ||
| Self::Anthropic => format!("/account switch {}", label), | ||
| Self::OpenAI => format!("/account openai switch {}", label), | ||
| Self::Cursor => format!("/account switch {}", label), |
There was a problem hiding this comment.
Cursor guidance emits /account switch <label>, but that shorthand only searches Claude and OpenAI accounts. Following it returns “No Anthropic or OpenAI account” instead of switching. This is non-blocking, but it makes the suggested recovery step unusable. Emit /account cursor switch <label>, which the new provider-specific path supports.
| Self::Cursor => format!("/account switch {}", label), | |
| Self::Cursor => format!("/account cursor switch {}", label), |
Ran code and verified through T-Rex
Prompt To Fix With AI
This is a comment left during a code review.
Path: crates/jcode-base/src/usage/model.rs
Line: 364
Comment:
**Cursor recovery command fails**
Cursor guidance emits `/account switch <label>`, but that shorthand only searches Claude and OpenAI accounts. Following it returns “No Anthropic or OpenAI account” instead of switching. This is non-blocking, but it makes the suggested recovery step unusable. Emit `/account cursor switch <label>`, which the new provider-specific path supports.
```suggestion
Self::Cursor => format!("/account cursor switch {}", label),
```
---
For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.| let path = directory.join(format!( | ||
| "{}-{}.lock", | ||
| lease_path_component(provider), | ||
| lease_path_component(label) |
There was a problem hiding this comment.
lease_path_component doubles every label byte, and imported labels have no length limit. On a filesystem with a 255-byte filename limit, a 120-character Cursor alias produces an oversized lock filename. Opening it fails, so shared failover treats the account as already leased and skips it. This is non-blocking for ordinary labels, but long aliases never work as alternates. Use a bounded hash for the filename.
Prompt To Fix With AI
This is a comment left during a code review.
Path: crates/jcode-base/src/auth/provider_pool.rs
Line: 107-110
Comment:
**Long labels block failover**
`lease_path_component` doubles every label byte, and imported labels have no length limit. On a filesystem with a 255-byte filename limit, a 120-character Cursor alias produces an oversized lock filename. Opening it fails, so shared failover treats the account as already leased and skips it. This is non-blocking for ordinary labels, but long aliases never work as alternates. Use a bounded hash for the filename.
---
For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.
Comments Outside DiffThese findings could not be posted inline.
|
Summary
Adds a provider-scoped account pool for authenticated providers, with durable metadata, safe account selection, quota-aware ranking, cooldowns, leases, failover, and account-management UI/CLI flows.
Closes #1238
Closes #1239
Refs #1130
Categorized changes
Validation
upstream/masterand zero commits behind it.scripts/dev_cargo.sh check -p jcode --bin jcodepassed from the final rebased branch.Scope notes
#1130 describes a broader Anthropic streaming failover report. This PR shares the account-first cooldown, lease, retry-after, and request-local failover foundation, but references rather than closes that issue because not every Anthropic-specific streaming behavior is claimed here.