Repository navigation
Description
This makes the advertised 30k threshold misleading.
Reproduction
-
Start a session whose reported context usage reaches at least 30k tokens, while most of that context is from
system instructions, loaded skills, recent content, or other retained context rather than old conversation
turns. -
Run:
/context-pivot <next phase> -
Let the agent prepare the brief and invoke context_pivot.
-
Observe:
Context pivot failed: Nothing to compact (session too small)
The same underlying error can also be seen when manually running /compact:
Compaction failed: Nothing to compact (session too small)
Root cause
OpenPI's context_pivot extension uses ctx.getContextUsage() and permits a pivot once context usage is at least
30,000 tokens.
After passing that check, it calls Pi's native ctx.compact().
Pi's compaction implementation has a different eligibility condition: it must find actual old session messages that
can be summarized and removed while retaining the recent-message budget (20k tokens by default). A session may
report more than 30k context tokens but still have no eligible historical message segment to compact.
Therefore, the OpenPI preflight condition and Pi's native compaction condition are not equivalent:
- OpenPI: total reported context is >= 30k
- Pi: there is a non-empty, discardable historical conversation segment
When only the first condition is true, the pivot starts and then fails.
Expected behavior
context_pivot should only be offered or started when native compaction can actually proceed. If it cannot proceed,
the user should receive a clear explanation and be directed to /handoff for a new session.
Suggested fix
-
Add a native-compaction eligibility/preflight API that extensions can query, ideally returning a reason when
compaction is unavailable. -
Make context_pivot use that eligibility result in addition to its context-size threshold.
-
If no discardable history exists, do not start the pivot; show a message such as:
This session has no discardable history to compact. Use /handoff to begin the next phase in a new session. -
As a fallback, translate native Nothing to compact failures into the same actionable /handoff guidance instead
of presenting it as an unexpected pivot failure.
Environment
- Pi coding agent with the OpenPI context-pivot extension enabled.
Activity
627150795 commentedon Aug 28, 2026
Hi! I am working on this issue. The current Pi extension API does not expose native compaction eligibility before calling compact(), so I will implement the smallest safe boundary: translate the native Nothing to compact failure into an actionable context-pivot message and add a regression test, without pretending to add a preflight API.
627150795 commentedon Aug 28, 2026
Implementation is ready in PR #235: #235. This is a focused, backward-compatible sub-fix for the native "Nothing to compact (session too small)" failure; the issue remains open for any broader eligibility API work.
627150795 commentedon Aug 28, 2026
Update: PR #235 is now based on the latest upstream main. The native no-history error handling remains scoped to context_pivot; focused context-pivot tests (4/4), lint, typecheck, and diff checks pass.
627150795 commentedon Aug 29, 2026
代码审计更新(对应 PR #235):
627150795 commentedon Aug 29, 2026
代码有效性审计结论:PR #235 的 native
Nothing to compact (session too small)错误映射确实能在 UI/headless 路径被触发,并能清理 pending/compacting 状态;但 Issue #24 的根因仍未消失:context usage 达到 30k 后仍可能先返回Context pivot started.,再由 native compaction 异步失败。当前 Pi 扩展 API 没有可查询的 native eligibility,因此本 PR应继续标记为“错误可见性子修复”,不宣称消除了 false-positive。testikun commentedon Aug 31, 2026
我想认领 #24 中尚未完成的核心 false-positive 子范围,不重复已合入的 PR #235(仅负责把原生错误转换为可行动提示)。
技术方案:复用 Pi 公开导出的
prepareCompaction与DEFAULT_COMPACTION_SETTINGS,在context_pivot进入ctx.compact()前,对当前ctx.sessionManager.getBranch()做原生 compaction preparation 资格检查。若 Pi 判断没有可丢弃的历史,则在同步阶段拒绝启动、保持pending/compacting状态不变,并返回与 #235 一致的/sessions引导;只有 preparation 存在时才继续走现有异步 compaction 回调。我会增加纯函数/工具回归测试,覆盖 system/context 占用达到 30k 但没有可压缩 Session message、存在可压缩历史、已 compaction 分支和 malformed/empty branch;同时保留原生错误回调作为最终防线。不会新增第二套压缩器、不会修改 Pi Session 持久化和 compaction 语义。完成后运行仓库要求的 check/test 并提交 PR。
testikun commentedon Aug 31, 2026
进度更新:当前 Pi 运行包的顶层实际导出不包含
prepareCompaction(仅类型声明暴露),因此没有引入未公开的 deep import。实现改为使用 Pi 公开的findCutPoint、sessionEntryToContextMessages和默认 compaction 配置,镜像原生的边界规则;ctx.compact()仍是最终执行权威,preflight 与异步读取之间的竞态由现有原生错误回调兜底。另外补齐了
/context-pivot命令路径:当上下文达到 30k 但没有可丢弃历史时,命令直接给出/sessions/新 Session 引导,不再排队一个随后无法调用的模型工具请求;损坏或缺少首个保留 entry id 的分支也会 fail-closed。testikun commentedon Aug 31, 2026
实现已提交 PR #320。
本 PR 修复的是 Issue #24 尚未覆盖的核心 false-positive:30k context usage 达标但没有可压缩历史时,context_pivot 不再启动;工具和 /context-pivot 命令都会在启动前 fail-closed,并保留 Pi 原生 compaction 错误回调处理检查与异步执行之间的竞态。
验证:仓库 check 通过;context-pivot 定向测试 9/9;完整 Node 测试 1079/1079(1 skip);Vitest 30/30。
testikun commentedon Aug 31, 2026
补充边界:ExtensionContext 当前不暴露 SettingsManager 的 keepRecentTokens,因此 preflight 使用 Pi 公开的默认 20k cut-point 配置;这不是新的 compaction source of truth。真正的 ctx.compact() 仍重新读取运行时配置并负责最终判定,若项目自定义 compaction 设置或分支在检查后变化,原生 onError 仍会 fail-closed 并给出相同引导。
tt-a1i commentedon Sep 9, 2026
源码对照(2026-09-09,未
pi install、未跑 TUI)。本地记录:docs/research/EXPERIMENT_CONTEXT_PIVOT_2026-09-09.md(checkouta9b40f0044ee59c360a6077c1c0bdbdbd30da10b)。资格门今天仍是 30k occupancy。
MIN_CONTEXT_PIVOT_TOKENS = 30_000+ctx.getContextUsage()。没有可丢弃历史预检。本 checkout 还没有 #235;origin/main0d17f45已有错误翻译与 headlessconsole.error,资格门本身没变。相对 #24 仍缺的: (1) Pi 按生效 Settings 给出的公开 eligibility 查询;(2) 在
ctx.compact()之前同步拒绝;(3) 模型可见的失败(不要先返回Context pivot started.)。#320 用默认 20kfindCutPoint镜像资格已被审查证伪(自定义keepRecentTokens假阴性;compaction 条目经sessionEntryToContextMessages假阳性)。Pi 0.85.1(6160683)包根仍不导出prepareCompaction,只有findCutPoint/DEFAULT_COMPACTION_SETTINGS。同意关闭评语:不要再送第二套 cut-point。Mid-tool 不是 fail-closed。 扩展
ctx.compact()是 fire-and-forget;AgentSession.compact()先abort()当前 turn。terminate: true只有 batch 内每个 finalized 结果都 terminate 才结束回合。30k 假阳性在工具路径上会先掐掉进行中的 turn,再异步Nothing to compact。失败只到 TUI notify / origin stderr,回不到已经拿到started的模型。/context-pivot命令不 compact,非 idle 只followUp——相对更安全,但仍会约一次随后可能假启动的工具。handoff ≠ pivot:同 Session brief ≠ 官方
/handoff新会话 ≠/sessions换文件 ≠ #154 rewind。本树 SETUP / 工具 description 仍写不存在的/handoffskill;origin SETUP 已改/sessions。文案债不是资格实现票。不实现、不重开 #320。#24 继续等 Pi-native eligibility API,接上后再同步拒绝。
tt-a1i commentedon Sep 9, 2026
PR 考古补充(相对此前 30k / mid-tool 对照;未
pi install)。本地记录:docs/research/EXPERIMENT_PIVOT_PREFLIGHT_320_2026-09-09.md。#320
6b14f2b比「默认 20k 预检」多三处硬门。hasDiscardableHistory()同时挡agent_start可见性、execute、/context-pivot命令。假阴性会把工具藏起来,onError兜不住——审查复现的compactCalls=0就是这个形状。try/catch → false还会把异常翻译成「无历史」。认领先写公开
prepareCompaction,一小时后改口用findCutPoint。 0.85.1(6160683)包根仍不导出prepareCompaction/CompactionPreparation。findCutPoint永远返回CutPointResult,不是谓词;shouldCompact问的是自动阈值(且读enabled),手动compact()/prepareCompaction都不把enabled: false当否决。PR 自带 9 个测试只锁默认 20k fixture 的自洽,从未拿原生prepare当 oracle,所以 check 全绿与两处 P2 同时成立。只把
prepareCompaction补进包根不够。 扩展 ctx 没有getCompactionSettings();#320 第一版认领会再撞「谁提供生效keepRecentTokens」。需要的是 Pi 拥有的、挂在ExtensionContext上的资格查询:与compact()同一 prepare 路径、带上已有的Already compacted/Nothing to compactreason、不abort()、不开始 summarization。不要再送 cut-point 克隆或 OpenPI Settings 读取器。不实现、不重开 #320。
tt-a1i commentedon Sep 9, 2026
Hook ownership (
session_compact_failed, 2026-09-09 source-read)Pi 0.85.1 (
6160683,types.tsblobeaff3a86) addssession_compact_failed. It is an after-the-fact observe hook, not an eligibility query.AgentSession.compact()throws"Nothing to compact (session too small)"/"Already compacted"beforesession_before_compactwhenprepareCompactionreturns null. The catch still emitssession_compact_failed(reason: "manual",errorMessage: "Compaction failed: …"). Overflow has its own emit.Official
examples/extensions/never subscribe. OpenPI checkouta9b40f0(peer 0.84.1) does not have the event type.origin/main0d17f45(0.8.1 / peer >=0.85.1) still does not subscribe.context_pivotonly writessession_before_compacton the customize path.This issue still waits on a Pi-owned preflight eligibility query (PIVOT_PREFLIGHT locally as
docs/research/EXPERIMENT_PIVOT_PREFLIGHT_320_2026-09-09.md). Listening tosession_compact_failedwould only observe afterctx.compact()alreadyabort()ed. That is Pi-native observe/warn, not a second compact OS. Do not adopt cyclotomy’ssession_before_compact{ cancel: true }veto.Canonical inventory:
docs/research/EXPERIMENT_OFFICIAL_HOOKS_2026-09-09.md. No new tracker.