mirror of
https://github.com/openai/codex.git
synced 2026-11-19 22:30:42 +00:00
## Why
Applying client context at submission time lets input stopped by a hook
affect the conversation. A queued prompt that is later blocked can also
supersede the context attached to an earlier accepted prompt.
## What changed
Keep each context update with its submitted input and apply updates in
delivery order after the input passes its hooks. Preserve context-only
submissions when a turn is suspended for host handoff before inference.
For experimental `additionalContext` on `turn/start` and `turn/steer`,
omission or `null` keeps the current set. A supplied map replaces it on
delivery, and `{}` clears it while preserving conversation history.
## Testing
Add regression coverage for context on prompts stopped by hooks, context
on accepted queued prompts, context-only host handoff, and context
delivery when continuing an idle thread.
GitOrigin-RevId: 160f4f90d9aebf5eb3ea4a939c67265a1c6422da
70 lines
2.6 KiB
Rust
70 lines
2.6 KiB
Rust
//! Verifies conditional checklist guidance preserves goal instructions and task data.
|
|
#![allow(dead_code)]
|
|
|
|
#[path = "../src/steering.rs"]
|
|
mod steering;
|
|
|
|
use codex_core::TurnInput;
|
|
use codex_core::context::ContextualUserFragment;
|
|
use codex_core::context::InternalContextSource;
|
|
use codex_core::context::InternalModelContextFragment;
|
|
use codex_protocol::ThreadId;
|
|
use codex_protocol::models::ContentItem;
|
|
use codex_protocol::models::ResponseItem;
|
|
use codex_protocol::protocol::AdditionalContextKind;
|
|
use codex_protocol::protocol::ThreadGoal;
|
|
use codex_protocol::protocol::ThreadGoalStatus;
|
|
use codex_utils_template::Template;
|
|
use pretty_assertions::assert_eq;
|
|
|
|
#[test]
|
|
fn enabled_checklist_preserves_the_original_continuation_prompt() {
|
|
let goal = test_goal("Finish the feature.");
|
|
let original = Template::parse(include_str!("../templates/goals/continuation.md"))
|
|
.expect("original continuation template")
|
|
.render([
|
|
("tokens_used", "100"),
|
|
("token_budget", "10000"),
|
|
("remaining_tokens", "9900"),
|
|
])
|
|
.expect("render original continuation prompt");
|
|
let expected: ResponseItem = ContextualUserFragment::into(InternalModelContextFragment::new(
|
|
InternalContextSource::from_static("goal"),
|
|
original,
|
|
));
|
|
let request = steering::continuation_request(&goal, /*update_plan_enabled*/ true);
|
|
assert_eq!(request.input, TurnInput::ResponseItem(expected));
|
|
}
|
|
|
|
#[test]
|
|
fn disabled_checklist_preserves_goal_text_that_mentions_the_tool() {
|
|
let objective = "Inspect update_plan.\n\n## Plan tool\nThis is user task data.";
|
|
let request =
|
|
steering::continuation_request(&test_goal(objective), /*update_plan_enabled*/ false);
|
|
let entry = &request.additional_context.as_ref().expect("goal context")["goal_objective"];
|
|
assert_eq!(entry.kind, AdditionalContextKind::Untrusted);
|
|
assert_eq!(entry.value, objective);
|
|
let TurnInput::ResponseItem(ResponseItem::Message { content, .. }) = request.input else {
|
|
panic!("expected goal continuation message");
|
|
};
|
|
let [ContentItem::InputText { text }] = content.as_slice() else {
|
|
panic!("expected goal continuation text");
|
|
};
|
|
assert!(!text.contains(objective));
|
|
assert!(!text.contains("If update_plan is available"));
|
|
assert!(text.contains("Completion audit:"));
|
|
}
|
|
|
|
fn test_goal(objective: &str) -> ThreadGoal {
|
|
ThreadGoal {
|
|
thread_id: ThreadId::new(),
|
|
objective: objective.to_string(),
|
|
status: ThreadGoalStatus::Active,
|
|
token_budget: Some(10_000),
|
|
tokens_used: 100,
|
|
time_used_seconds: 0,
|
|
created_at: 0,
|
|
updated_at: 0,
|
|
}
|
|
}
|