Skip to content

Agent usage: config-dir cache key and owner-only modes - #12265

Closed
chessing234 wants to merge 10 commits into
omacom:quattrofrom
chessing234:fold/agent-usage-cache
Closed

chessing234 wants to merge 10 commits into
omacom:quattrofrom
chessing234:fold/agent-usage-cache

Conversation

@chessing234

@chessing234 chessing234 commented Sep 17, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Test plan

  • bash test/shell.d/agent-usage-claude-limits-test.sh (includes dual CLAUDE_CONFIG_DIR isolation + legacy unlink + 0700 dir)
  • bash test/shell.d/agent-usage-claude-scanner-test.sh (concurrent write leaves 0600)
  • Local check that Codex cache_root/write_json clamp to 0700/0600
  • CI agent-usage-codex-scanner-test.sh (expects cache mode 600; needs Linux stat -c)

@llstrk

llstrk commented Sep 18, 2026

Copy link
Copy Markdown

Recommendation: fix the Codex syntax error and update permission tests

Finding 1: the Codex collector cannot start

tmp.replace(path) at omarchy-agent-usage-codex:382 is over-indented. On f3e74aac, parsing and --help both fail with IndentationError: unexpected indent; baseline succeeds. The Codex scanner suite goes from 21 passing checks to failing immediately.

Impact: failure occurs before any collector code executes, not just when writing a cache.

Requested change: correct the indentation without restoring public-read permissions, then rerun the scanner suite.

Finding 2: scanner tests still require the old permissions

The Claude scanner reaches its mode assertion with the intended 0600 output but fails because it expects 0644. Codex has the same stale expectation, currently hidden by the syntax failure.

Requested change: update both scanner assertions to expect owner-only files.

Verified: Claude caches are isolated by configuration directory

Two directories share a cache root; synthetic HTTP returns A=10% and B=80%:

Request sequence        A       B       A again
Baseline                10%     10%     10%
PR                      10%     80%     10%
                                ^       ^
                         isolated B    reuse A

Baseline: one shared cache file, 0644
PR:       two keyed cache files, 0600

Test scope: synthetic HTTP, not live accounts. Codex permission behavior remains unverified until it can parse. These results do not establish retroactive hardening of existing or abandoned caches.

Automated AI review: Astra inspected the PR, Fable 5.1 and a separate Astra session reviewed it independently, then findings were checked against targeted tests.

@chessing234

Copy link
Copy Markdown
Contributor Author

fixed the codex indent and kept cache files at 0600

tmp.replace was over-indented so the scanner could not start.
mkdir(exist_ok) left older 0755 trees alone, and prior runs wrote 0644
cache files. Create the directory at 0700 and tighten any world bits on
existing files so plan/usage details stay private after upgrade.
Assert two CLAUDE_CONFIG_DIR accounts get distinct digests, the unkeyed
claude-limits.json is removed, the cache dir stays 0700, and the Codex
scanner expects 0600 instead of the old world-readable mode.
@chessing234
chessing234 force-pushed the fold/agent-usage-cache branch from ec686f6 to a83e319 Compare September 30, 2026 05:13
@greptile-apps

greptile-apps Bot commented Sep 30, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 5/5

[Medium impact] The PR appears safe to merge; no new actionable issue or outstanding previous finding remains.

Findings

  1. P2 Missing limits pass the test ▶

Summary

The PR isolates Claude limits caches by account configuration and makes agent-usage caches owner-only. Since the previous review, the accounts test now supplies a primary-cache value and requires the collector to return it when it inherits another account’s configuration.

Reviews (6) · Last reviewed commit: "Assert the primary account keeps its own..." · Reviewed by Greptile

Comment thread bin/omarchy-agent-usage-claude Resolved
Comment thread bin/omarchy-agent-usage-claude Resolved
Comment thread bin/omarchy-agent-usage-claude Resolved
@omarchybot omarchybot added the bug Something isn't working label Oct 14, 2026
With no recorded account identity the primary account fell back on the default cache name, which collect_limits keys by config_dir() -- the collector's inherited CLAUDE_CONFIG_DIR rather than the home it just read credentials from. Run with CLAUDE_CONFIG_DIR pointing at an added account, the primary account would then show that account's cached allowance as its own when its probe failed.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@omarchybot omarchybot added the verified Omarchy Triage has verified that this issue is ready for final review label Oct 14, 2026
collector.main()
PY
)
[[ $(jq -c '.accounts[0].limits | map(.percent)' <<<"$inherited") != *0.66* ]] ||

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

P2 Missing limits pass the test

The primary account’s probe is made to fail, but this assertion passes even if the collector returns no limits. That means the test does not verify its stated behavior: retaining the primary account’s own cached limits when CLAUDE_CONFIG_DIR points to another account. Check for the expected cached percentage as well as the absence of the other account’s percentage.

Knowledge Base Used: Agent accounts and provider usage

