Skip to content

Commit f770e44

Browse files
LYJW131claude
andauthored
feat(limits): Claude 登录剩 3 天内时在 Plan 旁提示重登 (#796)
- feat(limits): Claude 登录剩 3 天内时在 Plan 旁提示重登 Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
1 parent 70beac6 commit f770e44

14 files changed

Lines changed: 154 additions & 13 deletions

File tree

‎docs/ops-facts.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@
107107
| Action 机没有拆除,但本仓库的工作流都只用 GitHub 托管机,不再调度到它;本条及下面两条是停用前核对的机器配置。各 runner 的 `_work` 是最大 16 GiB 的 tmpfs,`_work/_tool` bind mount 到同一 runner 的持久目录 `toolcache`;挂载写入 `89.185.24.102:/etc/fstab`。systemd drop-in `workspace.conf` 用 `RequiresMountsFor` 保证挂载先于 runner 启动,并设置失败自动重启;`BindPaths` 在每个服务独立的 mount namespace 中把各自 `_work` 映射成 `/home/runner/work`,`.runner` 的 `workFolder` 使用该绝对路径,让 CodeQL 缓存版本与托管机一致。各 runner 的 `.env` 设置 `HOME=/home/runner/work/_home`,实际目录按服务隔离;`.env` 的 `SEGMENT_DOWNLOAD_TIMEOUT_MINS=0.5` 为 CodeQL 缓存下载覆盖过短的单段超时,`CODEQL_THREADS=8` 与 `CODEQL_RAM=16384` 给每个扫描任务设置独立资源预算;`ExecStartPre` 创建 HOME;CI 通过 `--store-dir "$CI_CACHE_DIR/pnpm-store"` 显式选用持久 store,避免 pnpm/action-setup 的 `PNPM_HOME` 使 store 落入临时安装目录。工作目录随重启清空,pnpm store、ESLint 与工具缓存落盘。路径映射的回退副本分别是 runner 目录的 `.runner.before-canonical-workspace`、`.env.before-canonical-workspace` 与服务 drop-in 的 `workspace.conf.before-canonical-workspace`;停止空闲服务、恢复这三项、reload / start 即撤销映射。磁盘工作目录的回退入口是 `89.185.24.102:/etc/fstab.before-lyjwpage-runner-tmpfs`;先撤销映射,再停止空闲 runner、卸载 `_work/_tool` 和 `_work`,恢复 fstab,将 `toolcache` 移回 `_work/_tool`,移除 drop-in 的挂载依赖,再 reload / start | 核对于 2026-10-11,方式:SSH `findmnt --verify`、`findmnt -T`、`systemctl show`、`nsenter` 逐服务写入互不覆盖的标记并检查工具挂载;CI 安装日志核对持久 store 命中;未重启整台机器验证开机流程 <!-- allow: 核对戳 --> |
108108
| Action 机 `89.185.24.102`:Debian 13、32 vCPU(Xeon Platinum 8259CL)、约 64 GB 内存、177 GiB 根盘;runner 名称 `action-89-185-24-102-1` 至 `-3`,仓库级标签 `self-hosted`、`linux`、`x64`、`lyjwpage`。安装于 `89.185.24.102:/opt/actions-runner/runner-{1,2,3}/`,由普通用户 `actions-runner` 的 systemd 服务运行并开机启动;Node 安装于 `89.185.24.102:/opt/node-24/`,`/usr/local/bin/node` 提供 CodeQL 所需的 PATH 入口。共享 pnpm store 位于 `89.185.24.102:/var/cache/lyjwpage-ci/pnpm-store/`,`.env` 设置 `CI_CACHE_DIR` 指向 `89.185.24.102:/var/cache/lyjwpage-ci/`;该目录另存 ESLint,`typecheck/` 下按 workspace 路径保存 `tsconfig.ci.tsbuildinfo`。pnpm 工具按版本安装在各 runner 的 `toolcache/pnpm/`(复用脚本已从仓库删除) | 核对于 2026-10-11,方式:SSH `lscpu`、`free`、`df`、systemd、`node --version`、显式 store 的全新目录离线安装与 GitHub runners API,实际 CI job 确认 runner 标签匹配 <!-- allow: 核对戳 --> |
109109
| Action 机提供 ffmpeg 与 libmp3lame;配乐工作流通过 browser-actions/setup-chrome 准备 Chrome for Testing,按工作流固定版本复用共享缓存 `89.185.24.102:/var/cache/lyjwpage-ci/chrome/`;未命中时从各 runner 的持久 `toolcache/setup-chrome/` 安装后原子写入共享缓存,渲染脚本经 `CHROME_PATH` 使用对应二进制 | 核对于 2026-10-11,方式:SSH ffmpeg 编码器清单、Chrome `--version` 与 `ldd` 无缺失依赖;实际 benchmark job 启动完整渲染 <!-- allow: 核对戳 --> |
110-
| misaka-jp(东京):`server-reporter` 与 `agents-reporter` 两个容器在同一个 compose project,目录 `/opt/lyjwpage`(`compose.yaml`,各服务的 `.env` 与 `data/` 卷)。ssh 直连 `ssh misaka-jp`(不用 dsm 跳板)。合进 main 后 `.github/workflows/build-reporters.yml` 用只能执行 `/opt/lyjwpage/deploy.sh` 的部署密钥 ssh 过去换镜像(源 `reporters/misaka-deploy.sh`),密钥与地址在 GitHub environment `misaka-jp` | 核对于 2026-09-13,方式:迁自 [核验记录](./reporter-endpoints.md)、`reporters/agents-reporter/README.md` 与 `.github/workflows/build-reporters.yml` 的注释;ssh 直连一项核对于 2026-10-29,方式:本机 `ssh -o BatchMode=yes misaka-jp` 只读列 `/opt/lyjwpage` <!-- allow: 核对戳 --> |
110+
| misaka-jp(东京):`server-reporter` 与 `agents-reporter` 两个容器在同一个 compose project,目录 `/opt/lyjwpage`(`compose.yaml`,各服务的 `.env` 与 `data/` 卷)。ssh 直连 `ssh misaka-jp`(不用 dsm 跳板);家里出口经软路由 OpenClash,规则 `DstPort 22` 走 `SSH` 分组,握手前就被断开(`kex_exchange_identification: Connection closed`)时换该分组的节点,JP-Misaka 能通。合进 main 后 `.github/workflows/build-reporters.yml` 用只能执行 `/opt/lyjwpage/deploy.sh` 的部署密钥 ssh 过去换镜像(源 `reporters/misaka-deploy.sh`),密钥与地址在 GitHub environment `misaka-jp` | 核对于 2026-09-13,方式:迁自 [核验记录](./reporter-endpoints.md)、`reporters/agents-reporter/README.md` 与 `.github/workflows/build-reporters.yml` 的注释;ssh 直连一项核对于 2026-10-29,方式:本机 `ssh -o BatchMode=yes misaka-jp` 只读列 `/opt/lyjwpage`;OpenClash 分组一项核对于 2026-11-03,方式:`ssh [email protected]` 读本机 Clash API 的 `/rules` 与 `SSH` 分组,切到 JP-Misaka 后直连成功 <!-- allow: 核对戳 --> |
111111
| misaka-jp 上报节奏:运行中的 `agents-reporter` 按 agent 使用情况采用 5 / 60 分钟两档(`.env` 的 `ACTIVE_INTERVAL_MS` / `IDLE_INTERVAL_MS`),活动查询超时 2.5 秒(`ACTIVITY_TIMEOUT_MS`);Cursor 活动快循环从 1 分钟退避到最多 4 分钟。运行中的 `server-reporter` 固定每 60 秒上报,推送超时 10 秒;其环境中虽有 `LIVE_INTERVAL_MS`、`OPEN_INTERVAL_MS`、`IDLE_INTERVAL_MS`,但服务配置不读取这些键 | 核对于 2026-09-30,方式:`ssh -J dsm misaka-jp` 只读检查两个运行容器的镜像、节奏变量白名单,并从容器内编译后的 `dist/config.js` 读取节奏字段;`agents-reporter` 一项核对于 2026-10-10,方式:读机器上 `.env` 与容器启动日志;对照 `reporters/agents-reporter/src/cadence.ts` 与 `reporters/server-reporter/src/config.ts` <!-- allow: 核对戳 --> |
112112
| misaka-jp 的 DNS:机房经 DHCP 下发、并以运行时设置写在网卡 `enp3s0` 上的 188.244.99.99 大量回 SERVFAIL(拉不下 GHCR 镜像、上报器 `fetch failed` 都源于此),已弃用。`misaka-jp:/etc/netplan/90-dns.yaml` 关掉 DHCP 下发的 DNS 并指定 1.1.1.1、8.8.8.8,`misaka-jp:/etc/systemd/resolved.conf.d/fallback.conf` 设兜底 1.0.0.1、8.8.4.4;删这两个文件后 `netplan apply` 即回滚。网卡又出现机房 DNS 时看 `networkctl status enp3s0 --json=short` 的 `ConfigSource`,是 `runtime` 就 `resolvectl revert enp3s0` | 核对于 2026-10-13,方式:dig 对比三台上游、`resolvectl dns enp3s0`,宿主机与 agents-reporter 容器内解析全部成功,生产 `/api/status/limits` 的 Claude 行恢复 <!-- allow: 核对戳 --> |
113113
| dsm(群晖):emby-reporter 在 compose 项目 `dsm:/volume3/docker/emby-proxy/`(`docker-compose.yml`),服务名 `emby-reporter`、容器名 `homepage-reporter`,`.env` 在项目根、权限 600;docker 不在群晖非交互 PATH,要写 `/usr/local/bin/docker`;Actions 够不着,服务定义使用 `build: ./homepage-reporter`,运行容器的镜像名是 `emby-proxy-emby-reporter`,并未使用 GHCR 镜像。部署到 dsm 仍需现场 build 或修改服务定义 | 核对于 2026-09-30,方式:SSH 读取 `docker-compose.yml` 的 `emby-reporter` 服务定义与 `/usr/local/bin/docker inspect homepage-reporter` 的镜像名、运行状态 <!-- allow: 核对戳 --> |

‎reporters/agents-reporter/README.md‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,8 @@ Claude 在 Linux 上把 OAuth 写到 `/data/.claude/.credentials.json`。登录
103103

104104
CLI 升级改变配置结构时,可更新扫描规则,或成对填写 `CLAUDE_OAUTH_TOKEN_URL` / `CLAUDE_OAUTH_CLIENT_ID` 暂时覆盖。日志不会输出令牌;撤销登录或 refresh token 本身失效仍需重新登录。
105105

106+
订阅登录的 refresh token 有硬期限,凭据里的 `refreshTokenExpiresAt` 记着它,轮换不会延长;过了这一刻续期回 400,当前 access token 到期后 usage 接口先回 401、之后回 429,只能重新登录。Claude 行把这个时刻原样带成 `authRefreshExpiresAt`(epoch 毫秒),站点在剩 3 天内时在 Plan 旁提示(`src/components/live/vibecoding/limits.ts#loginExpiryNote`)。`claude setup-token` 的长期 token 只有 `user:inference`,读不了 `/api/oauth/usage`,不能拿来替代登录。
107+
106108
Codex 的 token 由上报器自己刷新,写回 `/data/.codex/auth.json`。
107109

108110
## cursor / devin / antigravity

‎reporters/agents-reporter/src/claude-oauth.ts‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ type OauthBlob = {
1616
subscriptionType?: unknown;
1717
rateLimitTier?: unknown;
1818
scopes?: unknown;
19+
refreshTokenExpiresAt?: unknown;
1920
[key: string]: unknown;
2021
};
2122

@@ -54,6 +55,12 @@ export async function readClaudeOauth(home = config.home): Promise<OauthBlob | n
5455
}
5556
}
5657

