Skip to content

fix(desktop,mobile,host): queued-reply order, approval tier switching, and mobile list/batch defects - #1582

Merged
jiangzhuqing000 merged 29 commits into
mainfrom
pr/dev-jiangzhuqing000
Nov 10, 2026
Merged

jiangzhuqing000 merged 29 commits into
mainfrom
pr/dev-jiangzhuqing000

Conversation

@jiangzhuqing000

Copy link
Copy Markdown
Collaborator

这批改动

桌面端、手机端与 host 的一批缺陷修复,全部来自最近的实测报告。

桌面端 · 队列与转录顺序

  • 排队的问题排在自己回答下方、回答被画两三遍。运行中重载会把 agent 中途保存的半截快照投影成一条“看起来已完成”的气泡,旁边还有实时气泡;队列里的问题落进来时,按 run 配对把它插到了两份回答中间,而重复本身也没人清。现在:applyRunMetadata 把暂扣的 run 标记放进 inFlightRunId 而不是丢掉,upsertUserMessage 按 runId ?? inFlightRunId 配对,collapseReplyDuplicates 保证一轮只留一份回答、且不跨过用户消息。
  • 切换列表时“多选”不消失。批次属于它打开时那个列表的标题,切列表即结束批次(在 render 期间重置,避免工具栏在新列表上多画一帧)。

桌面端 · 审批模式

  • 旧会话切换审批等级无效。徽标读的是会话自己报的等级,而点击只写了设置存储。现在 host 新增 update_thread_approval_tier,切换时立刻推给该会话(沙箱不可用照旧降级成手动审批),徽标读“点击写入的那份设置”并乐观更新,不再依赖一次往返。
  • 旧的“按会话”模式。那是徽标 unknown 态的文案,而它并不是可选模式。读取会话状态时会用默认值补齐并回报真实等级;真正未知时文案改为「未知 / Unknown」。
  • 顺带修掉我自己在上一版引入的顺序错误:乐观写入后强制重读会把值盖回去。

手机端

  • 模型可见性页面点开关会跳动。写入 → 桌面端广播 → 列表重拉 → “加载中”那一行插入又消失。useDesktopResource 在已有数据时把重拉视为刷新(新增 refresh),开关的值先按点击结果显示再交回权威值。
  • 多选会话缺少批量归档。桌面端早就有;现在手机端工具栏在删除旁提供归档,规则一致:按机器、逐个发送,失败保留勾选;批次里有正在运行的一次性确认“停止并归档”。
  • 改名后所有设备显示“已被其他设备接管”。重命名会替换 pairing.desktops,而 forgetUnpaired 与 onTaskFinished 闭包捕获了它/label,导致每台机器的连接被重建一次;重建的 client 没有心跳,于是被判成 standby。两处改为执行时读取当前值。

验证

  • Rust:cargo test -p future-host --lib(新增两个用例:审批等级立刻生效、会话无等级时回填)、cargo clippy --all-targets -D warnings、cargo fmt --check、cargo check -p futureos 全部通过
  • packages/thread-projection:452 全通过(含 7 个去重用例)
  • desktop:tsc --noEmit、eslint 干净;vitest 因沙箱拒绝派生子进程(spawn EPERM)未能本地跑,已交由 CI 兜底
  • mobile:tsc --noEmit、eslint 干净;jest 同上

说明

  • 无合并冲突,dev-jiangzhuqing000 已包含当前 main。
  • PR head 是冻结分支 pr/dev-jiangzhuqing000(dev-jiangzhuqing000 仍会继续接收后续任务,那属于下一个 PR)。

jiangzhuqing000 and others added 25 commits November 9, 2026 14:46
…counted

The workspace list drew every heading with the connected desktop's id
(`withMachine`), while a conversation read from the single-machine catalogue
carried no machine at all (`listTargets` answers `null`, because there is only
one it could be). Comparing those two spellings directly read them as different
machines, so a workspace whose badge said it held a conversation matched none of
them and its confirmation reported "0 conversations will be deleted".

