Skip to content

chore(ratchet): tighten panic baseline from 140 to 62 after the refactor - #73

Closed
KooshaPari wants to merge 9 commits into
masterfrom
chore/ratchet-62-final
Closed

KooshaPari wants to merge 9 commits into
masterfrom
chore/ratchet-62-final

Conversation

@KooshaPari

@KooshaPari KooshaPari commented Oct 15, 2026 •

Copy link
Copy Markdown
Owner

User description

Summary

Lowers the panic-prone baseline from 140 to 62 now that the refactor has landed, so the ratchet regains its regression-prevention value.

Why this is a separate PR

The refactor PRs (#69, #70, #71) remove 78 occurrences. That is a genuine improvement, but the ratchet gate treats a decrease as a pass without tightening the baseline — so with the baseline left at 140, 78 new panics could land before CI complains. The code would be cleaner while the gate stayed toothless.

This PR closes that gap. It depends on #69, #70 and #71 and should merge after them.

Not the anti-pattern

Raising a baseline to absorb new panics is the anti-pattern, and this is the opposite: the count only moves down, and only to a number that the merged code actually achieves.

This matches the repo's existing ratchet-tightening commits: 29c85cbdf and 660d9152c.

Effect

total:        140 -> 62
tracked files: 46 -> 20

Verification that the gate bites again

Adding a single .unwrap() to crates/jcode-render-core/src/reasoning.rs:

Panic-prone usage budget exceeded:
  - total panic-prone count grew: 62 -> 63
  - new production panic-prone usage: crates/jcode-render-core/src/reasoning.rs (1)

With that probe reverted, the gate reports Panic-prone budget OK: total=62 files=20 and exits 0.

Ledger

tx-agent: jcode
tx-task: panic-budget-ratchet
tx-validated: manual
tx-scope: scripts/panic_budget.json
tx-intent: restore the panic ratchet's regression-prevention value after the cleanup landed

Refs #69, #70, #71.


CodeAnt-AI Description

Reduce crashes on exceptional failures and prevent panic-related regressions

What Changed

  • Telemetry setup failures now produce a warning and drop the event instead of crashing the process.
  • Login, SSH, and other failure paths return errors or use safe fallbacks rather than panicking.
  • CI now blocks increases above the reduced limit of 62 panic-prone calls.

Impact

✅ Fewer crashes when telemetry setup fails
✅ Clearer login and SSH failure handling
✅ CI blocks regressions above 62 panic-prone calls

💡 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.

jcode-test added 9 commits October 14, 2026 16:52
Bring crates/jcode-telemetry-core/src/lib.rs back under its tracked
baseline count and drive concurrency.rs to 0, tightening the
panic-prone ratchet with no baseline change.

lib.rs: 5 -> 1 (remaining is #[cfg(test)] unwrap, below baseline of 2)
concurrency.rs: 2 -> 0
Total gate: 140 -> 126

Changes:
- TELEMETRY_HTTP_CLIENT: OnceLock<Client> -> OnceLock<Option<Client>>,
  HTTP client build failure logs warning and returns false instead of
  panicking
- background_sender() and transcript_background_sender() return
  Option<&SyncSender> instead of panicking on thread spawn failure
- Callers handle None with warning logs and graceful false returns
- concurrency.rs: replace .unwrap() on file_name() with match and
  and_then+unwrap_or for safe fallback

tx-agent: jcode
tx-task: panic-budget-ratchet
tx-validated: cargo-check
tx-scope: crates/jcode-telemetry-core/src/lib.rs, crates/jcode-telemetry-core/src/concurrency.rs
tx-intent: restore telemetry-core panic counts to or below tracked baseline
Replace all 8 panic-prone call sites in the fake ACP test fixture
binary with proper io::Result error propagation. The binary is a
[[bin]] in jcode-provider-grok-build-runtime used by integration
tests as a subprocess ACP peer.

fake_acp.rs: 8 -> 0
Total gate: 126 (continues improvement from telemetry commit)

Changes:
- main() returns io::Result<()> instead of ()
- append_log(), send(), response() all return io::Result<()>
- All .expect() calls replaced with ? operator
- panic!("unexpected ACP method") replaced with eprintln + Err return
- append_log failure is non-fatal (let _ =) since logging should not
  block the JSON-RPC response loop

Judgement: this is a test fixture binary (used via CARGO_BIN_EXE by
integration tests), but it is a published [[bin]] with no feature gate.
Converting to Result is preferred over leaving panics — a subprocess
that exits with an error code is more debuggable than one that panics.

tx-agent: jcode
tx-task: panic-budget-ratchet
tx-validated: cargo-check
tx-scope: crates/jcode-provider-grok-build-runtime/src/bin/fake_acp.rs
tx-intent: convert fake_acp test binary from panics to Result error propagation
Replace 13 unwrap/expect occurrences in the SDK auth and ssh modules with
typed error propagation. The panic-prone ratchet treats this as an
improvement, tightening the budget from 140 to 127 with no baseline change.

tx-agent: jcode
tx-task: panic-budget-ratchet
tx-validated: cargo-check
tx-scope: crates/jcode-sdk/src/auth.rs, crates/jcode-sdk/src/ssh.rs
tx-intent: drive panic-prone count in the SDK auth/ssh modules from 13 to 0
… modules

Replace 32 unwrap/expect occurrences across app-core, base, cache-vectors,
command-risk, herdr, provider-openai, provider-openrouter-runtime,
render-core, tool-search, tui and the cli entry points with typed error
propagation or a documented fallback.

The panic-prone ratchet treats this as an improvement (140 -> 108) with no
baseline change. Two fallbacks are deliberate rather than silent:
cache_hash falls back to the empty-document djb2 value so a serialization
failure cannot crash a cache lookup, and the poisoned-lock arms recover the
inner value rather than propagating the poison.

tx-agent: jcode
tx-task: panic-budget-ratchet
tx-validated: cargo-check
tx-scope: crates/jcode-app-core, crates/jcode-base, crates/jcode-cache-vectors, crates/jcode-command-risk, crates/jcode-herdr, crates/jcode-provider-openai, crates/jcode-provider-openrouter-runtime, crates/jcode-render-core, crates/jcode-tool-search, crates/jcode-tui/src/tui/ui_inline_interactive.rs, src/cli
tx-intent: drive panic-prone count in small production modules from 32 to 0 without moving the ratchet baseline
The previous panic-budget commit converted a poisoned Mutex::lock into a
match with two recovery arms, but the Err arm bound the recovered guard
as 'mut' even though 'into_inner' does not need a mutable binding.
Drop the unneeded 'mut' to keep the crate warning-free after the
panic-budget refactor.

tx-agent: jcode
tx-task: panic-budget-ratchet
tx-validated: cargo-check
tx-scope: crates/jcode-app-core/src/tool/bash.rs
tx-intent: silence 'variable does not need to be mutable' warning left by the poison-recovery edit
The panic-prone refactor removed 78 occurrences, but the baseline stayed
at 140, leaving the ratchet toothless: 78 new panics could land before CI
complained. This lowers the baseline to the achieved count so the gate
regains its regression-prevention value.

This is the ratchet-tightening step after real cleanup, matching the
existing pattern in 29c85cb and 660d915. It is not the anti-pattern of
raising the baseline to absorb new panics.

Verified the gate bites: adding a single .unwrap() to
crates/jcode-render-core/src/reasoning.rs now fails with
"total panic-prone count grew: 62 -> 63" and
"new production panic-prone usage: crates/jcode-render-core/src/reasoning.rs (1)".

Merged state: total=62, tracked files 46 -> 20.

tx-agent: jcode
tx-task: panic-budget-ratchet
tx-validated: manual
tx-scope: scripts/panic_budget.json
tx-intent: restore the panic ratchet's regression-prevention value after the cleanup landed
Copilot AI balanced review requested due to automatic review settings October 15, 2026 06:12
@codeant-ai

codeant-ai Bot commented Oct 15, 2026 •

Copy link
Copy Markdown

🤖 CodeAnt AI — Review Status

Status Commit Started (UTC) Finished (UTC)
✅ Reviewed your PR 649bf9d Oct 15, 2026 · 06:12 06:23

@codeant-ai

codeant-ai Bot commented Oct 15, 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

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.

@coderabbitai

coderabbitai Bot commented Oct 15, 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 49 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
  • Configuration used: Organization UI
  • Review profile: ASSERTIVE
  • Plan: Advanced
  • Run ID: 91f1eb14-2b88-4cfd-8304-f78ce5c19b8b
📥 Commits

Reviewing files that changed from the base of the PR and between 50f91b7 and 649bf9d.

📒 Files selected for processing: 24
  • crates/jcode-app-core/build.rs
  • crates/jcode-app-core/src/agent/provider.rs
  • crates/jcode-app-core/src/tool/bash.rs
  • crates/jcode-app-core/src/tool/discover.rs
  • crates/jcode-base/src/provider_activity_oauth.rs
  • crates/jcode-cache-vectors/src/cache_hash.rs
  • crates/jcode-command-risk/src/heredoc.rs
  • crates/jcode-command-risk/src/redirection.rs
  • crates/jcode-herdr/src/env.rs
  • crates/jcode-herdr/src/reporter.rs
  • crates/jcode-provider-grok-build-runtime/src/bin/fake_acp.rs
  • crates/jcode-provider-openai/src/stream.rs
  • crates/jcode-provider-openrouter-runtime/src/openrouter_sse_stream.rs
  • crates/jcode-render-core/src/reasoning.rs
  • crates/jcode-sdk/src/auth.rs
  • crates/jcode-sdk/src/ssh.rs
  • crates/jcode-telemetry-core/src/concurrency.rs
  • crates/jcode-telemetry-core/src/lib.rs
  • crates/jcode-tool-search/src/tool_name.rs
  • crates/jcode-tui/src/tui/ui_inline_interactive.rs
  • scripts/panic_budget.json
  • src/cli/acp.rs
  • src/cli/ssh.rs
  • src/cli/tui_launch.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

Comment @coderabbitai help to get the list of available commands.

@codeant-ai codeant-ai Bot added the size:L This PR changes 100-499 lines, ignoring generated files label Oct 15, 2026
Comment on lines +442 to +443
if let Some((text, _)) = notice.as_ref() {
lines.push(Line::from(Span::styled(text.clone(), dim)));

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: When too few rows remain, notice_rows is zero but this still appends the notice, making lines.len() exceed the available height and underflowing the caller's popover row.

Assessment: 🟠 Major · 🔁 Occurrence: Rarely · 🏷️ Logic error

Use CodeAnt Skill Fix in Cursor Fix in VSCode Claude

Prompt for AI Agent 🤖
This is a comment left during a code review.

**Path:** crates/jcode-tui/src/tui/ui_inline_interactive.rs
**Line:** 442:443
**Comment:**
	*Logic Error: When too few rows remain, `notice_rows` is zero but this still appends the notice, making `lines.len()` exceed the available height and underflowing the caller's popover row.

Validate the correctness of the flagged issue. If correct, How can I resolve this? If you propose a fix, implement it and please make it concise.
Once fix is implemented, also check other comments on the same PR, and ask user if the user wants to fix the rest of the comments as well. if said yes, then fetch all the comments validate the correctness and implement a minimal fix
👍 | 👎

@codeant-ai

codeant-ai Bot commented Oct 15, 2026

Copy link
Copy Markdown

CodeAnt Nitpicks

1 code suggestion

1. If another flow operation panicked while holding state, this returns after killing the child without running Operation::Cancel, leaving pending login state uncleared.

Incomplete implementation · crates/jcode-sdk/src/auth.rs:322

@codeant-ai

codeant-ai Bot commented Oct 15, 2026

Copy link
Copy Markdown

CodeAnt PR Risk: Medium Risk

  • The PR needs attention before merging because the notice is rendered even when notice_rows is zero.
  • This can make the popover content exceed its allocated height and disrupt layout when space is limited.

Assessed commit: 649bf9d7a006

@KooshaPari

Copy link
Copy Markdown
Owner Author

Superseded. Rebuilt cleanly on top of the now-merged refactor PRs (#69, #70, #71), so the replacement branch contains only the ratchet change. Merging this branch as-is would revert the already-merged picker fix and duplicate the refactors.

Replacement branch: chore/ratchet-62-clean (same one-file change, clean base on master).

@KooshaPari KooshaPari closed this Oct 15, 2026
@kilo-code-bot

kilo-code-bot Bot commented Oct 15, 2026

Copy link
Copy Markdown

Code Review Summary

This review did not finish. The model reached its output limit before it
could write the review — a reasoning model can spend the whole budget thinking.
Re-run the review, or lower the model's thinking effort, and it should get
further. Any inline comments below are from an earlier review.

KooshaPari added a commit that referenced this pull request Oct 17, 2026
…one)

Subagent session_daisy_1792220259698_483f4ca0aa2846ee (Tier 1 M3,
read-only) scanned 109 PRs on KooshaPari/Jcode. Result: PRs #64,
#67, #75 are the SAME 3 §22-pattern PRs on BOTH the Jcode and KCode
forks — identical SHAs (4d676f0, fed2378, a1e9530), identical
parents, identical tx-intent trailers. This is because the forks
share pre-2026-10-08 history; the squash-merge commits predate the
brand split.

The §22 finding is therefore NOT fork-specific — it generalizes to
any KooshaPari/ fork with shared pre-2026-10-08 history.

16 other CLOSED+mergedAt=null PRs returned 0 commits from
'git log origin/master --grep="(#N)"'. Several are likely
superseded by merged siblings: #94→#96, #73→#74, #62→#75. 11
appear genuinely abandoned.

22-NEW-FINDING-gh-pr-view-closed-vs-merged.md extended with a
'Cross-fork audit (2026-10-17T07:00Z)' section containing:
  - The 3-PR SHA-equivalence table
  - The 16 superseded/abandoned table
  - Operator follow-up note (apply same body-scrub to Jcode fork
    PRs if a consistent record is desired; out of scope for this
    audit)

STATE.md §4 row U updated: IN FLIGHT -> DONE — 3 MATCHES.

tx-agent: jcode
tx-validated: manual
tx-task: jcode-fork-22-audit
tx-scope: docs/sessions/2026-10-15-portal-xirp-resume/{22-NEW-FINDING,STATE.md}
tx-parent: 92d6609
tx-intent: Land the Jcode-fork §22 audit so PR 103 carries the cross-fork generalization, not just the KCode single-fork evidence
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:L This PR changes 100-499 lines, ignoring generated files

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants