Self-hosted managed agent sessions fail after ~60 minutes when sessions_token expires, and environment key fallback cannot access memory stores

未关闭
#2,026 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

评估

难度
4/5
预计耗时
3-5 天
新手友好度
48/100
Issue 类型
缺陷
描述清晰度
基本清楚
活跃度
活跃
技术栈
python

调研方向

Start with src/anthropic/lib/environments/_worker.py, focusing on _sessions_token_from_secret(...) and EnvironmentWorker._handle_item(...), then inspect SessionMemoryStores(...) to understand the credential requirement. Check how the worker obtains and uses the session token during long-running work. Done means the supported credential flow for sessions that outlast token expiry is clear and memory-store calls can continue; the issue does not identify tests.

由索引模型根据 Issue 内容生成。

描述

We’re seeing a blocker with self-hosted Claude managed agents running on anthropics/anthropic-sdk-python at commit bcd55fe1d3f0f1240765f8cef04295b67337f55a.

Problem
When a self-hosted session runs for about 60 minutes, the per-work-item sessions_token appears to expire exactly at that point. After that, requests start returning 401 Unauthorized.

The worker currently uses the session token extracted from the work item secret for session-level calls and memory-store operations. This is a problem because:

the session token is required for memory-store endpoints
the environment key can be used as a fallback for some work/session operations
but the environment key does not work with memory stores
So when the session token expires, we hit a catch-22:

session token → expired, causes 401s
environment key → works for some calls, but cannot access memory stores
Impact
This breaks long-running self-hosted sessions that rely on memory stores. The session can continue from a work-lease perspective, but the SDK has no obvious way to renew the session token while preserving memory-store access.

Evidence / code path
In the SDK, the self-hosted worker extracts a sessions_token from the work secret and uses it as the bearer credential for session calls:

src/anthropic/lib/environments/_worker.py
credential extraction and fallback logic around sessions_token
memory-store setup requires the session token and explicitly fails if only the environment key is available
The relevant code path appears to be:

_sessions_token_from_secret(...)
EnvironmentWorker._handle_item(...)
memory store initialization in SessionMemoryStores(...)
Expected behavior
For long-running managed-agent sessions, there should be a supported way to:

refresh or rotate the session token before expiry, or
continue memory-store operations after token refresh, or
use a supported credential flow that does not break memory-store access after 60 minutes.
Actual behavior
After ~60 minutes:

requests start failing with 401
session token appears expired
environment-key fallback is not usable for memory stores
long-running sessions become effectively stuck
Questions
Is there a supported way to renew a session token for self-hosted managed agents?
Are session tokens expected to expire after 60 minutes?
If so, what is the supported approach for long-running sessions that need memory stores?
Should the worker SDK be refreshed to re-fetch or rotate the token during a session?
Environment
Repository: anthropics/anthropic-sdk-python
Commit: bcd55fe1d3f0f1240765f8cef04295b67337f55a
Relevant feature: Claude managed agents / self-hosted environment / memory stores

主要语言
Python
星标
4.1k
派生
915
PR 合并指标
30 天内没有已合并 PR

环境准备

在 Codespaces 中打开

在浏览器里用你自己的 GitHub 账号启动这个项目的开发容器。

  • 没有 Dockerfile 或 Docker Compose 文件
  • 没有 Pull Request 模板
  • 阅读贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

anthropics/anthropic-sdk-python 的其他 Issue

查看 anthropics/anthropic-sdk-python 的全部 Issue

相似的 Issue

更多 Python Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。