( sessionId: string, baseUrl: string, accessToken: string | undefined, orgUUID: string, timeoutMs: number, )
| 947 | | 'server_5xx' |
| 948 | |
| 949 | async function archiveSession( |
| 950 | sessionId: string, |
| 951 | baseUrl: string, |
| 952 | accessToken: string | undefined, |
| 953 | orgUUID: string, |
| 954 | timeoutMs: number, |
| 955 | ): Promise<ArchiveStatus> { |
| 956 | if (!accessToken) return 'no_token' |
| 957 | // Archive lives at the compat layer (/v1/sessions/*, not /v1/code/sessions). |
| 958 | // compat.parseSessionID only accepts TagSession (session_*), so retag cse_*. |
| 959 | // anthropic-beta + x-organization-uuid are required — without them the |
| 960 | // compat gateway 404s before reaching the handler. |
| 961 | // |
| 962 | // Unlike bridgeMain.ts (which caches compatId in sessionCompatIds to keep |
| 963 | // in-memory titledSessions/logger keys consistent across a mid-session |
| 964 | // gate flip), this compatId is only a server URL path segment — no |
| 965 | // in-memory state. Fresh compute matches whatever the server currently |
| 966 | // validates: if the gate is OFF, the server has been updated to accept |
| 967 | // cse_* and we correctly send it. |
| 968 | const compatId = toCompatSessionId(sessionId) |
| 969 | try { |
| 970 | const response = await axios.post( |
| 971 | `${baseUrl}/v1/sessions/${compatId}/archive`, |
| 972 | {}, |
| 973 | { |
| 974 | headers: { |
| 975 | ...oauthHeaders(accessToken), |
| 976 | 'anthropic-beta': 'ccr-byoc-2025-07-29', |
| 977 | 'x-organization-uuid': orgUUID, |
| 978 | }, |
| 979 | timeout: timeoutMs, |
| 980 | validateStatus: () => true, |
| 981 | }, |
| 982 | ) |
| 983 | logForDebugging( |
| 984 | `[remote-bridge] Archive ${compatId} status=${response.status}`, |
| 985 | ) |
| 986 | return response.status |
| 987 | } catch (err) { |
| 988 | const msg = errorMessage(err) |
| 989 | logForDebugging(`[remote-bridge] Archive failed: ${msg}`) |
| 990 | return axios.isAxiosError(err) && err.code === 'ECONNABORTED' |
| 991 | ? 'timeout' |
| 992 | : 'error' |
| 993 | } |
| 994 | } |
no test coverage detected