GeezerVison is showing github.com — fix(usage): distinct email-less hub accounts no longer collapse by StiensWout · Pull Request #36561 · pingdotgg/t3code
fix(usage): distinct email-less hub accounts no longer collapse
#36561
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 our terms of service and
privacy statement . We’ll occasionally send you account related emails.
Already on GitHub?
Sign in
to your account
Uh oh!
There was an error while loading. Please reload this page.
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
8032bca
fix(usage): distinct email-less hub accounts no longer collapse
StiensWout Nov 14, 2026
877459d
test(usage): drop redundant key-uniqueness assertion
StiensWout Nov 14, 2026
82d8d0a
fix(usage): keep local hub identities portable across clients
StiensWout Nov 14, 2026
080a250
Merge remote-tracking branch 'origin/main' into t3/usage-limit-hub-id…
juliusmarminge Nov 14, 2026
d41c1ff
refactor(usage): keep host classification unchanged and trim hub iden…
juliusmarminge Nov 14, 2026
4b9755a
fix(usage): hubs sharing an origin in one environment stay apart
juliusmarminge Nov 14, 2026
08dff37
fix(usage): localhost subdomain and mapped loopback hubs stay per mac…
juliusmarminge Nov 14, 2026
b6e129a
fix(usage): hubs under different paths of one origin stay apart
juliusmarminge Nov 14, 2026
252f9b9
fix(usage): different logins in one hub file keep distinct keys
juliusmarminge Nov 14, 2026
be14aa2
fix(usage): trailing-dot localhost hubs stay per machine
juliusmarminge Nov 14, 2026
File filter
Filter by extension
.ts
(5)
All 1 file type selected
Viewed files
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Hide whitespace
Diff view
Hide whitespace
fix(usage): hubs under different paths of one origin stay apart
Origins drop the endpoint path, so independent hubs behind one proxy merged
when each was seen from its own environment. The server now reports each
hub's origin and base path as its endpoint, and only a remote endpoint
names a hub across environments; servers that send none stay scoped to
their environment.
Co-Authored-By: Claude Opus 5.5 <[email protected] >
Loading branch information
Uh oh!
There was an error while loading. Please reload this page.
commit b6e129addb5b8b5e895ab9118731c81ddfe21bc4
There are no files selected for viewing
Original file line number
Diff line number
Diff line change
Expand Up
@@ -44,6 +44,7 @@ it.effect("keeps malformed source URLs encodable for config subscribers", () =>
"https://hub.test:8317",
undefined,
]);
expect(snapshots[3]?.endpoint).toBe("https://hub.test:8317/team-a");
expect(() =>
encodeConfigEvent({
version: 1,
Expand Down
Expand Up
@@ -84,7 +85,7 @@ it.effect("keeps malformed source URLs encodable for config subscribers", () =>
},
[UsageLimitSourceId.make("valid-hub")]: {
kind: "cliproxy",
url: "https://hub.test:8317",
url: "https://hub.test:8317/team-a/management.html ",
managementKey: "",
enabled: true,
},
Expand Down
Original file line number
Diff line number
Diff line change
Expand Up
@@ -86,7 +86,12 @@ export const make = Effect.gen(function* () {
id,
kind: config.kind,
label: sourceLabel(id, config),
...(url && /^https?:$/.test(url.protocol) ? { origin: url.origin } : {}),
...(url && /^https?:$/.test(url.protocol)
? {
origin: url.origin,
endpoint: `${url.origin}${url.pathname.replace(/(\/management\.html)?\/*$/i, "")}`,
}
: {}),
checkedAt,
} as const;
const managementKey = yield* readManagementKey(config);
Expand Down
Original file line number
Diff line number
Diff line change
Expand Up
@@ -88,6 +88,8 @@ export const UsageLimitSourceSnapshot = Schema.Struct({
label: TrimmedNonEmptyString,
/** Origin of the hub, which also serves the agents sent through it. */
origin: Schema.optional(TrimmedNonEmptyString),
/** Origin and base path of the hub, which tell apart hubs served from one origin. */
endpoint: Schema.optional(TrimmedNonEmptyString),
checkedAt: IsoDateTime,
accounts: ForwardCompatibleArray(UsageLimitSourceAccount),
error: Schema.optional(TrimmedNonEmptyString),
Expand Down
Original file line number
Diff line number
Diff line change
Expand Up
@@ -752,6 +752,13 @@ describe("pools", () => {
1,
],
["two remote hubs under one id", "http://hub:8317", "hub", "http://hub-8317", 2],
[
"two remote hubs under paths of one origin",
"https://proxy.example/team-a",
"hub-b",
"https://proxy.example/team-b",
2,
],
[
"a shared IPv6 tailnet hub",
"http://[fd7a:115c:a1e0::1]:8317",
Expand Down
Expand Up
@@ -782,34 +789,34 @@ describe("pools", () => {
2,
],
["each machine's own wildcard hub", "http://0.0.0.0:8317", "hub", "http://0.0.0.0:8317", 2],
["hubs that report no origin ", undefined, "hub", undefined, 2],
["hubs that report no endpoint ", undefined, "hub", undefined, 2],
] as const)(
"keeps email-less hub identity across environments: %s",
(_, firstOrigin , secondId, secondOrigin , count) => {
(_, firstEndpoint , secondId, secondEndpoint , count) => {
const seat = {
id: "claude-team-seat.json",
driver: claude,
usageLimits: { checkedAt, windows: [window] },
};
const hubAt = (id: string, origin : string | undefined) => ({
const hubAt = (id: string, endpoint : string | undefined) => ({
...source,
id: UsageLimitSourceId.make(id),
...(origin ? { origin } : {}),
...(endpoint ? { origin: new URL(endpoint).origin, endpoint } : {}),
accounts: [seat],
});
const input = new Map([
[
EnvironmentId.make("env-a"),
{
...laptop,
serverConfig: { providers: [], usageLimitSources: [hubAt("hub", firstOrigin )] },
serverConfig: { providers: [], usageLimitSources: [hubAt("hub", firstEndpoint )] },
},
],
[
EnvironmentId.make("env-b"),
{
entry: { target: { label: "Desktop" } },
serverConfig: { providers: [], usageLimitSources: [hubAt(secondId, secondOrigin )] },
serverConfig: { providers: [], usageLimitSources: [hubAt(secondId, secondEndpoint )] },
},
],
]);
Expand All
@@ -819,33 +826,6 @@ describe("pools", () => {
},
);
it("keeps hubs that share an origin apart within one environment", () => {
const seat = {
id: "claude-team-seat.json",
driver: claude,
usageLimits: { checkedAt, windows: [window] },
};
const hubAt = (id: string) => ({
...source,
id: UsageLimitSourceId.make(id),
origin: "https://proxy.example",
accounts: [seat],
});
const input = new Map([
[
EnvironmentId.make("env-a"),
{
...laptop,
serverConfig: { providers: [], usageLimitSources: [hubAt("hub-a"), hubAt("hub-b")] },
},
],
]);
expect(collectLimitAccounts(input).map((account) => account.key)).toEqual([
"env-a:hub-a:claude-team-seat.json",
"env-a:hub-b:claude-team-seat.json",
]);
});
it("labels a default-named instance merged with a hub account by e-mail, keeping a chosen name", () => {
const native = provider({
driver: claude,
Expand Down
Original file line number
Diff line number
Diff line change
Expand Up
@@ -255,30 +255,18 @@ function accountKeyResolver(reports: Iterable<AccountReport>) {
const hubAccountName = (account: { readonly id: string }) => account.id.replace(/\.json$/i, "");
// The server supplies canonical origins; native URL polyfills can misparse IPv6 hosts.
const remoteHubOrigin = (source: UsageLimitSourceSnapshot): string | null => {
const origin = source.origin;
const host = origin?.match(/^https?:\/\/(\[[\da-f:.]+\]|[^:/?#@]+)(?::\d+)?$/)?.[1];
if (!origin || !host || isLocalLoopbackHost(host) || isWildcardHost(host)) return null;
// Each machine resolves these to itself too; shared host classification leaves them out.
return /\.localhost$|^\[::ffff:(?:127\.|7f[\da-f]{2}:)/i.test(host) ? null : origin;
};
// Source ids are environment-local, so only a remote origin names the same hub across environments.
// Origins drop the path, so hubs sharing one within an environment stay apart by id.
function hubIdentities(
environmentId: EnvironmentId,
sources: ReadonlyArray<UsageLimitSourceSnapshot>,
): (source: UsageLimitSourceSnapshot) => string {
const counts = new Map<string, number>();
for (const source of sources) {
const origin = remoteHubOrigin(source);
if (origin) counts.set(origin, (counts.get(origin) ?? 0) + 1);
}
return (source) => {
const origin = remoteHubOrigin(source);
return origin && counts.get(origin) === 1 ? origin : `${environmentId}:${source.id}`;
};
// Source ids are environment-local, so only a remote endpoint names the same hub across environments.
function hubIdentity(environmentId: EnvironmentId, source: UsageLimitSourceSnapshot): string {
// The server supplies canonical endpoints; native URL polyfills can misparse IPv6 hosts.
const endpoint = source.endpoint;
const host = endpoint?.match(/^https?:\/\/(\[[\da-f:.]+\]|[^:/?#@]+)(?::\d+)?(?:\/|$)/)?.[1];
const local =
!host ||
isLocalLoopbackHost(host) ||
isWildcardHost(host) ||
// Each machine resolves these to itself too; shared host classification leaves them out.
/\.localhost$|^\[::ffff:(?:127\.|7f[\da-f]{2}:)/i.test(host);
return endpoint && !local ? endpoint : `${environmentId}:${source.id}`;
}
export interface LimitAccount {
Expand Down
Expand Up
@@ -401,15 +389,13 @@ export function collectLimitAccounts(presentations: LimitPresentations): readonl
}
const labelEnvironment = presentations.size > 1;
for (const [environmentId, presentation] of presentations) {
const sources = presentation.serverConfig?.usageLimitSources ?? [];
const hubIdentity = hubIdentities(environmentId, sources);
for (const source of sources) {
for (const source of presentation.serverConfig?.usageLimitSources ?? []) {
const sourceLabel = labelEnvironment
? `${presentation.entry.target.label} · ${source.label}`
: source.label;
for (const account of source.accounts) {
if (limitsNotice(account.usageLimits) !== null) continue;
const key = `${hubIdentity(source)}:${account.id}${account.workspaceId ? `:${account.workspaceId}` : ""}`;
const key = `${hubIdentity(environmentId, source)}:${account.id}${account.workspaceId ? `:${account.workspaceId}` : ""}`;
merge(resolveKey(account) ?? key, {
key,
driver: account.driver,
Expand Down
Loading
Oops, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.