Synced from monorepo

Synced from monorepo

Changes:
- Shell: accept target response id on rewind execute
- Shell: stamp response id on chat user message chunks
- Worktree: optional rebuild and stale git registration cleanup in auto-GC
- Worktree: kind-aware auto-GC TTLs and config knobs
- Worktree: macOS process CWD scan and Unix PID liveness for GC guards
- Worktree: automatic throttled GC on startup (Linux age-based; non-Linux dead-only)
- Pager: add `[ui].combine_queued_prompts` to batch queued follow-ups
- Shell: stop overwriting user skills
- Tools: read markdown in `skills/` directories untruncated
- `/usage` shows per-session token and dollar usage in the TUI
- Security: prompt on environment-dumping `ps` variants
- Security: always-safe `kubectl` no longer runs arbitrary kubeconfig credential plugins without permission
- Tools: make scheduler deletion durable
- Shell: add relocation storage primitives
- Shell: give side model calls their own conversation ids
- Fix five workflow-runtime bugs (budget, pause, cancel, reconnect)
- Security: peel `env -S` / `--split-string` operands in the Bash permission gate (managed deny/ask)
- Pager: expose doctor in the TUI
- Security: block unauthorized RCE via abused safe commands
- Pager idle watcher cue: "1 subagent still running" instead of "watching · 1 subagent"
- Security: block `rg --pre` arbitrary code execution in auto-mode
- Voice: diagnose silent-mic failures (macOS permission) and add doctor/terminal-setup Voice section
- App builder deployer: `allow_forking` and `show_built_with_grok`
- Pager: stop stacking duplicate "Worked for" markers on parked turns
- Shell: support `max` as a distinct reasoning effort tier
- Tools: serialize background `/loop` fires on the whole work unit
- Shell: add working-directory relocation state primitives
- Proto: `ClientToolResult` and `ChatConfig` client-side tools
- Shell: model providers
- Chat: select App Builder product on the Build path
- Shell: attach author identity to feedback when the deployment opts in
- Doctor: fix for SSH wrap setup
- Workflow authoring skills: create-workflow and import-claude-workflow docs
- Add read-only grok doctor
- Sandbox: apply Landlock without a controlling TTY
- Pager: recover image paste over grok wrap on headless remotes
- Pager: make actions screen-mode aware
- Shell: resume sessions when the working directory moves
- Pager: centralize terminal diagnostics
- Workspace: gate inline shell file access
- Pager: centralize terminal probes
- Pager: edit minimal prompts in an external editor
- Pager: standardize backgrounding on Ctrl+B
- Shell: recap rides the parent turn's prompt cache
- Tools: add scheduler lifecycle version clock

Source-Revision: 0f4d7c91b8b2b408333f6de1e8a76cb8eaa71899
This commit is contained in:
grokkybara[bot] 2026-07-21 18:10:23 +00:00
commit 3af4d5d398
556 changed files with 56609 additions and 21892 deletions

View file

