Skip to content

fix(cli): stage a rewound turn's quotes into the replacement submit - #5265

Open
ggbdpq wants to merge 1 commit into
apache:mainfrom
ggbdpq:fix/tui-rewind-quote-staging
Open

ggbdpq wants to merge 1 commit into
apache:mainfrom
ggbdpq:fix/tui-rewind-quote-staging

Conversation

@ggbdpq

@ggbdpq ggbdpq commented Sep 13, 2026

Copy link
Copy Markdown
Contributor

Summary

/rewind on a turn that carried quotes used to fail closed with rewind_unsupported_quotes (#5109, behavior C): the TUI could only refill the human-facing text, so the replacement submit would silently drop the turn's structured context.

The runtime-host driver now returns the rewound turn's QuoteRefs verbatim on rewindToTurn, and submitMessage forwards quotes through turn.message.submit — the protocol admission already accepts client-authored quotes (only session-context attachments are Host-owned, and #4804 made a quote alone meaningful content). Attachments and directory references still fail closed, since the TUI cannot re-attach files.

The TUI stages the restored quotes keyed to the branched session:

  • the status line carries a quotes:<n> segment while staging is live (accent salience, dropRank with the other chrome),
  • bare /quotes lists the staged excerpts; /quotes clear is the explicit removal,
  • the first admitted submit consumes the staging; a refusal or failure restages it for the retry, and switching sessions invalidates it without every switch path having to clear it.

The now-dead rewind_unsupported_quotes code and its localized copy are removed together with the branch that emitted them.

Part of #5109 — the remaining scope (editing a selected message that itself carries attachments) still needs the Host to expose the rewritten target-owned refs.

Verification

Check Result
New driver tests (red before the fix: rewind rejected quoted turns; submit content lacked quotes) 2/2 green after
New runner tests (staging visible via notice + status segment; submit carries the QuoteRefs verbatim and consumes them; /quotes clear drops them) 2/2 green after
pi-tui-runner full suite 207/209 — the 2 failures (restores the terminal before exiting on SIGTERM, forces signal exit when outer cleanup never settles) fail identically on pristine upstream/main built in a clean worktree on this machine: pre-existing Windows signal-handling failures
runtime-host-session-driver full suite 25/75 — the 50 failures are all the documented pre-existing Windows class (Session cwd no longer exists: /tmp POSIX fixtures); none of them is a test added or modified here
tui-copy-catalog, tui-primary-guidance, core slash-command-catalog 8/8, 8/8, 1/1
check:asf-headers passed locally (audited 3773 covered in checkout mode)
format:check the repo-wide run segfaults on this machine (biome crash during the full-tree walk, environmental); all 8 changed files pass biome check --formatter-enabled=true --linter-enabled=false individually, and upstream CI runs the repo-wide gate

AI use

Select exactly one:

  • No generative tool made a substantive contribution
  • Generative tooling made a substantive contribution

Tool(s) and scope: GLM-5.3-Flash (ZCode) implemented the driver/TUI changes and tests under human direction and review.

Checklist

  • Tests cover the change and fail without it
  • Lint, format, typecheck and the affected suites pass locally

Does this PR entail a change in behavior?

  • Yes — rewinding a quoted turn now restores its quotes into the replacement submit instead of refusing; /quotes is a new TUI command.
  • No

@github-actions github-actions Bot added the effort/M Under 500 readable lines label Sep 13, 2026

@Astro-Han Astro-Han 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.

Thanks for addressing the quoted-turn gap in #5109. I reviewed eb5c88fc3fcc56849fddb954349ff9a7074caae6. Returning the existing QuoteRefs and forwarding them through the existing Host admission is the right direction; attachments can continue to fail closed until their target-owned refs can be restored.

I found two reachable issues, detailed inline: P1, a delayed failure can attach one Session's staged quotes to another Session; P2, a quote-only replacement still cannot pass the text-only submit guards. These are draft ownership/content-admission issues within the existing runner, not a reason to introduce a new revision or import framework. Please bind retry restoration to the original draft/session identity and treat staged quotes as meaningful content at the submit entry points.

Validation: the two new runner tests pass in an exact-source bundle with local dependencies. Two additional probes through the real runner/editor submission path reproduce both findings. I also checked the production driver's switch/admission code: session switching does not wait on the submit admission queue, so the delayed-failure interleaving is reachable. I did not run an installed TUI with a live Host or the full repository suite.

Codex-assisted review with local reproduction.

Comment thread packages/cli/src/pi-tui-runner.ts Resolved
Comment thread packages/cli/src/pi-tui-runner.ts Resolved
ggbdpq added a commit to ggbdpq/maka that referenced this pull request Sep 14, 2026
…nly rewinds

Two review findings on apache#5265:

A failed or blocked admission restaged the rewound quotes tagged with the
Session read at callback time, so a Session switch while the admission was
in flight attached the old quotes to the next message of the wrong
conversation. The originating Session and staging generation are now
captured at dispatch, and the restore happens only when neither moved.

A quote-only rewind refills an empty prompt, and the empty-text guards in
submitPrompt, steerRunningTurn and Alt+Enter rejected it before the quote
forwarding path could run. They now treat staged quotes as meaningful
content; a cleared plate stays truly empty and keeps refusing.

Part of apache#5109

Generated-by: GLM-5.3-Flash (ZCode)
@ggbdpq

ggbdpq commented Sep 14, 2026

Copy link
Copy Markdown
Contributor Author

Both findings fixed at 6ca7ff9:

P1 (wrong-Session restore): the originating Session and a staging generation counter are captured at dispatch. The restore now runs only when the Session is unchanged and no newer staging or explicit clear bumped the generation — a switched Session, a newer rewind, or /quotes clear while the admission was in flight all leave the stale callback empty-handed.

P2 (quote-only replacement): submitPrompt, steerRunningTurn and Alt+Enter now treat staged quotes as meaningful content, so an unchanged quote-only rewind reaches the driver; after /quotes clear the empty draft is truly empty and keeps refusing.

Regressions: restores a failed quote submit only to its originating session (rewind → held admission → switch → reject → next submit in the new Session carries no quotes) and lets a quote-only rewind reach the submit path unchanged (empty prompt + staged quotes submits verbatim; after clear, nothing). Full pi-tui-runner suite 209/211 — the 2 failures are the pre-existing Windows SIGTERM pair already characterized on this PR's base.

@github-actions github-actions Bot added effort/L Under 1000 readable lines and removed effort/M Under 500 readable lines labels Sep 15, 2026

@Astro-Han Astro-Han 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.

Thanks for the quick turnaround — the quote-only submit path reads correctly. Two findings on the restage guard, reviewed at 6ca7ff99b.

P1 — restageForRetry can never restore. originGeneration is captured before clearStagedQuotes() runs (pi-tui-runner.ts: the capture sits above the stagedGeneration += 1 inside clearStagedQuotes). By the time a blocked result or a failure lands, stagedGeneration !== originGeneration is always true, so the restore never executes. Reachable on the ordinary failure path: /rewind → submit → admission refused or fails → the staged quotes are silently dropped instead of returning for the retry the feature promises. The new tests can't see it: "restores a failed quote submit only to its originating session" asserts the other session stays clean, which also holds when restage never runs; nothing covers the same-session restore. Smallest fix: read stagedGeneration after clearStagedQuotes(), and add the positive case — same-session failed submit restages the quotes.

P2 — a newer rewind does not invalidate an in-flight restage. The rewind path assigns stagedRewindQuotes/stagedQuotesSessionId directly (~pi-tui-runner.ts:2193) without bumping stagedGeneration, so after the capture order is fixed, a re-rewind landing while an admission is in flight would still be overwritten by the older failure's restage — the exact case the comment lists. Bump the generation on that assignment too (or route both writes through one setter).

Everything else in the delta looks right — session-id capture and the empty-text-with-quotes gates in submitPrompt/steerRunningTurn/handleSubmit cover the paths we discussed.

@me2seeks you know the TUI submit path best — could you sanity-check the restage semantics above?

中文版

在 6ca7ff99b 复核。P1:originGeneration 在 clearStagedQuotes()(内部 stagedGeneration += 1)之前捕获,失败或 blocked 落地时守卫恒真,restageForRetry 永不执行——带 staged quotes 的提交失败后 quotes 静默丢失,不回到草稿供重试。新测试只断言另一会话不继承,restage 不执行时也成立,所以没兜住;最小修法是把 generation 读取挪到 dispatch-clear 之后,并补同会话失败恢复的正例。P2:rewind 重新 stage 的赋值(~pi-tui-runner.ts:2193)不 bump generation,修好顺序后「in-flight 期间新 rewind」仍会被旧失败回调覆写,需在赋值处一并 bump。其余 delta(session 捕获、空文本+quotes 放行)没问题。

AI assistance: I used Devin to re-check the delta against the earlier findings; the assessment is mine.

@ggbdpq

ggbdpq commented Sep 16, 2026

Copy link
Copy Markdown
Contributor Author

Both findings fixed at 399f15e:

P1 (restage unreachable): originGeneration is now read after the dispatch's own clearStagedQuotes(), so the guard compares against the staging state the submit actually left behind — an ordinary failure passes and restages, while a Session switch, a newer rewind, or an explicit clear landing in flight still vetoes. Added the positive case: a same-session failed submit restages the quotes onto the next submit (fails on the old order — restage never ran).

P2 (stale restage overwrites newer staging): all staged-quote writes now route through one setStagedQuotes setter that bumps stagedGeneration (the rewind assignment included), so the write-site invariant no longer depends on the clear happening to sit next to it. Added the displacement case: a re-rewind landing while the first admission is in flight wins — the stale failure's restage is vetoed and the next submit carries the newer rewind's quotes (asserted with per-rewind distinct quote texts).

Verification: full pi-tui-runner suite 211/213 — the only 2 failures are the pre-existing SIGTERM pair documented in the local baseline (fail identically on the unmodified base); biome clean on both touched files.

@Astro-Han Astro-Han 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.

Thanks for pushing this through three review rounds — I re-reviewed the current head (399f15e0) with fresh eyes, focusing on the staging semantics rather than the earlier findings.

What I verified

  • Both earlier findings are genuinely fixed. originGeneration is now read after the dispatch's own clearStagedQuotes() (pi-tui-runner.ts:1310-1324), and every write routes through setStagedQuotes, which bumps the generation (:623-628, used by the rewind path at :2199-2205). So an ordinary failure restages, while a Session switch, a newer rewind, or /quotes clear landing in flight vetoes the stale callback. All four new runner tests (__tests__/pi-tui-runner.test.ts:6780-7082) exercise exactly those vetoes plus the positive restage case.
  • Quote-only submits are admissible end to end. hasMeaningfulMessageContent (packages/core/src/events.ts:186) is the single predicate shared by protocol admission (packages/runtime-host/src/protocol/turn.ts:472-489), storage and compaction, so empty text + quotes is legal at every boundary. I also confirmed pi-tui's editor does call onSubmit('') for Enter on an empty buffer (editor.js:submitValue), so the new gates at :1227, :1367, :1385 are actually reachable — and that addToHistory drops empty input, so no empty history entry is created.
  • No duplication when the admission outcome is lost. RuntimeHostMakaSessionDriverImpl#submitMessage swallows outcome_unknown / interrupted-after-dispatch and resolves undefined, i.e. success, so the staging stays consumed rather than being re-sent on a retry. That's the right call for this feature.
  • Quotes are the right refs, verbatim, in order. rewindToTurn returns promptMessage.quotes from the rewound turn (runtime-host-session-driver.ts:901), the revision copy retains the copied turn ids, and the driver forwards a copy unchanged (:546). A newer rewind replaces (not appends to) the staging, so no cross-turn accumulation. No dedup is needed — the refs come from the Host, which already applied TURN_MESSAGE_QUOTE_MAX_COUNT/size limits when they were admitted.
  • Attachments and directory refs still fail closed before any branch exists — the driver test asserts no session.revision.create for those carriers (__tests__/runtime-host-session-driver.test.ts:2125-2213), so a quoted and attached turn can't half-rewind.
  • Repo-wide grep finds no leftover references to the removed rewind_unsupported_quotes code or copy outside the two changed files; the new /quotes entry is wired through both catalogs with all three locales filled in.

Findings

1. A quoted replacement submit renders as nothing in the TUI transcript. This is the one thing I'd like a decision on. The TUI never renders QuoteRefs: the durable user projection emits message.displayText ?? message.text only (pi-transcript.ts:1086-1096), renderUserBlock returns [] for blank text (:2229-2230), and the pending bar prints Steering: with an empty preview for a queued one (:1972). So for the quote-only flow this PR explicitly enables (:6987), the user sends a message and sees no row for it — just an assistant reply to an invisible prompt, with the quotes:<n> segment gone and /quotes now reporting "No restored quotes are staged", i.e. no remaining evidence of what went out. The desktop already solves both halves: quote chips plus a structured-only branch that avoids an empty bubble (packages/ui/src/chat-turn.tsx:250-275). Rendering the quotes (or at least a · N restored quote(s) hint) in the durable user entry would close the loop; happy for it to be a follow-up, but it's user-visible as-is.

2. nit — the staging is hidden on a Session switch, not invalidated. effectiveStagedQuotes() compares stagedQuotesSessionId to getSessionId() (:615-619), so leaving the branched session drops quotes:<n>, but coming back later (/session, the side-conversation toggle, /resume) silently re-arms the old quotes and the next submit carries them with no notice — potentially many turns later. The comment at :609-611 says switch paths "invalidate" the staging, which isn't quite what the code does. If resurrection isn't intended, bump stagedGeneration (or clear) when the view leaves that session; if it is, the comment and the copy could say so.

3. nit — /quotes clear always reports success. The handler clears and pushes quotesCleared unconditionally (:4296-4302), so it claims "Restored quotes discarded" when nothing was staged, and also when the quotes are currently riding an in-flight submit (which will still carry them). Bare /quotes already distinguishes the empty case with quotesNone; clear could reuse that check.

4. nit — a few cheap coverage gaps.

  • restageForRetry() is called on the disposition === 'blocked' branch (:1337) but no test covers it — only the rejected-promise path does. The existing HostSkillDriver (__tests__/pi-tui-runner.test.ts:11545) can refuse, so a quoted rewind plus a refused skill would cover it directly.
  • Every staging test uses a single quote, so ordering, the quotes:<n> count, and the /quotes listing order for >1 excerpt are unverified. A two-quote rewind result would pin all three.
  • /quotes is declared midTurn: 'local' but no test runs it mid-turn, which is the disposition most likely to regress silently.

5. nit — a second rewind can dangle the quotes' provenance. Nothing validates sourceTurnId against the branched session, and a revision copy slices before the target turn (packages/runtime-host/src/server/session-revision-coordinator.ts:371-380). Rewinding twice in a row can therefore stage refs whose source turn no longer exists in the new branch. The inline text is intact so nothing is dropped from the model input; only a chip click-through in the desktop may fail to resolve. Not worth changing here — just noting the staging deliberately carries refs it doesn't re-validate.

Net: I found no correctness bug in the staging/restage logic itself — the generation + session-id guards hold up under the interleavings I traced. Item 1 is the one I'd want an explicit answer on; the rest are nits.

@Astro-Han Astro-Han 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.

Thanks for pushing this through three review rounds — I re-reviewed the current head (399f15e0) with fresh eyes, focusing on the staging semantics rather than the earlier findings.

What I verified

  • Both earlier findings are genuinely fixed. originGeneration is now read after the dispatch's own clearStagedQuotes() (pi-tui-runner.ts:1310-1324), and every write routes through setStagedQuotes, which bumps the generation (:623-628, used by the rewind path at :2199-2205). So an ordinary failure restages, while a Session switch, a newer rewind, or /quotes clear landing in flight vetoes the stale callback. All four new runner tests (__tests__/pi-tui-runner.test.ts:6780-7082) exercise exactly those vetoes plus the positive restage case.
  • Quote-only submits are admissible end to end. hasMeaningfulMessageContent (packages/core/src/events.ts:186) is the single predicate shared by protocol admission (packages/runtime-host/src/protocol/turn.ts:472-489), storage and compaction, so empty text + quotes is legal at every boundary. I also confirmed pi-tui's editor does call onSubmit('') for Enter on an empty buffer (editor.js:submitValue), so the new gates at :1227, :1367, :1385 are actually reachable — and that addToHistory drops empty input, so no empty history entry is created.
  • No duplication when the admission outcome is lost. RuntimeHostMakaSessionDriverImpl#submitMessage swallows outcome_unknown / interrupted-after-dispatch and resolves undefined, i.e. success, so the staging stays consumed rather than being re-sent on a retry. That's the right call for this feature.
  • Quotes are the right refs, verbatim, in order. rewindToTurn returns promptMessage.quotes from the rewound turn (runtime-host-session-driver.ts:901), the revision copy retains the copied turn ids, and the driver forwards a copy unchanged (:546). A newer rewind replaces (not appends to) the staging, so no cross-turn accumulation. No dedup is needed — the refs come from the Host, which already applied TURN_MESSAGE_QUOTE_MAX_COUNT/size limits when they were admitted.
  • Attachments and directory refs still fail closed before any branch exists — the driver test asserts no session.revision.create for those carriers (__tests__/runtime-host-session-driver.test.ts:2125-2213), so a quoted and attached turn can't half-rewind.
  • Repo-wide grep finds no leftover references to the removed rewind_unsupported_quotes code or copy outside the two changed files; the new /quotes entry is wired through both catalogs with all three locales filled in.

Findings

1. A quoted replacement submit renders as nothing in the TUI transcript. This is the one thing I'd like a decision on. The TUI never renders QuoteRefs: the durable user projection emits message.displayText ?? message.text only (pi-transcript.ts:1086-1096), renderUserBlock returns [] for blank text (:2229-2230), and the pending bar prints Steering: with an empty preview for a queued one (:1972). So for the quote-only flow this PR explicitly enables (:6987), the user sends a message and sees no row for it — just an assistant reply to an invisible prompt, with the quotes:<n> segment gone and /quotes now reporting "No restored quotes are staged", i.e. no remaining evidence of what went out. The desktop already solves both halves: quote chips plus a structured-only branch that avoids an empty bubble (packages/ui/src/chat-turn.tsx:250-275). Rendering the quotes (or at least a · N restored quote(s) hint) in the durable user entry would close the loop; happy for it to be a follow-up, but it's user-visible as-is.

2. nit — the staging is hidden on a Session switch, not invalidated. effectiveStagedQuotes() compares stagedQuotesSessionId to getSessionId() (:615-619), so leaving the branched session drops quotes:<n>, but coming back later (/session, the side-conversation toggle, /resume) silently re-arms the old quotes and the next submit carries them with no notice — potentially many turns later. The comment at :609-611 says switch paths "invalidate" the staging, which isn't quite what the code does. If resurrection isn't intended, bump stagedGeneration (or clear) when the view leaves that session; if it is, the comment and the copy could say so.

3. nit — /quotes clear always reports success. The handler clears and pushes quotesCleared unconditionally (:4296-4302), so it claims "Restored quotes discarded" when nothing was staged, and also when the quotes are currently riding an in-flight submit (which will still carry them). Bare /quotes already distinguishes the empty case with quotesNone; clear could reuse that check.

4. nit — a few cheap coverage gaps.

  • restageForRetry() is called on the disposition === 'blocked' branch (:1337) but no test covers it — only the rejected-promise path does. The existing HostSkillDriver (__tests__/pi-tui-runner.test.ts:11545) can refuse, so a quoted rewind plus a refused skill would cover it directly.
  • Every staging test uses a single quote, so ordering, the quotes:<n> count, and the /quotes listing order for >1 excerpt are unverified. A two-quote rewind result would pin all three.
  • /quotes is declared midTurn: 'local' but no test runs it mid-turn, which is the disposition most likely to regress silently.

5. nit — a second rewind can dangle the quotes' provenance. Nothing validates sourceTurnId against the branched session, and a revision copy slices before the target turn (packages/runtime-host/src/server/session-revision-coordinator.ts:371-380). Rewinding twice in a row can therefore stage refs whose source turn no longer exists in the new branch. The inline text is intact so nothing is dropped from the model input; only a chip click-through in the desktop may fail to resolve. Not worth changing here — just noting the staging deliberately carries refs it doesn't re-validate.

Net: I found no correctness bug in the staging/restage logic itself — the generation + session-id guards hold up under the interleavings I traced. Item 1 is the one I'd want an explicit answer on; the rest are nits.

@ggbdpq

ggbdpq commented Sep 17, 2026

Copy link
Copy Markdown
Contributor Author

Addressed everything actionable at 8822a0911 — thank you for tracing the editor's empty-buffer Enter and the driver's outcome-unknown swallow; both were load-bearing for the original findings.

Item 1 (quote-only submit renders as nothing) — implemented now, not deferred. The durable user entry carries the restored-quote count and renders a trace line: blank text renders · N restored quote(s) as its row, and a quoted message with text appends the hint under it. Locale-free structural text, matching the quotes:<n> status segment's convention; localized chips stay desktop-side as you noted. Pinned in pi-transcript.test.ts through replaceTranscriptWithStoredMessages + renderMakaPiTranscript (blank+quotes, text+quotes, and no-quotes cases).

Item 2 (hidden vs invalidated) — the staging is now invalidated. applySwitchResult — the single choke point every session change routes through — clears the staging outright; the rewind re-stages its own quotes after the switch settles. The stale comment now describes what the code does. Resurrection is no longer possible from any path.

Item 3 (clear always reports success) — fixed. /quotes clear with nothing staged reports quotesNone instead of claiming a discard; this also covers the in-flight case, where the honest answer is that there is nothing left to clear. The quote-only test that had pinned the old lying copy now asserts the truthful one.

Item 4 (coverage) — all three gaps closed:

  • blocked-disposition restage: a quoted rewind whose replacement the Host refuses (blocked + failed skill invocation) restages; the retry carries the refs again.
  • two-quote rewind: quotes:2, the /quotes listing order, and the replacement submit's ref order are all pinned (two distinct excerpts).
  • /quotes mid-turn: with a running Turn claiming busy, the listing still routes through the local disposition.

Item 5 (dangling provenance after a second rewind) — agreed, no change here: the refs are carried deliberately un-revalidated, and the desktop chip click-through is the place that resolves them.

Verification: full pi-tui-runner + pi-transcript suites 328/332 — the only failures are the two pre-existing SIGTERM cases on the local baseline (fail identically without this branch's changes); biome clean on all four touched files.

@github-actions github-actions Bot added effort/XL Under 2500 readable lines and removed effort/L Under 1000 readable lines labels Sep 18, 2026
@ggbdpq

ggbdpq commented Sep 20, 2026

Copy link
Copy Markdown
Contributor Author

Gentle ping — everything actionable from your 09-17 review landed at 8822a0911 (the transcript trace line for quote-only submits, switch-path invalidation via applySwitchResult, the truthful /quotes clear copy, and the three coverage gaps). The head is now a127b13e: same tree plus a merge of main and a CI retrigger. Checks are green and the branch merges cleanly — re-review whenever you have a moment.

@me2seeks me2seeks 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.

Review(对抗式复核,head a127b13ed)

方向认可:把 rewind 掉的 turn 的 QuoteRef 原样返回并转发进替换 submit,而不是 fail-closed(rewind_unsupported_quotes),同时删掉死代码和对应文案,这是干净的做法。前几轮 review 的 P1(generation 读取顺序)和 switch 失效化确实已修好,我复核确认。

不过还有 1 个 P1 和 1 个 P2 需要处理。


P1 — outcome_unknown 路径下 staged quotes 会被静默吞掉,且永不 restage

restageForRetry() 只在两个分支被调用(packages/cli/src/pi-tui-runner.ts):

  • .then 里 result?.disposition === 'blocked'
  • .catch 里

但真实 driver 在「投递结果未知」时不抛异常,而是 resolve undefined(packages/cli/src/runtime-host-session-driver.ts:551-557):

} catch (error) {
  if (
    (error instanceof RuntimeHostOperationError && error.code === 'outcome_unknown') ||
    (error instanceof RuntimeHostRequestInterruptedError && error.dispatch === 'dispatched')
  ) {
    return undefined;   // 注意:resolve,不是 reject
  }
  throw error;
}

#admit(:1271)把这个 undefined 原样透传。于是对于 outcome_unknown / interrupted-after-dispatch 的 submit:

  • .then 里 result?.disposition 是 undefined、if (result) 为 false → 不 restage;
  • .catch 不触发 → 不 restage。

而 staging 在 dispatch 时已经被 clearStagedQuotes() 清掉,所以 quotes 被静默消费、永久丢失。

这里需要纠正上一轮 review 的一个判断。上一轮把这条路径读成了「resolve undefined,i.e. success,所以 staging 保持消费是正确的」。但按 RuntimeHostRequestInterruptedError 自己的文案(packages/runtime-host/src/client/connection.ts:328-330),dispatch === 'dispatched' 的含义是:

'the operation outcome is unknown; do not retry it automatically'

message-coordinator.ts:1236 的 outcome_unknown 同样是「Message disposition cannot be proven in this Host Epoch」——结果无法证明,而不是「已确认接纳」。所以这不是一个「有意保持消费」的设计,而是一个未被识别的缺口:恰恰在「消息可能没被接纳」时,把上下文静默丢掉了。

需要说明的是,这里存在一个真实的两难:如果消息其实已经被接纳,restage 会导致重试时重复发送 quotes。但当前代码既没有注释说明这是有意为之,也没有测试覆盖这条路径。建议明确决策并写清理由(例如「outcome_unknown 视为已接纳,故不 restage,避免重复」),或者按语义选择 restage 并说明重复风险。

测试盲区:所有新测试用的 HeldSubmitQuotedDriver.submitMessage 都是 reject(packages/cli/src/__tests__/pi-tui-runner.test.ts 的 new Promise((_, reject) => ...)),没有任何用例走 resolve-undefined 这条真实路径。


P2 — 任意带 quotes 的用户消息都会被标成「restored quote」,不只是 rewind 恢复的

packages/cli/src/pi-transcript.ts(本 PR 新增):

const restoredQuotes = message.quotes?.length;
entries.push({
  kind: 'user',
  messageId: message.id,
  text: message.displayText ?? message.text,
  ...(restoredQuotes ? { quotes: restoredQuotes } : {}),
});

渲染时无条件加标签:

const hint = `· ${entry.quotes} restored quote${entry.quotes === 1 ? '' : 's'}`;

问题是 StoredMessage.quotes 并不是「rewind 恢复」专属字段——桌面端普通引用消息也写入同一个字段,并且会进入 TUI 渲染的同一份 durable transcript:

  • apps/desktop/src/renderer/features/workbar/tools/side-chat/use-quote-companion.ts:1238(普通引用提交)
  • apps/desktop/src/main/session-local-service.ts:198(把 content.quotes 投影回本地消息)
  • 桌面端 edit & resend 的 restage 路径(#5274)同样会写入该字段

而 TUI 在打开/切换会话时会走 applySwitchResult → replaceTranscript(messages) → storedMessagesToTranscriptEntries(pi-tui-runner.ts:1878、pi-transcript.ts:422),所以任何带引用的用户消息都会显示「· N restored quotes」,事实错误。

本 PR 自己的测试也把这个错误固化了:pi-transcript.test.ts 里 message-2 是 text: 'with words' + 一个 quote,断言输出 · 1 restored quote。而 packages/ui 对同一字段的中性投影是「Inline quoted excerpts」(packages/ui/src/materialize.ts:62),两边语义已经分叉。

建议:把标签改成中性(例如「· N quote(s)」),或者给 entry 增加一个真正的「restored」标记(由 rewind 路径显式设置),而不是用「有没有 quotes」来推断。


已确认没问题的点

  • 删除的代码没有残留引用:全仓 grep 无 rewind_unsupported_quotes / unsupportedQuotes 残留。
  • quote-only submit 链路通:hasMeaningfulMessageContent 是 protocol admission / 存储 / compaction 共用的单一谓词,空 text + quotes 在各边界都合法;/quotes 三个 locale(en / zh-CN / zh-TW)文案齐全。
  • /quotes 解析:parts = trimmed.split(/\s+/),/quotes、/quotes clear、其它形式走 usage 提示,与文件内其它命令(如 /host)一致;midTurn: 'local' 是合法取值。
  • /new 路径:newSession 不调用 clearStagedQuotes(),但 startNewSession 会把 #sessionId 置 null,effectiveStagedQuotes() 因 session 不匹配返回 [],且之后任何切回都会经 applySwitchResult 清空——不会 resurrect,属于注释措辞不够精确,不是 active bug。

小结:P1 建议在合并前明确决策并补测试;P2 建议改中性标签。其余为已澄清项。

@ggbdpq

ggbdpq commented Sep 20, 2026

Copy link
Copy Markdown
Contributor Author

Thanks for the adversarial re-read — both findings confirmed and fixed on cb6d10882 (merged latest main first, no conflicts).

P1 — outcome_unknown restage. Confirmed: the real driver resolves undefined for outcome_unknown and for an interruption after dispatch, and the .then arm only handled disposition === 'blocked', so the staging was silently consumed exactly when admission was least proven. Decision: restage on the unknown path and surface a notice ("Submit outcome unknown; staged quotes restored for retry."). An unproven outcome is not an admission; losing the user's explicitly staged context is the irreversible branch, while the duplicate-ride risk if the message did land stays visible (status line quotes:N) and discardable (/quotes clear). The restage still routes through the same session/generation guards, so a Session switch, newer rewind, or explicit clear landing in flight keeps winning.

P2 — neutral trace. Also confirmed: StoredMessage.quotes carries every quoted user message (desktop plain quotes and edit-restaged ones included), not just rewind restages, so the durable trace mislabeled them. The trace line is now the neutral · N quote(s), matching @maka/ui's neutral projection of the same field.

Tests: new UnknownOutcomeSubmitDriver pins the resolve-undefined path (all prior held-submit tests rejected — the reviewer-noted blind spot), and the transcript test now asserts the neutral wording instead of enshrining the old label. Both fail against the pre-fix source and pass on cb6d10882; the rest of the two suites is unchanged (only the two known SIGTERM flakes, pre-existing and unrelated).

@ggbdpq

ggbdpq commented Sep 20, 2026

Copy link
Copy Markdown
Contributor Author

Follow-up on c07c577a7: the first push's CI failure was my mistake, not the fix itself — the unknown-outcome notice was a visible literal in pi-tui-runner, which check:tui-copy correctly rejects. The notice now goes through the rewind copy catalog (quotesRestoredUnknown, en / zh-CN / zh-TW), guard green, test re-run green.

@ggbdpq

ggbdpq commented Sep 24, 2026

Copy link
Copy Markdown
Contributor Author

Gentle ping — the head is dcb9c22a4 (CI green, merges cleanly into the current main): the fixes for your 09-20 review plus one style cleanup commit. Everything actionable from that review is in — the outcome_unknown restage with the catalog notice and the neutral N quote(s) label — so a re-review whenever you have a moment would be much appreciated.

@hqhq1025 hqhq1025 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.

This change now carries rewound QuoteRefs through the CLI driver and into the replacement submit, accepts quote-only submits, and uses neutral wording in the durable transcript. I found one remaining failure-ordering issue below. The current-head test check passed, but I did not run local TUI tests or a cross-surface smoke test. The earlier CHANGES_REQUESTED review is attached to an older commit, not this head.

Automated review notice: This comment was posted by an automated review agent operated by hqhq1025. It is not an independent human review and does not replace one.

Comment thread packages/cli/src/pi-tui-runner.ts Resolved

@hqhq1025 hqhq1025 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.

At this head, I found no new substantiated P0–P3 issue. The follow-up increments the quote-staging generation for a quote-less submit and for an explicit /quotes clear when staging is empty. The earlier quoted submission's failure/unknown-outcome callback checks that generation before restoring, so these later intents no longer inherit its quotes. I also rechecked the rewind-to-staging-to-Host submission path, quote-only input, session-switch invalidation, and transcript disclosure. The PR changes 9 files; no schema migration is involved.

The current-head CI test check passed, and the diff and merge-tree checks were clean against the latest main. I did not run local TUI tests or a terminal smoke test. The two newly fixed interleavings do not have dedicated black-box regressions; input gating may make them unreachable in the current harness, so a future routing change should preserve this generation guard. An older CHANGES_REQUESTED review remains in GitHub's review decision; human reviewers need to decide readiness.

Automated review notice: This comment was posted by an automated review agent operated by hqhq1025. It is not an independent human review and does not replace one.

@Astro-Han Astro-Han 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.

Reviewed at this head by three independent AI reviewers (different model families). The fix is sound, but all three found the same context-loss path (P2, inline), so we would hold the merge until it is addressed.

What works: the driver now returns the rewound turn's QuoteRefs and they travel verbatim in content.quotes through the single submit path; attachments and directory references still fail closed. Staging is keyed by session and cleared on switch; the generation guard (including the bump for quote-less submits and /quotes clear on an empty stage) stops a stale failure callback from restaging over newer intent; quote-only input is accepted at all three entry points; the transcript marks quoted user messages. About 79% of the +1071 lines are tests, and they distinguish the new behaviour from the old refusal.

The P2: quotes that ride a queued or steered message are dropped silently when the user takes that message back (Alt+↑ or Esc). The Host's queue.retract returns full MessageContent, including quotes, but RuntimeHostSessionDriver.retractQueued() (runtime-host-session-driver.ts:587-597) keeps only text and message ids, and acceptRetraction (pi-tui-runner.ts:1389) refills only the text. A resubmit then goes out without the quotes, and for a quote-only message the whole input disappears. The PR's own MidTurnQuotesDriver test sets up exactly this state. Please carry the quotes through retraction and restage them (with a test covering one and several queued messages), or refuse to queue staged quotes until they can be preserved.

Smaller notes:

  • On an unknown outcome the quotes are restaged without checking whether the message was actually accepted, so they can be sent twice.
  • When a later plain submit supersedes a failed quoted submit's restore, the quotes are dropped with no notice.
  • A quote-only message leaves no row while pending, queued or steered, and the · N quote(s) line reads like typed text.
  • Unused ShellRunSnapshotResult import in session-driver.ts.

Also: an older CHANGES_REQUESTED review on a previous head still affects the PR's review decision.

Not verified: a real terminal session against a live Host.


Automated review notice: This review was posted by an automated review agent operated by Astro-Han. It combines independent reviews from several AI models. It is not an independent human review and does not replace one.

Comment thread packages/cli/src/pi-tui-runner.ts Resolved
@ggbdpq

ggbdpq commented Sep 27, 2026

Copy link
Copy Markdown
Contributor Author

Addressed on head fea2f7ac2:

P2 (quotes lost on retraction): MakaRetractedMessages now carries the retracted entries' quotes — the Host already returns the full MessageContent — and acceptRetraction restages them on the current session through the generation-guarded setter, so the restoration obeys the same veto rules as every other staging write (a session switch, a newer rewind, or /quotes clear landing in flight still wins). Two runner tests cover the steered case and a multi-message retraction where one entry carries quotes and one does not. The unused ShellRunSnapshotResult import is dropped too.

On the smaller notes:

  • Restage without an acceptance receipt (double-send risk): this is the deliberate outcome-unknown stance this series settled on earlier — when no receipt comes back, the quotes return visibly (the quotes: N status line) and /quotes clear is the escape hatch. Distinguishing "delivered but unacknowledged" from "never admitted" needs a delivery receipt from the Host, which this PR deliberately does not build.
  • No notice when a later plain submit supersedes a pending restoration: agreed this is a UX gap; surfacing a notice needs a small render-side change I would rather keep out of this series. Happy to follow up.
  • Quote-only messages render no pending row: same — follow-up material, tracked here so it does not get lost.

On the older CHANGES_REQUESTED: its P1 (quotes swallowed on outcome-unknown, never restaged) is what the generation-guarded restage on this head fixed, and its P2 (quote-only replacement refused at the submit guards) was confirmed fixed in the second-round review. Nothing outstanding is tracked against that review that this head does not address — happy to re-review or have it re-checked.

Local verification: cli build clean, pi-tui-runner suite 232/234 with the only two failures the pre-existing Windows SIGTERM pair (same baseline as earlier rounds), new tests green; CI is running on this head.

@hqhq1025 hqhq1025 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.

Reviewed the current head 92615d63 (nine files, +1071/-71 overall; the latest two commits change five CLI files). This revision carries retracted MessageContent.quotes through the Runtime Host driver (runtime-host-session-driver.ts:587-600) and restages them in the TUI (pi-tui-runner.ts:1394-1402). The new TUI tests cover a quoted queued message and a quoted message among multiple retracted entries. The earlier generation-supersession fix remains in place.

I found one P2 cross-Session race in the new restaging path, noted inline. The current-head test check succeeds, the static merge with fresh main 2a568ef9 and git diff --check are clean, and I found no schema/migration change. I did not run the local TUI suite (dependencies are not installed here), a real Host/TUI concurrency test, or terminal smoke. An older CHANGES_REQUESTED review remains on this PR; a green current-head check does not resolve that human review.

Automated review notice: This comment was posted by an automated review agent operated by hqhq1025. It is not an independent human review and does not replace one.

Comment thread packages/cli/src/pi-tui-runner.ts Resolved
@ggbdpq

ggbdpq commented Sep 27, 2026

Copy link
Copy Markdown
Contributor Author

Fixed on head 668a57654. The runner now captures the owning session before the first await in both retraction paths (interrupt and Alt+Up), and a response that lands after the driver has re-keyed is discarded outright — neither its text nor its quotes reach the session the switch landed on, whose staging stays as applySwitchResult left it. A delayed-retract/session-switch regression covers it (discards a retraction that lands after a mid-turn session switch): the retraction is held on a gate, the switch completes, the response is released, and the switched-to session's status line shows no staged quotes. Full pi-tui-runner suite green locally (232/234 with only the pre-existing Windows SIGTERM pair); CI running on this head.

@hqhq1025 hqhq1025 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.

Reviewed the two-file follow-up and the surrounding TUI/driver session-switch paths. The new response-time check prevents a late A retraction from staging quotes into B in the covered test, but it does not bind the retraction request or the subsequent interrupt to A. The two races below can affect B. Node 24 build:test and the focused quote/retraction tests (3/3) pass; current-head CI test succeeds, and the merge-tree against current main and diff-check are clean. No schema/migration change. I did not run an interactive TUI/Host race reproduction; the findings follow the reachable asynchronous control flow and driver target selection.

Automated review notice: This comment was posted by an automated review agent operated by hqhq1025. It is not an independent human review and does not replace one.

Comment thread packages/cli/src/pi-tui-runner.ts Resolved
Comment thread packages/cli/src/pi-tui-runner.ts Resolved

ghost 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.

I reviewed the current head against the two previously reported cross-session retraction races. Both production paths now check the originating session after pending enqueues settle and again after the retraction response (packages/cli/src/pi-tui-runner.ts:1317-1330,1544-1553). The interrupt no longer calls stop() after a session switch. I did not find a remaining substantiated production P0-P2 in this delta. One P3 test gap is noted inline. Local Node 24 clean install, build:test, both new focused tests, and diff-check passed. This is not merge-ready: fresh main 542f04a conflicts in packages/cli/src/tests/runtime-host-session-driver.test.ts, and no checks are reported for this head. I did not run a real Runtime Host/TUI switch race or the full test suite.

Automated review notice: This comment was posted by an automated review agent operated by hqhq1025. It is not an independent human review and does not replace one.

ghost 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.

This head is a tree-identical, empty CI-retrigger commit on top of d9aa90e; the two earlier production P1 fixes remain present at packages/cli/src/pi-tui-runner.ts:1317-1330,1544-1553. The P3 regression-test gap remains (inline). My prior Node 24 clean build and two focused tests apply to the identical tree; I did not rerun an unchanged suite. This is not merge-ready: the PR still conflicts with fresh main 9e765ab in packages/cli/src/tests/runtime-host-session-driver.test.ts, and this head currently has no registered CI checks. Real Runtime Host/TUI switch races and the full test suite remain unverified.

Automated review notice: This comment was posted by an automated review agent operated by hqhq1025. It is not an independent human review and does not replace one.

@ggbdpq
ggbdpq force-pushed the fix/tui-rewind-quote-staging branch from 79dbea6 to 4e61b5f Compare September 28, 2026 02:15
@ggbdpq

ghost commented Sep 28, 2026

Copy link
Copy Markdown
Contributor Author

Merged latest main (f58f302) and closed out the P3 — head is now 4e61b5fe5.

Merge: one file conflicted (runtime-host-session-driver.test.ts) — the fake driver gained this PR's session.revision.create stub and main's turn.resume.start stub side by side; both kept.

P3 (the regression test never retracts): fixed. The switched-queue case now sends Alt+Up (�[1;3A) while the enqueue gate is still held, then switches sessions, then resolves the gate — so the retraction request is genuinely in flight across the switch, which is the interleaving the two P1 fences guard. Red-checked: with the post-settlePendingEnqueues() session fence neutered, the updated test fails (the retraction lands on the switched-to session); with the fence restored it passes. All six focused retraction tests pass on the rebuilt cli.

On the 53 runtime-host-session-driver failures locally: all of them are Session cwd no longer exists: /tmp — main's newer tests in that file assume a POSIX /tmp. They come from the merge, fail identically on Windows regardless of this branch's changes, and are unaffected on Linux CI.

Remaining from your review: nothing else on my side — the two production P1 fences are present at pi-tui-runner.ts:1317-1330,1544-1553 as you confirmed, and the P3 is now closed with a test that actually discriminates.

ghost 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.

Automated review notice: This review was prepared and posted by an automated review agent operated by me2seeks. It does not replace independent human review.

Reviewed exact head b8b41ee8b53684e6c57c304673fcb871c5518eee, including the integration of #6070. The earlier neutral quote-label finding is addressed, and receipt-less submission now explicitly restores staging with an uncertainty notice. That policy can carry the quotes again on a later user submit if the first admission actually succeeded; the code documents this tradeoff.

One remaining P2 is detailed inline: retracting multiple independently valid queued messages can create a combined quote payload that the Host rejects on resubmission. This concerns Shift+Left queue retraction, not /rewind: rewinding a selected turn restores that turn's own prompt quotes rather than accumulating later turns.

Validation on this head: isolated workspace dependency/CLI builds passed; the complete pi-tui-runner, runtime-host-session-driver and pi-transcript test files passed 481 tests with 3 platform skips and no failures. TUI copy boundaries and diff whitespace checks passed. A synthetic merge with current main 728b9627b4 was clean. An additional probe through the actual session driver and actual Host admission decoder reproduced the P2; no running Host, installed TUI, or packaged application was exercised. Exact-head hosted CI is successful.

Please preserve every recovered excerpt while providing an admissible resubmit path, and add coverage for several quoted queue entries whose aggregate crosses the single-message limits. Silently truncating the recovered quotes would lose user context.

@ggbdpq

ghost commented Oct 13, 2026

Copy link
Copy Markdown
Contributor Author

The remaining P2 from the re-review of b8b41ee8b is fixed at 87fb4fcfb: retraction restaging now respects TURN_MESSAGE_QUOTE_MAX_COUNT — the first 16 recovered quotes stage for the immediate resubmit, the overflow is inlined into the restored draft as quoted text with an info notice, so nothing is lost and the resubmit is admissible. The cap is exported from the runtime-host protocol surface (one targeted re-export) so the TUI enforces the same constant the admission decoder does. New driver-level regression covers the 9+9 → 16+2 case including the resubmit; pi-tui-runner 281/281, driver 87/87, transcript 114 pass / 3 platform skips, copy/biome/asf clean. CI queued on the new head.

One edge flagged for transparency: the aggregate encoded size of 16 large quotes can still exceed the per-message content budget — that needs message-boundary splitting (a queue-of-drafts shape) rather than a staging cap, and I'd rather scope it separately than improvise it here.

cc @liugddx — this was the last finding blocking the rebased head; ready for your review whenever you have a moment.

@github-actions github-actions Bot added effort/XXL Over 2500 readable lines and removed effort/XL Under 2500 readable lines labels Oct 13, 2026

ghost 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.

Automated review notice: This comment was posted by an automated review agent. It is not an independent human review and does not replace one.

At 87fb4fcfb53c9931f93a64cd76d84904f9b5b2ad, the new 16-quote staging cap fixes the count-limit refusal after retracting multiple queued messages, but I found two P2 issues in this four-file update.

  1. Overflow drops the user's quote annotations (packages/cli/src/pi-tui-runner.ts:1481). The plaintext conversion preserves only label and excerpt, not QuoteRef.comment. I exercised the real TUI with two independently valid nine-quote queue entries, each quote carrying a distinct annotation. The next submit retained annotations 1–16 in its structured quotes and excerpt text 17–18 in its body, but annotations 17–18 were absent from both. The source queue rows had already been removed. Preserve the overflow annotations in the restored text as well as the excerpt.
  2. The added protocol export fails CI's compatibility check (packages/runtime-host/src/protocol/index.ts:92). The current CI run stops at the protocol epoch guard because the file changed without a compatible-change declaration. I reproduced the failure against the branch's original base and its clean merge with current main. Exporting this existing constant does not change message decoding or the wire contract; use the documented compatible-change declaration, pinned to the integrated epoch, rather than unnecessarily changing peer compatibility.

A fresh dependency installation and clean full test build succeeded. Six complete related test files passed 495 tests with three Windows-only skips; the independent annotated-overflow scenario reproduced the loss above. CLI type checking, changed-file lint and TUI copy checking passed. The head merges cleanly with main 32b17504, but its current CI is not green. The branch itself still declares epoch 217; the synthetic main merge declares 219. I did not run native Windows/macOS terminal journeys or the full local repository suite.

Comment thread packages/cli/src/pi-tui-runner.ts Resolved
@Astro-Han

ghost commented Oct 13, 2026

Copy link
Copy Markdown
Contributor

Correction to my review above: current main (32b17504) is already at protocol epoch 220, not 219 (219 was only the base of the CI run). Both findings stand. When you add the compatible-change declaration, pin it to the epoch of the main you rebase onto (currently 220).

@ggbdpq

ghost commented Oct 13, 2026

Copy link
Copy Markdown
Contributor Author

CI's red on 87fb4fcfb was the protocol epoch guard, not the fix itself: the re-export of TURN_MESSAGE_QUOTE_MAX_COUNT touches packages/runtime-host/src/protocol/index.ts without moving RUNTIME_HOST_COMPATIBILITY_EPOCH. The re-export only lets the TUI import the same cap literal the admission decoder enforces — a constant move, which the guard's README lists as a legitimate compatible change — so it is declared rather than bumped: protocol-compatible-changes/turn-message-quote-cap-reexport.json, pinned to epoch 220 after merging current main. Checks are green on b7c01c7a4.

ghost 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.

Automated review notice: This comment was posted by an automated review agent. It is not an independent human review and does not replace one.

Incremental review from 87fb4fcf to b7c01c7a45a36ff135ece63e23dc3a75aacc4faf. Apart from merging main, the only new commit is b7c01c7a, which adds protocol-compatible-changes/turn-message-quote-cap-reexport.json.

  1. Protocol compatibility (earlier P2): fixed. The declaration names packages/runtime-host/src/protocol/index.ts, pins epoch 220 (current main and the branch both declare 220), and gives an accurate reason: re-exporting the existing TURN_MESSAGE_QUOTE_MAX_COUNT changes no message shape or accepted value. CI on this head now passes, including the protocol epoch guard.

  2. Overflow drops quote annotations (earlier P2): still open. formatQuoteOverflow at packages/cli/src/pi-tui-runner.ts:1566-1567 is unchanged and still serializes only label and text. When retracted entries hold more than 16 quotes, the comment on quote 17 onward is lost from both the restored text and options.quotes, and the source queue rows are already gone. Please include the annotation in the restored plaintext (for example, as a line after the excerpt) and add a regression with annotated overflow quotes.

The branch merges cleanly with main.

@ggbdpq

ghost commented Oct 13, 2026

Copy link
Copy Markdown
Contributor Author

Merged current main (6c63fa057) into the branch (6d5d20338) — one real conflict in the TUI copy catalog (main added a zh-TW locale section around our quotes entries), resolved as a union; suites re-run green on the merged head (pi-tui-runner 286/286, driver 87/87, transcript 119 with 3 platform skips, copy-catalog 9/9, check:tui-copy ok).

ghost 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.

Automated review notice: This comment was posted by an automated review agent. It is not an independent human review and does not replace one.

Incremental review from b7c01c7a to exact head 6d5d2033. The increment is one author commit, 52ee6e50 ("keep overflow quote comments when restaging degrades to text"), plus a merge of main at 6c63fa05 that resolved a conflict in packages/cli/src/tui-copy-catalog.ts. I compared each head against its own merge-base to keep main's changes out. Apart from the catalog, the merge brings in no author changes.

Previous finding

  • P2, formatQuoteOverflow dropped QuoteRef.comment for quotes past the 16-quote cap: fixed. Each overflow excerpt now gets a > comment: … line under it (pi-tui-runner.ts:1566-1575). I added a local regression with two 9-quote queue entries and a distinct comment on all 18 quotes, then retracted and resubmitted. Quotes 1-16 reach options.quotes with their comments intact. The comments for quotes 17 and 18 reach the submitted text (… > [q17] excerpt 17\n> comment: note-17-zz\n> [q18] excerpt 18\n> comment: note-18-zz). All 18 survive. The author's updated test only puts comments on quotes 17 and 18. That is enough to guard the overflow path.

New findings

  • P2: CI format:check will fail on this head. The conflict resolution in tui-copy-catalog.ts left the new quotes* rewind keys at the old 6/8-space indent inside main's restructured objects (lines 125-132, 1392-1399, 1415-1422). The new waitFor in pi-tui-runner.test.ts:9020-9022 also is not biome-formatted. npx biome format . reports exactly these 2 files. main at 6c63fa05 is clean, and CI runs npm run format:check (ci.yml:257). Running npm run format and committing the result fixes it.
  • P3: the overflow plaintext only prefixes the first line of each field. If a quote's text or comment has more than one line, only the first line gets > . With text: "excerpt 17\nsecond line 17" and comment: "note-17-zz\nmore 17", the draft I observed was > [q17] excerpt 17\nsecond line 17\n> comment: note-17-zz\nmore 17. Markdown's lazy continuation keeps these lines inside the blockquote when rendered. In the raw text the model receives, though, it is unclear where the excerpt ends and the comment begins. Also, an excerpt that contains its own comment: line looks the same as an annotation. Pasted excerpts are usually multi-line, so this is the common case. Suggested fix: prefix every line of both fields with > . Optionally, put a bare > or a blank line between excerpts so adjacent quotes do not merge into one paragraph.

Protocol epoch: the PR touches only packages/runtime-host/src/protocol/index.ts, with a re-export of TURN_MESSAGE_QUOTE_MAX_COUNT. The compatible-change declaration turn-message-quote-cap-reexport.json pins epoch 220. That matches RUNTIME_HOST_COMPATIBILITY_EPOCH on both current main and this head, so the merge-result check takes the declared-compatible path. No collision.

Validation (local, at 6d5d2033): I built the workspace deps and the CLI. These suites pass with 0 failures (512 pass, 3 skipped): pi-tui-runner, pi-transcript, runtime-host-session-driver, tui-copy-catalog, tui-copy-command and tui-shortcut-copy. scripts/check-tui-copy.mjs is ok and biome lint is clean.

CI / merge state: the test check is still queued on this head, so there is no result yet. I expect it to fail at format:check for the reason above. The PR is MERGEABLE; merge is BLOCKED because review is required.

Verdict: the previous P2 is fixed. Fix the formatting before merge. The multi-line quoting is an optional P3.

Comment thread packages/cli/src/tui-copy-catalog.ts Resolved
Comment thread packages/cli/src/pi-tui-runner.ts Resolved

ghost 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.

Automated review notice: This comment was posted by an automated review agent. It is not an independent human review and does not replace one.

Incremental review from 6d5d2033 to exact head d0d142e3. The increment is one author commit, d0d142e3 ("quote every overflow line and reformat the merged copy catalog"). It touches pi-tui-runner.ts, its test and tui-copy-catalog.ts. There is no main merge in the range, and no protocol files are touched.

Previous findings

  • P2, format:check failed: partly fixed, still failing. The tui-copy-catalog.ts change is whitespace-only (git diff -w is empty) and the file is now biome-clean. The old waitFor is also fixed. However, the commit adds a new unformatted waitFor at pi-tui-runner.test.ts:9027-9029, and biome wants it collapsed to one line. On this head, npm run format:check (CI ci.yml runs it) reports Found 1 error in exactly this file. Current main 6c63fa05 is clean, so this check is still PR-caused and will fail CI. Running npm run format and committing the result fixes it. This finding stays open at P2.
  • P3, multi-line quotes and comments were ambiguous in the overflow plaintext: fixed. Every line of both the excerpt and the comment now gets the > prefix, and adjacent excerpts are separated by a bare >. One small edge case remains: an excerpt line that itself begins with comment: still looks the same as the annotation. This is optional and does not block merge.

Verification (local, exact head)

  • I added a temporary regression with two 9-quote entries. Every one of the 18 quotes has a distinct comment, and some excerpts and comments are multi-line. I then retracted and resubmitted. Quotes 1-16 reach options.quotes with their comments intact, including the multi-line ones. The submitted text ends with > [q17] excerpt 17\n> line2 17\n> comment: note-17-zz\n>\n> [q18] excerpt 18\n> comment: note-18-zz\n> more-18-zz. All 18 comments survive. I removed the probe afterwards.
  • Built the workspace deps and the CLI. pi-tui-runner and tui-copy-catalog tests pass, 295/295.

CI / merge state: the hosted test check is still queued on this head, so there is no result yet. I expect it to fail at format:check for the reason above. The PR is MERGEABLE with no conflicts against main 6c63fa05. Merge is BLOCKED because review is required. The epoch is unchanged: the head and main both have epoch 220.

Verdict: the P3 is fixed and all 18 comments survive. One formatting fix to the test file is still needed before merge.

ghost 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.

Automated review notice: This comment was posted by an automated review agent. It is not an independent human review and does not replace one.

Incremental review from d0d142e3 to 90ae756fd352d2f88e1ceedd147e10b653d66c6b. The only new commit, 90ae756f, joins the waitFor(...) call at packages/cli/src/__tests__/pi-tui-runner.test.ts:9027 onto one line. That was the formatting issue behind the previous P2, so the format:check failure is resolved. There are no other changes.

All earlier findings are now closed: the dropped overflow annotations, the protocol compatible-change declaration, the multi-line quote prefixes, and formatting. I found no P0–P3 issue at this head. CI on this exact head passed, and the branch merges cleanly with main.

ghost left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Verified at 90ae756fd:

  • the quote-side changes survive in all five QuoteRef pipeline files;
  • rewind_unsupported_quotes is gone in favour of restaging;
  • a06a9e293 and 27a82ea71 are replayed;
  • the quote-only side-close guard coexists with #6070's kept-draft abort and the /new drain.

The compatible-change declaration for the TURN_MESSAGE_QUOTE_MAX_COUNT re-export, pinned at epoch 220, matches the guard README ("moving a constant").

me2seeks's P2 is still half open. The count cap is in, but the "aggregate crosses the single-message limits" case he asked to cover also includes bytes. You flagged that edge yourself, and the latest automated review treated the finding as closed. Host admission enforces TURN_MESSAGE_CONTENT_MAX_BYTES (52 KiB) and TURN_MESSAGE_TEXT_MAX_BYTES (48 KiB) in addition to the 16-quote count (turn.ts:84-86), while acceptRetraction caps only the count (pi-tui-runner.ts:1590-1591).

Concretely: two queued messages, each carrying a ~28 KB large-paste QuoteRef, are each admissible on their own. After a Shift+Left retraction they become one ~56 KB payload, which is rejected with Message content exceeds byte limit even though only two quotes are staged. restageForRetry then restores the same inadmissible staging, so every retry fails, and the only way out is /quotes clear, which discards every excerpt.

Please budget staging by encoded size as well as count (spill the rest into the draft or a follow-up message, guarded by the text limit), and add a regression for the aggregate-bytes case.

Minor:

  • The two new notices (pi-tui-runner.ts:1609, :2588) are hardcoded English behind the check-tui-copy allowlist, while the rest of the /quotes copy is localized.
  • The merge reintroduced the seven pre-split tests instead of main's table-driven #6070 versions, so the diff is no longer quote-scoped.

@ggbdpq

ghost commented Oct 18, 2026

Copy link
Copy Markdown
Contributor Author

Re-reviewed at 5c6dac6e8 — each item of your 10-14 review:

Bytes budget (the half-open half of me2seeks's P2) — fixed in 3fba85aed.

acceptRetraction now projects the exact content a TUI submit will carry — { text, quotes }, the shape runtime-host-session-driver.#submitMessage builds — and demotes staged quotes into the restored draft as quoted text (newest first, matching the count cap's prefix preference) until the projection fits both TURN_MESSAGE_TEXT_MAX_BYTES and TURN_MESSAGE_CONTENT_MAX_BYTES. The two limits are re-exported from the protocol index so the TUI measures with the same constants the decoder enforces; the compatible-change declaration is renamed and re-pinned to epoch 222 (the branch integrates at current main's epoch), and the guard passes on the merge result with current main.

One honest scope note: demotion moves bytes between the structured and quoted-text lanes, so an aggregate that cannot fit one Message at all (your exact two-~28 KB case, ~56 KB > 52 KiB) ends up entirely in the draft — no staging split can make that resubmit admissible, and the failure is now the visible, editable text limit instead of an invisible staged trap. The notice names the policy (count limit vs size budget) and tells the user to trim or split the draft; the copy is localized (en / zh-CN / zh-TW).

Regression, red before the fix (the size-notice predicate never became true because the old code staged the whole aggregate — reproduced against a driver that mirrors Host admission, including the restaged-set retry):

  • degrades recovered quotes past the single-message size budget into the draft — two ~28 KiB QuoteRefs: nothing restages as a staged set (quotes:2 never renders), both excerpts ride the restored draft as quoted text, the resubmit carries no quotes, and a history-recall retry carries no quotes either (no resurrection of an inadmissible staging).
  • keeps staging quotes whose aggregate stays within the encoded content budget — over-demotion guard: two ~25 KiB quotes still stage together and resubmit cleanly through real admission.

Minor: the two hardcoded notices — fixed. The overflow notice moved into the copy catalog with the budget commit (3fba85aed, now naming count vs size policy); the side-close kept-draft / staged-quotes notices in 5c6dac6e8. All three live in the rewind catalog (en / zh-CN / zh-TW) and their allowlist entries are gone — check-tui-copy passes with the stale-allowance check enforcing the removal.

Minor: the seven pre-split tests — fixed in 1950d4954. The merge-conflict resurrection is replaced by main's two table-driven #6070 versions (drains a pending retraction before a navigation re-keys, blocks Shift+Left while a navigation re-key is still in flight); both pass on this branch. The only seam they need beyond the quote-capable driver fold is retractedTexts, which RetractingQuotesDriver now records. The diff against main for that region is now zero.

Verification on this head: pi-tui-runner 283/283 (the 2 known SIGTERM-era failures on your Windows machine pass here), pi-transcript 119 tests 0 fail, runtime-host-session-driver 87/87, tui-copy-catalog 9/9, check:tui-copy ok, repo-wide biome format clean, check:asf-headers clean, protocol epoch guard green on the merge result.

ghost 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.

Automated review notice: This comment was posted by an automated review agent. It is not an independent human review and does not replace one.

Incremental review from d0d142e3 to exact head 5c6dac6e. The range has four author commits on the same merge-base as before (6c63fa05), with no rebase and no main merge: 90ae756f (format fix), 1950d495 (restores main's table-driven retraction fencing tests), 3fba85ae (budgets recovered quote staging by encoded message size) and 5c6dac6e (localizes the side-close notices). Protocol files are touched: the re-export in protocol/index.ts is widened, and the compatible-change declaration is renamed and re-pinned.

Previous findings

  • P2, format:check failed on the test file: fixed. 90ae756f collapses the waitFor to one line. npx biome format . on this head reports "No fixes applied" across 2349 files, and the CI test job (which runs format:check) passes.
  • P3 (optional), an excerpt line starting with comment: looks the same as the annotation: still open. This is not touched in this range and does not block merge.

Increment review

  • 1950d495: the PR no longer re-adds the seven pre-split fencing tests. Compared with merge-base 6c63fa05, the test file now only adds quote-scoped tests and drops none of main's tests.
  • 3fba85ae: fitsSingleMessageAdmission measures Buffer.byteLength(JSON.stringify({text, quotes?})). That is the same shape runtime-host-session-driver#submitMessage sends (the TUI never passes modelText), and the same measure requireEncodedByteLimit applies against TURN_MESSAGE_CONTENT_MAX_BYTES (52 KiB), plus the 48 KiB text check. This closes the case where two queued ~28 KiB quotes left a staged set that could never be admitted. The new regression and the over-demotion guard both pass. The size and count notices are now localized.
  • 5c6dac6e: the two side-close notices move into the en/zh-CN/zh-TW rewind catalog, and their allowlist entries are removed. check-tui-copy passes.

New findings

  • P3, the size budget can demote quotes that never needed it, and it ignores an existing editor draft (pi-tui-runner.ts:1606, 1631). The text check does not depend on the quotes. So when the joined retracted text alone is over 48 KiB (for example, two ~30 KiB queued texts), every staged quote is turned into draft text, even small ones that would still fit as structured quotes once the user trims the text. They lose label and sourceTurnId for no gain. Also, restoreDraft puts the restored text in front of any text already in the editor, but the projection measures only retracted.text plus the overflow. A pre-existing draft can therefore push the resubmit over the limit. The user can still recover by editing, so neither case is the old "only /quotes clear" trap. A related point: moving a quote into the text keeps its bytes inside the same content budget. In practice the loop is all-or-nothing, so "demote everything when over budget" would say the same thing more simply. Optional.

Protocol epoch: the head is at epoch 220, while the declaration turn-admission-limit-reexports.json pins 222 (current main's epoch). It re-exports only the existing constants TURN_MESSAGE_QUOTE_MAX_COUNT, TURN_MESSAGE_TEXT_MAX_BYTES and TURN_MESSAGE_CONTENT_MAX_BYTES, so nothing changes on the wire. I built the merge result with main 368f5c9a (clean, epoch 222) and ran scripts/protocol-epoch-check.mjs --base origin/main on it: "Protocol added a declared compatible extension at epoch 222". No collision. The --staged pre-commit mode on the branch alone would see 222 against 220 until main is merged in. That affects only local hooks, not CI.

Validation (local, exact head): after building the workspace deps, the pi-tui-runner, tui-copy-catalog and runtime-host-session-driver suites pass 379/379. biome format is clean and check-tui-copy passes.

CI / merge state: test passes on 5c6dac6e (run 39119136955, pull_request event). The PR is MERGEABLE with no conflicts against main 368f5c9a. Merge is BLOCKED because review is required.

Verdict: the previous P2 is fixed and no P0-P2 issues remain. The only open items are two optional P3s.

Comment thread packages/cli/src/pi-tui-runner.ts Resolved

ghost 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.

Automated review notice: This comment was posted by an automated review agent. It is not an independent human review and does not replace one.

Incremental review: 5c6dac6 → cf64e0a (fast-forward, one commit: "budget rewind quote staging against the real editor text").

Prior P3 (the size check ignored the editor draft and demoted every quote when the recovered text alone was too big): fixed.

  • projectedDraft() builds the same string restoreDraft writes (${restoredDraft}\n\n${draft}, or either side alone), so the budget now measures the text the resubmit will actually carry.
  • The demotion loop only runs while the projected text fits TURN_MESSAGE_TEXT_MAX_BYTES. Demoting moves bytes into the text lane, so it cannot fix a text-lane overflow; now it no longer strips quotes in that case. The draft is still over the limit, admission rejects it visibly, and the user can trim the text while the quotes stay structured.
  • The two new tests pin both cases.

Still open (optional, unchanged by this range): the older P3 about an excerpt line that starts with comment: looking like the annotation.

New findings: none.

CI: test is still running on cf64e0a. It passed on 5c6dac6, and this range only touches pi-tui-runner.ts and its test. No protocol files changed; epoch stays 222.

@ggbdpq

ghost commented Oct 22, 2026

Copy link
Copy Markdown
Contributor Author

Hi @me2seeks — following up on your Oct 13 review (head b8b41ee8). The one remaining P2 you detailed inline — a combined quote payload from multiple independently valid retracted queue entries that the Host would reject on resubmission — has since been addressed in two steps on the way to the current head cf64e0a7:

  • 87fb4fcfb: acceptRetraction stages at most TURN_MESSAGE_QUOTE_MAX_COUNT recovered quotes and inlines the remainder into the resubmit text, so nothing is silently dropped;
  • 3fba85aed: staging is additionally budgeted by encoded size, so an aggregate crossing the single-message limits can't exceed the admission envelope either. Both behaviors are covered by the suite you asked for (several quoted queue entries whose aggregate crosses the limits).

Since your review: @liugddx verified the quote pipeline at 90ae756fd (Oct 14), the retraction/switch fencing was split into #6070 as you and liugddx discussed, and Astro-Han's incremental reviews through cf64e0a7 report no new findings. All 25 review threads on this PR are resolved, CI is green, and the branch is MERGEABLE against current main. Could you re-review when you get a chance?

ghost 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.

Automated review notice: This comment was posted by an automated review agent. It is not an independent human review and does not replace one.

Integration follow-up for unchanged head cf64e0a7a0026e12e3d2bc63e8a83d7fa9f6a159: one P3 integration update is needed. A static merge with main 15d0a0dd19d39e2bc09ae35940e432c636982315 is clean, but the actual protocol guard rejects the merged tree because turn-admission-limit-reexports.json still declares epoch 222 while the merged protocol is at 228.

I fetched the head again and inspected its protocol contribution: it re-exports the existing turn-admission constants and adds that compatible-change declaration. The merged protocol delta is only packages/runtime-host/src/protocol/index.ts. Passing the actual declaration through parseDeclaration reproduces the mismatch; changing only its epoch to 228 in the guard input makes the real parser and compatibility evaluator pass. Please rebase onto the actual target, re-check that the compatibility explanation still holds, pin the declaration to the resulting epoch, and rerun the guard. A compatible constant re-export does not by itself require a new wire epoch.

This is a P3 declaration/integration issue, not a newly established runtime defect. The prior quote-staging fixes remain closed. Existing branch-head CI test is successful, but it does not establish that the current merge result passes this guard. I did not rerun TUI behavior, builds or the broader test suite for this narrowly scoped follow-up.

ghost 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.

Automated review notice: This comment was posted by an automated review agent. It is not an independent human review and does not replace one.

Reviewed 305f411588cc94391788f671b2f66ed58bd50010 against cf64e0a7 and current main. The merge commit's tree exactly matches Git's clean automatic merge with main; the two following commits only re-pin and format packages/runtime-host/protocol-compatible-changes/turn-admission-limit-reexports.json:2. The previous P3 is fixed: the declaration now agrees with epoch 228, and the actual protocol guard accepts the existing-constant re-export as compatible. Restoring only its old 222 pin makes the actual declaration parser reject it. There is no new wire change from that re-export and no confirmed new P0–P2 issue.

The normal clean root build passed using dependencies/patches freshly installed for the immediately preceding head with byte-identical dependency inputs. Six CLI/core test files completed with 503 passes and 3 skips, including quote staging, rewind/retraction, transcript rendering, driver and localized command behavior. Declaration Biome, ASF headers, diff checks and clean static merge passed. Earlier quote correctness fixes remain in the code; this follow-up does not repeat their complete historical negative-control matrix.

Current-head CI 39964209495 failed four Runtime Host startup/wait cases: the old-epoch message test, one busy event-wait case, and two Host-kernel readiness/launcher cases. All four pass when selected locally. The runtime implementation is identical to main, the Host implementation differs only by the protocol index's constant re-exports, and main's run 39947633160 succeeded. I have not established that this PR caused those CI timeouts or independently reproduced them on main. I requested one rerun of the failed job; it is not yet a successful current-head CI result.

The PR is conflict-free. I did not run the entire Runtime Host or repository suite, native Windows terminal behavior, or build a separate synthetic merge tree. Recheck the compatible declaration's pin if another protocol epoch lands first.

@Astro-Han

ghost commented Oct 23, 2026

Copy link
Copy Markdown
Contributor

Automated review notice: This comment was posted by an automated review agent. It is not an independent human review and does not replace one.

CI follow-up for unchanged head 305f411588cc94391788f671b2f66ed58bd50010: the single rerun of CI 39964209495, attempt 2 succeeded. The current-head test check is now successful and the PR is mergeable against current main 15d0a0dd.

The previous four Host startup/wait failures do not remain as a pending CI result. Their cause was not established as a PR regression; success on the same commit does not establish the original timeout's cause either. The code review and its validation limits remain unchanged. This follow-up checks CI and commit identity only; I did not run additional local tests or a new code review.

@ggbdpq

ghost commented Oct 28, 2026 •

Copy link
Copy Markdown
Contributor Author

Self-audit note (three-pillar review of the open PRs): three sub-arms of the restage/supersede flow are not directly pinned by a test — (1) supersedePendingRestage advancing the generation on a quote-less plain submit, (2) the /quotes clear empty-state supersede arm, (3) takeDraftQuotes' early return for turn-staged drafts. The adjacent tests (generation preemption, /quotes list) partially overlap each, and the main rewrite/staging paths are pinned. Recording the boundary here; happy to add table-driven pins if you want them.

@github-actions github-actions Bot added the stale No qualifying activity within the lifecycle policy window label Nov 23, 2026
@github-actions

ghost commented Nov 23, 2026

Copy link
Copy Markdown

This pull request has had no new commits for 30 days and has been marked stale. It will be closed in 7 days unless a new commit is pushed.

Comments do not reset this timer: only a new commit does. If the pull request is intentionally long-lived, a maintainer can apply the pinned label.

Rewinding to a turn that carried quotes used to fail closed with
rewind_unsupported_quotes, because the TUI could only refill the
human-facing text and the replacement submit would silently drop the
turn's structured context (apache#5109).

The runtime-host driver now returns the rewound turn's QuoteRefs
verbatim and forwards quotes given to submitMessage through
turn.message.submit, whose admission already accepts them (only
session-context attachments are Host-owned). Attachments and directory
references still fail closed, since the TUI cannot re-attach files.

The TUI stages the restored quotes keyed to the branched session: the
status line carries a quotes:<n> segment while staging is live, bare
/quotes lists the staged excerpts, /quotes clear discards them, and the
first admitted submit consumes the staging while a refusal or failure
restages it for the retry. Retractions restage a queued message's
quotes, capped at the per-message admission budget, and side-view
drafts carry their staged quotes across toggles.

Rebased onto the TypeScript line tip 9175a2b (upstream main has since
switched to the rust-preview line).

Part of apache#5109

Generated-by: GLM-5.3-Flash (ZCode)
@ggbdpq

ghost commented Nov 24, 2026

Copy link
Copy Markdown
Contributor Author

Rebase & full-chain verification refresh (2026-11-25)

Context: upstream main switched to the native/rust-preview line after 9175a2b8 (2026-11-22), removing the TypeScript app stack this fix targets. Per contributor decision, this PR is re-verified against the last TypeScript main tip 9175a2b8fc04edeac87423d90ff637bbdf4ad45d (2026-11-22) so it stays reviewable/mergeable when the TypeScript line returns.

Rebased onto 9175a2b8, 305f411588cc94391788f671b2f66ed58bd50010 → 1648b1d112e4e6a0cf6520fbc56e73f279ded640, force-pushed. Note on history: the branch's old 49-commit stack (interleaved upstream merges and the retraction/switch-fencing split that upstream already landed) did not replay meaningfully onto the new base, so the rebased result is a single squashed commit carrying the quote-staging feature; the fencing half it once split out is already in 9175a2b8 and was preserved from the base side during conflict resolution.

Check Result
Branch fix/tui-rewind-quote-staging
Rebase conflicts resolved across pi-tui-runner.ts, session-driver.ts, runtime-host-session-driver.ts, tui-copy-catalog.ts, test files (base-side fencing kept verbatim; quote-staging feature re-applied on top; base-side evolutions — holdSwitchWindow, rewind copy catalogs, zh-TW locales — retained)
git am 1 squashed patch applies cleanly onto 9175a2b (throwaway worktree)
Build @maka/core, @maka/runtime-host, maka-agent (tsc -p) all clean
Tests pi-tui-runner.test.js: 297/299 pass — the only 2 failures (restores the terminal before exiting on SIGTERM, forces signal exit when outer cleanup never settles) reproduce identically on pristine 9175a2b8 (baseline-prefixed: Windows signal semantics, actual 'SIGTERM' vs expected null; unrelated surface); pi-transcript.test.js: 117/119 (2 skipped, 0 fail); runtime-host-session-driver.test.js: 88/88; node scripts/check-tui-copy.mjs: ok (18 files)
Ablation rewound-quote staging block disabled in the runner → 29/299 red (incl. stages a rewound turn quotes into the replacement submit, discards staged quotes only through the explicit /quotes clear, the restage family — waited 250ms for a predicate that never became true: the quotes:1 status segment never appears) → re-applied → 297/299 green
Sibling sweep rg rewind_unsupported_quotes → 0 remaining references (fail-closed refusal fully replaced by quote carriage); QuoteRef pipeline checked end-to-end: session-driver.ts exposes quotes on the rewind result (L84) and submit options (L136); the runtime-host driver forwards at 3 sites (submit L686, queue.retract L738, rewind L1044); the runner's staging machinery has 14 touch points (setStagedQuotes/takeDraftQuotes/stagedRewindQuotes); retractQueued contract typed MakaRetractedMessages (L139/205)
Lint / headers biome check --linter-enabled=true on touched sources: clean; npm run check:asf-headers: pass
Real-path repro Not verified locally — a live rewind inside the interactive TUI against a running Runtime Host needs an interactive terminal session; covered by the deterministic TUI regression tests (picker → rewind → staged quotes:1 status → replacement submit carries the QuoteRefs verbatim)

Attribution: original fix by @ggbdpq; rebase, conflict resolution & verification refresh by GLM-5.3-Flash (ZCode).

@ggbdpq
ggbdpq force-pushed the fix/tui-rewind-quote-staging branch from 305f411 to 1648b1d Compare November 24, 2026 18:32
@github-actions github-actions Bot removed the stale No qualifying activity within the lifecycle policy window label Nov 25, 2026

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

effort/XXL Over 2500 readable lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants