Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion bin/omarchy-agent-usage-codex
Original file line number Diff line number Diff line change
Expand Up @@ -565,8 +565,13 @@ def fetch_codex_rpc():
if entry:
result["limits"].append(entry)
except Exception as exc:
# rpc_request raises with the RPC method name as its message, which reads
# like a permission or sign-in problem in the panel. Say what happened.
result["usageStatusText"] = "Codex limits unavailable"
result["authHelpText"] = str(exc)
if isinstance(exc, TimeoutError):
result["authHelpText"] = "Codex didn't answer the usage request in time. It will retry on the next refresh."
else:
result["authHelpText"] = "Couldn't read usage limits from Codex."
finally:
try:
proc.terminate()
Expand Down
14 changes: 13 additions & 1 deletion test/shell.d/agent-usage-codex-scanner-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ while read -r request; do
jq -cn --argjson id "$id" '{id: $id, result: {account: {}}}'
;;
account/rateLimits/read)
jq -cn --argjson id "$id" --argjson limits "${CODEX_RATE_LIMITS:-{\}}" '{id: $id, result: {rateLimits: $limits}}'
[[ -n ${CODEX_RATE_LIMITS_HANGS:-} ]] ||
jq -cn --argjson id "$id" --argjson limits "${CODEX_RATE_LIMITS:-{\}}" '{id: $id, result: {rateLimits: $limits}}'
;;
esac
done
Expand Down Expand Up @@ -616,3 +617,14 @@ result=$(HOME="$TEST_HOME" CODEX_HOME="$TEST_HOME/.codex" XDG_DATA_HOME="$TEST_H
[[ $(jq -c '{tierLabel, usageStatusText, limits: [.limits[] | {label, percent}]}' <<<"$result") == '{"tierLabel":"pro","usageStatusText":"","limits":[{"label":"Weekly (7-day)","percent":0.36}]}' ]] ||
fail "Codex collector reads limits even when account/read never answers" "$result"
pass "Codex collector reads limits even when account/read never answers"

# A limits read that never answers must not surface the RPC method name: the
# panel shows authHelpText as guidance, and "account/rateLimits/read" reads
# like a sign-in problem.
result=$(HOME="$TEST_HOME" CODEX_HOME="$TEST_HOME/.codex" XDG_DATA_HOME="$TEST_HOME/.local/share" PATH="$TEST_HOME/bin:$PATH" \
CODEX_RATE_LIMITS_HANGS=1 "$ROOT/bin/omarchy-agent-usage-codex" --limits-only)
[[ $(jq -r '.usageStatusText' <<<"$result") == "Codex limits unavailable" ]] ||
fail "Codex collector reports unavailable limits when the read times out" "$result"
[[ $(jq -r '.authHelpText' <<<"$result") != *"/"* ]] ||
fail "Codex collector keeps RPC method names out of the help text" "$result"
pass "Codex collector keeps RPC method names out of the help text"