Skip to content

perf: align nudge/system prompts with pi-side direct-action discipline - #439

Open
ranxianglei wants to merge 1 commit into
masterfrom
2026-09-18_nudge-prompt-align-bcp
Open

ranxianglei wants to merge 1 commit into
masterfrom
2026-09-18_nudge-prompt-align-bcp

Conversation

@ranxianglei

Copy link
Copy Markdown
Owner

Problem (#436)

With compress.candidates enabled, the standing prompt and nudge guidance steered the model into a speculative acp_status pre-check turn before compressing listed candidates ("use acp_status for a fresh view", "call acp_status first"). On local models each extra round trip costs 15–23s, and the extra small turn amplifies prompt-prefix invalidation after compression.

Fix (prompt-only, aligned with billion-context-pi / acp-kernel discipline)

The candidate list is already authoritative: planCompressionCandidates() validates every MICRO/EPISODE entry against the real range executor at nudge construction (lib/messages/inject/candidates.ts) — stronger than the kernel's static suggestions. So only the prompt discipline needed porting; no arming/state/tool changes were required.

  • lib/prompts/context-limit-nudge.ts — CANDIDATE_GUIDANCE now states candidates were validated when the nudge was built; compress directly; on a stale-ID failure run acp_status once and re-issue using only reported refs.
  • lib/prompts/system.ts — candidate bullet de-hedged ("do not call acp_status first"); new failure-recovery bullet (no arithmetic range adjustment; re-issue same turn, batched); removed the MULTI-TIER "call acp_status first" paragraph.
  • lib/prompts/compress-range.ts — CANDIDATE GUIDANCE tail: direct-action + post-failure recovery instead of "use acp_status when stale".
  • acp_status remains fully functional as an optional refresh/diagnostic path; stale-plan and structure-version validation untouched.

Not ported verbatim from the kernel: "every successful compress renumbers the remaining refs" — opencode-acp refs are sticky per raw message ID (lib/message-ids.ts), so the recovery line is phrased generically.

Tests

  • tests/prompts.test.ts, tests/nudge-text.test.ts: constant-level regression tests pinning the new wording and asserting removal of the old hedging phrases.
  • tests/compression-candidates.test.ts: multi-turn injectCompressNudges regression test per AGENTS.md §5.7.1 — two consecutive calls sharing one SessionState, asserts shouldInjectThisTurn + lastPerMessageNudgeTokens/lastNudgeShownTokens side effects after each turn, rendered nudge carries the new guidance without old hedging, production-style preserveRecentMessages: 20. Verified to exercise the max-limit anchor path (guidance renders only once usage crosses maxContextLimit).

Verification: typecheck ✓, prettier (changed files) ✓, build ✓, full suite 1270/1272 — both failures are environmental in the review sandbox (read-only /tmp; tests/soft-block.test.ts:14 mkdir and tests/inactive-block-decompress.test.ts:206 hardcoded /tmp toFile path) and reproduce independently of this diff.

No version bump (release branches only).

Closes #436

Listed compression candidates are validated against the real range executor
at nudge construction, so the prompt no longer steers the model into a
speculative acp_status pre-check turn before compressing. acp_status stays
available as an optional diagnostic/refresh path and is mandated only for
failure recovery (re-issue compress in the same turn using only reported refs).

- context-limit-nudge CANDIDATE_GUIDANCE: validated-at-build-time wording
- system prompt: candidate bullet de-hedged, failure-recovery bullet added,
  MULTI-TIER 'call acp_status first' paragraph removed
- compress-range CANDIDATE GUIDANCE tail: post-failure recovery instead of
  'use acp_status when stale'
- regression tests pin new wording / absence of old hedging
- multi-turn injectCompressNudges regression test per AGENTS.md 5.7.1
  (shared SessionState, side-effect assertions, preserveRecentMessages: 20)

Closes #436
@github-actions

Copy link
Copy Markdown
Contributor

📦 Built Plugin Artifact

Branch: 2026-09-18_nudge-prompt-align-bcp (1501b2c)

Option A — Install from npm PR tag (recommended)

opencode plugin opencode-acp@pr-439 --global

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

Option B — Install from GitHub

opencode plugin "github:ranxianglei/opencode-acp#2026-09-18_nudge-prompt-align-bcp" --global

Option C — Download artifact

  1. Download the artifact from the Actions run
  2. Extract the tarball and install:
tar xzf opencode-acp-pr439.tgz
cp -r package/dist ~/.cache/opencode/packages/opencode-acp@latest/node_modules/opencode-acp/dist
  1. Restart opencode to pick up changes.

This comment is automatically updated on each push.

@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

PR #439 verification — code confirmed, CI green, ready for human merge.

Treated this as already-completed work (per the ework-agent-pr marker): pulled the branch, verified the diff + CI rather than redoing it. No changes made — CI is green and nothing needed fixing.

What the change does (prompt-only; no logic/state/tool changes):

  • Removes the standing instruction to run acp_status before compressing listed candidates. The premise holds up: planCompressionCandidates() (lib/messages/inject/candidates.ts:466) validates every surviving MICRO/EPISODE entry against the real executor (prepareExecutableRangePlans) at nudge-build time, gated by a selectionMatchesSource() drift check (candidates.ts:429) → omitted as executor-selection-drift/executor-rejected otherwise. So the list is authoritative when built, and the pre-check turn was pure overhead (15–23s/round-trip on local models + extra prefix invalidation).
  • Adds same-turn failure-recovery wording: stale ref → run acp_status once, re-issue with only reported refs, batched; no arithmetic range math.
  • acp_status stays fully functional as an optional diagnostic; stale-plan / structure-version validation untouched.

Files: lib/prompts/context-limit-nudge.ts, lib/prompts/system.ts, lib/prompts/compress-range.ts (+ devlog REQ/WORKLOG, 3 test files). I swept every remaining acp_status mention in lib/prompts/ — none still tell the model to pre-check before compressing; the rest are tool-definition lines, a historical-ref safety note (system.ts:63, about past compress calls), or optional "for details" pointers.

Independent verification I ran:

  • typecheck ✓
  • Full suite 1270/1272 — the 2 failures are environmental and reproduce without this diff: tests/soft-block.test.ts (EACCES … mkdir '/tmp/…') and tests/inactive-block-decompress.test.ts (hardcoded /tmp toFile path rejected by the allowed-paths guard). Neither file is touched by this PR.
  • Targeted tests/prompts.test.ts + tests/nudge-text.test.ts + tests/compression-candidates.test.ts: 35/35 pass, including the 4 new wording-pinning regression tests (direct-action bullet, same-turn failure recovery, old-hedging absence).
  • CI on head 1501b2c0: e2e ✓ build ✓ build-artifact ✓ test(22) ✓ test(24) ✓ pr-validation ✓ — all green.
  • No version bump — correct per §5.1.1.1 (release branches only); pr-validation confirms branch name + devlog presence.

Two things to note before merge:

  1. Branch is 9 commits behind master (06efd39c → 026dbe73). GitHub reports mergeable: true (no conflicts) and I confirmed zero file overlap between this PR and those 9 commits (they touch index.ts, lib/hooks.ts, lib/messages/*, and unrelated tests). A quick rebase onto current master gives clean history + fresh CI on the latest base; merging as-is is also safe.
  2. No formal reviews recorded yet. §5.3 requires ≥2 independent agent reviews for lib/ changes. This pass counts as one; a second independent review is still outstanding before a human merges.

Bottom line: code is correct and tightly scoped, premise verified, CI fully green. Ready for a human to merge (rebase-then-merge recommended); the merge itself stays human-only per policy.


中文摘要:核对已完成的 PR #439(纯提示词改动——让模型直接压缩"构建时已用真实执行器校验过"的候选、不再先调 acp_status,失败才在同轮兜底重试)。逐条验证了 diff 与描述一致、核心前提成立(candidates.ts 确实在 nudge 构建时对每个候选跑真实执行器并做 drift 校验)、typecheck 通过、全量测试 1270/1272(仅 2 个与本 diff 无关的只读 /tmp 环境失败)、CI 六项全绿。分支落后 master 9 个提交但与本 PR 零文件重叠、可无冲突合并(建议 rebase 后合并);仅剩 §5.3 要求的第二次独立 agent review 尚未记录,合并操作按规范由人工执行。

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.

perf: nudge-driven smart compression requires redundant model round trip

1 participant