58+
// 订阅登录的 refresh token 有硬期限(约 30 天),轮换不延长;过了它续期回 400,只能重新登录。
59+
export function claudeRefreshExpiresAt(oauth: OauthBlob): number | null {
60+
const value = oauth.refreshTokenExpiresAt;
61+
return typeof value === "number" && Number.isFinite(value) && value > 0 ? value : null;
62+
}
63+
5764
export function claudeAccessExpired(oauth: OauthBlob, now = Date.now()): boolean {
5865
const expires = expiryMs(oauth.expiresAt);
5966
if (expires == null) return false;

‎reporters/agents-reporter/src/providers/claude-oauth.test.mts‎

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,3 +144,37 @@ test("套餐以 profile 为准,凭据里登录时的旧档只在 profile 取
144144
profileStatus = 403;
145145
assert.deepEqual((await collectAgents())[0]?.plan, { tier: "Max", label: "Max" });
146146
});
147+
148+
test("Claude 行带上 refresh token 的硬期限,429 时也带", async (t) => {
149+
const { file, original } = await fixture(t);
150+
const refreshTokenExpiresAt = Date.now() + 2 * 86_400_000;
151+
await writeFile(file, JSON.stringify({
152+
...original,
153+
claudeAiOauth: { ...original.claudeAiOauth, expiresAt: Date.now() + 3_600_000, refreshTokenExpiresAt },
154+
}));
155+
let usageStatus = 200;
156+
t.mock.method(globalThis, "fetch", async (url) => {
157+
if (url === profileUrl) return new Response(null, { status: 401 });
158+
assert.equal(url, usageUrl);
159+
if (usageStatus !== 200) return new Response(null, { status: usageStatus, headers: { "retry-after": "60" } });
160+
return Response.json({ five_hour: { utilization: 1 }, seven_day: { utilization: 2 } });
161+
});
162+
assert.equal((await collectAgents())[0]?.authRefreshExpiresAt, refreshTokenExpiresAt);
163+
usageStatus = 429;
164+
const [row] = await collectAgents();
165+
assert.match(row?.limitsError ?? "", /429/);
166+
assert.equal(row?.authRefreshExpiresAt, refreshTokenExpiresAt);
167+
});
168+
169+
test("凭据没有 refresh token 期限时 Claude 行不带这个字段", async (t) => {
170+
const { file, original } = await fixture(t);
171+
await writeFile(file, JSON.stringify({
172+
...original,
173+
claudeAiOauth: { ...original.claudeAiOauth, expiresAt: Date.now() + 3_600_000 },
174+
}));
175+
t.mock.method(globalThis, "fetch", async (url) => {
176+
if (url === profileUrl) return new Response(null, { status: 401 });
177+
return Response.json({ five_hour: { utilization: 1 }, seven_day: { utilization: 2 } });
178+
});
179+
assert.equal(Object.hasOwn((await collectAgents())[0] ?? {}, "authRefreshExpiresAt"), false);
180+
});

