Skip to content

feat(acp): scope nudge + compress-outcome bookkeeping per session (#317) - #327

Merged
ranxianglei merged 1 commit into
masterfrom
2026-09-07_sid-scoped-bookkeeping
Sep 10, 2026
Merged

feat(acp): scope nudge + compress-outcome bookkeeping per session (#317)#327
ranxianglei merged 1 commit into
masterfrom
2026-09-07_sid-scoped-bookkeeping

Conversation

@ranxianglei

Copy link
Copy Markdown
Owner

Part of #317 — seam #3: session-scoped runtime bookkeeping.

What

Keys two pieces of per-turn runtime state by session id, so one extension instance serving multiple concurrent sessions (Prime's inline RLM model) cannot cross-contaminate them:

  • nudgeShownTurns: process-global Set<turnKey>Map<sid, Set<turnKey>>
  • compress-failure tracker: single global slot (compressFailTurnKey / compressFailCount + shared seen) → Map<sid, { seen, failTurnKey, failCount }>

This matches the isolation already used for overflowEpisodes, throttleEpisodes, and deadCompressCounts. Six methods now take a sid; call sites in src/index.ts and src/compress-tool.ts pass it, and session_shutdown drops each session's entries (memory hygiene for long-lived multi-session processes).

Scope / non-goals

Verification

  • npm run typecheck clean
  • npm test: 615 tests — 612 pass / 0 fail / 3 pre-existing skips
  • 3 new tests in tests/compress-retry.test.ts assert same-turn cross-session isolation (independent counters, per-session clear, per-session nudge ledger)
  • npm run build succeeds (self-contained bundle)

Base: master (v0.1.58).

@ranxianglei

Copy link
Copy Markdown
Owner Author

解决冲突 pull master 重写review这个 并给出一句话总结

Issue #317 seam #3: key nudge-dedup and compress-failure bookkeeping by session id.

nudgeShownTurns was a process-global Set and the compress-outcome tracker a single global slot; under a host that runs multiple concurrent sessions through one extension instance (Prime's inline RLM model) they clobbered each other. Both are now Map<sid,...>, matching the existing overflow/throttle/dead isolation pattern. Six methods take a sid; index.ts/compress-tool.ts pass it, and session_shutdown drops each session's entries.

Single-session behavior is unchanged (full suite green); three new tests cover same-turn cross-session isolation. Part of #317.
@ranxianglei
ranxianglei force-pushed the 2026-09-07_sid-scoped-bookkeeping branch from 1c14fd2 to 1f4576d Compare September 10, 2026 14:54
@github-actions

Copy link
Copy Markdown

📦 Built Extension Artifact

Branch: 2026-09-07_sid-scoped-bookkeeping (1f4576d)

Option A — Install from npm PR tag (recommended)

pi install npm:billion-context-pi@pr-327

Each push to this PR publishes a new version under the pr-327 npm tag.

Option B — Download artifact

  1. Download the artifact from the Actions run
  2. Extract the tarball and install:
tar xzf billion-context-pi-pr327.tgz
pi install ./package

This comment is automatically updated on each push.

@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

Re-reviewed after syncing onto latest master. Conflicts resolved; PR is green and mergeable.

What conflicted & how it was resolved
master landed the growth-aware re-inject floor (issue #269 / PR #316) in the same nudge-ledger code this PR scopes — so src/runtime.ts and src/index.ts collided on markNudgeShown/nudgeShownFor/the token-stamp map. I rebased this single-commit branch onto master (v0.1.65) and merged both intents rather than picking one side:

  • Kept this PR's sid-scoping: nudgeShownTurns → Map<sid, Set<turnKey>>, compress-failure tracker → Map<sid, {seen,failTurnKey,failCount}>.
  • Kept master's token-stamp feature (tokenCount, reInjectFloor, shownAt, drop-reanchor) — and also scoped the new nudgeShownTokens map by sid (Map<sid, Map<turnKey, number>>). Without that, two concurrent sessions sharing a turnKey would corrupt each other's re-anchor baseline, reintroducing exactly the cross-session leak seam fix: release workflow grep lookbehind error #3 is meant to fix.
  • session_shutdown now drops all four per-session maps together (clearDeadCompress + dropTokenScale + clearNudgeTracking + clearCompressRetryTracking) for clean memory hygiene in long-lived multi-session processes.

All call sites in src/index.ts / src/compress-tool.ts pass sid; signatures are consistent across src and tests.

Diff cleanliness — 4 files only (src/runtime.ts, src/index.ts, src/compress-tool.ts, tests/compress-retry.test.ts); every line is on-purpose. No package.json/version touched, no lockfile churn, no stray whitespace/reformat.

Verification

  • npm run typecheck — clean
  • npm test — 699 tests: 696 pass / 0 fail / 3 pre-existing skips (incl. the 3 new cross-session isolation tests)
  • npm run build — self-contained bundle OK
  • GitHub CI — all 9 checks green (test ubuntu/windows × node 22/24, e2e ubuntu/windows, docker, pr-validation, build-artifact)

One-sentence summary
This PR keys the nudge-dedup ledger and the compress-failure circuit-breaker by session id so one extension instance serving multiple concurrent sessions can't cross-contaminate their per-turn state, matching the isolation pattern already used for overflow/throttle/dead-compress — single-session behavior is unchanged.


一句话总结:把 nudge 去重账本和压缩失败熔断器按 session id 隔离,避免多会话共用同一扩展实例时互相串台(与既有 overflow/throttle 隔离模式一致),单会话行为不变;已 rebase 到最新 master、解决与 #316 重注入逻辑的冲突并同步按 sid 隔离了新增的 token 戳表,typecheck/test/build + 全部 CI 均绿,可以合并。

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