Skip to content

fix(jcode-tui): cache_expected_warm returns false on estimates, not just cold (re-land of #134) - #158

Closed
KooshaPari wants to merge 3 commits into
masterfrom
fix/tui-cache-estimate-not-evidence
Closed

KooshaPari wants to merge 3 commits into
masterfrom
fix/tui-cache-estimate-not-evidence

Conversation

@KooshaPari

@KooshaPari KooshaPari commented Oct 20, 2026 •

Copy link
Copy Markdown
Owner

User description

Re-land the cache_expected_warm guard from #134 as a single-file fix-forward directly on master. The mod.rs re-export reorder from #134 is intentionally dropped — it is owned by #150 fix/tui-cache-expected-warm-unused-import, which both reorders the block AND gates cache_expected_warm behind #[cfg(test)] so the existing tui::tests regression test can call super::cache_expected_warm() correctly.

cache_expected_warm now requires both:

  • a concrete TTL reading (NOT is_estimate), AND
  • not already cold (NOT is_cold)

Before: any non-cold value was considered warm. That misclassified heuristic estimates (is_estimate: true) as warm — a 60%-confidence guess is not evidence of a cached-state hit.

After: cache is only considered expected-warm when we have a TTL measurement AND it is not already cold.

The regression test cache_estimate_is_not_evidence_of_an_expected_warm_hit already lives at crates/jcode-tui/src/tui/mod.rs:1881 on master and will be enabled by PR #150's #[cfg(test)] gating. This branch intentionally does NOT touch mod.rs.

cargo test -p jcode-tui --lib -- cache_estimate is run in this branch's validation step (see validation field).

Closes #155.


CodeAnt-AI Description

Document why estimated cache readings do not count as warm-cache evidence

What Changed

  • Explains that only a measured, non-cold TTL reading is evidence that the cache should be warm; estimated readings are guesses.

Impact

✅ Clearer cache-warm check rationale

💡 Usage Guide

Checking Your Pull Request

Every time you make a pull request, our system automatically looks through it. We check for security issues, mistakes in how you're setting up your infrastructure, and common code problems. We do this to make sure your changes are solid and won't cause any trouble later.

Talking to CodeAnt AI

Got a question or need a hand with something in your pull request? You can easily get in touch with CodeAnt AI right here. Just type the following in a comment on your pull request, and replace "Your question here" with whatever you want to ask:

@codeant-ai ask: Your question here

This lets you have a chat with CodeAnt AI about your pull request, making it easier to understand and improve your code.

Example

@codeant-ai ask: Can you suggest a safer alternative to storing this secret?

Preserve Org Learnings with CodeAnt

You can record team preferences so CodeAnt AI applies them in future reviews. Reply directly to the specific CodeAnt AI suggestion (in the same thread) and replace "Your feedback here" with your input:

@codeant-ai: Your feedback here

This helps CodeAnt AI learn and adapt to your team's coding style and standards.

Example

@codeant-ai: Do not flag unused imports.

Retrigger review

Ask CodeAnt AI to review the PR again, by typing:

@codeant-ai: review

Check Your Repository Health

To analyze the health of your code repository, visit our dashboard at https://app.codeant.ai. This tool helps you identify potential issues and areas for improvement in your codebase, ensuring your repository maintains high standards of code health.

…ust cold

Re-land the cache_expected_warm guard from PR #134 as a single-file
fix-forward. Drop the mod.rs re-export reorder (owned by PR #150
fix/tui-cache-expected-warm-unused-import, which also gates the
re-export behind #[cfg(test)] so the existing mod.rs regression test
calls super::cache_expected_warm() correctly).

cache_expected_warm now requires both:
  - a concrete TTL reading (i.e. not is_estimate), AND
  - not already cold (i.e. !is_cold)

Before: any non-cold value was considered warm. That misclassified
estimates ("is_estimate: true") as warm — a 60% confidence guess is
not evidence of a cached-state hit. With the new guard, the cache is
only considered expected-warm when we have a TTL measurement, which
matches what the regression test in tui::tests asserts.

The regression test cache_estimate_is_not_evidence_of_an_expected_warm_hit
already lives in crates/jcode-tui/src/tui/mod.rs at master (line 1881)
and is reachable via PR #150's #[cfg(test)] gate. This PR intentionally
does NOT touch mod.rs per the fix-forward constraint.

tx-agent: jcode
tx-validated: test
tx-task: ci-stabilization-2026-10-19
tx-scope: jcode-tui
tx-intent: fix cache_expected_warm to require non-estimate TTL evidence, matching the regression test
Closes #NEW_FOR_PR_C
Copilot AI balanced review requested due to automatic review settings October 20, 2026 01:44
@codeant-ai

codeant-ai Bot commented Oct 20, 2026 •

Copy link
Copy Markdown

CodeAnt  CodeAnt Review Status

✅  Review completed

Status Commit Started (UTC) Finished (UTC)
✅  #7a6a0 Incremental review completed b0bc6a7 Nov 03, 2026 · 07:23 07:24
✅  Incremental review completed 47b42e2 Oct 21, 2026 · 05:26 05:27
✅  Reviewed your PR e620e47 Oct 20, 2026 · 01:44 01:47

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@codeant-ai

codeant-ai Bot commented Oct 20, 2026

Copy link
Copy Markdown

Thanks for using CodeAnt! 🎉

We're free for open-source projects. if you're enjoying it, help us grow by sharing.

Share on X ·
Reddit ·
LinkedIn

@coderabbitai

coderabbitai Bot commented Oct 20, 2026 •

Copy link
Copy Markdown

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 57 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

Learn how review limits work.

Review configuration:

Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: ASSERTIVE
  • Plan: Advanced
  • Run ID: 8a4a65a8-b1fd-47d4-b0e1-850d6a0f3962
Commits

Reviewing files that changed from the base of the PR and between ac34906 and b0bc6a7.

Files selected for processing: 1
  • crates/jcode-tui/src/tui/kv_cache_problem.rs
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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

CodeRabbit Verify

  • Run CodeRabbit Verify to test the changes in this pull request.

@codeant-ai codeant-ai Bot added the size:XS This PR changes 0-9 lines, ignoring generated files label Oct 20, 2026
@codeant-ai

codeant-ai Bot commented Oct 20, 2026 •

Copy link
Copy Markdown

CodeAnt  CodeAnt PR Risk

🟢  Low Risk

  • The PR appears safe to merge; no actionable issues were identified in the review.

Assessed commit: b0bc6a730a27

// already cold. See `cache_estimate_is_not_evidence_of_an_expected_warm_hit`
// in the tui::tests module for the regression this guards against.
cache_ttl
.map(|info| !info.is_estimate && !info.is_cold)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

WARNING: is_estimate is provider-derived, so this silently disables KV-cache-problem detection for OpenAI / Gemini / OpenRouter / Jcode-subscription routes

CacheTtlInfo::is_estimate is not a per-measurement flag. The only production constructor sets it from crate::provider::cache_ttl_is_estimate(&baseline.provider) (crates/jcode-tui/src/tui/app/tui_state.rs:2133), and that helper returns true for every OpenAI auth route (openai, openai-api, openai-oauth, ...) plus openrouter, jcode subscription and gemini. Those providers therefore always produce is_estimate: true, so cache_expected_warm is now permanently false for them and detect_kv_cache_problem can never report a problem - including the UnexpectedCacheCreation branch (kv_cache_problem.rs:118), whose evidence is the provider's explicit cache-write telemetry in the same turn and does not depend on TTL confidence. Net effect: the feature shrinks to Anthropic/Claude (+ non-OpenAI-compatible profiles), and the openai / gemini arms of supports_reliable_zero_cache_read_warning (kv_cache_problem.rs:52-69) become unreachable for direct OpenAI and Gemini routes.

The unit tests do not catch this because they build synthetic CacheTtlInfo values with is_estimate: false for openai and gemini (crates/jcode-tui/src/tui/mod.rs:1987 and 2044), which production never produces.

Consider scoping the exclusion to estimates that are actually close to expiry (for example treat an estimate as warm only while remaining_secs stays comfortably above the TTL), or applying it only to the ExpectedCacheReadMissing branch so the explicit cache-creation signal survives. Please also update the detect_kv_cache_problem doc comment (crates/jcode-tui/src/tui/kv_cache_problem.rs:94-100): it still lists the precondition as a prior turn within the provider's expected cache TTL and does not mention the new known-TTL requirement.

cache_ttl.map(|info| !info.is_cold).unwrap_or(false)
// An `is_estimate` value is a heuristic guess, not evidence: only treat the
// cache as expected-warm when we have a concrete TTL reading AND it is not
// already cold. See `cache_estimate_is_not_evidence_of_an_expected_warm_hit`

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SUGGESTION: Cover this guard with a unit test in the module that owns it

kv_cache_problem.rs has no #[cfg(test)] module. The only regression coverage for this guard lives in tui::tests (crates/jcode-tui/src/tui/mod.rs:1881) and reaches the function through the mod.rs re-export, so the guard is only covered as long as that re-export keeps working - and PR #150 (fix/tui-cache-expected-warm-unused-import) reworks exactly that re-export. Adding a small #[cfg(test)] mod tests here (estimate => not warm, cold => not warm, known TTL => warm, and detect_kv_cache_problem returning None for an estimate TTL) keeps the behaviour covered by the file that owns it and removes the cross-module dependency.

@kilo-code-bot

kilo-code-bot Bot commented Oct 20, 2026 •

Copy link
Copy Markdown

Code Review Summary

Status: 2 Issues Found | Recommendation: Merge after PR #150 lands (with notes)

Overview

Severity Count
CRITICAL 0
WARNING 1
SUGGESTION 1
Issue Details (click to expand)

WARNING

File Line Issue
crates/jcode-tui/src/tui/kv_cache_problem.rs 88 is_estimate is derived from the provider name, not from measurement quality, so the new guard makes cache_expected_warm permanently false for OpenAI / Gemini / OpenRouter / Jcode-subscription routes and silently disables detect_kv_cache_problem there (including the explicit cache-creation signal). The detect_kv_cache_problem doc comment (lines 94-100) is now stale.

SUGGESTION

File Line Issue
crates/jcode-tui/src/tui/kv_cache_problem.rs 85 No unit test in the module that owns the guard; the only regression coverage lives in tui::tests and depends on the mod.rs re-export that PR #150 reworks.

Summary

This PR re-lands the cache_expected_warm guard from #134 as a single-file change to crates/jcode-tui/src/tui/kv_cache_problem.rs: the cache now counts as expected-warm only with a concrete TTL reading (!is_estimate) and not already cold (!is_cold). That is exactly what the already-present regression test cache_estimate_is_not_evidence_of_an_expected_warm_hit (crates/jcode-tui/src/tui/mod.rs:1881) asserts, and it fixes a test that is red on master today.

The diff is 7 added lines in a 144-line module, adds no dependencies, touches no public API or crate boundary, and stays consistent with the existing !is_estimate pattern used by CacheTtlInfo::expiring_soon / expiry_notification_active (crates/jcode-tui/src/tui/mod.rs:1054-1062). The chain in the new body exceeds the default chain_width of 60, so the broken-chain form is what cargo fmt produces.

Must Fix

  • None in the diff itself: no compilation-breaking change, no new dependency, no API break, no security or data-handling concern.
  • Merge-order dependency (not introduced by this diff): land this together with, or after, PR fix(jcode-tui): gate cache_expected_warm re-export behind #[cfg(test)] #150 so the clippy gate is green. On this head pub(crate) use kv_cache_problem::cache_expected_warm; (crates/jcode-tui/src/tui/mod.rs:1070) is re-exported unconditionally while its only reference is inside the #[cfg(test)] test module, and the test module imports the same name at crates/jcode-tui/src/tui/mod.rs:1850 while calling it as super::cache_expected_warm(...) (crates/jcode-tui/src/tui/mod.rs:1883-1885). Both are unused-import risks under cargo clippy --workspace -- -D warnings (and --all-targets). They are pre-existing on master and explicitly owned by fix(jcode-tui): gate cache_expected_warm re-export behind #[cfg(test)] #150, so no inline comments were anchored on those unchanged lines.

Should Fix

  • Confirm the provider-coverage impact before merging (inline WARNING at line 88): CacheTtlInfo::is_estimate is provider-derived (cache_ttl_is_estimate, crates/jcode-base/src/provider/mod.rs:3002), so this turns KV-cache-problem detection off entirely for direct OpenAI, Gemini, OpenRouter and Jcode-subscription providers - and also suppresses the UnexpectedCacheCreation branch, whose evidence is the provider's explicit cache-write telemetry rather than TTL confidence. If that is not intended, scope the exclusion to estimates near the expiry boundary, or apply it only to the ExpectedCacheReadMissing branch.
  • Keep the detect_kv_cache_problem doc comment (crates/jcode-tui/src/tui/kv_cache_problem.rs:94-100) in sync with the new precondition (a known, non-estimate TTL), and add a local #[cfg(test)] module in kv_cache_problem.rs (inline SUGGESTION at line 85).

Consider

  • The unit tests in tui::tests construct synthetic CacheTtlInfo values with is_estimate: false even for openai and gemini (crates/jcode-tui/src/tui/mod.rs:1987 and 2044), so they do not reflect the production values those providers actually produce. A provider-aware test would have surfaced the coverage loss above.
  • Validation gap: this was a read-only review session, so no cargo build, cargo clippy or cargo test was executed. All conclusions come from reading the diff, the crate sources and the PR metadata; the clippy/test claims in the PR description were not independently verified.

Approve / Request Changes

  • Approve with notes, conditional on fix(jcode-tui): gate cache_expected_warm re-export behind #[cfg(test)] #150 landing first (or together with it). The logic is correct and idiomatic, the diff is minimal and clean, and it repairs a failing regression test; the one substantive question is the silent loss of detection coverage for estimate-based providers, which deserves an explicit decision.
Files Reviewed (1 file)
  • crates/jcode-tui/src/tui/kv_cache_problem.rs - 2 issues

Context read (not changed by this PR): crates/jcode-tui/src/tui/mod.rs, crates/jcode-tui/src/tui/app/tui_state.rs, crates/jcode-tui/src/tui/app/state_ui_runtime.rs, crates/jcode-tui/src/tui/ui_input.rs, crates/jcode-tui/src/tui/ui_tests/basic/frame_flicker.rs, crates/jcode-base/src/provider/mod.rs, crates/jcode-provider-core/src/auth_mode.rs

Fix these issues in Kilo Cloud

Kilo fix


Reviewed by free · Input: 70.2K · Output: 25.8K · Cached: 672.3K

crates/jcode-tui/src/tui/kv_cache_problem.rs conflicted inside pub(crate) fn cache_expected_warm: master carries the bare predicate while this branch carries the same predicate with an explanatory comment. Took the branch version. The two predicate orderings are logically equivalent, so the comment is the only genuine content this PR still contributes against master -- it records that an is_estimate value is a heuristic guess rather than evidence and points at the regression test it guards.

tx-agent: jcode
tx-validated: manual
tx-scope: crates/jcode-tui/src/tui/kv_cache_problem.rs
tx-intent: Keep the is_estimate rationale comment so this branch merges into master cleanly
KooshaPari added a commit that referenced this pull request Oct 21, 2026
…olved conflicts

The recomputed residuals (recomputed against origin/master 2aea04d
via git merge-tree --write-tree) now cover 12 open PRs in the KCode
stack. The four PRs previously flagged as needing hand-resolved
conflicts (#140, #127, #157, #158) have already been merged against
origin/master by a parallel agent as real 2-parent merge commits at
d6e4cfa, b6508e6, 264c09a, and 47b42e2 respectively; merge-tree
reports zero conflict markers for all four. Two new PRs (#163 transport
pipe-stem, #164 CI timeout headroom) extend the stack to 12.

The CI Quality Guardrails clippy gate has a coverage gap that no
existing PR fixes: the command is 'cargo clippy --all-targets
--all-features -- -D warnings' with no --workspace, so exactly one
workspace member (jcode-sdk) is unreachable from the root package and
is never linted. In the green run id 39390720989 the cargo test -p
jcode-sdk parity step still emitted the 'never used' warning for the
Subscriber alias at crates/jcode-sdk/src/client.rs:330. The --workspace
change is NOT a no-op and may surface additional pre-existing
violations; this is recorded as an OPEN RISK, not a resolved fact.

The KCode self-hosted runner desk-kcode-1 wedged on 2026-10-21 in the
Build & Test (desk-linux) job of run 39530002307. Root cause: the
desk WSL2 instance is capped by .wslconfig at memory=16GB (not the
64GB the Windows host has), was competing with a 1h43m orphaned
cargo llvm-cov --workspace job, and the Build step in
.github/workflows/ci.yml has no per-step run_with_timeout.py wrapper.
Remediation (terminating the orphan) brought memory from 13.9/16 GB to
9.4/16 GB and recovered the runner.

Detailed conflict resolutions and the runner wedge root-cause analysis
moved to a new companion file 05a_MERGE_EVIDENCE.md so the plan itself
fits the 500-line cap.

tx-agent: jcode
tx-validated: manual
tx-scope: docs/sessions/2026-10-19-orchestration-governance/
tx-intent: Refresh the merge plan against recomputed 12-PR residuals + 4 applied conflict resolutions + clippy coverage gap + runner wedge
@sonarqubecloud

sonarqubecloud Bot commented Nov 3, 2026

Copy link
Copy Markdown

@KooshaPari

Copy link
Copy Markdown
Owner Author

Closing under the host-ops closure audit (2026-11-11): 22 days old with failing checks; not landable as-is. The branch fix/tui-cache-estimate-not-evidence is preserved on the remote, so the work is recoverable with git fetch origin fix/tui-cache-estimate-not-evidence or by reopening this PR. Nothing was deleted.

@KooshaPari KooshaPari closed this Nov 11, 2026
KooshaPari added a commit that referenced this pull request Nov 28, 2026
… plan (#375)

* docs(sessions): add cross-harness orchestration governance proposal

Proposes 4 enforcement mechanisms for the "Always Subagent — main context is management-only" operator directive (2026-10-11 21:08); records the 2026-10-19 manual cross-harness propagation of the rule to all 4 derivative AGENTS.md copies (codex, forge, kcode, helioslite); lists operator-approved next steps (none yet; each mechanism awaiting decision).

tx-agent: jcode
tx-validated: manual
tx-task: governance-2026-10-19
tx-scope: docs/sessions/2026-10-19-orchestration-governance
tx-intent: capture the cross-harness propagation decision + enforcement backlog in the repo

* docs(sessions): add fix-forward merge integration plan for the KCode PR stack

tx-agent: jcode
tx-validated: manual
tx-task: governance-2026-10-19
tx-scope: docs/sessions/2026-10-19-orchestration-governance
tx-intent: give the operator a no-force-push merge order for PRs #152/#127/#140/#148/#129/#132/#134/#150/#145

* docs(ci): rebuild the merge integration plan against master 2aea04d

tx-agent: jcode
tx-validated: manual
tx-task: 143
tx-scope: docs/sessions/2026-10-19-orchestration-governance
tx-intent: replace the stale 2026-10-19 PR stack plan with one built from current master ground truth

* docs(ci): rebuild the merge integration plan against master 2aea04d

tx-agent: jcode
tx-validated: manual
tx-task: 143
tx-scope: docs/sessions/2026-10-19-orchestration-governance
tx-intent: replace the stale 2026-10-19 PR stack plan with one built from current master ground truth

* docs(merge): refresh the merge plan with the recomputed stack and resolved conflicts

The recomputed residuals (recomputed against origin/master 2aea04d
via git merge-tree --write-tree) now cover 12 open PRs in the KCode
stack. The four PRs previously flagged as needing hand-resolved
conflicts (#140, #127, #157, #158) have already been merged against
origin/master by a parallel agent as real 2-parent merge commits at
d6e4cfa, b6508e6, 264c09a, and 47b42e2 respectively; merge-tree
reports zero conflict markers for all four. Two new PRs (#163 transport
pipe-stem, #164 CI timeout headroom) extend the stack to 12.

The CI Quality Guardrails clippy gate has a coverage gap that no
existing PR fixes: the command is 'cargo clippy --all-targets
--all-features -- -D warnings' with no --workspace, so exactly one
workspace member (jcode-sdk) is unreachable from the root package and
is never linted. In the green run id 39390720989 the cargo test -p
jcode-sdk parity step still emitted the 'never used' warning for the
Subscriber alias at crates/jcode-sdk/src/client.rs:330. The --workspace
change is NOT a no-op and may surface additional pre-existing
violations; this is recorded as an OPEN RISK, not a resolved fact.

The KCode self-hosted runner desk-kcode-1 wedged on 2026-10-21 in the
Build & Test (desk-linux) job of run 39530002307. Root cause: the
desk WSL2 instance is capped by .wslconfig at memory=16GB (not the
64GB the Windows host has), was competing with a 1h43m orphaned
cargo llvm-cov --workspace job, and the Build step in
.github/workflows/ci.yml has no per-step run_with_timeout.py wrapper.
Remediation (terminating the orphan) brought memory from 13.9/16 GB to
9.4/16 GB and recovered the runner.

Detailed conflict resolutions and the runner wedge root-cause analysis
moved to a new companion file 05a_MERGE_EVIDENCE.md so the plan itself
fits the 500-line cap.

tx-agent: jcode
tx-validated: manual
tx-scope: docs/sessions/2026-10-19-orchestration-governance/
tx-intent: Refresh the merge plan against recomputed 12-PR residuals + 4 applied conflict resolutions + clippy coverage gap + runner wedge
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:XS This PR changes 0-9 lines, ignoring generated files

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix(jcode-tui): cache_expected_warm returns false on estimates, not just cold (re-land of #134)

2 participants