‎reporters/agents-reporter/src/providers/claude.ts‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { config } from "../config.js";
2-
import { readClaudeOauth } from "../claude-oauth.js";
2+
import { claudeRefreshExpiresAt, readClaudeOauth } from "../claude-oauth.js";
33
import type { AgentRow } from "../site.js";
44
import { agentPlanLabel, claudeWindows, object, rowFromWindows, text } from "../windows.js";
55

@@ -276,12 +276,14 @@ export async function fetchClaude(): Promise<AgentRow | null> {
276276
rateLimitTier: text(oauth.rateLimitTier),
277277
};
278278

279+
const refreshExpiresAt = claudeRefreshExpiresAt(oauth);
280+
const auth = refreshExpiresAt == null ? {} : { authRefreshExpiresAt: refreshExpiresAt };
279281
try {
280282
const body = await fetchClaudeUsageBody(accessToken);
281-
return rowFromClaudeUsage(body, hints);
283+
return { ...rowFromClaudeUsage(body, hints), ...auth };
282284
} catch (error) {
283285
if (isClaudeAuthExpired(error)) throw error;
284286
const message = error instanceof Error ? error.message : String(error);
285-
return { id: "claude", plan: null, limits: [], limitsError: message };
287+
return { id: "claude", plan: null, limits: [], limitsError: message, ...auth };
286288
}
287289
}

