Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

feat: fetch hostname suffix from API#103

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
spikecurtis merged 2 commits intomainfromspike/49-fetch-suffix
May 20, 2025
Merged

Conversation

spikecurtis
Copy link
Collaborator

@spikecurtisspikecurtis commentedMay 15, 2025
edited
Loading

Fixes#49

Adds support to query the hostname suffix from Coder server, and then propagates any changes to the agent view models.

@spikecurtisGraphite App
Copy link
CollaboratorAuthor

spikecurtis commentedMay 15, 2025
edited
Loading

@spikecurtisspikecurtis marked this pull request as ready for reviewMay 15, 2025 10:34
private string _domainSuffix = DefaultSuffix;
private bool _dirty = false;
private bool _getInProgress = false;
private CredentialModel _credentialModel = new() { State = CredentialState.Invalid };
Copy link
Member

Choose a reason for hiding this comment

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

We should just fetch this on-demand from the CredentialManager (since it's cheap) rather than storing it here.

Copy link
CollaboratorAuthor

Choose a reason for hiding this comment

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

I tried this, but it complicates things considerably in terms of race conditions because you can't synchronize changes toGetCachedCredentials with the other items we track here like_dirty, so its hard to guarantee the correct behavior. Writing updates to this while holding the lock ends up being much simpler.

using var _ = _lock.Lock();
_logger.LogDebug("credentials updated with state {state}", credentials.State);
_credentialModel = credentials;
if (credentials.State != CredentialState.Valid) return;
Copy link
Member

Choose a reason for hiding this comment

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

Should you set the stored domain back to the default in this case?

Copy link
Member

Choose a reason for hiding this comment

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

Maybe it would be better to just always create the task if the credentials changed (i.e. remove this check here) and do the check once in the task.

Copy link
CollaboratorAuthor

Choose a reason for hiding this comment

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

I don't think we should set the stored domain back to the default. The most common scenario for getting invalid creds is probably a logout or expired token --- so it's not particularly likely that the Default is more correct.

In any case, once we sign back in we'll get the correct value.


In terms of avoiding the check and always creating the task, seems like a lot of churn (locking, creating tasks, dropping logs) to avoid one conditional.

}

using var l = await _lock.LockAsync(CancellationToken.None);
if ((_dirty || prev.IsFaulted) && _credentialModel.State == CredentialState.Valid)
Copy link
Member

Choose a reason for hiding this comment

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

_dirty seems to only be true here if the credentials became invalid between when the event was handled and the task started. So the only way for this to trigger would be if credentials became valid, then became invalid, then became valid again, which seems very unlikely to actually happen. The user would need to sign in or start the app, then sign out, then enter their credentials and sign back in (with API auth check latency included).

You could probably also accomplish the same thing without needing a bool by throwing in the credential state guard at the top ofRefresh(), and only relying onprev.IsFaulted here

Copy link
CollaboratorAuthor

Choose a reason for hiding this comment

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

The idea of_dirty is that while we are making the network call a new, valid credential for a different deployment could come in. That is, just because we had a valid credential when we started our work, and have a valid credential at the end, it doesn't mean thatit was the same credential. If that happens then we refresh to ensure we have the correct value from the new credential.

}
}

private async Task Refresh()
Copy link
Member

Choose a reason for hiding this comment

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

This should probably just take the credentials model as an argument.

Copy link
CollaboratorAuthor

@spikecurtisspikecurtisMay 16, 2025
edited
Loading

Choose a reason for hiding this comment

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

We want to clear the_dirty flag while grabbing the most up to date credential (holding the lock), then any later valid credentials that come in will re-set the_dirty flag. That doesn't work if we pass the credential as an argument because we can't guarantee it's the "latest" if we're not holding the lock.

@spikecurtisspikecurtis changed the base branch fromspike/49-dynamic-hostname-suffix tographite-base/103May 16, 2025 05:54
@spikecurtisspikecurtis changed the base branch fromgraphite-base/103 tomainMay 16, 2025 07:11
@spikecurtisspikecurtis merged commitbe72f80 intomainMay 20, 2025
1 check passed
@spikecurtisspikecurtis deleted the spike/49-fetch-suffix branchMay 20, 2025 06:07
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@deansheatherdeansheatherdeansheather approved these changes

Assignees
No one assigned
Labels
None yet
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

Incorporate dynamic workspace suffix into UI
2 participants
@spikecurtis@deansheather

[8]ページ先頭

©2009-2025 Movatter.jp