Repository navigation
Conversation
# Conflicts: # crates/jcode-harness-api-server/src/translate_tests.rs # crates/jcode-harness-api/src/lib.rs # sdk/typescript/src/protocol.ts
…ibutors-20260913 Welcome pull requests from all contributors
|
| .unwrap_or_else(|| self.provider.display_name()) | ||
| } else { | ||
| self.provider.name().to_string() | ||
| // The profile the session talks to, not the transport slot that | ||
| // multiplexes every direct OpenAI-compatible profile (#1286). | ||
| self.provider.display_name() |
There was a problem hiding this comment.
For direct OpenAI-compatible profiles, this saves a presentation label such as NVIDIA NIM as the KV-cache baseline provider. The expiration check later passes that value to TTL classification, which recognizes the canonical openrouter family but not NVIDIA NIM; after 301 seconds the miss is no longer labeled Expired. This is a non-blocking telemetry regression: idle-cache diagnostics lose the expiration reason for these profiles. Keep a canonical TTL provider identity separate from the rendered profile label.
Artifacts
Rust harness for NVIDIA NIM TTL classification
- The authored executable harness selects the repository's real NVIDIA NIM profile and compares its prior canonical provider value with its changed display-label value, proving the differing expiration decisions.
NVIDIA NIM TTL classification harness output
- Captured output from running the Rust harness shows `openrouter` is expired at 301 seconds while `NVIDIA NIM` has no TTL and is not expired, confirming the regression.
Ran code and verified through T-Rex
Prompt To Fix With AI
This is a comment left during a code review.
Path: crates/jcode-tui/src/tui/app.rs
Line: 2446-2450
Comment:
**Keep TTL identity canonical**
For direct OpenAI-compatible profiles, this saves a presentation label such as `NVIDIA NIM` as the KV-cache baseline provider. The expiration check later passes that value to TTL classification, which recognizes the canonical `openrouter` family but not `NVIDIA NIM`; after 301 seconds the miss is no longer labeled `Expired`. This is a non-blocking telemetry regression: idle-cache diagnostics lose the expiration reason for these profiles. Keep a canonical TTL provider identity separate from the rendered profile label.
---
For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.…ot the openrouter slot
The OpenRouter provider is a multiplexing slot: `Provider::name()` reports the
provider *class* (`OpenRouter` for the slot, `openrouter` for a concrete
runtime instance) while `display_name()` resolves the profile the session
actually talks to (DeepSeek, NVIDIA NIM, ...). Surfaces that read the class id
where a profile identity belongs therefore reported DeepSeek sessions as
OpenRouter:
- the log prefix tagged every line `prv:OpenRouter` / `prv:openrouter`
- both `History` emission paths could report the class name: the
persisted-session path fell back to `provider.name()`, and
`handle_get_model_catalog`'s busy-agent fallback always did
- `/usage` attributed spend to an `openrouter` bucket on hosts where OpenRouter
is not configured and was never used (the ledger key is derived from that
provider name)
- KV-cache telemetry printed `provider=OpenRouter` for a DeepSeek model
Report the profile-aware label instead. A direct OpenAI-compatible profile is
persisted both bare (`deepseek`, the session vocabulary) and as its source key
(`openai-compatible:deepseek`), so both shapes now report the profile's display
name; the existing "unknown runtime profile" test moved to a genuinely unknown
key (`remote-catalog`) because `opencode-go` is itself a catalog profile.
Import-source codes (`opencode`, `claude-code`, `openai-codex`) share the same
field but are not profile routes, so they stay verbatim. An already-prefixed key
also survives `source_key_for_provider_label`, which used to fall through
`contains("openai")` and bill `openai:api-key`.
KV-cache telemetry keeps the canonical family id in `provider=` (the baseline
identity the TTL/expiry classifier keys on) and adds a separate `label=` field
with the profile, so diagnostics stay correct for both machines and people.
`Provider::name()` keeps its documented contract as the stable machine-facing
identifier, so routing, auth and restore decisions are untouched.
Known limitations (deliberate scope): `@provider`-pinned models still persist
`provider_key = "openrouter"` (route/restore identity, overlaps 1jehuang#1116);
structured telemetry keeps the class id per the `name()` contract; and the
ledger write has no end-to-end test because it is TUI-side and spawns a writer
thread.
Closes 1jehuang#1286
419b4fc to
1b07253
Compare
|
Reviewed the Greptile P2 and fixed it in 1b07253. KV-cache TTL identity (valid): Fix: the baseline identity is canonical again (
|
|
Merged into master. The combined candidate passed history-provider, model-catalog, log-context, provider-activity and KV-cache identity tests. Real isolated CLI calls using the OpenAI-compatible profile returned History provider Integrated with original PR ancestry and contributor attribution preserved, applying only the actual contribution rather than the divergent old upstream tree. Validation is local targeted testing and isolated public-interface acceptance, not a claim that hosted CI is green. |
Closes #1286
Problem
The
openrouterprovider is a multiplexing slot: it serves the public OpenRouter aggregator and every direct OpenAI-compatible profile (deepseek,nvidia-nim,zai, ...).Provider::name()is the stable machine id for the class (OpenRouterfor the slot,openrouterfor a concrete runtime instance), whiledisplay_name()resolves the active profile (DeepSeek). Surfaces that read the class id where a profile identity belongs reported DeepSeek sessions as OpenRouter:prv:OpenRouter/prv:openrouterHistoryfallback paths could report the class name/usageattributed spend to anopenrouterbucket on hosts where OpenRouter is not configured and was never used (the ledger key is derived from that provider name)provider=OpenRouterformodel=deepseek-flashPer the contract clarified in #691 and the
Providertrait docs,name()stays the machine id; the fix belongs in the surfaces that read it.Changes
crates/jcode-app-core/src/agent/environment.rsprv:) usesdisplay_name()crates/jcode-app-core/src/server/client_state.rsHistoryprovider name: the persisted-session path now maps both persisted shapes of a direct OpenAI-compatible profile (deepseekandopenai-compatible:deepseek) to the profile's display name and falls back todisplay_name(); thehandle_get_model_catalogbusy-agent fallback (a second emission path into the same field) now does too. Import-source codes (opencode,claude-code,openai-codex) share the field but are not profile routes, so they stay verbatimcrates/jcode-base/src/provider_activity.rssource_key_for_provider_labelkeeps an already-prefixedopenai-compatible:<id>label instead of falling throughcontains("openai")toopenai:api-keycrates/jcode-tui/src/tui/app.rsprovider=(the baseline identity the TTL/expiry classifier keys on) and adds alabel=field with the profile, instead of overwriting the identity with a labelProvider::name()is untouched, so routing, auth and restore decisions are unchanged.Evidence
Real-binary A/B on one machine, throwaway sandboxes per path.
Local run (
jcode run -p deepseek -m deepseek-flash "hi"):masterv0.84.75-dev (168358c3d)[ses:…|prv:openrouter|mod:deepseek]v0.84.57-dev (419b4fc97)[ses:…|prv:DeepSeek|mod:deepseek]Daemon path (
serve+ a debug session, i.e. the multiplexing slot path that produced the real logs):masterv0.84.75-dev (168358c3d)prv:OpenRouter|mod:deepseek×14v0.84.57-dev (419b4fc97)prv:DeepSeek|mod:deepseek×14Both runs use two throwaway
JCODE_HOMEsandboxes and the same command (jcode run -p deepseek -m deepseek-flash "hi"for the first table;serveplus a debug session for the second), so the two prefixes never mix in one log file.Release-binary evidence for the ledger half: on a host where
jcode auth statusreportsopenrouter not_configured, no OpenRouter credential exists and no OpenRouter model was ever selected,provider_activity.jsonstill carried anopenrouterbucket with real spend while the same host's logs held 503k+prv:OpenRouter|mod:deepseeklines.Tests
Every changed surface is pinned by a test that fails when its fix is reverted (verified by reverting each hunk and re-running):
agent::environment::tests::log_context_names_the_profile_not_the_transport_slot— newserver::client_state::tests::history_provider_name_maps_a_compatible_profile_key_to_its_label— newserver::client_state::tests::history_provider_name_maps_a_bare_compatible_profile_key— new (reverting the bare-key mapping fails it withleft: Some("deepseek") / right: Some("DeepSeek"))server::client_state::tests::history_provider_name_keeps_import_source_codes_verbatim— newserver::client_state::tests::history_provider_name_falls_back_to_the_profile_label— newserver::client_state::tests::source_key_mapping_keeps_an_already_prefixed_profile_key— newtui::app::tests::kv_cache_baseline_identity_stays_canonical_while_the_label_is_the_profile— new (fails withleft: "DeepSeek" / right: "openrouter"if the baseline stores the display label)handle_get_model_catalog_*tests now guard the busy fallback: the shared mock'sdisplay_name()differs from itsname(), so reaching forname()fails the assertionhistory_provider_name_preserves_unknown_runtime_profiletest moved fromopencode-go(itself a catalog profile, i.e. no longer "unknown") toremote-catalogValidation:
jcode-baseprovider_activity 13/13,jcode-app-corehistory + log-context 5/5,jcode-tuikv_cache 13/13jcode-app-core --lib: 1225 passed / 24 failed on the branch vs 1223 passed / 23 failed on pristinemaster; the failure-name sets are identical apart fromtool::bash::tests::test_background_command_respects_timeout, which passes when run alone (load-sensitive flake, unrelated)An independent reviewer with clean context re-ran the suites, re-derived every revert failure, and reported no blocker; the two should-fix items it raised (a second
Historyemission path, and overstated wording aboutname()'s casing) are addressed above.Greptile's P2 was valid and is fixed: storing the rendered profile label in the KV-cache baseline disabled
KvCacheMissReason::Expiredfor direct profiles, becausecache_ttl_for_provider_modelrecognises provider families (openrouter), not labels (NVIDIA NIM). The baseline now keeps the canonical identity and the log line gained the separatelabel=field.Tooling note
Developed with jcode running deepseek-v4-flash: the fix, the regression tests and the A/B evidence above come from that session, plus a second clean-context jcode subagent that reviewed the diff independently and found the second
Historyemission path now fixed here.CI notes
Two pre-existing guardrails are red on
masterindependent of this PR, in files it does not touch:cargo fmt --all --checkalso wants to reformat 9 files none of which are in this diff (jcode-harness-api-server/src/translate.rs,translate_tests.rs,jcode-protocol/src/wire.rs,jcode-provider-core/src/lib.rs,jcode-sdk/src/lib.rs,jcode-tui-markdown/src/lib.rs,jcode-tui/src/tui/app/remote/server_events.rs,jcode-tui/src/tui/backend.rs,src/cli/acp.rs). Only the two files this PR changes were formatted.scripts/check_code_size_budget.pyandscripts/check_test_size_budget.pyalready exit non-zero on pristinemaster(verified in a clean checkout oforigin/master). This PR adds 2 lines tocrates/jcode-tui/src/tui/app.rs, which is already over its recorded budget onmaster(2563 → 2565 LOC); the failure set is otherwise byte-identical.clippy -D warningsalso trips on a crate this PR does not touch:crates/jcode-render-core/src/markdown.rs:426(clippy::collapsible_if), so clippy cannot currently be used as a signal for this diff.Known limitations (deliberate scope)
opencode,claude-codeandopenai-codexare stored in the same field as profile keys, andopencodecollides with theOpenCode Zenprofile id. They stay verbatim rather than guessing. Unifying the session vocabulary with the ledger vocabulary would remove this collision properly (Provider/model runtime identity can diverge across config reload, session restore, UI, model refresh, and reload recovery #380).@provider-pinned models still persistprovider_key = "openrouter"(agent/status.rsreconcile_explicit_provider_pin_route). That is route/restore identity rather than a label, and it overlaps Switching Claude between OAuth and API key leaks JCODE_RUNTIME_PROVIDER process-wide, mislabeling and breaking restore for other sessions #1116; left untouched.provider=openrouterinside internal diagnostics) per theProvider::name()contract. Only the human-facing surfaces changed.