@ -4,6 +4,10 @@
//! [`SamplingEvent`]s. Pure: no I/O, no shell coupling.
use std::collections::BTreeMap;
use std::sync::{
Arc,
atomic::{AtomicBool, Ordering},
};
use std::time::{Duration, Instant};
use futures_util::StreamExt;
@ -45,8 +49,15 @@ pub(crate) fn responses_event_has_meaningful_content(event: &rs::ResponseStreamE
ResponseStreamEvent::ResponseCodeInterpreterCallCodeDone(event) => !event.code.is_empty(),
ResponseStreamEvent::ResponseCustomToolCallInputDelta(event) => !event.delta.is_empty(),
ResponseStreamEvent::ResponseCustomToolCallInputDone(event) => !event.input.is_empty(),
ResponseStreamEvent::ResponseFailed(event) => {
!event.response.output.is_empty()
|| event
.response
.usage
.as_ref()
.is_some_and(|usage| usage.output_tokens > 0)
}
ResponseStreamEvent::ResponseCompleted(_)
| ResponseStreamEvent::ResponseFailed(_)
| ResponseStreamEvent::ResponseIncomplete(_)
| ResponseStreamEvent::ResponseOutputItemAdded(_)
| ResponseStreamEvent::ResponseOutputItemDone(_)
@ -78,6 +89,11 @@ pub(crate) fn responses_event_has_meaningful_content(event: &rs::ResponseStreamE
}
}
pub(crate) fn responses_event_may_have_output(event: &rs::ResponseStreamEvent) -> bool {
!matches!(event, rs::ResponseStreamEvent::ResponseError(_))
&& responses_event_has_meaningful_content(event)
}
/// Transform a raw Responses API event stream into a stream of
/// [`SamplingEvent`]s.
///
@ -97,6 +113,24 @@ pub fn stream_responses<'a>(
request_id: RequestId,
idle_timeout: Duration,
doom_loop: Option<crate::doom_loop::DoomLoopSignalCollector>,
) -> impl Stream<Item = SamplingEvent> + Send + 'a {
stream_responses_tracked(
raw_stream,
model_metadata,
request_id,
idle_timeout,
doom_loop,
Arc::new(AtomicBool::new(false)),
)
}
pub(crate) fn stream_responses_tracked<'a>(
raw_stream: BoxStream<'a, Result<rs::ResponseStreamEvent, SamplingError>>,
model_metadata: Option<ResponseModelMetadata>,
request_id: RequestId,
idle_timeout: Duration,
doom_loop: Option<crate::doom_loop::DoomLoopSignalCollector>,
output_observed: Arc<AtomicBool>,
) -> impl Stream<Item = SamplingEvent> + Send + 'a {
async_stream::stream! {
use rs::{ResponseStreamEvent, Status};
@ -158,6 +192,10 @@ pub fn stream_responses<'a>(
}
};
if responses_event_may_have_output(&event) {
output_observed.store(true, Ordering::Relaxed);
}
// A confident server-detected loop aborts the attempt (dropping
// the SSE connection) so the retry loop can resample instead of
// streaming the burning tail. Checked before the event is
@ -658,6 +696,15 @@ mod tests {
}
}
#[test]
fn empty_failed_response_is_not_treated_as_output() {
let event = rs::ResponseStreamEvent::ResponseFailed(rs_types::ResponseFailedEvent {
response: failed_response_with_error("boom"),
sequence_number: 0,
});
assert!(!responses_event_may_have_output(&event));
}
#[tokio::test]
async fn response_failed_yields_failed_500() {
let failed = rs::ResponseStreamEvent::ResponseFailed(rs_types::ResponseFailedEvent {
@ -766,6 +813,67 @@ mod tests {
assert!(responses_event_has_meaningful_content(&completed_event()));
}
#[test]
fn output_classifier_covers_non_forwarded_backend_events() {
let queued = rs::ResponseStreamEvent::ResponseQueued(rs_types::ResponseQueuedEvent {
sequence_number: 0,
response: empty_completed_response(),
});
assert!(!responses_event_may_have_output(&queued));
let response_error = rs::ResponseStreamEvent::ResponseError(rs_types::ResponseErrorEvent {
sequence_number: 1,
code: Some("server_error".into()),
message: "failed before output".into(),
param: None,
});
assert!(!responses_event_may_have_output(&response_error));
let refusal =
rs::ResponseStreamEvent::ResponseRefusalDelta(rs_types::ResponseRefusalDeltaEvent {
sequence_number: 1,
item_id: "item-1".into(),
output_index: 0,
content_index: 0,
delta: "no".into(),
});
assert!(responses_event_may_have_output(&refusal));
let backend_progress = rs::ResponseStreamEvent::ResponseWebSearchCallSearching(
rs_types::ResponseWebSearchCallSearchingEvent {
sequence_number: 2,
output_index: 0,
item_id: "search-1".into(),
},
);
assert!(responses_event_may_have_output(&backend_progress));
}
#[tokio::test]
async fn tracked_stream_marks_non_forwarded_refusal_as_output() {
let output_observed = Arc::new(AtomicBool::new(false));
let refusal =
rs::ResponseStreamEvent::ResponseRefusalDelta(rs_types::ResponseRefusalDeltaEvent {
sequence_number: 0,
item_id: "item-1".into(),
output_index: 0,
content_index: 0,
delta: "no".into(),
});
let raw = stream::iter(vec![Ok(refusal), Ok(completed_event())]).boxed();
let _ = collect(stream_responses_tracked(
raw,
None,
rid(),
Duration::from_secs(60),
None,
Arc::clone(&output_observed),
))
.await;
assert!(output_observed.load(Ordering::Relaxed));
}
fn function_call_added_event(
output_index: u32,
call_id: &str,