Skip to content

feat(prompt): expand MLX behavior protocols + KV-cache doc verification - #153

Merged
dahai80 merged 1 commit into
mainfrom
feat/mlx-prompt-kvcache-doc
Aug 27, 2026
Merged

dahai80 merged 1 commit into
mainfrom
feat/mlx-prompt-kvcache-doc

Conversation

@dahai80

@dahai80 dahai80 commented Aug 27, 2026

Copy link
Copy Markdown
Owner

Summary

Ar-plan PR #2 (P0, M1): expand local MLX behavior prompts + verify KV-cache doc accuracy.

Part 1 — Behavior protocol expansion

Two new protocol sections in src/constants/behavioral-protocols.ts:

  • getToolResultProcessingProtocol — tool failure retry limit (≤3 same-op, then STOP and report), failure-mode classification (schema error / permission denied / timeout / file not found), partial-read guard. More specific than the general error-recovery protocol.
  • getLongTaskCheckpointProtocol — 3+ step checkpoint pattern, progress survival across context compression, recovery after interruption.

Registration by tier in src/constants/mlx-system-prompt.ts (equal-replacement to stay within the compact ≤3K budget):

  • compact (32B on ≤32K context): drops getErrorRecoveryProtocol (its content overlaps the new, more-specific tool-result protocol — ≤3 retry limit + failure-mode classification subsumes the generic "retry at most TWICE" rule), keeps the two new sections + coding standards. Measured 2940 tokens (≤3000 budget).
  • standard / extended / full: keep getErrorRecoveryProtocol AND the two new sections (budget ample, general + specific coexist).

Part 2 — KV-cache doc verification

docs/model-providers.md §P1.2 already documents the accurate conclusion (defer item 8): fusion-mlx /v1/messages honors cache_control (upstream issues #196/#241/#289/#386 all CLOSED), fusion-code MLX adapter goes /v1/chat/completions dropping cache_control = large adapter refactor, not a gap. Grep found no contradiction in docs/ or src/. No edit needed.

Files

  • src/constants/behavioral-protocols.ts — +2 functions
  • src/constants/mlx-system-prompt.ts — import + compact-tier registration (compact-only branch, drops errorRecovery)

Acceptance

  • compact-tier prompt ≤3K tokens (measured 2940)
  • new sections present in compact + standard+ tiers (verified)
  • no duplicate sections across tiers (re-measured all 5 tiers clean)
  • KV-cache doc no contradiction
  • 4 gates pass

Gates

  • bun run typecheck — 0 errors
  • bun test src/__tests__/ — 537 pass, 0 fail
  • bun run lint — no new errors (baseline-identical: 1 error / 2 warnings / 1 info both before and after, all pre-existing grandfathered file-style)
  • bun run build:dev — passes

Risk

Compact-tier budget: adding 2 sections (~556 tokens) exceeded 3K → solved by equal-replacement dropping getErrorRecoveryProtocol from compact (459 tokens, subsumed by the more-specific tool-result protocol). Standard+ tiers unaffected (budget ample).

Co-Authored-By: Claude Fable 5 [email protected]

Add two behavior protocol sections for local MLX models (ar-plan PR #2):
- getToolResultProcessingProtocol: tool failure retry limit (≤3 same-op),
  failure-mode classification (schema/permission/timeout/not-found), partial
  read guard. More specific than the general error-recovery protocol.
- getLongTaskCheckpointProtocol: 3+ step checkpoint pattern, progress
  survival across context compression, recovery after interruption.

Registration by tier (equal-replacement, compact ≤3K budget):
- compact: drops getErrorRecoveryProtocol (overlaps with the new specific
  tool-result protocol), keeps the two new sections + coding standards.
  Measured 2940 tokens (≤3000 budget).
- standard/extended/full: keep getErrorRecoveryProtocol AND the two new
  sections (budget ample, no overlap concern at scale).

KV-cache (part 2): docs/model-providers.md already documents the accurate
conclusion (defer item 8): fusion-mlx /v1/messages honors cache_control
(issues #196/#241/#289/#386 CLOSED), fusion-code adapter /v1/chat/completions
drops it = large refactor, not a gap. No doc contradiction found.

Gates: typecheck 0, 537 tests pass, lint no new errors (baseline-identical),
build:dev passes.

Co-Authored-By: Claude Fable 5 <[email protected]>
@dahai80
dahai80 merged commit 2f121d1 into main Aug 27, 2026
1 check passed
@dahai80
dahai80 deleted the feat/mlx-prompt-kvcache-doc branch August 27, 2026 05:27
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