‎reporters/agents-reporter/src/site.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ export type AgentRow = {
2020
plan: { tier: string; label: string } | null;
2121
limits: AgentLimit[];
2222
limitsError: string | null;
23+
// epoch 毫秒:过了这一刻登录续期失效,当前 access token 到期后这一行就取不到了。只有 Claude 带。
24+
authRefreshExpiresAt?: number;
2325
};
2426

2527
export type PushPayload = {

‎shared/agent-limits-parse.test.mts‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,9 @@ test("agents 入口:按 id 收行,plan 缺了是 null,坏窗口丢掉、
1616
{ key: "weekly_all", usedPercent: "12" },
1717
],
1818
limitsError: null,
19+
authRefreshExpiresAt: 1_800_000_000_000,
1920
},
20-
{ id: "codex", limits: [], limitsError: "Codex:token expired" },
21+
{ id: "codex", limits: [], limitsError: "Codex:token expired", authRefreshExpiresAt: "soon" },
2122
{ id: "grok", plan: { tier: "" } },
2223
],
2324
});
@@ -35,6 +36,8 @@ test("agents 入口:按 id 收行,plan 缺了是 null,坏窗口丢掉、
3536
resetsAt: 1_800_000_000,
3637
},
3738
]);
39+
assert.equal(parsed.agents[0]?.authRefreshExpiresAt, 1_800_000_000_000);
40+
assert.equal(parsed.agents[1]?.authRefreshExpiresAt, null);
3841
assert.equal(parsed.agents[1]?.limitsError, "Codex:token expired");
3942
assert.deepEqual(parsed.agents[1]?.limits, []);
4043
assert.equal(parsed.agents[2]?.plan, null);

