Conversation
added 6 commits
July 9, 2026 11:56
…istic-guardrails # Conflicts: # statgpt/app/chains/main.py
Address review findings on the concurrent out-of-scope guardrail: - Move the toggle from DIAL_APP_OPTIMISTIC_GUARDRAILS to a per-channel out_of_scope.optimistic flag (default off) - Route the shared performance stage through the recording via adopt_stage, so speculative debug rows are held back until commit; drop the second event gate in the agent - Reap tasks and drop un-flushed output on every exit via an async context manager (fixes a live, ungated agent task after a mid-replay flush failure) - Log committed vs discarded speculation; surface a speculative agent failure that was silently swallowed on the out-of-scope path - Extract a shared check_with_stage; rename BufferedChoice/BufferedStage -> RecordingChoice/RecordingStage, OOS_VERDICT_EVENT -> SIDE_EFFECT_GATE, resolve_skip -> try_short_circuit
- Note at spec_inputs that any real-choice object must be substituted or routed through the recording, or speculative writes leak before commit - Narrow _await_side_effect_gate docstring: it gates the main-loop tool dispatch; fake tool calls run ungated
Post-review hardening and cleanup of the optimistic out-of-scope guardrails, no user-facing behavior change. - Extract MainChainFactory._build_speculative_inputs() and split the orchestrator into _commit_speculation/_abort_speculation; add a tripwire test that rejects any un-substituted choice/stage write surface on spec_inputs. - Collapse the double try_short_circuit on the checker-only path; rename try_short_circuit -> resolve_short_circuit (returns bool). - Add ChainParameters.get_side_effect_gate accessor; type recording_choice proxies with StageI. - Deduplicate the start-new-conversation threshold check into _maybe_start_new_conversation. - Document the side-effect-free constraint on FakeCall/fake tool calls, the state deepcopy-ability contract, and the speculative-flow divergences; trim verbose comments to one-line invariant notes.
ypldan
marked this pull request as ready for review
July 9, 2026 12:51
Author
|
/deploy-review
|
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.
Applicable issues
Description of changes
The out-of-scope checker ran before the supreme agent, adding an LLM round-trip to time-to-first-token even though verdicts are almost always "in scope". When a channel opts in, the checker and agent now run concurrently: the agent runs speculatively against a recording choice, a copied history, and a deepcopied state, and only commits once the verdict confirms "in scope". Out of scope, the speculative run is cancelled and its output discarded, so the user sees exactly the sequential flow's output — minus one round-trip of latency.
RecordingChoice/RecordingStagerecord every choice write; on an in-scope verdict the buffer is flushed to the real choice and history/state committed, otherwise it is discarded. Irreversible side effects (real tool dispatch) wait on a permission gate.adopt_stage-wrapped performance stage), so nothing can leak to the real choice before commit. The substitution is built in one place (_build_speculative_inputs) and a unit test guards the invariant by rejecting any un-substituted choice/stage surface on the speculative inputs.async withcontext manager reaps both tasks and drops any un-flushed output on every exit (commit, out-of-scope, checker failure, cancellation, or a mid-replay flush failure).out_of_scope.optimistic(default off); off keeps the exact sequential check-then-agent chain.Checklist
Reviewenvironment.By submitting this pull request, I confirm that my contribution is made under the terms of the MIT license.