Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions MEMORY.md
Original file line number Diff line number Diff line change
Expand Up @@ -322,3 +322,5 @@ Launcher의 `latest`/`next`는 rc.8이며 실제 모델 품질 평가는 인증
- 연구 방향(사용자 결정, 2026-11-29): 모델을 바꾸기보다 지금 수준 모델(agy `gemini-3.8-flash-low`)로 높은 성능을 내는 하네스를 연구한다. 핵심은 LLM에게 무엇을 어떻게 전달하고(메모리·도구·피드백) 실행 경로를 마련하느냐다. 측정은 공식 실행기 Harbor로 Terminal-Bench 2.1(89개)을 돌리고, 실패를 전달 관점(문맥 누락·도구 계약 오해·실행 경로 없음·검증 누락·형식 오류·루프/예산)으로 분류한다. 측정 도구는 `research/harbor-bench` 브랜치에 있다(아직 PR 전).
- agy 내장 manage_task(ADR-0096, 구현·실제 모델 검증): agy 1.5.18은 planner-only agent와 deny 설정에서도 `manage_task`를 실행하고 끌 방법이 없다(agent `disabledTools` 무시, settings 키 없음, deny 규칙 무효). 기준선의 정상 응답 14%가 이 호출을 포함해 Run이 Unknown으로 멈췄다. `Action=list` 단독 호출만 허용하고 나머지 native step은 계속 실패로 닫는다. 유도 목표 비교에서 기존 2/8 정지, 수정 0/10 정지. agy 쪽 과제: 이 도구를 끄는 설정이 생기면 허용을 제거한다.
- 기준선 중간 관찰(2026-11-29): 응답이 거절되면 모델은 `previousResponseRejection.meaning`의 일반 문구만 받고 구체 이유(빠진 필드, 문자열 안 제어 문자)를 받지 못해 같은 실수를 반복했다(write-compressor 3연속 → Run 거절). 사례를 더 모은 뒤 첫 개선 후보로 본다. agy 개인 할당량(약 3.5시간·호출 700여 회) 초과로 50개 과업이 오염되어 할당량을 확인하며 다시 돌리는 중이다.
- 기준선 확정(2026-11-29, 89개): 34개 통과(38%). 실패 55개 중 32개가 `request_too_large`였다. 원인은 planning 예산(512 KiB)과 agy prompt 한도(100,000바이트)가 따로 있고 `toolOutputs`가 packing 대상이 아니라는 점이다. 나머지는 완료 주장 후 검증 실패 10, invalid 응답 3연속 7, 기타 6이다.
- 요청 한도 안 도구 출력 전달(ADR-0097 1단계, 구현·실측 진행 중): planner port가 prompt 한도를 알리고(agy는 transport 한도, HTTP는 `XGEN_OPENAI_MAX_PROMPT_BYTES`일 때만), 넘칠 때만 최근 3개를 뺀 오래된 출력 본문을 stub으로 바꾼다. 한도 안 요청은 바이트가 같다(diff-model-requests 8/8). 실측은 too_large 32과업을 설계 16·held-out 16으로 나눠 돌린다. 2단계(생략 순서 비교)는 실측 뒤 결정한다.
9 changes: 7 additions & 2 deletions crates/xgen-cli/examples/planning_boundary_probe/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -145,10 +145,15 @@ impl PlannerPort for Planner {
let mut completed = BTreeMap::new();
for output in request.context().tool_outputs() {
completed.insert(
output.output()["operation"].as_str().unwrap().to_owned(),
output.output().expect("probe outputs are not elided")["operation"]
.as_str()
.unwrap()
.to_owned(),
output.step_id().to_owned(),
);
if let Some(next) = output.output()["value"].get("next") {
if let Some(next) =
output.output().expect("probe outputs are not elided")["value"].get("next")
{
visible.extend(
serde_json::from_value::<Vec<Operation>>(next.clone())
.map_err(|_| PlannerPortFailure::Unavailable)?,
Expand Down
4 changes: 3 additions & 1 deletion crates/xgen-cli/src/agy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,9 @@ fn settings(workspace: &str) -> Value {
"allowNonWorkspaceAccess":false,"disableSlashCommands":true,"useG1Credits":false,"notifications":false,
"permissions":{"deny":["command(*)","read_file(*)","write_file(*)","read_url(*)","execute_url(*)","mcp(*)"]}})
}
fn prompt_limit() -> usize {
/// Largest prompt agy accepts through `-p` (the OS per-argument limit on Unix); larger prompts
/// fail as `request_too_large`, so the planner fits its context below it (ADR-0097).
pub(crate) fn prompt_limit() -> usize {
if cfg!(windows) { 24_000 } else { 100_000 }
}

Expand Down
41 changes: 36 additions & 5 deletions crates/xgen-cli/src/composition.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2210,6 +2210,13 @@ impl PlannerPort for LocalPlanner {
}
}

fn max_context_bytes(&self) -> Option<u64> {
match self {
Self::Remote(planner) => planner.max_context_bytes(),
Self::Disabled { .. } => None,
}
}

fn request_profile_digest(&self) -> &str {
match self {
Self::Remote(planner) => planner.request_profile_digest(),
Expand Down Expand Up @@ -2589,12 +2596,36 @@ fn remote_planner(
let spec = crate::agy::Spec::parse(base_url).map_err(|()| PublicRunError::Configuration)?;
let mut transport = crate::agy::Transport::new(spec, config.model(), limits.timeout())
.map_err(|()| PublicRunError::Configuration)?;
return Ok(OpenAiPlanner::with_external_transport(
config,
move |body, limit| transport.send(body, limit),
));
return Ok(
OpenAiPlanner::with_external_transport(config, move |body, limit| {
transport.send(body, limit)
})
.with_prompt_byte_limit(crate::agy::prompt_limit()),
);
}
OpenAiPlanner::new(config, credential).map_err(map_provider_config)
let planner = OpenAiPlanner::new(config, credential).map_err(map_provider_config)?;
Ok(match http_prompt_byte_limit()? {
Some(limit) => planner.with_prompt_byte_limit(limit),
None => planner,
})
}

/// Smallest and largest whole-prompt limit `XGEN_OPENAI_MAX_PROMPT_BYTES` accepts.
const MIN_PROMPT_BYTE_LIMIT: usize = 16 * 1024;
const MAX_PROMPT_BYTE_LIMIT: usize = 1024 * 1024;

/// Optional whole-prompt limit for an HTTP model whose context window is smaller than the Run's
/// context budget, such as a local model served with a short context (ADR-0097). It only bounds
/// the planning context the runtime builds; requests under it are unchanged.
fn http_prompt_byte_limit() -> Result<Option<usize>, PublicRunError> {
let Some(raw) = std::env::var_os("XGEN_OPENAI_MAX_PROMPT_BYTES") else {
return Ok(None);
};
raw.to_str()
.and_then(|value| value.trim().parse::<usize>().ok())
.filter(|value| (MIN_PROMPT_BYTE_LIMIT..=MAX_PROMPT_BYTE_LIMIT).contains(value))
.map(Some)
.ok_or(PublicRunError::Configuration)
}

fn map_provider_config(_error: OpenAiPlannerConfigError) -> PublicRunError {
Expand Down
3 changes: 3 additions & 0 deletions crates/xgen-cli/src/final_response.rs
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,9 @@ impl PlannerPort for ReceiptReportPlanner {
fn request_profile_digest(&self) -> &str {
self.inner.request_profile_digest()
}
fn max_context_bytes(&self) -> Option<u64> {
self.inner.max_context_bytes()
}
fn plan(
&mut self,
request: &PlannerCallRequest<'_>,
Expand Down
26 changes: 26 additions & 0 deletions crates/xgen-provider-openai/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ const PROVIDER_DIALECT: &str = "openai.chat-completions/json-schema-v1";
const JSON_OBJECT_DIALECT: &str = "openai.chat-completions/json-object-v1";
const DEFAULT_MAX_OUTPUT_TOKENS: u32 = 4_096;
const DEFAULT_MAX_REQUEST_BYTES: usize = 1024 * 1024;
/// Room for the request envelope around the planning context (`profileVersion`, `callId`,
/// `requestDigest`, keys) and a transport's own framing of the prompt (ADR-0097).
const PROMPT_ENVELOPE_RESERVE_BYTES: usize = 2048;
const DEFAULT_MAX_RESPONSE_BYTES: usize = 512 * 1024;
const DEFAULT_MAX_PROPOSAL_BYTES: usize = 256 * 1024;
const DEFAULT_MAX_JSON_DEPTH: usize = 64;
Expand Down Expand Up @@ -812,6 +815,7 @@ pub struct OpenAiPlanner {
transport: Box<dyn Transport + Send>,
usage_observer: Option<Box<dyn FnMut(ModelCallObservation) + Send>>,
rejection_observer: Option<Box<dyn FnMut(ProviderRejection) + Send>>,
prompt_byte_limit: Option<usize>,
}

impl OpenAiPlanner {
Expand All @@ -834,6 +838,7 @@ impl OpenAiPlanner {
transport: Box::new(transport),
usage_observer: None,
rejection_observer: None,
prompt_byte_limit: None,
})
}

Expand All @@ -852,6 +857,7 @@ impl OpenAiPlanner {
transport: Box::new(transport),
usage_observer: None,
rejection_observer: None,
prompt_byte_limit: None,
}
}

Expand All @@ -868,6 +874,7 @@ impl OpenAiPlanner {
transport: Box::new(ExternalTransport(send)),
usage_observer: None,
rejection_observer: None,
prompt_byte_limit: None,
}
}

Expand Down Expand Up @@ -910,6 +917,16 @@ impl OpenAiPlanner {
Ok(proposal)
}

/// Declare the transport's whole-prompt byte limit (the system prompt plus the request
/// envelope and planning context) when it is lower than the HTTP request limit, so the
/// runtime fits the planning context to it instead of building a request it rejects
/// (ADR-0097).
#[must_use]
pub const fn with_prompt_byte_limit(mut self, limit: usize) -> Self {
self.prompt_byte_limit = Some(limit);
self
}

/// Observe completed HTTP attempts without changing proposal or request semantics.
#[must_use]
pub fn with_usage_observer(
Expand Down Expand Up @@ -1348,6 +1365,7 @@ impl fmt::Debug for OpenAiPlanner {
.field("transport", &"<redacted>")
.field("usage_observer", &self.usage_observer.is_some())
.field("rejection_observer", &self.rejection_observer.is_some())
.field("prompt_byte_limit", &self.prompt_byte_limit)
.finish()
}
}
Expand All @@ -1357,6 +1375,14 @@ impl PlannerPort for OpenAiPlanner {
self.config.planner_id()
}

fn max_context_bytes(&self) -> Option<u64> {
let limit = self.prompt_byte_limit?;
let capacity = limit
.saturating_sub(self.config.system_prompt().len())
.saturating_sub(PROMPT_ENVELOPE_RESERVE_BYTES);
u64::try_from(capacity).ok()
}

fn request_profile_digest(&self) -> &str {
self.config.request_profile_digest()
}
Expand Down
Loading