The same confirmation was wrong on the archived shelf for a second reason: it
counted from the batch list, which is empty by design while the shelf is
showing, and which has the shelved rows filtered out everywhere else. Deleting a
shelved workspace therefore always counted zero — and a workspace holding only
shelved conversations counted zero on the workspace list too.

Both halves of a workspace are now read from the catalogue the screen is drawing
(`listTargets(merged, remote.sessions)`), the machine comparison reads the
missing spelling as the connected desktop, and the half that goes is still
chosen below it, so each page keeps reporting only its own side. The batch list
is untouched: its job is deciding what a selection may hold, not what a delete
will take.

`onSameMachine` names the rule once; `sessionsInWorkspace` (the workspace's
"select all") compared the same two spellings and had the same fault.

The shared i18n mock in the tests answered `title` before `count`, so no test
could see the number this dialog was telling the reader. It now appends the
count when both are given, and the three existing confirmations assert their
real numbers.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
Reported: ask a question, and while the first round is still only *thinking*
(nothing written yet) queue a second prompt. When everything settles the
question renders BELOW the reply it produced — a "7s thinking" bubble, then the
question, then the queued run's bubble — and the wrong order survives switching
conversations, though a full reload shows it correctly. Waiting until the first
round had written some text avoided it.

Two halves, and the reload observation is what separates them: the stored
transcript is right (a full reload reads it and renders correctly), so the order
was wrong only in the in-memory array the thread switch restores from its warm
snapshot.

A prompt is placed above its own reply by matching run ids
(`upsertUserMessage`). But `applyRunMetadata` *withholds* an in-flight reply's
`runId` so the live bubble keeps growing after a mid-run reload rather than the
frozen partial taking over — and the withheld stamp was the only link between
reply and prompt. With it gone the prompt matched nothing and was appended past
its own answer.

- `AgentMessage.inFlightRunId` carries the identity while `runId` is withheld;
  `applyRunMetadata` moves the stamp there instead of dropping it, clears it when
  the run settles and `runId` is restored, and keeps such a reply out of the
  positional legacy fallback (it still has a known owner — that was already the
  intent, and it is now explicit).
- `upsertUserMessage` pairs on `runId ?? inFlightRunId`.

Tests: a mid-run partial keeps its owner and the queued prompt is placed above
it (desktop), and the pairing itself (thread-projection). The desktop test is
what pins the bug — with only the pairing half reverted it fails.
…ts answer

Second half of the reported bug, found by reading the dev journal for the
conversation: the stored transcript is right (user, reply, queued user, reply)
and a full reload renders it right — so only the in-memory array was wrong, and
the screenshot showed why: TWO reply bubbles for one run ("5s · 380 tokens" then,
below the question, a fresh one). The agent persists a partial snapshot mid-run,
a reload projects it into the array as a settled-looking reply, and the live
bubble for the same run is drawn beside it.

Placing the prompt before its run's bubble then put it *between* the two halves
of its own answer, and because that array is what the warm snapshot keeps, the
wrong order outlived a thread switch — while reloading from the journal fixed it.

`upsertUserMessage` now swallows the stale fragment: the contiguous replies
directly above the matched reply, with no prompt between them, which carry no run
of their own (the shape `applyRunMetadata` leaves when it withholds a stamp so
the live bubble keeps ownership). Only that run is touched — an older exchange
above it is left exactly as it was.

Tests: the prompt lands above the single surviving reply, and an earlier
exchange is untouched. Without the swallow the first one produces the reported
`[stale reply, prompt, live reply]`.
…during it

Third report on the same conversation, and the decisive one: the answer appeared
TWICE on screen (a settled "49s · 2,557 tokens" copy, then the same text under
"✓ 13 · 思考 11 次"), with a third starting below the question. Switching
conversations left two; Ctrl+R showed one. The dev journal for that conversation
holds one reply per run, and `history_display` is in the right order — so again
only the in-memory array was wrong, and this time the defect is the duplication
itself, not where the prompt went.

The agent saves a partial snapshot after every model call, so a reload *during*
a run projects that snapshot into the array as a settled-looking reply carrying
no run of its own; the live bubble writing the same run is a second copy beside
it. Each further reload added another, and nothing collapsed them: the live
writers only ever looked at the trailing assistant.

