CodexBar icon indicating copy to clipboard operation
CodexBar copied to clipboard

Let user plugins report when usage was last measured

Open caseclose opened this issue 4 weeks ago • 2 comments

Could a user plugin optionally tell CodexBar when its source last measured usage, so the menu’s “Updated” time reflects the age of that measurement? This follows up on the plugin timestamp discussion in #4937.

For a synthetic example, suppose a collector records 25% usage at 10:00 UTC and then goes offline. At 10:12 UTC a plugin successfully reads the cached sample. The plugin can show 10:00 in a detail row, but the snapshot gets the 10:12 fetch time. Another successful fetch at 10:13 makes the same sample look fresh again.

At 10:12 I’d expect the menu to say “Updated 12 minutes ago.” If the collector measures the same 25% again at 10:14 and the plugin fetches it immediately, “Updated just now” would then be accurate.

Would an optional plugin result field such as observedAt fit the snapshot API? Plugins that omit it could keep today’s fetch-time behavior, and CodexBar could still track successful fetches separately for refresh scheduling.

caseclose avatar Nov 06 '26 07:11 caseclose

Codex review: this still needs some work.

Summary Keep open: current main lacks source-timestamp publication, and the owner explicitly reserved this capability for a separate host-contract decision.

Reproducibility: Current source proves that each successful plugin fetch supplies the host clock to snapshot.updatedAt and that the menu formats that timestamp; no live reproduction was run.

Maintainer decision needed

  • Question: Should user plugins be allowed to supply canonical measurement time, and how should that time affect quota hooks versus successful refresh tracking?
  • Recommendation: Approve an additive timestamp contract: Define validation, omission fallback, repeated-sample behavior, and fetch-success semantics before implementing shared mapper, type, documentation, and regression changes.
  • Why: The owner explicitly deferred this contract, and current source uses the same timestamp for menu age and quota observations.

Next step Decide the source-timestamp contract, then cover repeated cached samples and same-percentage remeasurement without changing refresh scheduling or quota hooks accidentally.

Review details

Best possible solution:

Support an optional validated measurement timestamp with fetch-time fallback and separately defined refresh-success semantics.

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

Current source proves that each successful plugin fetch supplies the host clock to snapshot.updatedAt and that the menu formats that timestamp; no live reproduction was run.

Is this the best way to solve the issue?

An additive timestamp field fits the existing plugin boundary, but its validation and downstream observation semantics require owner approval before implementation.

AGENTS.md: found and applied where relevant.

Remaining risk / open question:

  • The contract must define timestamp validation and handling of future or out-of-order measurements.
  • Changing snapshot.updatedAt also changes quota-transition inputs; display age, successful fetches, and hook behavior need explicit semantics.

Codex review notes: model internal, reasoning medium; reviewed against 20ada8abf0e4.

Label changes

Label changes:

  • add P3: This is a bounded optional plugin API improvement; the report establishes no outage or broken existing contract.
  • add impact:ux-friction: Successful reads of cached measurements can present misleading freshness in the menu.
  • add issue-rating: 🦞 diamond lobster: Current issue advisory state selects this label.
  • add clawsweeper:source-repro: Current issue advisory state selects this label.
  • add clawsweeper:no-new-fix-pr: Current issue advisory state selects this label.
  • add clawsweeper:needs-maintainer-review: Current issue advisory state selects this label.
  • add clawsweeper:needs-product-decision: Current issue advisory state selects this label.

Label justifications:

  • P3: This is a bounded optional plugin API improvement; the report establishes no outage or broken existing contract.
  • impact:ux-friction: Successful reads of cached measurements can present misleading freshness in the menu.
Evidence reviewed

What I checked:

  • Current host contract lacks measurement time: The snapshot allowlist has no observedAt or updatedAt input, and mapped snapshots unconditionally receive updatedAt: now. (Sources/CodexBarCore/Plugins/ProviderPluginSnapshotMapper.swift:97, 20ada8abf0e4)
  • Documented validation prevents a plugin workaround: The documented result envelope rejects unknown result and snapshot keys; the TypeScript snapshot interface likewise exposes no source measurement timestamp. (docs/plugins.md:529, 20ada8abf0e4)
  • Displayed age uses snapshot time: The normal menu subtitle formats snapshot.updatedAt, establishing the reported path from fetch time to the displayed Updated age. (Sources/CodexBar/Menu/MenuCardView.swift:1178, 20ada8abf0e4)
  • Timestamp semantics extend beyond presentation: User-plugin quota transitions consume snapshot.updatedAt as observation time, and reset processing skips timestamps that do not advance. (Sources/CodexBar/UsageStore/UsageStore+UserPlugins.swift:167, 20ada8abf0e4)
  • Explicit owner direction: In https://github.com/steipete/CodexBar/pull/4937#issuecomment-6667594585, steipete closed the bundled-provider approach, recommended approved loopback endpoints in user plugins, and explicitly left source-timestamp publication to a separate host-contract decision.
  • Existing capture-age work addresses a different trigger: Merged https://github.com/steipete/CodexBar/pull/4737 displays retained snapshot age after failed refreshes; it does not preserve source age across successful reads of cached samples.
How this review workflow works
  • 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; those execution lanes are retired.
  • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.

Reviewed November 6, 2026, 2:45 AM ET / 07:45 UTC.

clawsweeper[bot] avatar Nov 06 '26 07:11 clawsweeper[bot]

Thanks for the clear cached-sample example. We checked the mapper and quota hooks: updatedAt is currently the fetch timestamp and also orders quota/reset observations, so replacing it changes behavior beyond the menu's age label. We're closing this request and retaining fetch time as the canonical snapshot time. A plugin can show the source measurement time in a detail row and reject stale samples using its own freshness policy. A separate display-only observation-time proposal that preserves hook ordering would be grounds to reconsider.

steipete avatar Nov 07 '26 04:11 steipete