diff --git a/bin/omarchy-agent-usage-codex b/bin/omarchy-agent-usage-codex index 6e2d918f926..797ab22288f 100755 --- a/bin/omarchy-agent-usage-codex +++ b/bin/omarchy-agent-usage-codex @@ -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() diff --git a/test/shell.d/agent-usage-codex-scanner-test.sh b/test/shell.d/agent-usage-codex-scanner-test.sh index 4b0b7fb6497..222a0e19821 100644 --- a/test/shell.d/agent-usage-codex-scanner-test.sh +++ b/test/shell.d/agent-usage-codex-scanner-test.sh @@ -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 @@ -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"