- `collapseReplyDuplicates` (thread-projection) keeps one bubble per turn: a
  later bubble carrying a run replaces an earlier one carrying the same run
  (`runId` or the withheld `inFlightRunId`), and an unidentified reply directly
  above an identified one — nothing but replies between them, so the same turn —
  is the earlier copy of that answer. A prompt between two replies is a new
  turn, and nothing crosses it.
- Every live-bubble writer starts from that array (`streamingBubbleBase`), so a
  duplicate cannot survive a reattach, a reload merge or a settle.
- `upsertUserMessage` uses the same collapse before it places the prompt, which
  replaces the narrower swallow from the previous fix with the general rule.

Tests: 7 cases for the rule (one copy out of three, newest wins, withheld stamp
counts as the run, never across a prompt, older exchange untouched, identity
returned when nothing moved).
…es effect

Reported: an older conversation was on automatic approval; picking a different
level changed nothing — the option stayed on the old one. Two facts made that
invisible rather than merely delayed:

- the chip draws the tier the conversation's *Agent session* reports, not the
  stored default (deliberately: rendering the default claimed a tier the gate was
  not enforcing);
- that session tier was only pushed to the Agent immediately before the next
  prompt, and picking a level wrote the settings store alone. So the control the
  reader pressed wrote somewhere the control does not read, and nothing on screen
  moved.

Model and thinking level already propagate the moment they are chosen
(`update_thread_model` / `update_thread_thinking_level`). The approval tier now
does the same:

- host: `application::threads::update_thread_approval_tier` stores the choice and
  applies it to that conversation's session over the same path a prompt uses
  (`set_agent_sandbox_policy_tier`, so an unavailable sandbox is downgraded to
  manual rather than claimed), then answers with the tier the machine accepted.
  Best-effort for the session, like its siblings: an unreachable Agent must not
  fail the preference the next prompt sends anyway.
- desktop: `update_thread_approval_tier` command, `applyThreadApprovalTier` in the
  agent client, and the shell's `changeApprovalTier` — which passes the accepted
  tier back to the store and revalidates the conversation's cached Agent state so
  the chip moves at once. A conversation with no session yet just writes the
  default, which is what its session will be created with.

Tests: the host case asserts the choice reaches the stored default a later prompt
sends (`update_thread_approval_tier_applies_to_the_session_now`).
Reported: several older conversations show "按会话" / "Per session" in the
approval chip, and no such mode exists to pick. It was the chip's *unknown*
state: a conversation created before the desktop ever pushed an approval tier
reports none, and the composer drew a fifth label for that instead of one of the
four modes — a name a reader can only read as a mode they cannot select.

The chip was deliberately not falling back to the app-wide default, because a
session that was genuinely running on another tier (a CLI-created one) would then
be described by a value the gate was not enforcing. That concern is about a
mismatch, and a mismatch has a better answer than a phantom mode: settle it.

- host: `get_thread_agent_state` now heals the conversation it is reading. When
  the session reports no tier, it pushes the stored default over the same path a
  prompt uses (so an unavailable sandbox is downgraded, not claimed) and answers
  with the tier the machine accepted. That is what the next prompt sends anyway,
  so the chip can name a real mode; the push is best-effort, so an Agent too old
  to take a policy keeps answering as before.
- desktop: the label for the remaining unknown case (an Agent that cannot be
  reached at all) says "未知" / "Unknown" rather than offering a mode that does
  not exist.

Tests: `get_thread_agent_state_settles_a_session_that_reports_no_tier` asserts the
payload ends up carrying the accepted tier and that it is one of the four modes;
the composer test now expects "Unknown".
…e next message

Reported after the host started applying the switch: the choice did work — the
next message ran under the newly picked mode — but the chip kept showing the old
one until that message was sent.

The chip draws the conversation's cached Agent state, which only moved once the
machine reported a new tier, and that happened at the next prompt. So the
control looked dead for exactly as long as the reader was looking at it.

