axios+telemetry cleanup

This commit is contained in:
2026-04-02 15:19:11 +03:00
parent a3cbca1e11
commit 7e1eac8002
100 changed files with 3048 additions and 4491 deletions

View File

@@ -24,7 +24,6 @@
* This avoids module-level mutable state and gives tests natural isolation.
*/
import axios from 'axios'
import { createHash } from 'crypto'
import { mkdir, readdir, readFile, stat, writeFile } from 'fs/promises'
import { join, relative, sep } from 'path'
@@ -45,8 +44,9 @@ import {
getClaudeAIOAuthTokens,
} from '../../utils/auth.js'
import { logForDebugging } from '../../utils/debug.js'
import { classifyAxiosError } from '../../utils/errors.js'
import { classifyHttpError } from '../../utils/errors.js'
import { getGithubRepo } from '../../utils/git.js'
import { isHttpError, nativeRequest } from '../../utils/http.js'
import {
getAPIProvider,
isFirstPartyAnthropicBaseUrl,
@@ -209,11 +209,10 @@ async function fetchTeamMemoryOnce(
}
const endpoint = getTeamMemorySyncEndpoint(repoSlug)
const response = await axios.get(endpoint, {
const response = await nativeRequest<any>(endpoint, {
method: 'GET',
headers,
timeout: TEAM_MEMORY_SYNC_TIMEOUT_MS,
validateStatus: status =>
status === 200 || status === 304 || status === 404,
})
if (response.status === 304) {
@@ -264,10 +263,8 @@ async function fetchTeamMemoryOnce(
checksum: responseChecksum,
}
} catch (error) {
const { kind, status, message } = classifyAxiosError(error)
const body = axios.isAxiosError(error)
? JSON.stringify(error.response?.data ?? '')
: ''
const { kind, status, message } = classifyHttpError(error)
const body = isHttpError(error) ? JSON.stringify(error.data ?? '') : ''
if (kind !== 'other') {
logForDebugging(`team-memory-sync: fetch error ${status}: ${body}`, {
level: 'warn',
@@ -324,10 +321,10 @@ async function fetchTeamMemoryHashes(
}
const endpoint = getTeamMemorySyncEndpoint(repoSlug) + '&view=hashes'
const response = await axios.get(endpoint, {
const response = await nativeRequest<any>(endpoint, {
method: 'GET',
headers: auth.headers,
timeout: TEAM_MEMORY_SYNC_TIMEOUT_MS,
validateStatus: status => status === 200 || status === 404,
})
if (response.status === 404) {
@@ -360,7 +357,7 @@ async function fetchTeamMemoryHashes(
entryChecksums,
}
} catch (error) {
const { kind, status, message } = classifyAxiosError(error)
const { kind, status, message } = classifyHttpError(error)
switch (kind) {
case 'auth':
return {
@@ -482,15 +479,12 @@ async function uploadTeamMemory(
}
const endpoint = getTeamMemorySyncEndpoint(repoSlug)
const response = await axios.put(
endpoint,
{ entries },
{
headers,
timeout: TEAM_MEMORY_SYNC_TIMEOUT_MS,
validateStatus: status => status === 200 || status === 412,
},
)
const response = await nativeRequest<any>(endpoint, {
method: 'PUT',
body: { entries },
headers,
timeout: TEAM_MEMORY_SYNC_TIMEOUT_MS,
})
if (response.status === 412) {
logForDebugging('team-memory-sync: conflict (412 Precondition Failed)', {
@@ -514,14 +508,12 @@ async function uploadTeamMemory(
lastModified: response.data?.lastModified,
}
} catch (error) {
const body = axios.isAxiosError(error)
? JSON.stringify(error.response?.data ?? '')
: ''
const body = isHttpError(error) ? JSON.stringify(error.data ?? '') : ''
logForDebugging(
`team-memory-sync: upload failed: ${error instanceof Error ? error.message : ''} ${body}`,
{ level: 'warn' },
)
const { kind, status: httpStatus, message } = classifyAxiosError(error)
const { kind, status: httpStatus, message } = classifyHttpError(error)
const errorType = kind === 'http' || kind === 'other' ? 'unknown' : kind
let serverErrorCode: 'team_memory_too_many_entries' | undefined
let serverMaxEntries: number | undefined
@@ -530,10 +522,8 @@ async function uploadTeamMemory(
// RequestTooLargeException includes error_code + extra_details with
// the effective max_entries (may be GB-tuned per-org). Cache it so
// the next push trims to the right value.
if (httpStatus === 413 && axios.isAxiosError(error)) {
const parsed = TeamMemoryTooManyEntriesSchema().safeParse(
error.response?.data,
)
if (httpStatus === 413 && isHttpError(error)) {
const parsed = TeamMemoryTooManyEntriesSchema().safeParse(error.data)
if (parsed.success) {
serverErrorCode = parsed.data.error.details.error_code
serverMaxEntries = parsed.data.error.details.max_entries