Skip to content

fix(codex): keep collaboration guidance before conversation - #1380

Draft
harryzhou2000 wants to merge 1 commit into
lidge-jun:devfrom
harryzhou2000:fix/collab-guidance-prefix
Draft

fix(codex): keep collaboration guidance before conversation#1380
harryzhou2000 wants to merge 1 commit into
lidge-jun:devfrom
harryzhou2000:fix/collab-guidance-prefix

Conversation

@harryzhou2000

@harryzhou2000 harryzhou2000 commented Aug 9, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Keep OpenCodex collaboration guidance in the developer prefix for array-form stateless Responses requests, after native system/developer metadata and before conversation input.
  • Preserve stateful continuation precedence: unchanged guidance is deduplicated only from the trusted replay prefix, while changed guidance remains newest and wins across stale/fresh/stale catalog transitions.
  • Preserve tool-result-first deltas and final compaction_trigger ordering, 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 typecheck
  • bun run privacy:scan
  • ASTRO_TELEMETRY_DISABLED=1 bun run build in docs-site
  • git diff --check
  • Full-suite attempt: 10,402 pass and 8 failures in unchanged tests/codex-auth-api.test.ts under an unsandboxed network environment; that file passed 189/189 under network isolation.

Checklist

  • Scope stays focused and avoids unrelated cleanup.
  • Docs or release notes were updated when needed.
  • Security-sensitive changes were reviewed for secrets, auth, and unsafe defaults.

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

    • Improved generated guidance placement in Responses requests, preserving leading developer metadata and conversational ordering.
    • Stateful continuations now reuse trusted guidance without creating duplicates.
    • Stateless requests consistently place guidance before conversation content while preserving compaction triggers.
    • Improved handling of replayed tool updates and replacement of outdated guidance.
  • Documentation

    • Added guidance explaining how generated instructions are positioned for stateless requests and stateful continuations.

@coderabbitai

coderabbitai Bot commented Aug 9, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

The 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.

Changes

Developer guidance injection

Layer / File(s) Summary
Guidance detection and placement
src/server/responses/collaboration.ts, docs-site/src/content/docs/guides/sub-agent-surface.md
Helpers classify generated developer text and leading developer prefixes. Stateful requests append guidance after existing messages. Stateless requests insert guidance after the developer/additional-tools prefix and before conversation content. Trailing compaction_trigger items remain last. Documentation describes these rules.
Placement regression coverage
tests/multi-agent-compat.test.ts, tests/responses-state.test.ts
Tests cover prefix preservation, repeated stateless requests, replayed tool deltas, stale guidance replacement, compaction ordering, and continuation input ordering.

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
Loading

Possibly related PRs

  • lidge-jun/opencodex#350: Both changes update injectDeveloperMessage to prevent duplicate replayed guidance and adjust insertion behavior.

Suggested reviewers: lidge-jun, wibias

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly summarizes the main change: keeping collaboration guidance before conversation content in Codex Responses requests.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@github-actions

github-actions Bot commented Aug 9, 2026

Copy link
Copy Markdown
Contributor

Deterministic PR hygiene checks passed.

@github-actions github-actions Bot added the bug Something isn't working label Aug 9, 2026
@github-actions

github-actions Bot commented Aug 9, 2026

Copy link
Copy Markdown
Contributor

⏳ DRAFT

  • review readiness checklist open (0/4 boxes ticked).

What to do

  • Tick all four boxes in the PR description once you're done (currently 0/4).

Review readiness checklist

  • ⬜ 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.

0/4 boxes ticked.

This PR stays in draft until every box above is ticked.

@Wibias

Wibias commented Aug 10, 2026

Copy link
Copy Markdown
Collaborator

@harryzhou2000 Please finish your pr.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

📥 Commits

Reviewing files that changed from the base of the PR and between ba1df18 and 8d5434a.

📒 Files selected for processing (4)
  • docs-site/src/content/docs/guides/sub-agent-surface.md
  • src/server/responses/collaboration.ts
  • tests/multi-agent-compat.test.ts
  • tests/responses-state.test.ts

Comment on lines +54 to +56
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.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📐 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.

Suggested change
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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants