Skip to content

feat: opt-in branch-aware block masking via persistedMessageIds - #516

Closed
SeniorHan wants to merge 4 commits into
ranxianglei:masterfrom
SeniorHan:feat/branch-aware-blocks
Closed

SeniorHan wants to merge 4 commits into
ranxianglei:masterfrom
SeniorHan:feat/branch-aware-blocks

Conversation

@SeniorHan

Copy link
Copy Markdown

Problem

Hosts with rewindable session trees (e.g. pi's /tree navigation) can land inside a block's range after a rewind. syncBlocks keeps a block active while any covered message is in view — so after the rewind, the block's summary (which describes messages that now live on another branch, including decisions made after the rewind point) replaces the few messages still in view. The model sees a future it has not reached.

Reproduced with pi 1.4.0 + acp-kernel 0.0.101: compress e1–e4 into a block, /tree back to e2, ask anything — the summary's "future decision" is injected into the model's view.

Proposal — additive, opt-in

ProcessTurnInput gains one optional field:

persistedMessageIds?: ReadonlySet<string>;

The host passes the ids of all persisted session entries (the full session tree, not just the current branch). When provided, a block is "off-branch" when some of its covered messages are in view and others are persisted-but-not-in-view. Such blocks are masked as expanded for the turn — their in-view messages show raw instead of being replaced by the other-branch summary.

The mask is turn-scoped and never persisted: the original expanded flags are restored on the result state, so returning to the full branch reactivates the block. Messages missing for other reasons (never persisted, host-side live ids) keep the default behaviour.

Hosts that omit the field: zero behaviour change.

Implementation

  • src/branch-awareness.ts (new): findOffBranchBlocks() — pure detection, mirrors syncBlocks' baseIdOf sub-id semantics.
  • src/compress.ts: mask applied to the pipeline's initial state; restore applied to result.state; input state never mutated.
  • tests/branch-awareness.test.ts: 4 tests — masking + no-persist + input-immunity, full-branch reactivation, unknown-ids fallback, live-instance sub-id matching.

npm test → 1237/1237 (1233 baseline + 4 new), tsc --noEmit clean.

Provenance

The mask/restore mechanics are extracted from a working host-side implementation battle-tested across ~80k messages of daily pi usage (weakmap-wrapper variant in a downstream extension), moved kernel-side so every host gets it without per-host wrapping. Detection runs fresh each turn from the declared persisted set — no cross-turn state.

SeniorHan added a commit to SeniorHan/acp-kernel that referenced this pull request Oct 23, 2026
@SeniorHan
SeniorHan force-pushed the feat/branch-aware-blocks branch from 3a100fa to 857b39f Compare October 23, 2026 15:23
@SeniorHan

Copy link
Copy Markdown
Author

Reopening as #518: renamed the branch to satisfy the YYYY-MM-DD_short-title convention and applied prettier formatting (CI failures were naming + format only, code unchanged).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant