fix(codex): keep collaboration guidance before conversation - #1380
fix(codex): keep collaboration guidance before conversation#1380harryzhou2000 wants to merge 1 commit into
Conversation
📝 WalkthroughWalkthroughThe Responses collaboration path now detects replayed guidance, preserves developer prefixes, and places generated guidance before conversation content for stateless requests. Stateful continuations reuse or replace guidance without duplication. Tests and documentation cover these rules. ChangesDeveloper guidance injection
Estimated code review effort: 3 (Moderate) | ~20 minutes Sequence Diagram(s)sequenceDiagram
participant ResponsesRequest
participant injectDeveloperMessage
participant ParsedInput
participant RawInput
ResponsesRequest->>injectDeveloperMessage: provide guidance and request state
injectDeveloperMessage->>ParsedInput: detect prefixes and duplicate guidance
injectDeveloperMessage->>RawInput: insert guidance at the state-specific position
injectDeveloperMessage-->>ResponsesRequest: return updated parsed and raw inputs
Possibly related PRs
Suggested reviewers: 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
✅ Deterministic PR hygiene checks passed. |
⏳ DRAFT
What to do
Review readiness checklist
0/4 boxes ticked. This PR stays in draft until every box above is ticked. |
|
@harryzhou2000 Please finish your pr. |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@docs-site/src/content/docs/guides/sub-agent-surface.md`:
- Around line 54-56: Update the documentation around the array-form stateless
Responses request ordering to explicitly state that generated guidance is
inserted after leading system and developer metadata, before conversational
input. Keep the existing stateful previous_response_id replay-prefix behavior
unchanged.
🪄 Autofix
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: ASSERTIVE
Plan: Pro Plus
Run ID: 405d5a07-ed5b-4f39-8780-45e28f90df7a
📒 Files selected for processing (4)
docs-site/src/content/docs/guides/sub-agent-surface.mdsrc/server/responses/collaboration.tstests/multi-agent-compat.test.tstests/responses-state.test.ts
| For array-form stateless Responses requests, opencodex places generated guidance after the leading | ||
| developer metadata and before conversational input. Stateful `previous_response_id` continuations | ||
| reuse an exact item from their trusted replay prefix instead of adding another copy. |
There was a problem hiding this comment.
📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win
Document the system-prefix rule.
Line 54 says that generated guidance follows leading developer metadata. injectDeveloperMessage also places guidance after leading system messages. This can cause users to expect different ordering for array-form requests with system metadata.
Proposed documentation fix
-For array-form stateless Responses requests, opencodex places generated guidance after the leading
-developer metadata and before conversational input. Stateful `previous_response_id` continuations
+For array-form stateless Responses requests, opencodex places generated guidance after the leading
+system and developer metadata, including developer `additional_tools`, and before conversational input. Stateful `previous_response_id` continuations📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| For array-form stateless Responses requests, opencodex places generated guidance after the leading | |
| developer metadata and before conversational input. Stateful `previous_response_id` continuations | |
| reuse an exact item from their trusted replay prefix instead of adding another copy. | |
| For array-form stateless Responses requests, opencodex places generated guidance after the leading | |
| system and developer metadata, including developer `additional_tools`, and before conversational input. Stateful `previous_response_id` continuations | |
| reuse an exact item from their trusted replay prefix instead of adding another copy. |
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@docs-site/src/content/docs/guides/sub-agent-surface.md` around lines 54 - 56,
Update the documentation around the array-form stateless Responses request
ordering to explicitly state that generated guidance is inserted after leading
system and developer metadata, before conversational input. Keep the existing
stateful previous_response_id replay-prefix behavior unchanged.
Source: Path instructions
Summary
compaction_triggerordering, with focused regression coverage and documentation.The root cause was tail placement. Stateless HTTP requests have no trusted replay prefix, so OpenCodex generates guidance for each request; appending it after current conversation made stable metadata look like fresh, recency-dominant input. For stateful replay, deduplication also needs to compare the latest tagged guidance rather than any older exact match.
Verification
bun test tests/multi-agent-compat.test.ts tests/responses-state.test.ts(141 pass, 0 fail)bun test tests/openai-responses-passthrough.test.ts tests/responses-compaction-routing.test.ts(94 pass, 0 fail)bun test tests/codex-auth-api.test.ts(189 pass, 0 fail; isolated follow-up for an unrelated full-suite timeout cascade)bun run typecheckbun run privacy:scanASTRO_TELEMETRY_DISABLED=1 bun run buildindocs-sitegit diff --checktests/codex-auth-api.test.tsunder an unsandboxed network environment; that file passed 189/189 under network isolation.Checklist
Review readiness checklist
This PR stays in draft until every box below is ticked. Tick all four boxes once the requirements are met:
All CI tests are green on my local testing.
I pushed my PR to the latest dev commit.
I resolved all correct Codex and CodeRabbit findings.
My PR is ready for review.
Summary by CodeRabbit
Bug Fixes
Documentation