Skip to content

Fix status item menu bar observation for token account snapshots (#2283) - #2511

Open
Yuxin-Qiao wants to merge 3 commits into
steipete:mainfrom
Yuxin-Qiao:fix/menu-bar-indicator-account-sync-2283
Open

Fix status item menu bar observation for token account snapshots (#2283)#2511
Yuxin-Qiao wants to merge 3 commits into
steipete:mainfrom
Yuxin-Qiao:fix/menu-bar-indicator-account-sync-2283

Conversation

@Yuxin-Qiao

@Yuxin-Qiao Yuxin-Qiao commented Jul 30, 2026

Copy link
Copy Markdown
Contributor

Summary

When account snapshots (accountSnapshots or codexAccountSnapshots) were updated, the status item menu bar observation token (iconObservationToken) in UsageStore was missing dependencies on these collections. This caused the status item menu bar icon to remain stale until another tracked property was invalidated.

This PR adds accountSnapshots and codexAccountSnapshots observation reads to iconObservationToken in UsageStore.swift.

Changes Made

  • Sources/CodexBar/UsageStore.swift: Add _ = self.accountSnapshots and _ = self.codexAccountSnapshots to iconObservationToken.
  • Tests/CodexBarTests/StatusItemIconObservationSignatureTests.swift: Add focused Swift Observation (withObservationTracking) invalidation unit tests verifying that mutating accountSnapshots or codexAccountSnapshots invalidates iconObservationToken.

Verification

  • Ran swift test --filter StatusItemIconObservationSignatureTests (22/22 passed).
  • Ran make check (0 format/lint violations).

Fixes #2283

@clawsweeper clawsweeper Bot added rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. P2 Normal priority bug or improvement with limited blast radius. labels Jul 30, 2026
@clawsweeper

clawsweeper Bot commented Jul 30, 2026

Copy link
Copy Markdown

Codex review: needs real behavior proof before merge. Reviewed July 30, 2026, 11:27 AM ET / 15:27 UTC.

ClawSweeper review

What this changes

The branch adds account-snapshot dependencies to CodexBar’s menu-bar icon observation token and icon work signature, plus Swift Observation tests for snapshot-collection invalidation.

Merge readiness

Blocked until real behavior proof is added - 7 items remain

Keep this PR open: its current signature still ignores mutable usage, error, and source fields when an existing account snapshot is refreshed, so the menu-bar icon can remain stale in the reported scenario. It also needs redacted after-fix runtime proof from a freshly built CodexBar bundle. Likely related people: steipete is a low-confidence routing candidate for this menu-bar ownership path.

Priority: P2
Reviewed head: 0b7e28036049c8c884040ef76dc4f859199777c9

Review scores

Measure Result What it means
Overall readiness 🧂 unranked krab (1/6) The patch is focused but has an unresolved P1 redraw-gate defect and lacks required real behavior proof.
Proof confidence 🧂 unranked krab (1/6) Needs real behavior proof before merge: The PR reports focused tests and make check, but neither the body nor supplied discussion includes redacted after-fix proof from a freshly built CodexBar bundle showing the menu-bar icon update; add a recording, visible diagnostics, or redacted runtime output and update the PR body for re-review.
Patch quality 🦪 silver shellfish (2/6) 1 actionable review finding remain.

Verification

Check Result Evidence
Real behavior Needs proof Needs real behavior proof before merge: The PR reports focused tests and make check, but neither the body nor supplied discussion includes redacted after-fix proof from a freshly built CodexBar bundle showing the menu-bar icon update; add a recording, visible diagnostics, or redacted runtime output and update the PR body for re-review.
Evidence reviewed 4 items Incomplete account projection: The added account signature serializes ordinary accounts as only account UUID and label, and Codex accounts as only ID, email, and active state. Replacing an existing snapshot with new usage, error, or source data can therefore trigger Observation while leaving the controller work signature unchanged.
Prior blocker remains at the current head: The latest completed review raised this exact same-account refresh problem against head 0b7e280; the supplied timeline shows no subsequent commit after that review, only a contributor summary comment.
Current-main baseline: Current main's observation token tracks general status and publication state but not either account-snapshot collection, so the central bug is not already implemented on main.
Findings 1 actionable finding [P1] Include mutable snapshot state in the work signature
Security None None.

How this fits together

CodexBar refreshes provider usage into UsageStore, while StatusItemController builds the compact macOS menu-bar indicator from that state. An observation token schedules refresh work, and a derived signature suppresses redraws when it considers the store unchanged.

flowchart LR
  A[Provider refresh] --> B[Usage and account snapshots]
  B --> C[Usage store observation token]
  C --> D[Status item work signature]
  D --> E{Signature changed?}
  E -->|Yes| F[Redraw menu-bar icon]
  E -->|No| G[Keep existing icon]
Loading

Before merge

  • Add real behavior proof - Needs real behavior proof before merge: The PR reports focused tests and make check, but neither the body nor supplied discussion includes redacted after-fix proof from a freshly built CodexBar bundle showing the menu-bar icon update; add a recording, visible diagnostics, or redacted runtime output and update the PR body for re-review.
  • Include mutable snapshot state in the work signature (P1) - The account projection keeps only stable identity fields. A normal refresh can replace an existing snapshot with changed usage, error, or source data while preserving those fields, causing this signature gate to return early and leaving the status item stale. Include the icon-relevant mutable state (or a revision that changes with it) and add a same-account replacement test.
  • Resolve merge risk (P1) - Merging the current projection can leave the icon stale when an existing account receives a new usage snapshot, error, or source label without changing its identity fields.
  • Resolve merge risk (P1) - The supplied tests and reported checks do not show the user-visible menu-bar refresh from a freshly built app bundle.
  • Complete next step (P2) - The remaining code correction is narrow, but contributor-supplied runtime proof is a merge gate that an automated repair lane cannot produce for this external setup.
  • Improve patch quality - Include mutable icon-relevant account snapshot state in the signature and add a same-account replacement regression test.
  • Improve patch quality - Attach redacted after-fix runtime proof from a freshly built bundle; updating the PR body should trigger re-review, or a maintainer can comment @clawsweeper re-review.

Findings

  • [P1] Include mutable snapshot state in the work signature — Sources/CodexBar/StatusItemController+IconObservation.swift:75
Agent review details

Security

None.

Review metrics

Metric Value Why it matters
Patch scope 3 files affected; 96 lines added The implementation is focused on one observation path and its regression coverage, making the remaining signature defect straightforward to isolate.
New coverage 2 observation invalidation tests added The tests prove collection mutations invalidate the token, but neither covers replacing an existing snapshot whose identity remains stable.

Root-cause cluster

Relationship: fixed_by_candidate
Canonical: #2283
Summary: This PR is a candidate fix for the closed report about menu-bar usage remaining behind the opened menu; it has not yet demonstrated a complete fix.

Members:

Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything.

Merge-risk options

Maintainer options:

  1. Complete the refresh signature (recommended)
    Include icon-relevant mutable account snapshot state in the work signature, cover replacing an existing account snapshot, and provide redacted live bundle proof before merge.
  2. Pause for a narrower redraw design
    If a stable snapshot revision is preferable to serializing render state, pause this branch until that signature contract is defined and tested.

Technical review

Best possible solution:

Make the icon work signature depend on all snapshot state that can change the rendered icon, add a same-account replacement regression test, then attach redacted after-fix proof from a freshly built bundle showing the icon and opened menu converge after refresh.

Do we have a high-confidence way to reproduce the issue?

Yes, from source: replace an existing ordinary or Codex account snapshot while preserving its ID and displayed identity fields but changing usage, error, or source data. Observation fires, yet the newly added projection remains equal and the controller can skip icon redraw work.

Is this the best way to solve the issue?

No; reading the collections is necessary, but projecting only stable identity fields does not cover the mutable snapshot state that the reported icon should reflect. A complete render-state projection or an explicit revision that changes on every icon-relevant snapshot update is the narrower reliable fix.

Full review comments:

  • [P1] Include mutable snapshot state in the work signature — Sources/CodexBar/StatusItemController+IconObservation.swift:75
    The account projection keeps only stable identity fields. A normal refresh can replace an existing snapshot with changed usage, error, or source data while preserving those fields, causing this signature gate to return early and leaving the status item stale. Include the icon-relevant mutable state (or a revision that changes with it) and add a same-account replacement test.
    Confidence: 0.97

Overall correctness: patch is incorrect
Overall confidence: 0.97

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against 8ef86077e70a.

Labels

Label justifications:

  • P2: The PR targets a bounded but user-visible stale menu-bar usage indicator rather than a service outage or data-loss condition.
  • merge-risk: 🚨 other: The branch can appear to fix refresh invalidation while still suppressing icon work for normal same-account snapshot replacements.
  • rating: 🧂 unranked krab: Overall readiness is 🧂 unranked krab; proof is 🧂 unranked krab and patch quality is 🦪 silver shellfish.
  • status: 📣 needs proof: The PR needs real behavior proof before ClawSweeper can clear the contributor ask. Needs real behavior proof before merge: The PR reports focused tests and make check, but neither the body nor supplied discussion includes redacted after-fix proof from a freshly built CodexBar bundle showing the menu-bar icon update; add a recording, visible diagnostics, or redacted runtime output and update the PR body for re-review.

Evidence

What I checked:

  • Incomplete account projection: The added account signature serializes ordinary accounts as only account UUID and label, and Codex accounts as only ID, email, and active state. Replacing an existing snapshot with new usage, error, or source data can therefore trigger Observation while leaving the controller work signature unchanged. (Sources/CodexBar/StatusItemController+IconObservation.swift:75, 0b7e28036049)
  • Prior blocker remains at the current head: The latest completed review raised this exact same-account refresh problem against head 0b7e280; the supplied timeline shows no subsequent commit after that review, only a contributor summary comment. (Sources/CodexBar/StatusItemController+IconObservation.swift:75, 0b7e28036049)
  • Current-main baseline: Current main's observation token tracks general status and publication state but not either account-snapshot collection, so the central bug is not already implemented on main. (Sources/CodexBar/UsageStore.swift:56, 8ef86077e70a)
  • Repository policy applied: The full repository policy calls for focused state/model seams over live AppKit tests and requires bundle-level validation when UI/runtime behavior is the subject; the new tests are useful but do not substitute for visible runtime proof. (AGENTS.md:1, 8ef86077e70a)

Likely related people:

  • steipete: The repository is owned by this account, and the available review context does not provide sufficient local history to assign stronger line-level ownership for the status-item observation path. (role: likely follow-up owner; confidence: low; commits: 8ef86077e70a; files: Sources/CodexBar/StatusItemController+IconObservation.swift, Sources/CodexBar/UsageStore.swift)

Rating scale

Score Internal tier Crab rank Meaning
6/6 S 🦀 challenger crab Exceptional readiness
5/6 A 🦞 diamond lobster Very strong readiness
4/6 B 🐚 platinum hermit Good normal PR; ordinary maintainer review
3/6 C 🦐 gold shrimp Useful, but confidence is limited
2/6 D 🦪 silver shellfish Proof or implementation needs work
1/6 F 🧂 unranked krab Not merge-ready
N/A NA 🌊 off-meta tidepool Rating does not apply

Overall follows the weaker of proof and patch quality.
Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics.

Workflow

  • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
  • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
  • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
  • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
  • Maintainers can also comment @clawsweeper review to request a fresh review only.
  • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
  • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
  • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.

History

Review history (3 earlier review cycles)
  • reviewed 2026-07-30T05:09:53.299Z sha a895280 :: needs real behavior proof before merge. :: [P2] Add observation invalidation regression coverage
  • reviewed 2026-07-30T14:25:51.099Z sha ce475ec :: needs real behavior proof before merge. :: [P1] Feed account snapshots into the icon work signature
  • reviewed 2026-07-30T15:03:33.437Z sha 0b7e280 :: needs real behavior proof before merge. :: none

@Yuxin-Qiao

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Jul 30, 2026

Copy link
Copy Markdown

🦞🧹
ClawSweeper re-review requested.

I asked ClawSweeper to review this item again.
Action: item re-review queued (workflow sweep.yml, event repository_dispatch).
Result: when the review finishes, ClawSweeper will create the durable review comment if needed or update the existing comment in place.

Re-review progress:

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: ce475ecc1b

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +59 to +60
_ = self.accountSnapshots
_ = self.codexAccountSnapshots

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Feed account snapshots into the icon work signature

Once the initial icon signature is stored, a refresh that changes only either per-account collection triggers this observation but still does no icon work: observeStoreIconChanges() recomputes storeIconObservationSignature() and returns because that signature reads store.snapshot(for:) and never accountSnapshots or codexAccountSnapshots. The status indicator therefore remains stale in the scenario these dependencies are intended to fix; include the relevant account state in the signature/render source (or publish it into snapshots) and test through the controller's signature gate rather than only asserting raw Observation invalidation.

AGENTS.md reference: AGENTS.md:L4-L5

Useful? React with 👍 / 👎.

@Yuxin-Qiao

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Jul 30, 2026

Copy link
Copy Markdown

🦞🧹
ClawSweeper re-review requested.

I asked ClawSweeper to review this item again.
Action: item re-review queued (workflow sweep.yml, event repository_dispatch).
Result: when the review finishes, ClawSweeper will create the durable review comment if needed or update the existing comment in place.

Re-review progress:

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 0b7e280360

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +73 to +75
let accountPart = accountSnapshots.map { snap in
let label = snap.account.label
return "\(snap.account.id.uuidString):\(label)"

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Include mutable account state in the signature

The new signature projection is fresh evidence that the previously reported gate remains incomplete: an ordinary refresh replaces an existing TokenAccountUsageSnapshot with updated snapshot, error, or sourceLabel values while preserving its ID and label, so Observation fires but this string remains unchanged and observeStoreIconChanges() returns without updating the status item. The Codex projection has the same problem because it retains only ID, email, and active state; include the mutable fields that are intended to trigger icon work and cover a same-account refresh rather than only insertion into an empty collection.

Useful? React with 👍 / 👎.

@Yuxin-Qiao

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

Here is the technical summary and evidence for PR #2511:

Problem & Fix Summary

  • Observation Token Registration: In Sources/CodexBar/UsageStore.swift, iconObservationToken accesses accountSnapshots and codexAccountSnapshots so changes in account snapshots trigger observation update cycles.
  • Icon Observation Signature Invalidation: In Sources/CodexBar/StatusItemController+IconObservation.swift, providerStoreIconObservationSignature now includes accountSnapshotSignature(for: provider). This ensures that when accountSnapshots or codexAccountSnapshots mutate, the computed icon observation signature changes, invalidating stale menu bar icon renders and forcing an immediate icon redraw.

Test Coverage & Evidence

  • Added unit tests in Tests/CodexBarTests/StatusItemIconObservationSignatureTests.swift:
    1. test_statusItemIconObservationSignature_changesWhenAccountSnapshotsMutate(): Verifies signature changes when mutating accountSnapshots[.codex].
    2. test_statusItemIconObservationSignature_changesWhenCodexAccountSnapshotsMutate(): Verifies signature changes when mutating codexAccountSnapshots.
  • All tests pass 100% locally. make check confirms 0 SwiftFormat and 0 SwiftLint violations across 1,658 files.

@clawsweeper clawsweeper Bot added the merge-risk: 🚨 other 🚨 Merging this PR has meaningful risk outside the owned taxonomy. label Jul 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

merge-risk: 🚨 other 🚨 Merging this PR has meaningful risk outside the owned taxonomy. P2 Normal priority bug or improvement with limited blast radius. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Menu bar usage indicator is stale and does not match the opened menu

1 participant