510 Commits

Author SHA1 Message Date
Codex Agent e70dab1f88 fix(v02): wire Keycloak OIDC runtime 2026-06-04 15:01:30 +08:00
Codex Agent 52af835500 fix: unify v02 browser launcher 2026-06-04 14:51:54 +08:00
Lyon 10c03e6c32 fix(web): v0.2 unify Code Agent trace polling path + persist fail (HWLAB #802) (#806)
Follow-up to PR #798 (#795 final). PR #798 closed the total-timeout /
hard-cap issue, but left two residual code-path inconsistencies that
#802 captures:

- Submit path and refresh path used different trace-polling code:
  submitMessage called `pollRunnerTrace` + `waitForAgentResult` (a
  dual function pair from pre-#798), while hydrate() never subscribed
  to the running trace at all. After a page refresh, the user saw
  the cloud-api "running" state but no live trace events.
- The submit fail branch only dispatched a local "Code Agent 超时"
  message; it never called `persistConversation`, so the failure was
  invisible after F5 — the cloud-api conversation would show
  "running" forever from the user's perspective.

This PR collapses both into a single `subscribeToTrace` entry point
and wires the refresh path into the same active subscription:

- `state/runner-trace.ts` — replace `waitForAgentResult` +
  `pollRunnerTrace` with a single `subscribeToTrace(config)` that
  handles both the result endpoint and the trace endpoint in one
  `for(;;)` loop. Calls `onActivity` on EVERY successful poll (not
  just on new events) so the per-poll inactivity window in
  `fetchJson` does not fire on a healthy polling loop. Terminal
  status -> `onComplete`; 5xx -> keep polling, no activity; 4xx ->
  `onInfrastructureError`; `signal.aborted` -> silent return. The
  hard-cap / 4x / `TRACE_HARD_CAP_ATTEMPTS` machinery is gone (was
  already removed by #798).
- `state/trace-reattach.ts` — new `useTraceReattach` hook that
  subscribes to the running trace on hydrate (same `subscribeToTrace`
  call as submitMessage). Reuses an existing agent message slot for
  the traceId if one exists; otherwise creates a placeholder. Persists
  on both onComplete and onInfrastructureError. Path unification
  achieved: one entry, two callers.
- `state/workbench.ts`:
  - `submitMessage` calls `subscribeToTrace` directly with a
    single-line `onActivity: () => updateActivity()` plus
    `onComplete` / `onInfrastructureError` callbacks. The
    `onInfrastructureError` branch now ALSO calls
    `persistConversation`, persisting the fail state to cloud-api.
  - The re-attach useEffect is replaced with a one-liner
    `useTraceReattach({...})` call (workbench.ts stays under the
    400-line guard).
- `scripts/fetchJson-inactivity.test.ts` — third case tightened:
  200ms-cadence activity for 10s with `timeoutMs: 3000`; the
  request must live the full 10s and abort only after activity
  stops. Asserts `elapsed >= 10_000`.
- `docs/reference/spec-v02-hwlab-cloud-web.md` — the "Code Agent
  Timeout Model" section is renamed "Code Agent Timeout Model 与
  Path Unification" and now also pins: (a) `subscribeToTrace` is
  the only entry; `waitForAgentResult` / `pollRunnerTrace` /
  `TRACE_HARD_CAP_ATTEMPTS` MUST NOT exist; (b) `useTraceReattach`
  MUST be wired in; (c) `persistConversation` is required in both
  onComplete and onInfrastructureError; (d) `state.workspace.activeTraceId`
  changes MUST re-attach. Includes a distilled history of
  #775 / #777 / #791 / #795 / #797 / #798 / #802.

Verification
- `bun run scripts/tsc-check.ts` → strict React TSX, 0 explicit any
- `bun run check` → 5 pass / 0 fail (3 inactivity + 2 dist-contract)
- `bun run build` → 9 dist files verified fresh; `app.js`
  238460 → 240990 B
- `state/trace-reattach.ts` is now wired in; `state/runner-trace.ts`
  exports only `subscribeToTrace` (verified by tsc + grep)
- `workbench.ts` line count 400 (under the 400-line guard)
- New 200ms-cadence 10s test passes; old 100ms-cadence 2s test
  and total-timeout 200ms test still pass.

Refs: HWLAB #802, #795, #777, #791, #798

Co-authored-by: Codex Agent <codex@hwlab.local>
2026-06-04 11:08:20 +08:00
Lyon f7731d1421 fix(web): v0.2 remove all total-timeout / hard cap on Code Agent turn (HWLAB #795 final) (#798)
Follow-up to PR #797: drop every wall-clock or attempt-count ceiling from
`state/runner-trace.ts` so the Web UI's Code Agent inactivity-timeout
contract is total-cap-free. The previous PR kept a
`max(totalTimeoutMs * 4, totalTimeoutMs + 60s)` outer-loop safety net
plus a `TRACE_HARD_CAP_ATTEMPTS = 120` poll-count cap, which would
re-introduce the same regression class that #795 was filed against: a
long-running operation that keeps emitting trace events could still be
killed by the outer ceiling even with an active `activityRef`. The
"Code Agent Timeout Model" section of
`docs/reference/spec-v02-hwlab-cloud-web.md` now pins the contract:

- The sole abort signal is per-poll `fetchJson` inactivity-timeout,
  driven by `activityRef`.
- The outer `waitForAgentResult` / `pollRunnerTrace` loops are
  `for (;;)`. They only exit when the upstream returns a terminal
  status, the request fails with a non-5xx, or the inactivity window
  fires inside `fetchJson`.
- The per-poll `getAgentChatResult` call passes the full
  `totalTimeoutMs`; the inactivity window is **not** shrunk by
  wall-clock elapsed time.
- `TRACE_HARD_CAP_ATTEMPTS` and the 4x / +60s outer cap are deleted.
- Runaway protection is the caller's responsibility: Web users have
  cancel / steer / close-tab; CLI has `--timeout-ms`. The browser does
  not introduce an implicit cap.

Changes

- `web/hwlab-cloud-web/src/state/runner-trace.ts`:
  - Drop `const hardCapMs = Math.max(totalTimeoutMs * 4, totalTimeoutMs + 60_000)`
    and the `if (Date.now() - startedAt >= hardCapMs) break;` checks in
    both `waitForAgentResult` and `pollRunnerTrace`.
  - Replace `while (Date.now() - startedAt < hardCapMs)` with
    `for (;;)`. Drop the now-unused `startedAt` locals and the
    `let attempt = 0; attempt > TRACE_HARD_CAP_ATTEMPTS` guard.
  - Pass `totalTimeoutMs` directly to `api.getAgentChatResult` instead
    of `totalTimeoutMs - (Date.now() - startedAt)` so the per-poll
    inactivity window is stable.
  - Delete `const TRACE_HARD_CAP_ATTEMPTS = 120;` (no longer referenced).

- `web/hwlab-cloud-web/scripts/fetchJson-inactivity.test.ts`:
  - Replace the "1.5s cadence 6.5s" case with a stricter "200ms cadence
    10s" case: `timeoutMs=3000` inactivity window, continuous 200ms
    activity for 10s, then stop. Assert `elapsed >= 10_000` and that
    the abort is the inactivity-timeout error. This pins the
    `elapsed >= 10000` invariant in the spec.

- `docs/reference/spec-v02-hwlab-cloud-web.md`:
  - Strengthen the existing bullet in "在系统中的职责划分" to
    explicitly forbid total-timeout, hard cap, `codeAgentTimeoutMs * N`,
    poll-count cap, and wall-clock-shrunk per-poll windows.
  - Add a dedicated "Code Agent Timeout Model" section after "## 内部架构"
    that distils the contract, lists the three invariants, and records
    the history of #775 / #777 / #791 / #795 leading to the final state.

Verification

- `bun run scripts/tsc-check.ts` → strict React TSX, 0 explicit any
- `bun run check` → 5 pass / 0 fail (3 inactivity + 2 dist-contract)
- `bun run build` → 9 dist files verified fresh; `app.js` 241802 → 238460 B
  (delta reflects the deleted hardCap / TRACE_HARD_CAP_ATTEMPTS code)
- New 200ms-cadence 10s inactivity test runs for ~13s and asserts the
  request lives the full window — proving the outer cap is gone.

Refs: HWLAB #795 (final), #777, #791, #775

Co-authored-by: Codex <codex@local>
2026-06-04 09:36:29 +08:00
Codex b23ba1cb82 docs: unify v0.2 user api key auth 2026-06-04 01:06:36 +08:00
Codex f81aad7ace docs: clarify AgentRun session resume boundaries 2026-06-04 01:02:12 +08:00
Codex ac0a7e57d8 docs: add v0.2 auth spec 2026-06-04 00:47:15 +08:00
Codex 6341015d3b feat(v0.2): Code Agent 默认 sessionStorage=persistent + eviction reset UX
PR D for #770:HWLAB Cloud Web Workbench 透传 session state 真正持久化

- code-agent-agentrun-adapter.ts:
  * 新 ensureAgentRunSessionPersistent:默认 sessionStorage=persistent,
    调 POST /api/v1/sessions 同步建 session + PVC
  * submitAgentRunChatTurn 改两步尝试:ensureSession 或 runner-jobs POST
    收到 session-store-evicted 时用新 sessionId(<base>-reset-<trace8>)
    + threadId=null 重试,trace 追加 agentrun:session-reset 事件
  * 新 shouldResetSessionAfterEviction / newSessionIdAfterEviction 辅助函数
- code-agent-response-contract.mjs: session-store-evicted 归
  session-blocked category
- code-agent-chat.ts: 新 userMessage
  「Code Agent session 存储已失效(PVC 被回收或 TTL 到期),
   HWLAB 已为你开新 sessionId,可继续发送下一条消息。」
- spec-v02-hwlab-cloud-web.md: 新增 'Session state 持久化与 eviction reset'
  章节,含禁止路径与实现情况表

env 控制:HWLAB_CODE_AGENT_AGENTRUN_SESSION_STORAGE=ephemeral
可退回 metadata-only 模式(PR 前默认行为)。
2026-06-03 21:47:14 +08:00
Codex 2f435fc736 fix: 改进手动 session CLI 摩擦 2026-06-03 11:06:43 +08:00
Codex d39d184eae docs: 固化 Code Agent session 手动化规格 2026-06-03 09:29:30 +08:00
Codex e2d4989468 fix: expose AgentRun skill assembly in v02 web 2026-06-03 07:02:09 +08:00
Codex 0d4f5ef098 fix: preserve code agent sessions after turn failures 2026-06-03 00:28:40 +08:00
Codex 9f287fa0d9 fix: allow code agent workspace concurrency 2026-06-02 21:54:28 +08:00
Codex 128daa4e45 docs: allow minimax m3 validation when deepseek balance exhausted 2026-06-02 21:49:32 +08:00
Codex bf7a8bfd49 fix: align hwpod lease guidance 2026-06-02 21:30:33 +08:00
Codex 58df53bce5 feat: assemble AgentRun prompts and skills 2026-06-02 20:56:36 +08:00
Codex 9c58faf3e3 docs: use admin workspace for cli validation 2026-06-02 20:28:28 +08:00
Codex 7f97b41404 fix: route hwpod through cloud-api 2026-06-02 18:48:56 +08:00
Codex bacfa24289 fix: replace device pod lease with api key 2026-06-02 18:11:32 +08:00
Codex f05446ec00 fix: restore cli workspace thread id visibility 2026-06-02 16:43:42 +08:00
Codex 29e9e23fb3 fix: use native codex stdio continuation 2026-06-02 16:22:27 +08:00
Codex 8bd44ce7d1 fix: 对齐 v0.2 AgentRun 默认分支 2026-06-02 16:17:29 +08:00
Codex cd58ee7989 feat: 增加 UniDesk SSH runner 工具别名 2026-06-02 16:07:54 +08:00
Codex 168c74b4ef feat: 增加 AgentRun Code Agent 调度装配 2026-06-02 16:06:41 +08:00
Codex 363fbc28de docs: record v02 CLI runtime endpoint friction 2026-06-02 13:01:10 +08:00
Codex 12560c9e91 Merge remote-tracking branch 'origin/v0.2' into fix/v02-context-completed-693 2026-06-02 12:37:41 +08:00
Codex e88951dadc fix: preserve AgentRun completed turn context 2026-06-02 12:34:55 +08:00
Codex 66282ba80f fix: unlock cloud web composer steer 2026-06-02 12:25:16 +08:00
Codex 36e4ba2068 Merge remote-tracking branch 'origin/v0.2' into fix/v02-workbench-orphan-active-trace
# Conflicts:
#	docs/reference/spec-v02-hwlab-cloud-api.md
#	internal/cloud/access-control.test.ts
#	internal/cloud/server-agent-chat.test.ts
2026-06-02 12:13:50 +08:00
Codex 8e9bea487d fix: proxy code agent steer through cloud web 2026-06-02 10:48:54 +08:00
Codex 2477190ae2 fix: unify device-pod runner entry 2026-06-02 10:40:03 +08:00
Codex 3497a8993b feat: support agentrun steer and idle continuation 2026-06-02 10:29:46 +08:00
Codex 3c6edb73a1 fix: 统一 AgentRun threadId 上下文连续性 2026-06-02 10:19:34 +08:00
Lyon da73598d60 fix: scope agentrun sessions by backend profile (#683)
Co-authored-by: Codex <codex@local>
2026-06-02 09:15:46 +08:00
Codex 48492ba267 fix: 释放孤儿 active trace 2026-06-02 08:55:10 +08:00
Codex f52eadfbe7 feat: route minimax m3 through agentrun 2026-06-02 08:50:27 +08:00
Lyon 5dc263e10a fix: align AgentRun trace rendering (#665)
Co-authored-by: Codex <codex@local>
2026-06-01 23:58:06 +08:00
Lyon 24060853e7 fix: reuse AgentRun runner for HWLAB turns (#662)
Co-authored-by: Codex <codex@local>
2026-06-01 23:18:40 +08:00
Codex b24dc9b1db fix(cicd): allow mirror fetch by exact commit 2026-06-01 22:48:27 +08:00
Codex 0fb8004896 fix: reuse agent worker env image in v02 ci 2026-06-01 22:29:54 +08:00
Codex d4c05d7963 docs(cli): align v02 web-equivalent cli entrypoint 2026-06-01 22:29:39 +08:00
Codex 095c042077 feat(cli): render agent trace with web rows 2026-06-01 21:44:39 +08:00
Codex b7285b30b1 feat(workbench): share account workspace across web and cli 2026-06-01 21:31:26 +08:00
Codex a686c37247 feat(cli): replay agent continuation from trace 2026-06-01 20:50:59 +08:00
Codex 63f08e6e75 fix: align web cli agentrun continuation 2026-06-01 20:01:58 +08:00
Codex 923fcf6e92 fix: align v02 gateway evidence environment 2026-06-01 08:26:21 +08:00
Codex da8792046d docs: align v02 commander workflow 2026-06-01 08:14:45 +08:00
Codex 61f58de2d9 docs: sync v02 cicd source isolation 2026-06-01 07:39:05 +08:00
Codex 64cdf37d27 fix: isolate v02 cicd source state 2026-06-01 01:02:19 +08:00
Lyon 7b64427690 Merge pull request #637 from pikasTech/fix/v02-runner-output-transport-hardening
fix: harden v0.2 code agent transport
2026-05-31 22:56:09 +08:00