Free, Open Source, Self-Hosted WhatsApp API Gateway
TypeScript apibotgatewayself-hostedwhatsappwhatsapp-apiwhatsapp-automationwhatsapp-botwhatsapp-gatewaywhatsapp-gateway-apiwhatsapp-webwhatsapp-web-api
docs(api): document the stop endpoint's incomplete-teardown 502
Yudhi Armyndharis4c173ef89eeb
diff --git a/docs/06-api-specification.md b/docs/06-api-specification.mdindex ccb1438ad..251b89e06 100644--- a/docs/06-api-specification.md+++ b/docs/06-api-specification.md@@ -577,7 +577,7 @@ No request body.Returned via `transformSession`; status typically becomes `disconnected`.-**Errors:** `401` · `403` · `404` not found+**Errors:** `401` · `403` · `404` not found · `502` `SESSION_STOP_INCOMPLETE` — session stopped locally but the engine teardown did not complete (retryable; the graceful disconnect and the force-destroy escalation both failed, status `disconnected`, no success audit)#### POST /api/sessions/:sessionId/logoutdiff --git a/openapi.json b/openapi.jsonindex 1a4953605..d1963510e 100644--- a/openapi.json+++ b/openapi.json@@ -633,6 +633,9 @@},"409": {"description": "Another node currently holds this session's live engine (multi-node deployments): stopping it here would report the session down while the owner keeps running it, so the request is refused. Retry against the owning node, or once its lease has lapsed."+ },+ "502": {+ "description": "Session was stopped locally, but the engine teardown did not complete (the graceful disconnect and the force-destroy escalation both failed, so the engine process may still be running). Retryable — the body carries `code: 'SESSION_STOP_INCOMPLETE'`; the status is settled to `disconnected` and no success audit is written. Retry the stop; restart the node to reap a leaked process."}},"summary": "Stop a session and disconnect WhatsApp",diff --git a/sdk/go/sessions.go b/sdk/go/sessions.goindex ed92a66e7..e871b32d1 100644--- a/sdk/go/sessions.go+++ b/sdk/go/sessions.go@@ -69,7 +69,12 @@ func (s *SessionsService) Start(ctx context.Context, sessionID string) (*Sessionreturn &out, nil}-// Stop disconnects a session gracefully.+// Stop disconnects a session gracefully. Returns an HTTP 502 error with+// code 'SESSION_STOP_INCOMPLETE' when the session was stopped locally but the engine+// teardown did not complete (the graceful disconnect and the force-destroy escalation+// both failed, so the engine process may still be running); the status is settled to+// disconnected and no success audit is written. Retry the stop; restart the node to+// reap a leaked process.func (s *SessionsService) Stop(ctx context.Context, sessionID string) (*SessionResponse, error) {var out SessionResponseerr := s.client.do(ctx, "POST", "/api/sessions/"+pathEscape(sessionID)+"/stop", nil, nil, &out)diff --git a/sdk/java/src/main/java/com/rmyndharis/openwa/resources/SessionsResource.java b/sdk/java/src/main/java/com/rmyndharis/openwa/resources/SessionsResource.javaindex 0b99be421..0435fad1f 100644--- a/sdk/java/src/main/java/com/rmyndharis/openwa/resources/SessionsResource.java+++ b/sdk/java/src/main/java/com/rmyndharis/openwa/resources/SessionsResource.java@@ -70,7 +70,14 @@ public final class SessionsResource {return client.request(HttpMethod.POST, "/api/sessions/" + encodeSegment(id) + "/start", null, null, SessionResponse.class);}- /** Stop a session and disconnect gracefully. */+ /**+ * Stop a session and disconnect gracefully. Throws on HTTP {@code 502} with+ * {@code code: 'SESSION_STOP_INCOMPLETE'} when the session was stopped locally but the engine+ * teardown did not complete (the graceful disconnect and the force-destroy escalation both+ * failed, so the engine process may still be running); the status is settled to+ * {@code disconnected} and no success audit is written. Retry the stop; restart the node to+ * reap a leaked process.+ */public SessionResponse stop(String id) {return client.request(HttpMethod.POST, "/api/sessions/" + encodeSegment(id) + "/stop", null, null, SessionResponse.class);}diff --git a/sdk/javascript/src/resources/sessions.ts b/sdk/javascript/src/resources/sessions.tsindex 404c6e174..40ed12e69 100644--- a/sdk/javascript/src/resources/sessions.ts+++ b/sdk/javascript/src/resources/sessions.ts@@ -74,7 +74,14 @@ export class SessionsResource {return this.client.request<SessionResponse>({ method: 'POST', path: `/api/sessions/${encodeSegment(id)}/start` });}- /** Stop a session and disconnect gracefully. */+ /**+ * Stop a session and disconnect gracefully. Rejects with HTTP `502` and+ * `code: 'SESSION_STOP_INCOMPLETE'` when the session was stopped locally but the engine+ * teardown did not complete (the graceful disconnect and the force-destroy escalation both+ * failed, so the engine process may still be running); the status is settled to+ * `disconnected` and no success audit is written. Retry the stop; restart the node to reap+ * a leaked process.+ */stop(id: string): Promise<SessionResponse> {return this.client.request<SessionResponse>({ method: 'POST', path: `/api/sessions/${encodeSegment(id)}/stop` });}diff --git a/sdk/php/src/Resources/SessionsResource.php b/sdk/php/src/Resources/SessionsResource.phpindex 7c2549637..f38b719ba 100644--- a/sdk/php/src/Resources/SessionsResource.php+++ b/sdk/php/src/Resources/SessionsResource.php@@ -79,7 +79,16 @@ class SessionsResourcereturn $this->http->request('POST', "/api/sessions/{$this->http->encodeSegment($id)}/start");}- /** @return array<string,mixed> */+ /**+ * Stop a session and disconnect gracefully. Throws on HTTP 502 with+ * `code: 'SESSION_STOP_INCOMPLETE'` when the session was stopped locally but the engine+ * teardown did not complete (the graceful disconnect and the force-destroy escalation both+ * failed, so the engine process may still be running); the status is settled to+ * `disconnected` and no success audit is written. Retry the stop; restart the node to reap+ * a leaked process.+ *+ * @return array<string,mixed>+ */public function stop(string $id): array{return $this->http->request('POST', "/api/sessions/{$this->http->encodeSegment($id)}/stop");diff --git a/sdk/python/openwa/resources/sessions.py b/sdk/python/openwa/resources/sessions.pyindex 6f0380863..d70f2533c 100644--- a/sdk/python/openwa/resources/sessions.py+++ b/sdk/python/openwa/resources/sessions.py@@ -70,7 +70,15 @@ class SessionsResource:return self._http.request("POST", f"/api/sessions/{quote_segment(session_id)}/start")def stop(self, session_id: str) -> SessionResponse:- """Disconnect a session gracefully."""+ """Disconnect a session gracefully.++ Raises on HTTP 502 with ``code: 'SESSION_STOP_INCOMPLETE'`` when the+ session was stopped locally but the engine teardown did not complete+ (the graceful disconnect and the force-destroy escalation both failed,+ so the engine process may still be running); the status is settled to+ ``disconnected`` and no success audit is written. Retry the stop;+ restart the node to reap a leaked process.+ """return self._http.request("POST", f"/api/sessions/{quote_segment(session_id)}/stop")def logout(self, session_id: str) -> SessionResponse:diff --git a/src/modules/session/session.controller.ts b/src/modules/session/session.controller.tsindex 4a9703144..c3a0130e8 100644--- a/src/modules/session/session.controller.ts+++ b/src/modules/session/session.controller.ts@@ -240,6 +240,15 @@ export class SessionController {'it here would report the session down while the owner keeps running it, so the request is ' +'refused. Retry against the owning node, or once its lease has lapsed.',})+ @ApiResponse({+ status: 502,+ description:+ 'Session was stopped locally, but the engine teardown did not complete (the graceful ' ++ 'disconnect and the force-destroy escalation both failed, so the engine process may still ' ++ "be running). Retryable — the body carries `code: 'SESSION_STOP_INCOMPLETE'`; the status " ++ 'is settled to `disconnected` and no success audit is written. Retry the stop; restart the ' ++ 'node to reap a leaked process.',+ })async stop(@Param('sessionId', ParseUUIDPipe) id: string): Promise<SessionResponseDto> {const session = await this.sessionService.stop(id);await this.auditService.logInfo(AuditAction.SESSION_STOPPED, {