Skip to content

fix(ec2): cache EC2 queries per account - #469

Open
irodotos7 wants to merge 1 commit into
floci-io:mainfrom
irodotos7:fix/ec2-account-scoped-query-keys
Open

irodotos7 wants to merge 1 commit into
floci-io:mainfrom
irodotos7:fix/ec2-account-scoped-query-keys

Conversation

@irodotos7

Copy link
Copy Markdown
Contributor

Summary

Several EC2 views cached their data under query keys without the account:

  • the Networking panel (security groups, key pairs, VPCs, subnets, internet gateways, route tables, Elastic IPs, instances, VPC attributes),
  • the Compute launch form (AMIs, key pairs, VPCs, subnets, security groups) and the instance console output,
  • the RDS create form's security groups,
  • every hook in api/aws/ec2.queries.ts.

The account switcher invalidates all queries, so these refetch, but until the refetch finishes they show the previous account's data.
In Networking, after switching from 000000000000 to 111111111111, the panel listed account 000000000000's VPC, subnet and route table while the resource table above it was loading account 111111111111.
If the refetch fails, the old account's data stays, and its Delete buttons send those ids to the new account.

Changes:

  • Every EC2 query key ends with the active account, as the instance detail query in ComputePanel already does.
    The account goes last, so existing invalidations of ['ec2', 'vpcs'] and similar still match every account's copy by prefix, and a response that arrives after a switch lands under the account it was requested for.
  • ec2.queries.ts does this in one small useAccountScoped helper used by each hook.
  • The launch form's optimistic security group insert (setQueryData, an exact key) writes to the account the group was created in, captured when the create started.

Type of change

  • Bug fix (fix:)
  • New feature / service UI (feat:)
  • Breaking change (feat!: or fix!:)
  • Docs / chore

Area

  • Frontend (packages/frontend)
  • API / Cloud Proxy (packages/api)
  • Cloud Explorer adapter / schema
  • Build / CI / Docker

Verification

AWS EC2 via Floci core built from floci-io/floci main at 0eef65385, EC2 mock mode, in-memory storage.
Fixtures: VPC uifix-vpc-a with a subnet in account 000000000000, VPC uifix-vpc-b in account 111111111111.
Checked in Chrome at 1440x1000, with API responses delayed by 4 s so the refetch window is visible: open Networking in 000000000000, switch to 111111111111 in Settings, return to Networking.

While account 111111111111 loads main this branch
Networking panel uifix-vpc-a, 10.40.1.0/24, its route table (account 000000000000) empty
After the load uifix-vpc-b uifix-vpc-b

The Compute launch form still lists the account's AMIs, subnets and security groups.

NetworkingPanel.test.tsx adds a test that switches the account while the new account's VPCs are pending and expects the previous account's VPC to be gone; it fails on main.

Checklist

  • pnpm lint, pnpm type-check, pnpm test, and pnpm build pass locally (API 2,795 pass, frontend 306 pass)
  • New or updated tests added where it makes sense (bun test in packages/api)
  • No fake/mock data added - unwired states stay empty or show an explicit placeholder
  • Commit messages / PR title follow Conventional Commits
  • Layout or look-and-feel changes close an issue that came from an accepted Discussion (UI and Design Changes), or this PR has none (new services through the existing views, bug fixes that restore the intended layout, and accessibility fixes are exempt)
  • I have no more than 2 open, non-draft pull requests and no more than 4 open pull requests in total (drafts included) in this repository (maintainers and dependency bots are exempt).

The EC2 lists in the Networking panel, the Compute launch form, the
instance console output, the RDS form's security groups and the shared
ec2.queries hooks were cached under keys without the account. Switching
accounts invalidated them, but until the refetch finished (or for good, if
it failed) the panel showed the previous account's VPCs, subnets and route
tables, with Delete buttons that would send those ids to the new account.

Every EC2 query key now ends with the active account, as the instance
detail query already does. Invalidations of the shorter keys still match
every account's copy by prefix. The launch form's optimistic security group
insert writes to the account the group was created in.
@greptile-apps

greptile-apps Bot commented Nov 15, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 5/5

[Medium impact] The PR appears safe to merge.

Summary

EC2 queries now keep separate cached data for each account.

  • EC2 screens keep query results with the account that requested them.

No actionable issues were found. Checks were not run during this review. The requested greptile_confidence label could not be added because GitHub authentication was unavailable.

Diagram

%%{init: {'theme': 'neutral'}}%%
flowchart LR
  A[Active account] --> K[EC2 query key includes account]
  K --> C[Separate cache entry per account]
  S[Switch account] --> N[Read the new account entry]
  N --> L[Show loading until data arrives]
  M[Create security group] --> W[Write to the captured account entry]
Loading

Reviews (1) · Last reviewed commit: "fix(ec2): cache EC2 queries per account" · Reviewed by Greptile

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant