The resource blueprint AuthSchema typed pincode as a number between
100000 and 999999, so PINs starting with 0 ("012345", a tenth of all
valid PINs) could not be expressed, although the PIN API accepts any
^\d{6}$ string. Resource-policy blueprints had the opposite problem and
rejected an unquoted pincode: 123456. Docker labels lost leading zeros
too, because convertValue turned every digit string into a number.
Use one PincodeSchema for both: a 6-digit string, or a number in the old
range normalized to a string. convertValue leaves digit strings with a
leading zero as strings. Existing configs keep working.
Signed-off-by: anant <170962632+antcybersec@users.noreply.github.com>
aiBudgetEnforcement.test.ts and deleteOrg.test.ts create a workdir with
mkdtempSync (temp SQLite DB, config and symlinks into the repo) and never
remove it, so every npm test run leaves two pangolin-* directories in the
OS temp dir. Remove the workdir in a finally block, the same way
migrationsSqlite.backup.test.ts already does. rmSync does not follow the
symlinks, so the repo's server/, test/ and node_modules/ are untouched.
Signed-off-by: anant <170962632+antcybersec@users.noreply.github.com>
invoke-with-response-stream wraps each model event as {"bytes":"<base64>"} inside event-stream frames, so the usage fields never appear in clear text. extractUsage returned null and the pipeline fell back to estimating tokens over the base64, losing real counts and cache tokens. Decode the chunks before scanning.
aiUsageRecords.createdAt is epoch seconds since e57826d6e, but
sumUsageForBudget still compared it against a lower bound in epoch ms, so
every budget except lifetime summed to 0.
Convert the bound to seconds for usage queries, leaving windowStart in ms
for aiBudgetBreachEvents. Sum model-scoped budgets per requested model in
SQL instead of loading every row in the window into JS.
extractOpenAiResponses only took response.usage from response.completed, so a
stream cut by max_output_tokens (response.incomplete) lost its usage and fell
back to estimateUsage over the whole SSE text, over-counting cost and budget.
Read response.usage from any event that carries it.
Gemini reports the tokens of tool results (Google Search, URL context) in usageMetadata.toolUsePromptTokenCount, separate from promptTokenCount. The extractor ignored it, so usage and cost were under-counted.
sendToExitNode used axios without a timeout, so a Gerbil that accepted
the connection but never answered left the caller (peer updates, SNI
sync, client association rebuilds) waiting indefinitely. Apply a 15s
default, overridable per request.
With prompt caching enabled, Bedrock reports inputTokens as the non-cached input only; cacheReadInputTokens and cacheWriteInputTokens are separate counters. Subtracting the cache reads again undercounted promptTokens (clamped to 0) in both the JSON and the stream-scan paths.
Reworks the org-scoped exchange-token endpoint into a root-gated create-session route,
addressing the review on the earlier version:
- Requires a ROOT API key holding the createIdpSession action, not an org-scoped key.
Minting a session is impersonation, so it is deliberately root-only.
- Gated behind flags.enable_idp_create_session (off by default, self-hosted only;
refused when build === "saas").
- Drops orgId entirely: the user must belong to the identity provider, not an
organization. The route becomes /idp/:idpId/oidc/create-session.
Removes the now-unused org-scoped createSessionForIdpUser helper.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Pangolin consults the IdP only at login and keeps its own session
afterwards, so disabling a user or revoking their sessions in the IdP
does not end their Pangolin sessions.
Store the IdP refresh token at OIDC login as a grant and redeem it at
most every server.idp_session_revalidation_minutes (default 5). If the
IdP rejects it with invalid_grant, the grant is marked revoked and all
sessions backed by it and their resource sessions are deleted. Other
errors (IdP unreachable or slower than 10 seconds, invalid_client after
a secret change) keep the sessions valid and are retried after at most
a minute instead of on every request.
Only the instance holding a lease on the grant in the primary database
redeems its refresh token, and it writes the result only while it still
holds the lease, so instances never redeem the same token concurrently.
The per-request lookup reads from a replica through safeRead.
Device logins of the Pangolin clients share the grant of the browser
session that approved them, read from the primary database, so a rotated
refresh token is never redeemed twice by separate sessions.
The Entra ID provider type hardcodes its scopes, so it now requests
offline_access to get a refresh token.