Skip to content

Add a dedicated pi agent usage collector - #10330

Open
surim0n wants to merge 5 commits into
omacom:quattrofrom
surim0n:fix/pi-usage-collector
Open

surim0n wants to merge 5 commits into
omacom:quattrofrom
surim0n:fix/pi-usage-collector

Conversation

@surim0n

@surim0n surim0n commented Sep 5, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Fixes #8270.

Add a dedicated local Pi/Oh My Pi usage record for every backend, including OpenRouter. Claude and Codex no longer aggregate Pi/OMP transcripts; native and opencode collection remains intact.

Changes

  • Discover default/configured session directories, Pi/OMP profiles, the explicit Pi session-directory override, and OMP XDG locations.
  • Count physical aliases and inherited fork responses once using lineage-scoped response identity, not globally unique short IDs. Cover OMP cost-reset forks and missing UUID parents.
  • Preserve exclusive per-response token categories and local-calendar windows; skip malformed records, counters, dates and parent paths.
  • Make caching optional, serialized, date/root-aware, and safe after empty forced scans or failed writes. Invalidation is best effort if the filesystem refuses both replacement and deletion.
  • Invalidate Codex caches from before the Pi split to prevent transitional double counting.
  • Label the record Local usage, not Subscription, and update existing documentation.

Validation

  • 25 Pi regressions plus the original four scanner assertions pass in UTC and Pacific/Kiritimati (UTC+14).
  • Claude, Codex, Claude limits, Fireworks, updater, agents-panel, plugin validation and first-party manifest schema suites pass in isolated Bash 5/Linux tests.
  • Full test/cli, metadata validation, Python compilation and git diff --check pass. Minimal-container CLI runs emit existing missing-theme-directory warnings. No full test/all pass is claimed.
  • Real updater integration discovers and writes pi.json; extracted panel functions select Local usage and make a nonempty record visible.
  • No live Quickshell/graphical acceptance run is claimed.

Coordination

Related active work: #8602 (fork deduplication), #9546 (profiles), #8345 (roots/cache identity), and #8649 (OMP collector). After this split, Pi fixes must target the dedicated collector rather than unused Claude/Codex Pi scanners. Agree on OMP ownership before adding another record.

Generated with Devin

pi and oh-my-pi sessions are currently folded into the Claude and Codex collectors, which only count Anthropic and openai-codex providers. Users on any other backend (OpenRouter, Kimi, etc.) never see their usage in the agents panel.

Add bin/omarchy-agent-usage-pi to scan ~/.pi and ~/.omp sessions for any provider, and stop counting those sessions in the Claude and Codex collectors.

Fixes omacom#8270

