Skip to content

Commit c5d6435

Browse files
fix(cli): hoist account_id hydration above register* so feature-flag gates resolve on first run
Previously `registerNodes` (and other `register*` calls that consult `isFeatureEnabled`) ran before `account_id` was hydrated, so the very first CLI invocation after login silently saw `false` for every flag and hid gated surfaces like `--enable-infiniband` until the cache was seeded by a subsequent run. The hydration is also now awaited so the analytics block reuses the same identifier without racing the config write. Generated with [Indent](https://indent.com) Co-Authored-By: sigmachirality <sigmachirality@users.noreply.github.com>
1 parent 87776f2 commit c5d6435

1 file changed

Lines changed: 15 additions & 12 deletions

File tree

src/index.ts

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,21 @@ async function main() {
4242
.description("The San Francisco Compute command line tool.")
4343
.version(pkg.version);
4444

45+
// Hydrate `account_id` before registering commands so feature-flag-gated
46+
// surfaces (e.g. `--enable-infiniband` on `sf nodes create`) resolve
47+
// correctly on the very first CLI invocation after login, rather than only
48+
// appearing after the cache has been seeded by a previous run.
49+
const config = await loadConfig();
50+
let exchangeAccountId = config.account_id;
51+
if (!exchangeAccountId) {
52+
const client = await apiClient(config.auth_token);
53+
const { data } = await client.GET("/v1/account/me", {});
54+
if (data?.id) {
55+
exchangeAccountId = data.id;
56+
await saveConfig({ ...config, account_id: data.id });
57+
}
58+
}
59+
4560
// commands
4661
registerLogin(program);
4762
registerContracts(program);
@@ -84,18 +99,6 @@ async function main() {
8499
process.exit(0);
85100
});
86101

87-
const config = await loadConfig();
88-
let exchangeAccountId = config.account_id;
89-
90-
if (!exchangeAccountId) {
91-
const client = await apiClient(config.auth_token);
92-
const { data } = await client.GET("/v1/account/me", {});
93-
if (data?.id) {
94-
exchangeAccountId = data.id;
95-
saveConfig({ ...config, account_id: data.id });
96-
}
97-
}
98-
99102
program.exitOverride((error) => {
100103
let isError = true;
101104

0 commit comments

Comments
 (0)