@omarchybot omarchybot added ready Good to merge and removed verified Omarchy Triage has verified that this issue is ready for final review labels Oct 14, 2026
The inherited CLAUDE_CONFIG_DIR test only checked the other account's percentage was absent, so a collector returning no limits at all would pass. Seed the primary's own cache and expect its value.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@omarchybot omarchybot added verified Omarchy Triage has verified that this issue is ready for final review ready Good to merge and removed ready Good to merge labels Oct 14, 2026
@omarchybot

Copy link
Copy Markdown
Collaborator

Reviewed and verified at 67ccd48; it fixes #9382. I pushed one fix and a test to your branch.

Reproduced on a worker built from the Omarchy ISO. Two CLAUDE_CONFIG_DIR directories, probed one after the other with stubbed HTTP (A answers 10%, B answers 80%). On the base commit, B showed A's 10%, and so did a third directory whose probe failed, all read from the shared claude-limits.json. With this branch B shows 80%, the failed one shows nothing, and each directory has its own cache file. The updated scanner, limits, accounts and permissions tests fail against the base collectors and pass here. All 17 test/shell.d/agent* files and ./test/cli pass on the worker at this head.

Fixed on your branch (f994279, 67ccd48): a registered primary account with no recorded account UUID went through the default cache name, and that name is keyed by the collector's CLAUDE_CONFIG_DIR, not by the home whose credentials it had just read. So with CLAUDE_CONFIG_DIR pointing at an added account, a failed primary probe showed that account's cached allowance as the primary's own. Greptile flagged this too. account_limits now keys that case by a digest of the primary's own home, which is the same key a standalone run of that home uses. The new test in agent-usage-accounts-test.sh expects the primary's own cached value and gets the other account's without the fix.

Second opinion: Codex Medium reviewed the whole diff and both commits, in two rounds. It agreed on the fix, and its independence is not guaranteed. It also noted that the permission sweep in cache_root() stops at the first file that disappears mid-loop. That changes nothing a user would see: the directory is already 0700 by then, and the next call sweeps again. It also pointed out that deleting the old unkeyed cache means the primary shows no percentages until its next successful probe, which is the right tradeoff for a file that can't say whose numbers it holds.

This now waits on the maintainer.

@omarchybot omarchybot removed ready Good to merge verified Omarchy Triage has verified that this issue is ready for final review labels Oct 25, 2026
@omarchybot

Copy link
Copy Markdown
Collaborator

This branch no longer merges into quattro. Since it was opened, quattro has moved both collectors onto the shared shell/plugins/agents/collectors.py, and it now fixes the bug #9382 reports another way, so I have not ported this branch onto it.

What quattro does now. 80e9460 (#14040) keys the Claude limits cache by the account a home is signed in as (oauthAccount.accountUuid, giving claude-limits-<uuid>.json), on the plain CLAUDE_CONFIG_DIR path as well as for registered accounts. I checked it on a worker built from the Omarchy ISO, with the usage probe stubbed and one collector run per CLAUDE_CONFIG_DIR home. On this branch's old base every home showed the first account's 10%. On quattro 631dacd, two signed-in homes showed their own 10% and 80%, and a third whose probe failed showed nothing. That is the case #9382 describes.

What quattro still leaves open:

  • A home that records no account UUID still uses the shared claude-limits.json, so two such homes can still read each other's numbers. This branch's per-directory key fixes that case. On the worker, a second identity-less home whose probe failed showed the first one's 30% on quattro and nothing here. A signed-in Claude Code home normally records its UUID, so this case is narrow. If it is wanted, it belongs as a fallback beside the UUID key rather than in its place: keying only by directory would lose quattro's protection when one home is signed in to a different account.
  • Owner-only cache modes (0700 directory, 0600 files). quattro still deliberately writes these files at 0644, in write_json in collectors.py, which every collector now shares. Whether usage and plan details should be private to the user is a policy call for the maintainer, and it would be a change to that shared module.

Second opinion: Codex Medium read this branch, quattro and the reproduction. It agreed that quattro fixes the reported case and that this is better closed than ported, and its independence is not guaranteed. It added two points of its own. First, forcing a fresh probe for the identity-less home still shows the other home's numbers on quattro, now marked stale. Second, porting this branch's directory key onto the main path would regress quattro's handling of an account switch within one home.

Thanks @chessing234, this found a real bug, and the two pieces above are still worth having. This now waits on the maintainer, and my recommendation is to close it in favour of #14040, with the identity-less fallback and the cache modes left to fresh changes against quattro if they are wanted.

@chessing234

Copy link
Copy Markdown
Contributor Author

closing this. quattro fixes #9382 by the account uuid, which is the case this was opened for. a no-uuid home and the cache file modes are a different change.

@chessing234 chessing234 closed this Nov 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

agents: Claude limits cache is shared across CLAUDE_CONFIG_DIR accounts

3 participants