Generated with [Devin](https://devin.ai)

Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
@surim0n
surim0n marked this pull request as draft September 8, 2026 03:50
Make local usage caching date-aware, optional and safe after empty or
failed refreshes. Validate transcript records, discover configured
session roots and profiles, and deduplicate inherited responses without
conflating independent short IDs or mutable billing fields.

Invalidate pre-split Codex caches, label Pi as local usage, and cover
the regressions in both UTC and UTC+14.

Generated with [Devin](https://devin.ai)

Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
@surim0n
surim0n marked this pull request as ready for review September 8, 2026 04:15
@surim0n

surim0n commented Sep 8, 2026

Copy link
Copy Markdown
Contributor Author

Pushed f481aa5 after a deeper audit. Added cache/date/write-failure regressions, malformed-record handling, configured roots/profiles, fork and physical-alias deduplication, and Codex cache-transition coverage. All 25 Pi tests plus the original assertions pass in UTC and UTC+14; adjacent collector/updater tests and the CLI suite pass in isolated Linux. The description documents validation limits and overlap with #8602, #9546, #8345 and #8649. Pi is labeled Local usage; no quota or cost is inferred.

@greptile-apps

greptile-apps Bot commented Oct 3, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 5/5

[Medium impact] The PR appears safe to merge, with one non-blocking improvement to the cache regression test.

Findings

  1. P2 Cache test passes incorrectly ▶

Summary

Adds a dedicated Pi/OMP record for usage across all backends.

  • Pi and Oh My Pi usage appears in its own local record.
  • Claude and Codex keep Pi and OMP usage out of their totals.

Diagram

%%{init: {'theme': 'neutral'}}%%
flowchart LR
  P[Pi and OMP sessions] --> PC[Pi collector]
  C[Claude transcripts] --> CC[Claude collector]
  N[Native Codex sessions] --> NC[Codex collector]
  O[opencode sessions] --> CC
  O --> NC
  PC --> U[Usage updater]
  CC --> U
  NC --> U
  U --> R[JSON usage records]
  R --> A[Agents panel]
Loading

Reviews (2) · Last reviewed commit: "Merge upstream/quattro into fix/pi-usage..." · Reviewed by Greptile

Comment thread bin/omarchy-agent-usage-pi Resolved
@moxuun

moxuun commented Oct 12, 2026

Copy link
Copy Markdown

Adding a concrete data point in favor of this landing.

Setup: Omarchy 4.0.4-1, Hyprland/Quickshell, 170 session files under ~/.pi/agent/sessions. No ~/.omp install, no PI_CODING_AGENT_DIR override.

Why the current collectors show nothing for me. scan_pi_sessions() in bin/omarchy-agent-usage-codex scans exactly two roots and filters with:

rg --json -e '"provider"\s*:\s*"openai-codex"' -e '"api"\s*:\s*"openai-codex'

My Pi sessions route to non-OpenAI backends through a local router, so nothing under ~/.pi/agent/sessions matches either pattern and the panel shows no Pi row at all. That is the gap this PR fills, and it is the ordinary case for anyone using Pi's provider-agnostic routing instead of a single OpenAI subscription — not an edge case.

On the labelling. Local usage rather than Subscription is the right call. Pi's backends are provider-agnostic, and a router can point at a prepaid balance, a flat-rate subscription, or a local model, so inferring a quota or a cost from token counts would be wrong for most setups. Reporting tokens and sessions without inventing a limit is the honest shape.

One practical blocker. The PR is currently CONFLICTING against quattro (8 files, +828/-28, last push 2026-10-03), and the only review so far is Greptile's, which still carries the open P1 about the empty Pi record hiding the first-setup flow. A rebase plus that fix would put it in a state a maintainer can merge.

Happy to build the branch and report back with real numbers from a Pi install — record shape, per-model buckets, and whether the fork/lineage dedupe holds across resumed sessions — if that helps move it along.

@omarchybot omarchybot removed the enhancement New feature or request label Oct 13, 2026
identity = str(self.home) + '\n' + str(self.home / '.codex') + '\n' + str(db)
old_cache = self.cache.parent / ('codex-scan-' + hashlib.sha1(identity.encode()).hexdigest()[:16] + '.json')
old_cache.parent.mkdir(parents=True, exist_ok=True)
old_cache.write_text(json.dumps({'schemaVersion': 1, 'scanDate': namespace['today'], 'stats': stats}))

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 Cache test passes incorrectly

test_codex_cache_from_before_pi_split_is_ignored writes schemaVersion: 1, but the Codex collector already required version 2 before this PR. The test therefore passes even if the new cache namespace is removed, leaving that change unprotected. Write version 2 in this fixture so the test catches reuse of old totals containing Pi usage.

Suggested change
old_cache.write_text(json.dumps({'schemaVersion': 1, 'scanDate': namespace['today'], 'stats': stats}))
old_cache.write_text(json.dumps({'schemaVersion': 2, 'scanDate': namespace['today'], 'stats': stats}))

@omarchybot omarchybot added the enhancement New feature or request label Oct 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Agents panel never appears for active pi users on non-Anthropic/non-Codex backends (e.g. OpenRouter)

3 participants