Skip to content

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

Open
harryzhou2000 wants to merge 2 commits into
lidge-jun:devfrom
harryzhou2000:fix/collab-guidance-prefix
Open

fix(codex): keep collaboration guidance before conversation#1380
harryzhou2000 wants to merge 2 commits 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 leading system/developer metadata and before conversation input.
  • Preserve stateful continuation precedence: unchanged guidance is deduplicated only from the trusted replay prefix, while changed non-null guidance is compared with the latest tagged replay item so current configuration or roster guidance remains newest.
  • 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.

Current dev separately suppresses OpenCodex guidance when the host-global catalog observation is stale or unknown (#1407). This PR applies when guidance is generated and does not reintroduce the removed catalog warning.

Verification

  • Full pre-push test suite under loopback-only network isolation: 10,932 pass, 0 fail, 11 skip
  • bun run typecheck
  • bun scripts/lint-gui-if-changed.ts
  • bun run privacy:scan
  • bun run doctor:gui:if-changed (React Doctor: no issues)
  • Final-rebase focused suite: bun test tests/multi-agent-compat.test.ts tests/responses-state.test.ts tests/openai-responses-passthrough.test.ts tests/responses-compaction-routing.test.ts (238 pass, 0 fail)
  • ASTRO_TELEMETRY_DISABLED=1 bun run build in docs-site
  • git diff --check

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 while preserving developer metadata, tool protocol items, and conversation order.
    • Stateful continuations now reuse trusted guidance without duplication or stale replacements.
    • Stateless requests place guidance before conversation content while preserving compaction history and tool updates.
    • Improved handling of repeated guidance across replay transitions.
  • Documentation

    • Added guidance on generated instruction placement for stateless requests and stateful continuations.

@coderabbitai

coderabbitai Bot commented Aug 9, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Important

Review skipped

No new commits to review since the last review.

⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: e29d0f47-d55a-4bba-8ae2-9a179ad825b3

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

The Responses parser now records continuation boundaries. Collaboration logic uses those boundaries to place generated guidance after leading protocol metadata and before conversation content. Stateful requests reuse or replace replayed guidance without duplication. Tests and documentation cover the updated ordering.

Changes

Developer guidance injection

Layer / File(s) Summary
Continuation boundary tracking
src/types.ts, src/responses/parser.ts
parseRequest records the parsed-message index before the first conversational item in a previous_response_id continuation, including string input and fallback-to-end cases.
Guidance detection and placement
src/server/responses/collaboration.ts
Helpers classify generated guidance, developer prefixes, and conversational items. Stateful requests reuse or replace replayed guidance. Stateless requests insert guidance after the leading developer/additional-tools prefix. Raw input preserves tool protocol items and trailing compaction triggers.
Placement regression coverage
tests/multi-agent-compat.test.ts, tests/responses-state.test.ts, docs-site/src/content/docs/guides/sub-agent-surface.md
Tests cover stateless placement, replay replacement, protocol ordering, compaction history, and A-B-A deduplication. Documentation describes the placement rules.

Estimated code review effort: 3 (Moderate) | ~25 minutes

Sequence Diagram(s)

sequenceDiagram
  participant ResponsesRequest
  participant parseRequest
  participant injectDeveloperMessage
  participant InputItems
  ResponsesRequest->>parseRequest: parse continuation input
  parseRequest->>injectDeveloperMessage: provide continuation boundary
  injectDeveloperMessage->>injectDeveloperMessage: detect replayed guidance
  injectDeveloperMessage->>InputItems: insert or replace guidance before conversation
Loading

Possibly related PRs

  • lidge-jun/opencodex#350: The main PR directly extends replay-prefix and guidance-injection changes in parseRequest, injectDeveloperMessage, OcxParsedRequest, and related tests.
  • lidge-jun/opencodex#953: Both PRs modify src/responses/parser.ts for specialized continuation and replay message state.
  • lidge-jun/opencodex#1407: Both PRs modify collaboration guidance handling, compatibility tests, and related documentation.

Suggested reviewers: lidge-jun, ingwannu

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
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.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes the main change: keeping collaboration guidance before conversation input.
✨ 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

✅ READY

  • all PR quality gates passed; the review readiness checklist is complete.

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.

4/4 boxes ticked.

This pull request has been marked Ready for Review.
The review-ready label marks this PR as ready; review automation runs independently. If no CodeRabbit review appears, comment @coderabbitai review to request one.
Maintainers notified: @lidge-jun @Ingwannu @Wibias

@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 thread docs-site/src/content/docs/guides/sub-agent-surface.md Outdated
@harryzhou2000
harryzhou2000 force-pushed the fix/collab-guidance-prefix branch from 8d5434a to df7ad09 Compare August 11, 2026 06:47

Copy link
Copy Markdown
Contributor Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Aug 11, 2026

Copy link
Copy Markdown
Contributor
✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@coderabbitai

coderabbitai Bot commented Aug 11, 2026

Copy link
Copy Markdown
Contributor

Note

GitHub couldn't provide a complete incremental comparison for this pull request, so CodeRabbit is performing a full review instead. This review may take a little longer.

@harryzhou2000
harryzhou2000 force-pushed the fix/collab-guidance-prefix branch from df7ad09 to 7108a85 Compare August 11, 2026 06:51
@github-actions
github-actions Bot marked this pull request as ready for review August 11, 2026 06:55
@coderabbitai

coderabbitai Bot commented Aug 11, 2026

Copy link
Copy Markdown
Contributor

@github-actions[bot] Pull request #1380 is ready for review. I will review the current changes.

⚠️ Action not completed

No files to review.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@Ingwannu Ingwannu left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

This is a real bug fix and the current implementation is a strong merge candidate. I found no remaining code-level blocker on head 7108a85251701c17bed4ae0a0289af5359069906: stateless guidance stays after leading system/developer metadata (including additional_tools) and before conversation, while stateful continuations preserve tool-result-first deltas, final compaction ordering, and latest-tagged guidance semantics.

Verification on the submitted head:

  • focused Responses/collaboration suite: 238 passed
  • typecheck: passed
  • privacy scan: passed
  • diff check: passed

I also transplanted the commit locally onto current dev@87e3ff9f63aa9e210d37e73fb5b64cc939ee03d5; the same 238 tests, typecheck, privacy scan, and diff check passed without conflict.

The only remaining blocker is integration provenance: the PR branch is currently 3 commits behind dev, and GitHub does not show the full exact-head platform matrix for this head. Please rebase onto current dev and let the complete exact-head CI finish. If that matrix is green, this should be ready for independent maintainer merge.

@Wibias Wibias left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Requesting changes on the current head 7108a852.

There is still one merge-blocking ordering hole in the stateful path. The PR fixes the stateless root cause by keeping generated guidance before conversation input, but previous_response_id continuations unconditionally append changed guidance to both parsed.context.messages and the raw input delta. That is necessary for an unexpanded function_call_output delta, where the tool result must stay first, but it is wrong for an ordinary stateful user-message delta: the new user turn is now immediately before the changed <multi_agent_mode> block, so stable collaboration metadata again becomes recency-dominant input after conversation.

Please distinguish the two cases instead of treating every stateful delta as tool-result-first. Preserve leading tool-result/call protocol items when required, but insert changed generated guidance before the first conversational item in an ordinary stateful delta. Add a regression test for previous_response_id + changed guidance + a new user message, alongside the existing tool-output-first case.

The current A→B→A test does not cover this because it asserts only that the replacement is newest; it does not exercise a fresh user-message delta or verify the conversation/guidance boundary.

@Wibias
Wibias marked this pull request as draft August 11, 2026 08:29
@coderabbitai

coderabbitai Bot commented Aug 11, 2026

Copy link
Copy Markdown
Contributor

@github-actions[bot] Pull request #1380 is marked ready for review. I will review the current changes.

⚠️ Action not completed

No files to review.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@harryzhou2000
harryzhou2000 force-pushed the fix/collab-guidance-prefix branch from 7108a85 to ea42264 Compare August 11, 2026 09:59
@coderabbitai

coderabbitai Bot commented Aug 11, 2026

Copy link
Copy Markdown
Contributor

@github-actions[bot] The readiness gate is complete. I will review pull request #1380.

✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@github-actions
github-actions Bot marked this pull request as ready for review August 11, 2026 10:01
@coderabbitai

coderabbitai Bot commented Aug 11, 2026

Copy link
Copy Markdown
Contributor

@github-actions[bot] Pull request #1380 is ready for review. I will review the current changes.

⚠️ Action not completed

Already reviewed.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@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 56-58: Update the continuation guidance in the paragraph
describing stateful previous_response_id replay to document latest-tagged
deduplication: injectDeveloperMessage reuses guidance only when it matches the
latest tagged replay item; for an A-B-A sequence, retain the earlier A and
insert a new A after the replay boundary.
🪄 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: f554d92c-8c93-42fc-a890-17d128099da8

📥 Commits

Reviewing files that changed from the base of the PR and between df7ad09 and ea42264.

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

Comment thread docs-site/src/content/docs/guides/sub-agent-surface.md Outdated

Copy link
Copy Markdown
Contributor Author

@Wibias The requested stateful-ordering fix is now on ea42264aa, rebased cleanly onto current dev@316f6758b.

Changed guidance now follows leading tool/protocol items but precedes the first current conversational item. Regressions cover an ordinary new-user continuation, function_call_output -> guidance -> user, compaction-history raw/parsed alignment, and unchanged replay deduplication. There are no unresolved inline review threads.

Local CI reproduction for this exact code:

  • Linux shards 1-4 completed. Raw failures were confined to tests that intentionally reject this host's mandatory proxy, plus one isolated load timeout; the owning files all passed when rerun proxy-free or individually.
  • Dedicated storage policy: 9 passed; API usage: 11 passed.
  • Gates: typecheck, GUI tests (the sole port-sandbox failure passed 13/13 with local-port access), privacy scan, release-helper build, and CLI help all passed.
  • Linux keyring create/read/delete smoke passed.
  • Node 20 npm-global packaging smoke passed through install, GUI build, pack asset verification, global install, and bundled-Bun ocx help.
  • Docs frozen install and 265-page Astro build passed.
  • After the final rebase: Responses regression set 438 passed / 3 skipped, changed upstream CLI test 53 passed, typecheck/help/diff check passed.

macOS and Windows remain platform-only checks for Actions. Could you please approve/trigger fork CI for exact head ea42264aa? CodeRabbit is also reviewing this head now; I will address any new actionable finding.

@harryzhou2000
harryzhou2000 force-pushed the fix/collab-guidance-prefix branch from ea42264 to 0651b86 Compare August 11, 2026 10:06
@coderabbitai

coderabbitai Bot commented Aug 11, 2026

Copy link
Copy Markdown
Contributor

@github-actions[bot] The PR is marked ready for review. I will review the current changes.

⚠️ Action not completed

Already reviewed.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@github-actions
github-actions Bot marked this pull request as draft August 11, 2026 10:06
@github-actions
github-actions Bot marked this pull request as ready for review August 11, 2026 10:08
@coderabbitai

coderabbitai Bot commented Aug 11, 2026

Copy link
Copy Markdown
Contributor

@github-actions[bot] Pull request #1380 is ready for review. I will review the current changes.

⚠️ Action not completed

Already reviewed.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

Copy link
Copy Markdown
Contributor Author

@Wibias Final exact head is now 0651b8697, rebased onto latest dev@37597869e. The only change since my matrix comment is CodeRabbit's docs-only clarification of latest-tagged A-B-A deduplication; its thread is replied to and resolved, the 265-page docs build passes, post-rebase collaboration/state tests pass 146/146, the new base CLI registry test passes 9/9, and CodeRabbit plus all readiness/hygiene checks are green. Please trigger fork CI for 0651b8697.

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

Labels

bug Something isn't working review-ready

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants