Skip to content

feat: renew the job user access token over the handler IPC pipe - #1995

Open
eduard-dumitru wants to merge 11 commits into
mainfrom
feat/job-token-refresh
Open

eduard-dumitru wants to merge 11 commits into
mainfrom
feat/job-token-refresh

Conversation

@eduard-dumitru

@eduard-dumitru eduard-dumitru commented Nov 16, 2026 •

Copy link
Copy Markdown
Contributor

What

A long-running job can outlive the user access token it starts with, and its calls then fail with 401. This change renews the token while the job runs and makes the SDK send the renewed token.

Changes

uipath-platform

  • A UiPath() whose secret came from the environment re-reads UNATTENDED_USER_ACCESS_TOKEN / UIPATH_ACCESS_TOKEN on every request. An explicit secret= or a client-credentials token is sent as before.
  • It stops following the environment once UIPATH_JOB_KEY there no longer matches the job the client was created in, and keeps its last token.
  • Request headers are copied per request instead of being written into the caller's mapping.

uipath

  • JobTokenRefresher (_cli/_job_token.py) renews the job's user access token at 80 % of its lifetime, at least two minutes before expiry, and writes it to the token environment variables that hold that token.
  • Renewal is opt-in, set by the job executor: the hidden uipath run --handler-ipc-token-refresh flag (needs --handler-ipc-pipe), or refreshAccessTokenOverIpc on a pooled run request. An opt-in that cannot be honored is ignored with a warning and the job still runs.
  • The trace exporter re-reads the token before each upload. The chat and voice bridges build their Authorization header on every connect and reconnect, the debug bridge when it connects.

Behavior

  • Nothing changes without the opt-in, or for clients given an explicit secret.
  • A failed renewal never fails the job: the current token is kept and renewal is retried every 30 seconds. Only the first failure is logged, until a renewal succeeds again.
  • Not covered: code that copies the token out of the environment once and keeps it.

Versions

uipath-platform 0.3.13, and uipath 2.15.5 requiring uipath-platform>=0.3.13.

Tests

New tests cover the per-request re-read, the refresher's timing, failure and stop behavior, a round trip over a real named pipe, the CLI flag, the pooled opt-in, the trace exporter and the three bridges.

The full test suite, ruff check, ruff format --check and mypy pass locally on both packages.

🤖 Generated with Claude Code

Copilot AI balanced review requested due to automatic review settings November 16, 2026 14:13
@github-actions github-actions Bot added test:uipath-langchain Triggers tests in the uipath-langchain-python repository test:uipath-runtime test:uipath-integrations labels Nov 16, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Outstanding issues include cross-job token leakage on teardown or cancellation, along with refresh scheduling and request retry defects.

8 open issues
What changed in this PR

Adds opt-in access-token renewal for long-running UiPath Python jobs, connecting the platform HTTP client to the executor’s existing IPC token API.

Changes:

  • Adds token providers and one-time renewal retries after HTTP 401 responses.
  • Implements cached, proactive IPC renewal with per-job CLI and pooled-server opt-ins.
  • Adds tests and documentation, and bumps package versions and the platform dependency minimum.
File Description
packages/​uipath/​uv.lock Updates SDK and platform package versions.
packages/​uipath/​tests/​cli/​test_server_ipc.py Tests pooled-job renewal opt-in and lifecycle hooks.
packages/​uipath/​tests/​cli/​test_run.py Tests the hidden renewal flag and connection wiring.
packages/​uipath/​tests/​cli/​test_job_token.py Tests caching, renewal, failures, teardown, and IPC transport.
packages/​uipath/​src/​uipath/​_cli/​cli_server_ipc.py Installs and removes providers for opted-in pooled jobs.
packages/​uipath/​src/​uipath/​_cli/​cli_run.py Adds and validates the executor’s renewal flag.
packages/​uipath/​src/​uipath/​_cli/​_job_token.py Implements IPC token caching and renewal scheduling.
packages/​uipath/​src/​uipath/​_cli/​_job_api.py Connects provider lifecycle to handler IPC connections.
packages/​uipath/​pyproject.toml Bumps the SDK version and platform dependency minimum.
packages/​uipath/​docs/​core/​environment_variables.md Documents renewal behavior and environment updates.
packages/​uipath-platform/​uv.lock Updates the platform package version.
packages/​uipath-platform/​tests/​services/​test_access_token_refresh.py Tests provider selection, authorization, and 401 retries.
packages/​uipath-platform/​src/​uipath/​platform/​common/​_config.py Defines provider interfaces and process-default configuration.
packages/​uipath-platform/​src/​uipath/​platform/​common/​_base_service.py Uses provider tokens and retries after renewal.
packages/​uipath-platform/​src/​uipath/​platform/​common/​_api_client.py Avoids copying stale authorization with folder headers.
packages/​uipath-platform/​src/​uipath/​platform/​common/​__init__.py Exports token-provider APIs.
packages/​uipath-platform/​src/​uipath/​platform/​_uipath.py Enables default providers for environment-configured clients.
packages/​uipath-platform/​pyproject.toml Bumps the platform package version.
packages/​uipath-platform/​CLAUDE.md Documents the token-renewal architecture.

Review effort: Balanced

@eduard-dumitru
eduard-dumitru marked this pull request as draft November 16, 2026 14:36
eduard-dumitru and others added 3 commits November 16, 2026 23:22
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
eduard-dumitru and others added 6 commits November 17, 2026 11:35
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
The same wait covers a failed call and a host that hands back a token
already due. Halving it picks up the serverless handler's renewed token
sooner and gives a short-lived token more tries before it expires.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
The host opts in on the command line, so the refresher no longer reads
the error's type to decide the host is "unsupported" and stop asking.
Any failure keeps the current token and is retried after the backoff.

Only the first failure is logged. Its warning now says so: later
failures to renew the job's token are not logged.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Comments and docstrings only; no code change. The environment variables
page now describes what a job sees instead of how renewal is wired.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
@eduard-dumitru
eduard-dumitru requested a review from erghe November 20, 2026 12:23
- A client follows the environment's token only while UIPATH_JOB_KEY
  there still matches the job it was created in; after that it keeps
  its last token.
- The chat and voice bridges give the socket library a callable for
  the headers, so a reconnect sends the current token.
- One warning per failure episode: the flag resets when a renewal
  succeeds, and the recovery is logged.
- An opt-in that cannot be honored warns and the job runs without
  renewal.
- The loop warns when it stops for lack of a token with an expiry, and
  waits in slices of at most a minute.
- Only the variables holding the job's token are rewritten.
- Remove properties and a wrapper that only tests used, and annotate
  the tests this change adds.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
@eduard-dumitru
eduard-dumitru marked this pull request as ready for review November 20, 2026 12:35
main took uipath-platform 0.3.9 to 0.3.12 and uipath 2.15.4, so this
change ships as uipath-platform 0.3.13 and uipath 2.15.5.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
@sonarqubecloud

Copy link
Copy Markdown

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

test:uipath-integrations test:uipath-langchain Triggers tests in the uipath-langchain-python repository test:uipath-runtime

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants