@mcp-abap-adt/connection 22.0.0 → 23.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -7,6 +7,58 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
7
7
 
8
8
  ## [Unreleased]
9
9
 
10
+ ## [23.0.0] - 2026-11-12
11
+
12
+ A stateless request keeps its answer when the SAP session was replaced
13
+ (fr0ster/mcp-abap-adt#354). Breaking for code that learned of the loss from the
14
+ `ADT_SESSION_REPLACED` rejection of a stateless request. See
15
+ [docs/MIGRATION-23.0.md](docs/MIGRATION-23.0.md).
16
+
17
+ ### Changed — breaking
18
+
19
+ - **A stateless request whose answer shows the session replaced gets that
20
+ answer.** A success resolves, a refusal rejects as itself; either carries
21
+ `sessionLost: 'ADT_SESSION_REPLACED'`. The session is lost before the answer
22
+ reaches the caller (the instance spent, the replacing session logged off), and
23
+ nothing is sent again: no CSRF retry and no credential renewal start from it.
24
+ A stateful request, the connection's own exchanges inside a request (a CSRF
25
+ fetch, a logon) and an answer saying the session no longer exists that shows
26
+ no replacement keep rejecting `ADT_SESSION_REPLACED`; `connect()` and a resumed
27
+ session behave as in 22.x. A refusal that cannot take the mark (frozen,
28
+ sealed) is answered by an object on top of it that reads through to it.
29
+
30
+ ### Added
31
+
32
+ - `sessionLost` on the resolved response and on the rejected refusal, typed by
33
+ `@mcp-abap-adt/interfaces-adt-connection` 4.2.0 (`AdtSessionLoss`).
34
+
35
+ ### Fixed
36
+
37
+ - **The CSRF retry's refused resend is observed.** Its answer used to be dropped
38
+ for the first attempt's `403` without being read, so a replacement on it went
39
+ unnoticed.
40
+ - **A refusal whose body is absent or does not serialise is read like any
41
+ other.** Its log preview threw (`JSON.stringify(undefined).slice`, a circular
42
+ body) before the answer was observed, so the caller got a `TypeError` and a
43
+ replacement on it went unnoticed; the preview is now empty instead.
44
+ - **A logger that throws on the success line no longer takes the answer.** The
45
+ `REQUEST_SUCCESS` debug line is written as the failure lines are, its throw
46
+ dropped.
47
+
48
+ ### Dependencies
49
+
50
+ - `@mcp-abap-adt/interfaces-adt-connection` `^4.2.0`.
51
+
52
+ ## [22.0.1] - 2026-11-12
53
+
54
+ ### Fixed
55
+
56
+ - **Recognize SAP ICM session-expired HTTP 400 responses (fr0ster/mcp-abap-adt#355).**
57
+ `Session Timed Out or Not Found` and `Session no longer exists` now follow the
58
+ existing `Session not found` lifecycle, case-insensitively: the session is lost
59
+ and the caller receives `ADT_SESSION_REPLACED`, including at LOCK. No automatic
60
+ retry or session reopening is added; unrelated HTTP 400 responses are unchanged.
61
+
10
62
  ## [22.0.0] - 2026-11-12
11
63
 
12
64
  Over RFC, a request carries its passport and a failure names its error by fields, and an RFC
@@ -2958,7 +3010,9 @@ const connection = createAbapConnection(config, logger);
2958
3010
  - JWT token refresh now properly handles connection errors (401/403 during initial connect)
2959
3011
  - Permission errors (403 with "ExceptionResourceNoAccess") no longer trigger JWT refresh loops
2960
3012
  - Proper separation: base class handles HTTP/session, concrete classes handle auth-specific errors
2961
- [Unreleased]: https://github.com/fr0ster/mcp-abap-connection/compare/v22.0.0...HEAD
3013
+ [Unreleased]: https://github.com/fr0ster/mcp-abap-connection/compare/v23.0.0...HEAD
3014
+ [23.0.0]: https://github.com/fr0ster/mcp-abap-connection/compare/v22.0.1...v23.0.0
3015
+ [22.0.1]: https://github.com/fr0ster/mcp-abap-connection/compare/v22.0.0...v22.0.1
2962
3016
  [22.0.0]: https://github.com/fr0ster/mcp-abap-connection/compare/v21.0.0...v22.0.0
2963
3017
  [21.0.0]: https://github.com/fr0ster/mcp-abap-connection/compare/v20.1.0...v21.0.0
2964
3018
  [20.1.0]: https://github.com/fr0ster/mcp-abap-connection/compare/v20.0.0...v20.1.0
package/README.md CHANGED
@@ -162,6 +162,7 @@ the packages above. See [Migration to 9.0.0](./docs/MIGRATION-9.0.md).
162
162
 
163
163
  - 📦 **[Installation Guide](./docs/INSTALLATION.md)** - Setup and installation instructions
164
164
  - 📚 **[Usage Guide](./docs/USAGE.md)** - Detailed usage examples and API documentation
165
+ - 🚚 **[Migration to 23.0.0](./docs/MIGRATION-23.0.md)** - a stateless request whose answer shows the SAP session replaced keeps that answer, marked `sessionLost`, and the instance is spent; a stateful request still rejects `ADT_SESSION_REPLACED`; nothing is resent; `@mcp-abap-adt/interfaces-adt-connection` ^4.2.0
165
166
  - 🚚 **[Migration to 22.0.0](./docs/MIGRATION-22.0.md)** - over RFC: a connection-ending RFC error on the stateful conversation is `ADT_SESSION_REPLACED` and spends the instance (no silent reconnect); a failed RFC call carries `rfc: { key, group, code, codeString }`; the `SAP-PASSPORT` header becomes the RFC call's passport; `@mcp-abap-adt/sap-rfc-lite` ^0.4.0
166
167
  - 🚚 **[Migration to 21.0.0](./docs/MIGRATION-21.0.md)** - the CSRF token fetch asks once: no retry, no delay; `CSRF_CONFIG.RETRY_COUNT` / `RETRY_DELAY`, the establish context's `retries` / `retryDelayMs` / `isFatal`, `fetchCsrfToken`'s retry parameters and `endsTheExchange` are removed
167
168
  - 🚚 **[Migration to 20.0.0](./docs/MIGRATION-20.0.md)** - an RFC config is an `ISapRfcConfig` that states its address (`ashost` + `sysnr`, or `mshost` + `msserv` / `sysid` + `group`), `client` and `language`: no URL, no defaults, no `SAP_SYSNR`; `getBaseUrl()` may answer `undefined`; hand-built HTTP transports take `baseUrl`; `IAdtSessionContext` has no `baseUrl`
@@ -706,8 +707,9 @@ await connection.connect();
706
707
  // as the attempt it repeats, so stale-request fencing applies. After a rejection
707
708
  // at 'request' it goes out on the same session; after one at 'logon' the wire
708
709
  // logs on again first. No 401 opens a new session: the resend stays in this
709
- // one, or fails with SESSION_REPLACED if SAP replaced it. For a new session,
710
- // create a new connection.
710
+ // one. If SAP replaced it, a stateful request fails with ADT_SESSION_REPLACED
711
+ // and a stateless one gets SAP's answer marked `sessionLost`; the instance is
712
+ // spent either way. For a new session, create a new connection.
711
713
  const response = await connection.makeAdtRequest({
712
714
  method: "GET",
713
715
  url: "/sap/bc/adt/programs/programs/your-program",
@@ -846,6 +848,13 @@ connection.setSessionType("stateless");
846
848
 
847
849
  ```
848
850
 
851
+ **When SAP replaced the session** (an idle timeout, usually): a stateful
852
+ request rejects `ADT_SESSION_REPLACED`; a stateless one gets SAP's answer as it
853
+ came — a success resolves, a refusal rejects as itself — marked
854
+ `sessionLost: 'ADT_SESSION_REPLACED'` (since 23.0.0). Either way the instance
855
+ is spent and nothing is sent again: create a new connection. See
856
+ [When the session is lost](./docs/USAGE.md#when-the-session-is-lost).
857
+
849
858
  ### Custom Logger
850
859
 
851
860
  ```typescript
@@ -6,6 +6,12 @@ import { type RequestLease, SessionLifecycle } from '../session/SessionLifecycle
6
6
  import type { AbapConnection, AbapRequestOptions } from './AbapConnection.js';
7
7
  import { type GuardedAnswer } from './authErrors.js';
8
8
  import { type IAdtSessionContext, type IAdtTransport } from './IAdtTransport.js';
9
+ /**
10
+ * What observing an answer decided: `'kept'` — the session is as it was, or the
11
+ * answer's effects are fenced; `'lost'` — the answer showed the session
12
+ * replaced, the session is lost, and the answer is the caller's.
13
+ */
14
+ type SessionObservation = 'kept' | 'lost';
9
15
  declare abstract class AbstractAbapConnection implements AbapConnection, ISessionLifecycleAware, ICriticalSection, IRequestProfiling {
10
16
  private readonly config;
11
17
  /**
@@ -488,7 +494,14 @@ declare abstract class AbstractAbapConnection implements AbapConnection, ISessio
488
494
  * later check reads `unchanged`. That is one call site forgetting, and it
489
495
  * happened — on the error path and on every retry response.
490
496
  */
491
- protected observeResponse(headers?: Record<string, unknown>, generation?: number): void;
497
+ protected observeResponse(headers?: Record<string, unknown>, generation?: number,
498
+ /**
499
+ * The answer is an attempt of a stateless caller's request: a replacement
500
+ * it shows loses the session as always, and the answer is then the
501
+ * caller's — `'lost'` is returned instead of the throw. Not given for the
502
+ * connection's own exchanges and for stateful requests.
503
+ */
504
+ keepAnswer?: boolean): SessionObservation;
492
505
  /**
493
506
  * Acts on what a response said about the session identity.
494
507
  *
@@ -512,8 +525,8 @@ declare abstract class AbstractAbapConnection implements AbapConnection, ISessio
512
525
  * One on-prem system answered HTTP 400 with "Session not found", answered in ~60 ms
513
526
  * with the cookie present — which is why identity comparison cannot see this:
514
527
  * the cookie, and therefore the fingerprint, is completely unchanged. The
515
- * exact match is landscape-specific and is one of the live probes this design
516
- * still owes.
528
+ * wording varies by landscape; SAP ICM also reports a timed-out or missing
529
+ * session with the phrases below.
517
530
  */
518
531
  private isDeadSessionResponse;
519
532
  /** Drops everything that described the session. Not a lifecycle transition. */
@@ -580,6 +593,15 @@ declare abstract class AbstractAbapConnection implements AbapConnection, ISessio
580
593
  * act inside a session the request was never admitted to.
581
594
  */
582
595
  private sendObserved;
596
+ /**
597
+ * SAP's refusal of a stateless request whose answer showed the session
598
+ * replaced, as the caller gets it: the refusal itself, marked `sessionLost`.
599
+ * The wire's error is its own object, made for this attempt, so the mark is
600
+ * set on it. One that cannot take it — frozen, sealed, or holding its own
601
+ * fixed `sessionLost` — is answered by an object on top of it: every field of
602
+ * the refusal read through to it, its class kept, the mark its own.
603
+ */
604
+ private markedLost;
583
605
  /**
584
606
  * One attempt's headers: the request's own, with what the credential writes
585
607
  * for THIS attempt on top.
@@ -1 +1 @@
1
- {"version":3,"file":"AbstractAbapConnection.d.ts","sourceRoot":"","sources":["../../src/connection/AbstractAbapConnection.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACV,gBAAgB,EAChB,gBAAgB,EAChB,iBAAiB,EACjB,sBAAsB,EACvB,MAAM,yCAAyC,CAAC;AAEjD,OAAO,KAAK,EACV,cAAc,EACd,YAAY,EACb,MAAM,+BAA+B,CAAC;AACvC,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,wBAAwB,CAAC;AACxD,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAC5C,OAAO,EACL,KAAK,YAAY,EACjB,gBAAgB,EAEjB,MAAM,gCAAgC,CAAC;AAExC,OAAO,KAAK,EAAE,c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EAAE,MAAM,GAAG,IAAI,GAAG,IAAI;IAMlD;;OAEG;IACH,SAAS,CAAC,UAAU,IAAI,MAAM,GAAG,IAAI;IAIrC;;;;;;OAMG;IACH,SAAS,CAAC,iBAAiB,CAAC,OAAO,EAAE,MAAM,GAAG,IAAI;IAMlD;;;;;;;;OAQG;YACW,eAAe;IAO7B;;;;;;;;;;;;;;;OAeG;IACH,OAAO,CAAC,aAAa;IAgCrB;;;;;;;;OAQG;IACH,OAAO,CAAC,iBAAiB;IAiBzB,OAAO,CAAC,eAAe;CA6BxB;AAED,OAAO,EAAE,sBAAsB,EAAE,CAAC"}
1
+ {"version":3,"file":"AbstractAbapConnection.d.ts","sourceRoot":"","sources":["../../src/connection/AbstractAbapConnection.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACV,gBAAgB,EAChB,gBAAgB,EAChB,iBAAiB,EACjB,sBAAsB,EACvB,MAAM,yCAAyC,CAAC;AAEjD,OAAO,KAAK,EACV,cAAc,EACd,YAAY,EACb,MAAM,+BAA+B,CAAC;AACvC,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,wBAAwB,CAAC;AACxD,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAC5C,OAAO,EACL,KAAK,YAAY,EACjB,gBAAgB,EAEjB,MAAM,gCAAgC,CAAC;AAExC,OAAO,KAAK,EAAE,cAAc,EAAE,kBAAkB,EAAE,MAAM,qBAAqB,CAAC;AAC9E,OAAO,EAEL,KAAK,aAAa,EAKnB,MAAM,iBAAiB,CAAC;AAEzB,OAAO,EACL,KAAK,kBAAkB,EACvB,KAAK,aAAa,EAGnB,MAAM,oBAAoB,CAAC;AA4C5B;;;;GAIG;AACH,KAAK,kBAAkB,GAAG,MAAM,GAAG,MAAM,CAAC;AA8C1C,uBAAe,sBACb,YACE,cAAc,EACd,sBAAsB,EACtB,gBAAgB,EAChB,iBAAiB;IAwIjB,OAAO,CAAC,QAAQ,CAAC,MAAM;IACvB;;;;;;;;;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;;;OAeG;IACH,OAAO,CAAC,aAAa;IAgCrB;;;;;;;;OAQG;IACH,OAAO,CAAC,iBAAiB;IAiBzB,OAAO,CAAC,eAAe;CA6BxB;AAED,OAAO,EAAE,sBAAsB,EAAE,CAAC"}
@@ -8,6 +8,7 @@ const networkErrors_js_1 = require("../utils/networkErrors.js");
8
8
  const authErrors_js_1 = require("./authErrors.js");
9
9
  const csrfConfig_js_1 = require("./csrfConfig.js");
10
10
  const IAdtTransport_js_1 = require("./IAdtTransport.js");
11
+ const statefulRequest_js_1 = require("./statefulRequest.js");
11
12
  /**
12
13
  * Declares the capabilities explicitly rather than satisfying them by accident.
13
14
  * `AbapConnection` is the base contract every transport honours; these two are
@@ -47,6 +48,34 @@ function hasHeader(headers, name) {
47
48
  * wire's session token and the request's content negotiation.
48
49
  */
49
50
  const OUTRANK_THE_CREDENTIAL = ['x-csrf-token', 'content-type', 'accept'];
51
+ /**
52
+ * The first 200 characters of a refusal's body, for a log line. The body is
53
+ * the wire's, from outside the type system: an absent one, or one that will
54
+ * not serialise (circular, a throwing `toJSON`), is no preview — never a throw
55
+ * that would stand in for the refusal and skip what the answer means.
56
+ */
57
+ function dataPreview(data) {
58
+ if (typeof data === 'string')
59
+ return data.slice(0, 200);
60
+ try {
61
+ return JSON.stringify(data)?.slice(0, 200);
62
+ }
63
+ catch {
64
+ return undefined;
65
+ }
66
+ }
67
+ /** Whether a thrown value is a refusal this connection marked `sessionLost`. */
68
+ function carriesSessionLost(error) {
69
+ return (typeof error === 'object' &&
70
+ error !== null &&
71
+ 'sessionLost' in error &&
72
+ error.sessionLost === interfaces_adt_connection_1.ADT_SESSION_ERROR.SESSION_REPLACED);
73
+ }
74
+ const DEAD_SESSION_PHRASES = [
75
+ 'session not found',
76
+ 'session timed out or not found',
77
+ 'session no longer exists',
78
+ ];
50
79
  /** What a spent instance answers to `connect()`. Fixed words. */
51
80
  function spentError() {
52
81
  return (0, SessionLifecycle_js_1.sessionError)(interfaces_adt_connection_1.ADT_SESSION_ERROR.NOT_CONNECTED, "This connection's SAP session has ended (it was disconnected, logged off or lost); one connection instance is one session. Create a new connection for a new session.");
@@ -974,7 +1003,8 @@ class AbstractAbapConnection {
974
1003
  const code = error?.code;
975
1004
  return (code === interfaces_adt_connection_1.ADT_SESSION_ERROR.SESSION_REPLACED ||
976
1005
  code === interfaces_adt_connection_1.ADT_SESSION_ERROR.NOT_CONNECTED ||
977
- code === interfaces_adt_connection_1.ADT_SESSION_ERROR.RELEASE_PENDING);
1006
+ code === interfaces_adt_connection_1.ADT_SESSION_ERROR.RELEASE_PENDING ||
1007
+ carriesSessionLost(error));
978
1008
  }
979
1009
  /**
980
1010
  * Folds a response into the session state AND acts on what it means, in one
@@ -985,7 +1015,14 @@ class AbstractAbapConnection {
985
1015
  * later check reads `unchanged`. That is one call site forgetting, and it
986
1016
  * happened — on the error path and on every retry response.
987
1017
  */
988
- observeResponse(headers, generation) {
1018
+ observeResponse(headers, generation,
1019
+ /**
1020
+ * The answer is an attempt of a stateless caller's request: a replacement
1021
+ * it shows loses the session as always, and the answer is then the
1022
+ * caller's — `'lost'` is returned instead of the throw. Not given for the
1023
+ * connection's own exchanges and for stateful requests.
1024
+ */
1025
+ keepAnswer = false) {
989
1026
  // Fenced by SESSION GENERATION, not by the teardown epoch. Only a
990
1027
  // caller-initiated teardown moves the epoch — a recovery deliberately does
991
1028
  // not — so after a session loss and a successful recovery, a request from
@@ -998,12 +1035,12 @@ class AbstractAbapConnection {
998
1035
  if (generation !== undefined &&
999
1036
  generation !== this.lifecycle.sessionGeneration) {
1000
1037
  this.logger?.debug('Ignoring a response from a previous session: its effects are fenced');
1001
- return;
1038
+ return 'kept';
1002
1039
  }
1003
1040
  // The wire folds the response into its own state; what the change MEANS
1004
1041
  // is decided here, because it is a question about the session's lifetime.
1005
1042
  this.transport.ingest(headers);
1006
- this.applyIdentityPolicy(this.lifecycle.observe(this.transport.sessionFingerprint()));
1043
+ return this.applyIdentityPolicy(this.lifecycle.observe(this.transport.sessionFingerprint()), keepAnswer);
1007
1044
  }
1008
1045
  /**
1009
1046
  * Acts on what a response said about the session identity.
@@ -1021,9 +1058,9 @@ class AbstractAbapConnection {
1021
1058
  * Being wrong in this direction costs a reconnect; being wrong the other way
1022
1059
  * costs a lock nobody can find.
1023
1060
  */
1024
- applyIdentityPolicy(classification) {
1061
+ applyIdentityPolicy(classification, keepAnswer) {
1025
1062
  if (classification !== 'replaced')
1026
- return;
1063
+ return 'kept';
1027
1064
  // The answer that replaced the session brought a session of its own,
1028
1065
  // which SAP opened and which nothing here will ever use: it is logged off
1029
1066
  // now, while the wire still holds its cookie, as `disconnect()` logs off
@@ -1042,6 +1079,12 @@ class AbstractAbapConnection {
1042
1079
  this.endSession(this.sessionContext());
1043
1080
  this.clearSessionState();
1044
1081
  this.raiseSessionLost('the session cookie changed under us');
1082
+ // A stateless request's answer is SAP's, and valid: it is returned, marked,
1083
+ // the session already lost (fr0ster/mcp-abap-adt#354). Nothing is sent
1084
+ // again for it. A stateful request — the one a lock is taken and released
1085
+ // in — and the connection's own exchanges keep failing loudly.
1086
+ if (keepAnswer)
1087
+ return 'lost';
1045
1088
  throw (0, SessionLifecycle_js_1.sessionError)(interfaces_adt_connection_1.ADT_SESSION_ERROR.SESSION_REPLACED, 'The SAP session this connection was using is gone and the requests are now on a different one; anything held against the old session — a lock and any write under it — is dead. ' +
1046
1089
  'The server does not swap sessions on a whim: the usual causes are the session idling out (the timeout is idle-based, so a quiet connection loses it while a busy one does not) or a request landing on a different application server. ' +
1047
1090
  'What to do about it is yours: re-establish and redo the work, or fail the operation. Nothing is retried here.');
@@ -1052,8 +1095,8 @@ class AbstractAbapConnection {
1052
1095
  * One on-prem system answered HTTP 400 with "Session not found", answered in ~60 ms
1053
1096
  * with the cookie present — which is why identity comparison cannot see this:
1054
1097
  * the cookie, and therefore the fingerprint, is completely unchanged. The
1055
- * exact match is landscape-specific and is one of the live probes this design
1056
- * still owes.
1098
+ * wording varies by landscape; SAP ICM also reports a timed-out or missing
1099
+ * session with the phrases below.
1057
1100
  */
1058
1101
  isDeadSessionResponse(error) {
1059
1102
  const refusal = (0, IAdtTransport_js_1.refusalOf)(error);
@@ -1067,7 +1110,7 @@ class AbstractAbapConnection {
1067
1110
  ]
1068
1111
  .join(' ')
1069
1112
  .toLowerCase();
1070
- return text.includes('session not found');
1113
+ return DEAD_SESSION_PHRASES.some((phrase) => text.includes(phrase));
1071
1114
  }
1072
1115
  /** Drops everything that described the session. Not a lifecycle transition. */
1073
1116
  clearSessionState() {
@@ -1279,12 +1322,15 @@ class AbstractAbapConnection {
1279
1322
  });
1280
1323
  try {
1281
1324
  const response = await this.sendObserved(requestConfig, lease);
1282
- this.logger?.debug(`Request succeeded with status ${response.status}`, {
1325
+ // The answer outranks the logger's word on it: a logger that throws
1326
+ // must not take a received answer — one marked `sessionLost` above all,
1327
+ // whose session is already gone — from the caller.
1328
+ this.logQuietly(() => this.logger?.debug(`Request succeeded with status ${response.status}`, {
1283
1329
  type: 'REQUEST_SUCCESS',
1284
1330
  status: response.status,
1285
1331
  url: requestUrl,
1286
1332
  method: normalizedMethod,
1287
- });
1333
+ }));
1288
1334
  return response;
1289
1335
  }
1290
1336
  catch (error) {
@@ -1312,8 +1358,42 @@ class AbstractAbapConnection {
1312
1358
  throw (0, SessionLifecycle_js_1.sessionError)(interfaces_adt_connection_1.ADT_SESSION_ERROR.NOT_CONNECTED, 'The session this request was admitted to is gone; nothing was sent');
1313
1359
  }
1314
1360
  const response = await this.transport.send(requestConfig);
1315
- this.observeResponse(response.headers, lease.generation);
1316
- return response;
1361
+ const observed = this.observeResponse(response.headers, lease.generation, !(0, statefulRequest_js_1.isStatefulRequest)(requestConfig));
1362
+ const answer = response;
1363
+ // The answer itself says the session is gone: a field, on the one object
1364
+ // that answers this request, never a word.
1365
+ return observed === 'lost'
1366
+ ? { ...answer, sessionLost: interfaces_adt_connection_1.ADT_SESSION_ERROR.SESSION_REPLACED }
1367
+ : answer;
1368
+ }
1369
+ /**
1370
+ * SAP's refusal of a stateless request whose answer showed the session
1371
+ * replaced, as the caller gets it: the refusal itself, marked `sessionLost`.
1372
+ * The wire's error is its own object, made for this attempt, so the mark is
1373
+ * set on it. One that cannot take it — frozen, sealed, or holding its own
1374
+ * fixed `sessionLost` — is answered by an object on top of it: every field of
1375
+ * the refusal read through to it, its class kept, the mark its own.
1376
+ */
1377
+ markedLost(error) {
1378
+ // A refusal is an object: `refusalOf` found its `response` on it.
1379
+ if (typeof error !== 'object' || error === null)
1380
+ return error;
1381
+ const mark = {
1382
+ value: interfaces_adt_connection_1.ADT_SESSION_ERROR.SESSION_REPLACED,
1383
+ enumerable: true,
1384
+ configurable: true,
1385
+ writable: false,
1386
+ };
1387
+ if (Object.isExtensible(error)) {
1388
+ try {
1389
+ Object.defineProperty(error, 'sessionLost', mark);
1390
+ return error;
1391
+ }
1392
+ catch {
1393
+ // An own `sessionLost` that cannot be redefined: marked from above.
1394
+ }
1395
+ }
1396
+ return Object.create(error, { sessionLost: mark });
1317
1397
  }
1318
1398
  /**
1319
1399
  * One attempt's headers: the request's own, with what the credential writes
@@ -1390,13 +1470,14 @@ class AbstractAbapConnection {
1390
1470
  };
1391
1471
  const refusal = (0, IAdtTransport_js_1.refusalOf)(error);
1392
1472
  if (refusal) {
1393
- errorDetails.data =
1394
- typeof refusal.data === 'string'
1395
- ? refusal.data.slice(0, 200)
1396
- : JSON.stringify(refusal.data).slice(0, 200);
1473
+ errorDetails.data = dataPreview(refusal.data);
1397
1474
  // Every wire's refusal, not only axios's. A response the connection
1398
- // never observed is a session replacement it never noticed.
1399
- this.observeResponse(refusal.headers, lease.generation);
1475
+ // never observed is a session replacement it never noticed. A stateless
1476
+ // request's refusal that showed one is the caller's answer: no recovery
1477
+ // starts from it — no CSRF retry, no credential renewal.
1478
+ const observed = this.observeResponse(refusal.headers, lease.generation, !(0, statefulRequest_js_1.isStatefulRequest)(requestConfig));
1479
+ if (observed === 'lost')
1480
+ throw this.markedLost(error);
1400
1481
  }
1401
1482
  this.throwIfSessionDead(error, lease);
1402
1483
  // Check if this is a network error (connection refused, timeout, DNS, etc.)
@@ -1445,6 +1526,14 @@ class AbstractAbapConnection {
1445
1526
  if (!this.lifecycle.isCurrent(lease)) {
1446
1527
  throw this.staleVerdict(retryError);
1447
1528
  }
1529
+ // The resend's refusal is observed like the first attempt's: a
1530
+ // replacement it shows is its own answer, not the first attempt's 403.
1531
+ const retryRefusal = (0, IAdtTransport_js_1.refusalOf)(retryError);
1532
+ if (retryRefusal) {
1533
+ const observed = this.observeResponse(retryRefusal.headers, lease.generation, !(0, statefulRequest_js_1.isStatefulRequest)(requestConfig));
1534
+ if (observed === 'lost')
1535
+ throw this.markedLost(retryError);
1536
+ }
1448
1537
  this.throwIfSessionDead(retryError, lease);
1449
1538
  // A session verdict outranks the error that started the retry: the
1450
1539
  // caller can retry a 403 itself, but it cannot discover that its lock
@@ -1474,6 +1563,10 @@ class AbstractAbapConnection {
1474
1563
  * `requestHeaders` are the request's own, and the resend is authorized anew.
1475
1564
  */
1476
1565
  async answerCredentialFailure(failure, requestConfig, requestHeaders, lease, renewal) {
1566
+ // A session verdict is already the caller's answer — a stateless
1567
+ // request's refusal marked `sessionLost` above all: no provider is asked.
1568
+ if (this.isSessionVerdict(failure))
1569
+ throw failure;
1477
1570
  // A resend inside the wire's recovery that met a dead session.
1478
1571
  this.throwIfSessionDead(failure, lease);
1479
1572
  const rejection = this.credentialRejection(failure);
@@ -1517,7 +1610,9 @@ class AbstractAbapConnection {
1517
1610
  // SAP replaced in between is SESSION_REPLACED, not a bare status.
1518
1611
  const refusal = (0, IAdtTransport_js_1.refusalOf)(again);
1519
1612
  if (refusal) {
1520
- this.observeResponse(refusal.headers, lease.generation);
1613
+ const observed = this.observeResponse(refusal.headers, lease.generation, !(0, statefulRequest_js_1.isStatefulRequest)(requestConfig));
1614
+ if (observed === 'lost')
1615
+ throw this.markedLost(again);
1521
1616
  }
1522
1617
  this.throwIfSessionDead(again, lease);
1523
1618
  const secondRejection = this.credentialRejection(again);
package/docs/INDEX.md CHANGED
@@ -15,6 +15,7 @@ mcp-abap-connection/
15
15
  │ ├── INSTALLATION.md # Setup and installation guide
16
16
  │ ├── USAGE.md # API documentation and examples
17
17
  │ ├── MIGRATION-2.0.md # Moving to the explicit session lifecycle
18
+ │ ├── MIGRATION-23.0.md # a stateless request keeps its answer when the session was replaced: sessionLost
18
19
  │ ├── MIGRATION-22.0.md # RFC: the session lost after a connection-ending error; rfc fields; the passport
19
20
  │ ├── MIGRATION-21.0.md # the CSRF token fetch asks once: no retry, no delay
20
21
  │ ├── MIGRATION-20.0.md # an RFC config states its address, client and language; no URL over RFC
@@ -0,0 +1,78 @@
1
+ # Migration to 23.0
2
+
3
+ 23.0.0 changes what a stateless request gets when the SAP session behind the
4
+ connection was replaced (fr0ster/mcp-abap-adt#354). Stateful requests, RFC and
5
+ everything else are unchanged.
6
+
7
+ ## What changed
8
+
9
+ - **A stateless request keeps its answer.** SAP replaces a session that idled
10
+ out: the next request's answer carries a new `SAP_SESSIONID`. A stateless
11
+ request — any request that is not stateful; it holds no lock and no lock
12
+ state — now gets that answer as SAP gave it: a success resolves, a refusal
13
+ rejects as itself. The answer carries `sessionLost: 'ADT_SESSION_REPLACED'`
14
+ (on the resolved `IAdtWireResponse`, or on the rejected error, beside its own
15
+ `code`). With 22.x the same request rejected `ADT_SESSION_REPLACED` and its
16
+ answer was thrown away, so a read-only call failed once and succeeded right
17
+ after on a new connection.
18
+ - **The session is still lost.** Before the answer reaches you the instance is
19
+ spent, as after any lost session: `isConnected()` is `false`,
20
+ `sessionCookies()` is `null`, every later request and `connect()` reject
21
+ `ADT_NOT_CONNECTED` with nothing sent, and the session SAP opened with that
22
+ answer is logged off. Nothing is sent again for it: no CSRF retry and no
23
+ credential renewal start from an answer that showed the replacement.
24
+ - **Stateful requests keep failing.** A stateful request (`LOCK`, `UNLOCK`, or
25
+ any request the session mode or the `x-sap-adt-sessiontype: stateful` header
26
+ marks stateful) whose answer shows the replacement rejects
27
+ `ADT_SESSION_REPLACED`, as before. So do the connection's own exchanges
28
+ inside a request (a CSRF fetch, a logon), and an answer saying the session no
29
+ longer exists when it shows no replacement — a stateless refusal that both
30
+ changes the `SAP_SESSIONID` and says the session is gone is that refusal,
31
+ marked. `connect()` and a resumed session (`createConnection({ session })`)
32
+ behave as in 22.x.
33
+ - **A refused CSRF resend is now observed.** The resend after a refused CSRF
34
+ token used to rethrow the first attempt's `403` without looking at the
35
+ resend's own answer; a replacement on it went unnoticed. Its answer is now
36
+ read like every other.
37
+ - **`@mcp-abap-adt/interfaces-adt-connection` ^4.2.0**, which types
38
+ `sessionLost` (`AdtSessionLoss`).
39
+
40
+ ## What to do
41
+
42
+ **Read `sessionLost` where you caught `ADT_SESSION_REPLACED` for a stateless
43
+ request.** The answer is valid and is yours to use; the instance is not. Create
44
+ a new connection for the next request:
45
+
46
+ ```typescript
47
+ import {
48
+ ADT_SESSION_ERROR,
49
+ type IAbapConnection,
50
+ type IAbapConnectionError,
51
+ type IAbapRequestOptions,
52
+ } from "@mcp-abap-adt/interfaces-adt-connection";
53
+
54
+ async function readOnce(
55
+ connection: IAbapConnection,
56
+ options: IAbapRequestOptions,
57
+ ): Promise<unknown> {
58
+ const response = await connection.makeAdtRequest(options);
59
+ if (response.sessionLost === ADT_SESSION_ERROR.SESSION_REPLACED) {
60
+ // the answer is valid; the next request needs a new connection
61
+ }
62
+ return response.data;
63
+ }
64
+
65
+ function sessionWasLost(error: Error & IAbapConnectionError): boolean {
66
+ return (
67
+ error.code === ADT_SESSION_ERROR.SESSION_REPLACED || // stateful
68
+ error.sessionLost === ADT_SESSION_ERROR.SESSION_REPLACED // stateless refusal
69
+ );
70
+ }
71
+ ```
72
+
73
+ **Do not resend on your own** unless you mean to: the connection never does.
74
+ A write that carried a lock handle of the old session is refused by SAP (`403`
75
+ for the old CSRF token, `423` for the gone lock), and that refusal is what you
76
+ get, marked.
77
+
78
+ `disconnect()` is still owed once on the spent instance; it sends nothing.
@@ -178,7 +178,9 @@ same session; after a rejection at `'logon'` the wire logs on again before the r
178
178
  **No 401 opens a new session, and the lock in the session is kept:** a mutation
179
179
  (POST / PUT / DELETE) refused with a 401 while a CSRF token is cached goes to the provider and is
180
180
  resent on the same session with the same token, inside a critical section or not, and if SAP did
181
- replace the session the request fails with `SESSION_REPLACED` instead of carrying on in a new one.
181
+ replace the session the instance is spent instead of carrying on in a new one: a stateful request
182
+ fails with `ADT_SESSION_REPLACED`, a stateless one (the mutation is) gets the resend's answer as SAP
183
+ gave it, marked `sessionLost` (since 23.0.0).
182
184
  Before 16.0.0, outside a critical section, that mutation discarded the session and retried in a
183
185
  new one on the same instance; that recovery is gone. One instance is one session: if you want a
184
186
  new session after a 401, create a new connection.
@@ -223,8 +225,9 @@ a substitute: a repeat call does not wait either.
223
225
  - A workflow cannot be resumed by restoring HTTP state into this package: the
224
226
  methods that once did that were removed in 0.2.0. Establish a session with
225
227
  `connect()` and take the locks again — a lock handle from a previous session
226
- is dead, and the connection will say so with `ADT_SESSION_REPLACED` rather
227
- than let you use it.
228
+ is dead. A stateful request (`LOCK`, `UNLOCK`) on a replaced session rejects
229
+ `ADT_SESSION_REPLACED`; a stateless one returns SAP's answer marked
230
+ `sessionLost` (since 23.0.0), and the instance is spent either way.
228
231
 
229
232
  ---
230
233
 
@@ -240,8 +243,9 @@ The link to the ABAP session is not guaranteed, and that is the whole problem:
240
243
 
241
244
  Both are reported, neither is worked around. `connect()` fails with the reason
242
245
  when no session was opened; a session lost afterwards surfaces as
243
- `ADT_SESSION_REPLACED` rather than a request quietly continuing somewhere it
244
- does not belong. What to do about either — wait, retry, create a new connection, release
246
+ `ADT_SESSION_REPLACED` on a stateful request, and as `sessionLost` on the answer
247
+ of a stateless one (since 23.0.0), rather than a request quietly continuing
248
+ somewhere it does not belong. What to do about either — wait, retry, create a new connection, release
245
249
  sessions the user still holds, carry on read-only — is the caller's decision,
246
250
  made with the cookies and the answers in hand.
247
251
 
@@ -349,7 +353,8 @@ close, belongs to whoever passes them around.
349
353
  The server never tells the client how long it has: the session cookie carries no
350
354
  expiry and no response header mentions one. The only honest signals are the ones
351
355
  you get by asking — `getSessionIdentity()` for which session you are in, and
352
- `ADT_SESSION_REPLACED` when the one you were in is gone.
356
+ `ADT_SESSION_REPLACED` (a stateful request) or `sessionLost` (on a stateless
357
+ answer) when the one you were in is gone.
353
358
 
354
359
  ## Troubleshooting
355
360
 
package/docs/USAGE.md CHANGED
@@ -219,7 +219,8 @@ What `connect()` does then:
219
219
  unchanged: the session is this instance's. A stateful request reaches the
220
220
  ABAP context `sap-contextid` names (an `UNLOCK` lands in the old context);
221
221
  later requests carry the credential as usual; a session lost later is
222
- reported as for any instance (`ADT_SESSION_REPLACED`); `disconnect()` logs it
222
+ reported as for any instance (`ADT_SESSION_REPLACED`, or `sessionLost` on a
223
+ stateless answer); `disconnect()` logs it
223
224
  off as for any instance.
224
225
  4. **Gone** — a `401`, a redirect (a `3xx` is not the session answering; it is
225
226
  not followed, so its target is never asked and nothing it sets is taken), or
@@ -512,7 +513,17 @@ side instead of a condition that silently stops matching. The codes live in
512
513
  `@mcp-abap-adt/interfaces-adt-connection` — import them from there, not from this package:
513
514
 
514
515
  ```typescript
515
- import { ADT_SESSION_ERROR } from '@mcp-abap-adt/interfaces-adt-connection';
516
+ import {
517
+ ADT_SESSION_ERROR,
518
+ type IAbapConnectionError,
519
+ } from '@mcp-abap-adt/interfaces-adt-connection';
520
+
521
+ // A caught value comes from outside the type system: your own check narrows it.
522
+ function isConnectionError(
523
+ value: unknown,
524
+ ): value is Error & IAbapConnectionError {
525
+ return value instanceof Error;
526
+ }
516
527
 
517
528
  const options = {
518
529
  method: 'GET',
@@ -521,11 +532,23 @@ const options = {
521
532
  };
522
533
 
523
534
  try {
524
- await connection.makeAdtRequest(options);
535
+ const response = await connection.makeAdtRequest(options);
536
+ if (response.sessionLost === ADT_SESSION_ERROR.SESSION_REPLACED) {
537
+ // A stateless request: SAP's answer is valid and here, and the SAP session
538
+ // is gone with it (since 23.0.0). The instance is spent: the next request
539
+ // needs a new connection.
540
+ }
525
541
  } catch (error) {
526
- if ((error as { code?: string }).code === ADT_SESSION_ERROR.SESSION_REPLACED) {
527
- // The SAP session was replaced under us. Anything locked over the old one
528
- // is orphaned: re-connect, then re-acquire the lock.
542
+ // Narrow the caught value with your own check, then read it by
543
+ // IAbapConnectionError — never by its message.
544
+ if (isConnectionError(error)) {
545
+ if (error.code === ADT_SESSION_ERROR.SESSION_REPLACED) {
546
+ // A stateful request (LOCK, UNLOCK): the session was replaced. Anything
547
+ // locked over the old one is orphaned: re-connect, then re-acquire.
548
+ } else if (error.sessionLost === ADT_SESSION_ERROR.SESSION_REPLACED) {
549
+ // A stateless request refused by SAP, its refusal as it came, and the
550
+ // session gone with it.
551
+ }
529
552
  }
530
553
  }
531
554
  ```
@@ -673,13 +696,34 @@ none over HTTP, and the RFC wire reads it not at all.
673
696
  Two different things can cost you the session, and they do not behave alike.
674
697
 
675
698
  **The session was replaced** — a session cookie (`SAP_SESSIONID`) that changed
676
- underneath you. The request rejects with `ADT_SESSION_REPLACED`: a lock handle
677
- you are carrying is now dead, which is the one thing you cannot work out for
678
- yourself.
699
+ underneath you, the usual cause an idle timeout. What the request gets depends
700
+ on whether it is stateful (since 23.0.0):
701
+
702
+ - **a stateful request** (`LOCK`, `UNLOCK`, anything the connection's session
703
+ mode or the caller's `x-sap-adt-sessiontype: stateful` header marks stateful)
704
+ rejects with `ADT_SESSION_REPLACED`: a lock handle you are carrying is now
705
+ dead, which is the one thing you cannot work out for yourself;
706
+ - **a stateless request** holds no lock and no lock state, so the answer SAP
707
+ gave it is valid and is returned as it came — a success resolves, a refusal
708
+ rejects as itself — with `sessionLost: 'ADT_SESSION_REPLACED'` on that
709
+ response or on that error (`IAdtWireResponse`, `IAbapConnectionError`,
710
+ `@mcp-abap-adt/interfaces-adt-connection` ^4.2.0). Only the request whose own
711
+ answer showed the replacement carries it. Nothing is sent again for it: no
712
+ CSRF retry, no credential renewal. The session is lost before the answer
713
+ reaches you.
714
+
715
+ The connection's own exchanges inside a request (a CSRF fetch, a logon) have no
716
+ answer of yours to keep: a replacement seen on one is `ADT_SESSION_REPLACED`.
717
+ `connect()` forgets the identity between its own requests, so what it sets up
718
+ is never read as a replacement.
719
+ A resumed session (`createConnection({ …, session })`) whose answer names another
720
+ `SAP_SESSIONID` rejects `connect()` with SAP's answer, as before.
679
721
 
680
722
  **The server says the session is gone** — an answer meaning the session it was
681
723
  given no longer exists. This is **always** fatal, window or not: the connection
682
- raises `ADT_SESSION_REPLACED` and stops being usable. Unlike a replacement,
724
+ raises `ADT_SESSION_REPLACED` and stops being usable — stateless or not, unless
725
+ the same answer also changed the `SAP_SESSIONID`: a stateless refusal that does
726
+ both is a replacement first, that refusal, marked. Unlike a replacement,
683
727
  nothing here suggests a working session to continue on — the one we had is
684
728
  confirmed dead, and re-establishing silently is what let the old connector
685
729
  carry on over a session the caller never opened.
@@ -691,7 +735,8 @@ an answer on a dead pooled socket — see "Kept-alive connections, and the one
691
735
  resend" under the transports; it never resends a request the server answered.)
692
736
 
693
737
  **A lost session spends the instance** (since 16.0.0), as `disconnect()` does.
694
- After either of these, `connect()` and every request on the instance reject
738
+ After either of these — a stateless answer marked `sessionLost` included —
739
+ `connect()` and every request on the instance reject
695
740
  `ADT_SESSION_ERROR.NOT_CONNECTED`, and a new session is a new connection.
696
741
  `disconnect()` is still owed once. It sends the logoff only if the instance
697
742
  still holds a live `SAP_SESSIONID`, and after a loss the connection has
@@ -706,7 +751,9 @@ timeout. `disconnect()` waits for that logoff's write, `flushGoodbye()` for
706
751
  its answer; a `connect()` that found its session replaced rejects once it is
707
752
  written. The old session SAP already ended, and a session reported gone
708
753
  (`400 "Session not found"`) brought no new one: nothing is sent for either.
709
- `ADT_SESSION_REPLACED` reaches the caller as before. Over RFC the
754
+ What reaches the caller is the replacement's answer above: `ADT_SESSION_REPLACED`
755
+ for a stateful request, SAP's answer marked `sessionLost` for a stateless one.
756
+ Over RFC the
710
757
  conversation is the session and no answer can replace it.
711
758
 
712
759
  **Over RFC, an RFC error can end the session** (22.0.0). When an RFC error
@@ -1278,8 +1325,9 @@ dropped, established anew — before the resend.
1278
1325
  the session's cookies to open another and retry there. A mutation that meets a
1279
1326
  401 with a CSRF token cached is put to the provider like any other 401; on Ok it
1280
1327
  is resent on the same session with the same token, inside a critical section or
1281
- not, and if SAP did replace the session the request fails with
1282
- `SESSION_REPLACED`. Before 16.0.0, outside a critical section, that mutation
1328
+ not, and if SAP did replace the session the instance is spent: a stateful
1329
+ request fails with `ADT_SESSION_REPLACED`, a stateless one gets the resend's
1330
+ answer marked `sessionLost` (since 23.0.0). Before 16.0.0, outside a critical section, that mutation
1283
1331
  discarded the session and retried in a new one on the same instance, a GET
1284
1332
  401 on a wire with no cookies fetched a token to open one, and a GET 401 with
1285
1333
  cookies held was resent once before the provider was asked; all three are
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mcp-abap-adt/connection",
3
- "version": "22.0.0",
3
+ "version": "23.0.0",
4
4
  "description": "ABAP connection layer for MCP ABAP ADT server",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -52,7 +52,7 @@
52
52
  },
53
53
  "dependencies": {
54
54
  "@mcp-abap-adt/auth-errors": "^2.2.1",
55
- "@mcp-abap-adt/interfaces-adt-connection": "^4.1.0",
55
+ "@mcp-abap-adt/interfaces-adt-connection": "^4.2.0",
56
56
  "@mcp-abap-adt/interfaces-auth": "^7.5.0",
57
57
  "@mcp-abap-adt/interfaces-auth-sap": "^4.0.0",
58
58
  "@mcp-abap-adt/interfaces-network": "^2.0.1",