[PR #1055] [MERGED] fix: Prevent division by zero in context percentage calculation #9790

Closed
opened 2026-02-16 18:14:10 -05:00 by yindo · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/anomalyco/opencode/pull/1055
Author: @monotykamary
Created: 7/16/2025
Status: Merged
Merged: 7/16/2025
Merged by: @adamdotdevin

Base: devHead: fix/context-percentage


📝 Commits (1)

📊 Changes

1 file changed (+4 additions, -1 deletions)

View changed files

📝 packages/tui/internal/components/chat/messages.go (+4 -1)

📄 Description

Summary

This PR fixes a bug where the context percentage would display a garbage value when using a custom provider with a context window of 0.

image

This was caused by a division-by-zero error. The code has been updated to check for a zero context window before performing the division.

Test plan

Manually tested with a custom provider with a context window of 0. The percentage now correctly displays 0%.


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/anomalyco/opencode/pull/1055 **Author:** [@monotykamary](https://github.com/monotykamary) **Created:** 7/16/2025 **Status:** ✅ Merged **Merged:** 7/16/2025 **Merged by:** [@adamdotdevin](https://github.com/adamdotdevin) **Base:** `dev` ← **Head:** `fix/context-percentage` --- ### 📝 Commits (1) - [`4adc2e4`](https://github.com/anomalyco/opencode/commit/4adc2e4aa7546774adc85a8d3b28cdff47974989) fix: context percentage ### 📊 Changes **1 file changed** (+4 additions, -1 deletions) <details> <summary>View changed files</summary> 📝 `packages/tui/internal/components/chat/messages.go` (+4 -1) </details> ### 📄 Description ## Summary This PR fixes a bug where the context percentage would display a garbage value when using a custom provider with a context window of 0. <img width="818" height="64" alt="image" src="https://github.com/user-attachments/assets/529571c8-5069-48b8-91cd-a6d299fd53b0" /> This was caused by a division-by-zero error. The code has been updated to check for a zero context window before performing the division. ## Test plan Manually tested with a custom provider with a context window of 0. The percentage now correctly displays 0%. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
yindo added the pull-request label 2026-02-16 18:14:10 -05:00
yindo closed this issue 2026-02-16 18:14:10 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: anomalyco/opencode#9790