‎shared/agent-limits-parse.ts‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ export type ParsedAgentLimitsRow = {
77
plan: VibeCodingPlan | null;
88
limits: VibeCodingLimit[];
99
limitsError: string | null;
10+
// epoch 毫秒:过了这一刻这家的登录续期失效,要重新登录。只有带登录期限的来源报(目前是 Claude)。
11+
authRefreshExpiresAt: number | null;
1012
};
1113

1214
export type ParsedAgentLimits = {
@@ -61,6 +63,7 @@ export function normalizeAgentLimits(input: unknown): ParsedAgentLimits | null {
6163
plan: normalizePlan(row.plan),
6264
limits: normalizeLimits(row.limits),
6365
limitsError: text(row.limitsError),
66+
authRefreshExpiresAt: positiveOrNull(row.authRefreshExpiresAt),
6467
});
6568
}
6669
if (agents.length === 0) return null;

‎shared/vibecoding-limits.test.mts‎

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,19 +18,21 @@ test("一封只带来的行整行替换,没出现的 id 留着上一次的", (
1818
{
1919
collectedAt: "2026-09-05T12:00:00.000Z",
2020
agents: [
21-
{ id: "claude", plan: { tier: "max", label: "Max" }, limits: [window], limitsError: null },
22-
{ id: "codex", plan: null, limits: [], limitsError: "过期" },
21+
{ id: "claude", plan: { tier: "max", label: "Max" }, limits: [window], limitsError: null, authRefreshExpiresAt: 9_000 },
22+
{ id: "codex", plan: null, limits: [], limitsError: "过期", authRefreshExpiresAt: null },
2323
],
2424
},
2525
1_000,
2626
);
2727
assert.equal(first.agents.claude?.updatedAt, 1_000);
28+
assert.equal(first.agents.claude?.authRefreshExpiresAt, 9_000);
29+
assert.equal(Object.hasOwn(first.agents.codex ?? {}, "authRefreshExpiresAt"), false);
2830

2931
const second = mergeAgentLimits(
3032
first,
3133
{
3234
collectedAt: "2026-09-05T12:10:00.000Z",
33-
agents: [{ id: "claude", plan: null, limits: [], limitsError: "token expired" }],
35+
agents: [{ id: "claude", plan: null, limits: [], limitsError: "token expired", authRefreshExpiresAt: null }],
3436
},
3537
2_000,
3638
);
@@ -48,16 +50,17 @@ test("一封只带来的行整行替换,没出现的 id 留着上一次的", (
4850
test("按 id 取限额:取到的带上收到时刻,没上报过或这份还没到按「没配」", () => {
4951
const stored = {
5052
agents: {
51-
claude: { plan: { tier: "max", label: "Max" }, limits: [window], limitsError: null, updatedAt: 4_000 },
53+
claude: { plan: { tier: "max", label: "Max" }, limits: [window], limitsError: null, authRefreshExpiresAt: 9_000, updatedAt: 4_000 },
5254
},
5355
};
5456
assert.deepEqual(agentLimitsOf(stored, "claude"), {
5557
plan: { tier: "max", label: "Max" },
5658
limits: [window],
5759
limitsError: null,
60+
authRefreshExpiresAt: 9_000,
5861
limitsAt: 4_000,
5962
});
60-
const none = { plan: null, limits: [], limitsError: null, limitsAt: null };
63+
const none = { plan: null, limits: [], limitsError: null, authRefreshExpiresAt: null, limitsAt: null };
6164
assert.deepEqual(agentLimitsOf(stored, "cursor"), none);
6265
assert.deepEqual(agentLimitsOf(null, "claude"), none);
6366
assert.deepEqual(agentLimitsOf(stored, "constructor"), none);

‎shared/vibecoding-limits.ts‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ export type AgentLimitsRow = {
66
plan: VibeCodingPlan | null;
77
limits: VibeCodingLimit[];
88
limitsError: string | null;
9+
// 源:shared/agent-limits-parse.ts#ParsedAgentLimitsRow
10+
authRefreshExpiresAt?: number;
911
updatedAt: number;
1012
};
1113

@@ -25,6 +27,7 @@ export function mergeAgentLimits(
2527
plan: row.plan,
2628
limits: row.limits,
2729
limitsError: row.limitsError,
30+
...(row.authRefreshExpiresAt != null && { authRefreshExpiresAt: row.authRefreshExpiresAt }),
2831
updatedAt: receivedAt,
2932
};
3033
}
@@ -39,13 +42,15 @@ export type AgentLimitFields = {
3942
plan: VibeCodingPlan | null;
4043
limits: VibeCodingLimit[];
4144
limitsError: string | null;
45+
authRefreshExpiresAt: number | null;
4246
limitsAt: number | null;
4347
};
4448

4549
const NO_LIMITS: AgentLimitFields = {
4650
plan: null,
4751
limits: [],
4852
limitsError: null,
53+
authRefreshExpiresAt: null,
4954
limitsAt: null,
5055
};
5156

@@ -56,6 +61,7 @@ export function agentLimitsOf(stored: AgentLimitsPayload | null, id: string): Ag
5661
plan: row.plan,
5762
limits: row.limits,
5863
limitsError: row.limitsError,
64+
authRefreshExpiresAt: row.authRefreshExpiresAt ?? null,
5965
limitsAt: row.updatedAt,
6066
};
6167
}

0 commit comments

Comments
 (0)