`changeApprovalTier` now writes the chosen tier into that cache first, so the
mode changes under the reader's finger; the host's answer then corrects it when
the machine kept something else (an unenforceable sandbox is downgraded to manual
rather than claimed), and the revalidation at the end still converges on the
machine's own state. A round trip that fails leaves the choice showing: it is
stored, and the next prompt applies it.

Same reason a stale dev build shows the old behaviour: the chip updated only via
the state read, so a build without the new command looked unchanged.
My own bug, from the previous commit: the optimistic write was immediately undone
by the state re-read after it.

The order was: write the choice into the cached Agent state (so the chip moves),
call the host, then force-revalidate. When the host call failed — a dev build
without the new command, or an Agent that refused the policy — the re-read asked
the machine what tier it was on and got the OLD one, replacing the whole cached
snapshot with it. The chip went back to where it started, which is why it still
looked like a dead control.

The re-read now happens only after the host has actually been told, so its answer
agrees with the choice. On failure the choice stays on the chip (it is stored, and
the next prompt sends it), and nothing asks the machine for a snapshot that would
contradict it.
A Desktop close could end in an error dialog titled "Cleanup failed" reading
"Agent shutdown deadline exceeded during Windows sandbox permissions; instance
ownership retained" — twice — followed by "更新、重置和重启已阻止". Nothing had
broken: the exit dialog was reporting a deferred housekeeping step as a failure,
and the deferral made it look unrecoverable.

Measured 2026-11-09 on a real machine: a stop entered the sandbox stage at
08:37:49.86 and the deadline watcher fired at 08:37:54.35, exactly the
five-second budget. The same two records were revoked by the next startup in
under a millisecond, so the time was not spent walking the trees the state file
names — the step is simply the one place where an unbounded platform call can
land anywhere, and nothing about it is safe to run on the thread whose verdict
it can then decide.

- `service/shutdown.rs`: run the revoke on its own thread and wait a fixed
  500 ms for the result. The drain no longer enters the stage at all, so the
  deadline watcher can never catch it there; past the budget the ACEs stay and
  the next startup revokes them, which is safe because they only grant
  FutureOS's own capability SID access to paths it already owns.
- `sandbox/windows/runner.rs`: check the deadline between revoke targets, so a
  bounded caller stops walking records instead of being carried to the end.
  `SANDBOX_RESET_BUDGET` promised this before but only covered the locks.
- `service/mod.rs`: a cleanup error the host error already names is no longer
  appended again — one deferred step was reaching the user as two problems.
- `agent_supervisor.rs`: the failed-exit dialog now says what is true (the app
  is closing, one housekeeping step moved to the next start, conversations and
  settings are unaffected) and keeps the diagnostic on its own line for a bug
  report. It is a warning, not an error.
- The two layout strings drop "已阻止 / blocked" for "暂不可用 / stay blocked
  until then", and the status gate leads with the same reassurance.

Tests: the drain reports Stopped when the revoke is stalled, the duplicate
error is collapsed, a distinct cleanup error still survives, and the dialog
wording is pinned.
…y can

Reported: selecting several conversations on the phone offers only delete —
the desktop's "Select chats" batch has had archive beside it since archiving
shipped, so clearing a shelf on the phone meant opening each conversation's own
menu.

The batch toolbar now carries an archive button next to the delete, with the
same rules that already govern the delete:

- offered while at least one machine in the batch answers `archive_v1`, refused
  only when none does (a machine too old to archive keeps its rows selected
  rather than failing them one by one);
- one machine at a time, one conversation at a time, so a desktop is not flooded
  and a failure leaves that row ticked for a retry;
- a batch holding conversations that are still running asks once, naming the
  count, and archives after stopping them — the same "stop and archive" answer
  the single-conversation and workspace archives use, with the retry window that
  covers the host settling its own run row.

Strings: "归档所选会话" / "Archive selected conversations", plus the partial
failure and running-batch confirmations.
@jiangzhuqing000
jiangzhuqing000 enabled auto-merge (squash) November 10, 2026 09:01
@jiangzhuqing000
jiangzhuqing000 merged commit cc44a58 into main Nov 10, 2026
33 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant