Skip to content

Fix prompt cache invalidation for active goals#17

Open
brandon93s wants to merge 1 commit into
prevalentWare:mainfrom
brandon93s:fix/cache-stable-system-reminder
Open

Fix prompt cache invalidation for active goals#17
brandon93s wants to merge 1 commit into
prevalentWare:mainfrom
brandon93s:fix/cache-stable-system-reminder

Conversation

@brandon93s

Copy link
Copy Markdown

Summary

Fixes #13 by keeping the goal-mode system reminder byte-stable while an objective and mode remain unchanged.

Active goals currently interpolate live elapsed time, token usage, remaining budget, auto-continue count, checkpoints, and status into output.system[0] on every model request. Prefix-based prompt caches therefore stop matching at the first changing counter, causing most of a long session's context to be processed as uncached input on every tool-call round trip.

This change separates stable goal guidance from dynamic operational state:

  • The per-request system reminder retains the objective, continuation behavior, evidence requirements, fidelity guidance, and completion/blocking audit rules, but omits live counters and checkpoints.
  • Plan-mode and paused reminders likewise contain only stable objective and mode guidance.
  • Dynamic budget/status values remain available through goal tools, the TUI, compaction context, and the trailing auto-continuation prompt, where they do not invalidate the reusable system prefix.
  • The generated server bundle is rebuilt for package consumers.

Regression Coverage

The server-hook test now renders an active-goal system prompt, records changed token usage and a new assistant checkpoint, renders the prompt again, and requires the two outputs to be exactly equal. It also asserts that volatile token and checkpoint labels are absent from the system reminder.

Validation

  • bun run lint
  • bun run typecheck
  • bun test (64 passing)
  • bun run build
  • npm pack --dry-run

nemowang2003 added a commit to nemowang2003/opencode-goal-plugin that referenced this pull request Jul 21, 2026
@danyel117

Copy link
Copy Markdown
Contributor

Thanks for addressing the prompt-cache invalidation. The active-goal reminder is now byte-stable when the objective and mode are unchanged, so the core direction looks correct.

I found a few semantic regressions that should be addressed before merge:

  1. Safety-limited goals are reported as paused. systemReminder() currently maps every open non-active state to the literal Status: paused. This hides budgetLimited and usageLimited, including their stopReason and wrap-up requirement. I reproduced a goal with status: budgetLimited and stopReason: token budget reached (10/10); the generated reminder only reported Status: paused. In Plan mode, the reminder also recommends switching to Build and resuming without mentioning that a safety limit was reached. Please preserve the actual stable status and stop reason/blocker, and retain the “do not start new substantive work; wrap up” guidance for limited goals.

  2. Fixed configured limits are removed unnecessarily. tokenBudget, maxAutoTurns, and maxDurationSeconds are stable for the lifetime of a goal, so keeping them in the active reminder would not invalidate the prompt cache. The volatile fields (timeUsedSeconds, tokensUsed, remainingTokens, autoTurns, checkpoints/status updates) can be omitted independently.

  3. The regression coverage only exercises an active goal. Please add cases for paused, budgetLimited, usageLimited, and Plan + limited states, and preserve the existing idempotence assertion that applying the system transform twice to the same output does not duplicate the reminder.

Local validation otherwise passed for me:

  • bun run typecheck
  • bun run lint
  • bun test (64 passed)
  • bun run build
  • bun run pack:dry-run
  • git diff --check main...HEAD

Once the distinct paused/limited semantics are preserved without reintroducing volatile counters, this should be ready for re-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.

[Bug]: Prompt-cache hit rate collapses (85%+ → ~40%) for active goals — live-mutating counters injected into the cached system prompt

2 participants