feat(contract): add captureRenderedPrompt opt-in + .promptRendered GenerationEvent#1884
Merged
Conversation
…nerationEvent Adds `GenerationEvent.promptRendered(text:)` — an opt-in diagnostic event that surfaces the fully-assembled prompt string to the consumer immediately before the first token. Off by default via `GenerationConfig.captureRenderedPrompt: Bool = false` to avoid unintentional retention of sensitive prompt content. - `GenerationEvent` gains the new case between `prefillProgress` and `token`. - `GenerationConfig` gains `captureRenderedPrompt: Bool = false` (runtime-only; excluded from Codable persistence like `jsonMode`/`thinkingMarkers`). - `GenerationQueue.dispatchToBackend` wraps the backend stream to prepend the event on both the TokenCountingBackend (preflight) path and the standard non-template / template paths when opt-in is true. - `GenerationStreamConsumer` maps `.promptRendered` to `.ignore` (advisory metadata, no chat-message state mutation). - All exhaustive `switch` sites updated: `BackendSeamConsumer`, `EventRecorder`, `FixtureComparator`, extractor-test `eventKey` helpers, `ScenarioRunner`, and per-backend test files. - `PromptRenderedEventTests` (XCTestCase, `ManifoldInferenceTests`) covers: opt-in fires event as first in stream, payload contains user message, token events follow, opt-out emits no event, event fires exactly once per turn. Closes #1879 Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
GenerationEvent.promptRendered(text:)— a new opt-in case that surfaces the fully-assembled prompt string as the first event in the generation stream.GenerationConfig.captureRenderedPrompt: Bool = false(off by default) to prevent unintentional retention of sensitive prompt content.GenerationQueue.dispatchToBackendby wrapping the backend stream on both theTokenCountingBackendpreflight path and the standard non-template/template path.What changed
Sources/ManifoldContract/GenerationEvent.swiftpromptRendered(text: String)placed betweenprefillProgressandtoken.Sources/ManifoldContract/InferenceBackend.swiftpublic var captureRenderedPrompt: Bool = falseonGenerationConfig. Runtime-only; excluded fromCodablepersistence likejsonModeandthinkingMarkers.Sources/ManifoldInference/Services/GenerationQueue.swiftdispatchToBackendwraps the returnedGenerationStreamwith a newprependingPromptRenderedhelper that yields.promptRenderedbefore forwarding all upstream events when the opt-in is set.Sources/ManifoldInference/Services/GenerationStreamConsumer.swift.promptRendered→.ignore(advisory metadata, no chat-message state mutation — mirrors.throttleDiagnosticand.kvCacheReuse).Exhaustive switch updates
BackendSeamConsumer(APIFreezeTests freeze tripwire)EventRecorder(ManifoldFuzz)ScenarioRunner(ManifoldTools)eventKeyhelpers inClaudeStreamEventExtractorTests,OllamaStreamEventExtractorTests,OpenAIStreamEventExtractorTests,OpenAIResponsesStreamEventExtractorTests(×2)CloudThinkingTokenTests,OllamaToolCallLiveReplayTests,OpenAIResponsesBackendTestsToolCallContractTests(×2),ParallelToolCallOrderingTestsTests/ManifoldInferenceTests/PromptRenderedEventTests.swift(new)test_captureRenderedPrompt_true_emitsPromptRenderedAsFirstEventtest_captureRenderedPrompt_true_promptRenderedTextMatchesUserMessagetest_captureRenderedPrompt_true_tokenEventFollowsPromptRenderedtest_captureRenderedPrompt_false_noPromptRenderedEventtest_captureRenderedPrompt_explicitFalse_noPromptRenderedEventtest_captureRenderedPrompt_true_emitsExactlyOnePromptRenderedEventTest plan
swift build --build-tests --traits Server,Macros— build complete, zero errorsscripts/test.sh --profile spike --spike-module ManifoldInferenceTests --skip-update— 2888 tests passed, 0 failuresBackendSeamConsumerexhaustive freeze tripwire compilesPromptRenderedEventTestscovers opt-in/opt-out, ordering, and exactly-once semanticsCloses #1879
🤖 Generated with Claude Code