Skip to content

Guard synced agent snapshot aggregation - #13339

Closed
AFOliveira wants to merge 2 commits into
omacom:quattrofrom
AFOliveira:fix/agents-snapshot-maps-20260926
Closed

AFOliveira wants to merge 2 commits into
omacom:quattrofrom
AFOliveira:fix/agents-snapshot-maps-20260926

Conversation

@AFOliveira

Copy link
Copy Markdown
Member

Synced provider and model names can collide with inherited JavaScript properties and disrupt Agents aggregation. Use prototype-free maps, own-property lookups, and validated input shapes while preserving device sums, account maxima, and active-date unions.

Focused Node/Qt tests and live desktop checks passed, including sync off/on, invalid-snapshot recovery, and peer-only provider tabs. ./test/cli reaches the same VS Code theme-path failure reproduced on the unchanged base.

Reported by Rooke Poole.

@llstrk

llstrk commented Sep 27, 2026

Copy link
Copy Markdown

Automated AI review

Community review: Independent automated community review, unaffiliated with the Omarchy team, intended to help prepare PRs for their review.

Verified: no problems found in the aggregation change. Colliding names are kept as own keys, and everything the panel reads is unchanged for the snapshot shapes the collectors write. Two test gaps and one small behaviour change are noted below.

The base and head functions were extracted from Main.qml the way the PR's test does and run in Node (V8, not Qt's V4):

input                                          base                                       head
provider id constructor / toString / __proto__  aggregateSnapshots throws at                own provider entries, other
  (any Object.prototype member)                 acc.devices[device] = true; aggregateData   providers still merged
                                                and syncRevision are not updated
model key __proto__ or constructor in           writes onto shared JS builtins              own model rows, builtins
  modelUsage                                    (Object.prototype or Object); with          unchanged
                                                __proto__, later aggregations throw
                                                even on clean data
synced-only provider with a colliding id        no tab                                      tab listed
local agent id __proto__                        missing from the written snapshot           written

On 2,000 generated snapshot sets in the collectors' shapes (device and account scope, numeric strings, legacy snapshots without activeDates, scope or hasPromptStats, duplicate device ids), head and base gave identical aggregates, enabledProviders and Panel modelRows() output. The other differences found are on inputs no Omarchy writer produces, plus extra modelUsage bucket fields (for example costUSD or contextWindow), because the Claude collector's stats-cache fallback copies modelUsage through as-is: the base summed them across devices, and the head drops them. Only the four token fields are read, and the Panel rows were identical in all 1,000 generated sets that carried such fields. The PR's own test passes on the head.

Test gaps

Optional test improvement: the assertion modelUsage.toString.inputTokens === 5 (test line 58) still passes if modelUsage goes back to ({}). The lookup then reaches the inherited Object.prototype.toString, which the old code wrote inputTokens onto, although the model row is missing from the output. Reverting todayTokensByModel to ({}) or removing the new numberValue type guard also leaves the test passing. Using __proto__, constructor and toString as keys in both modelUsage and todayTokensByModel, asserting Object.keys(...) on both maps, and setting one numeric field to {"toString":1,"valueOf":1} catches all three. These assertions pass on the head and fail on the base and on each of the three reversions.

Optional test improvement: the Qt fixture runs only with OMARCHY_AGENTS_QML_TEST=1. When the flag is unset, the file prints no skip line, so ./test/shell cannot show that the runtime check was left out. The "Compositor-dependent tests" section of docs/testing.md and neighbouring runtime tests gate on require_compositor alone. Dropping the flag, or calling skip when it is unset, keeps the missing coverage visible.

Smaller notes

  • Empty deviceId: a peer snapshot with deviceId: "" used to count as device. It now reaches safeDeviceId(""), which substitutes this machine's hostname, so the device count can drop by one. No Omarchy writer emits an empty id. typeof snapshot.deviceId === "string" && snapshot.deviceId ? snapshot.deviceId : "device" would keep the old fallback.
  • Overlapping open PRs: Add cached SSH machine usage to Agents #11546 (draft) renames property var enabledProviders to localProviders, and Read Codex day totals from the account, and label each usage section's source #12865 replaces combineNumber and combineObjectNumbers with tally helpers. Both patches keep plain {} maps with for...in in the rewritten code. The new test finds property var enabledProviders: { and those two functions by exact text. Whichever lands later needs to carry the null-prototype guards and update the test's exact-text lookups.

Review information

Test scope: source review of shell/plugins/agents/Main.qml, Panel.qml and the new tests, plus qtdeclarative v6.11.2 (V4) source for __proto__, JSON.parse, Object.create(null) and QVariant handling. Isolated Node runs of the PR's test, base/head comparisons on collision names, 3,000 generated snapshot sets and edge inputs, and single-change reversions of the head against the PR's test. Not run: anything in Qt or Quickshell (including the opt-in fixture), a live desktop with sync, or ./test/cli. Qt-specific behaviour is inferred from source.

AI process: Opus 5.5 Medium coordination and synthesis, Opus 5.5 Xhigh technical review and final fact check, GPT 6 Sol Xhigh search for related issues, Opus 5.5 Medium editorial check.

Opt out: To stop receiving these reviews, reply to this comment saying so.

@dhh

dhh commented Oct 2, 2026

Copy link
Copy Markdown
Contributor

Thank you! Brought in with your authorship in #14049.

@dhh dhh closed this Oct 2, 2026
@dhh

dhh commented Oct 3, 2026

Copy link
Copy Markdown
Contributor

Update: this was pulled back out of #14049. Syncing usage between machines turned out to be more machinery than it's worth for Omarchy, so we're not taking it after all. Thanks for the work regardless.

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.

4 participants