Skip to content

fix: close remaining protocol gaps (metadata, status, lifecycle)#108

Merged
teng-lin merged 2 commits intomainfrom
fix/protocol-gaps-v3
Feb 21, 2026
Merged

fix: close remaining protocol gaps (metadata, status, lifecycle)#108
teng-lin merged 2 commits intomainfrom
fix/protocol-gaps-v3

Conversation

@teng-lin
Copy link
Copy Markdown
Owner

Summary

Closes the remaining protocol gaps identified in the unified message protocol audit. Builds on #105 (close-protocol-gaps-v2).

Metadata normalization (ISSUE 2):

  • Add canonical error key to OpenCode error metadata so the consumer mapper's mapResultMessage fallback works
  • Remove unused done: true metadata from Codex adapter (3 locations) — no other adapter or consumer uses this field

Status inference (ISSUE 3):

  • Add status: "running" to OpenCode busystatus_change mapping so the router recognizes it
  • Add turnRunningEmitted flag to ACP session — emits status_change(running) on first agent_message_chunk per turn, reset on completion/error/new prompt

Auth flow:

  • Emit auth_status before provider_auth errors in OpenCode session (mirrors ACP pattern at acp-session.ts:376)

Session lifecycle model:

  • Define SessionLifecycleSubtype type (session_created | session_deleted | session_compacted | message_removed | message_part_removed)
  • Map OpenCode session.created, session.deleted, message.part.removedsession_lifecycle messages
  • Emit session_lifecycle(session_created) on Codex thread/started

Documentation:

  • Categorize all 12 remaining silent drops (intentional, defensive, heartbeat, future)
  • Document future work: connection health (heartbeats), session title updates, ACP host capabilities
  • Update feature matrix, gap status, and drop counts

Test plan

  • npx tsc --noEmit — zero type errors
  • npx vitest run — 2454 tests passing across 158 test files
  • New tests: ACP turnRunningEmitted (3 tests), OpenCode auth_status emission, OpenCode lifecycle events (3 tests + info shape), Codex thread/started lifecycle
  • Updated tests: ACP adapter test consumes new status_change(running), Codex e2e removes done assertions
  • Dual code review (Claude + Gemini) — all high/medium findings addressed

Generated with Claude Code

@gemini-code-assist
Copy link
Copy Markdown
Contributor

Summary of Changes

Hello @teng-lin, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request significantly enhances the unified message protocol by closing several identified gaps related to metadata consistency, status reporting, authentication flow, and session lifecycle events. It standardizes how various backend adapters communicate these critical states, improving the reliability and predictability of the system. The changes ensure that the frontend receives more consistent and actionable information, while also clarifying which previously 'dropped' events are now intentionally handled or categorized for future consideration.

Highlights

  • Metadata Normalization: Added a canonical 'error' key to OpenCode error metadata to ensure consistent error handling, and removed the unused 'done: true' metadata field from Codex adapter messages.
  • Status Inference: Introduced 'status: "running"' to OpenCode's 'busy' status_change mapping. An internal 'turnRunningEmitted' flag was added to the ACP session to emit 'status_change(running)' only on the first 'agent_message_chunk' per turn, resetting on completion, error, or new prompt.
  • Authentication Flow: Ensured that 'auth_status' messages are emitted before 'provider_auth' errors in the OpenCode session, aligning with the ACP adapter's pattern for better frontend feedback.
  • Session Lifecycle Model: Defined a new 'SessionLifecycleSubtype' type to standardize session events. OpenCode's 'session.created', 'session.deleted', and 'message.part.removed' events are now mapped to 'session_lifecycle' messages, and Codex's 'thread/started' event also emits a 'session_lifecycle(session_created)' message.
  • Documentation Updates: Categorized all remaining silent drop points (intentional, defensive, heartbeat, future) in the unified message protocol documentation. Future work items such as connection health, session title updates, and ACP host capabilities were also documented.
Changelog
  • docs/unified-message-protocol.md
    • Updated GAP 4 status to 'RESOLVED' and expanded details on session lifecycle events.
    • Revised the feature matrix for Auth flow and Session lifecycle to reflect new mappings.
    • Updated the silent drop inventory, categorizing remaining drops and detailing future work.
    • Resolved metadata key inconsistencies for 'Error detail' and 'Tool status' in the documentation.
    • Adjusted the context section to accurately reflect the number of resolved audit gaps.
  • src/adapters/acp/acp-adapter.test.ts
    • Added a test expectation for the emission of a 'status_change(running)' message.
  • src/adapters/acp/acp-session.test.ts
    • Added new tests to verify the correct emission logic for 'status_change(running)' messages.
    • Updated existing tests to account for the new 'status_change(running)' message in the message stream.
  • src/adapters/acp/acp-session.ts
    • Introduced a 'turnRunningEmitted' flag to track status emission per turn.
    • Reset the 'turnRunningEmitted' flag upon new user prompts, session completion, or errors.
    • Implemented logic to emit 'status_change(running)' on the first 'agent_message_chunk' of a turn if not already emitted.
  • src/adapters/codex/codex-message-translator.test.ts
    • Removed assertions related to the 'metadata.done' flag from tool progress and assistant message tests.
  • src/adapters/codex/codex-message-translator.ts
    • Removed the 'done: true' metadata field from translated 'tool_progress' messages.
  • src/adapters/codex/codex-session.test.ts
    • Added tests to confirm that 'thread/started' notifications now correctly emit 'session_lifecycle(session_created)' messages.
  • src/adapters/codex/codex-session.ts
    • Implemented emission of 'session_lifecycle(session_created)' messages upon receiving 'thread/started' notifications.
    • Removed the 'done: true' metadata field from tool progress messages.
  • src/adapters/opencode/opencode-message-translator.test.ts
    • Added 'status: "running"' to the metadata of 'status_change' messages for 'session.status busy' events.
    • Included an 'error' key assertion for 'session.error' events to ensure canonical error representation.
    • Updated tests for 'session.created', 'session.deleted', and 'message.part.removed' to expect 'session_lifecycle' messages instead of being filtered out.
  • src/adapters/opencode/opencode-message-translator.ts
    • Mapped 'session.created', 'session.deleted', and 'message.part.removed' events to new 'session_lifecycle' messages.
    • Added 'status: "running"' to the 'status_change' message metadata for 'session.status busy' events.
    • Included a canonical 'error' key in the 'result' metadata for 'session.error' events.
  • src/adapters/opencode/opencode-session.test.ts
    • Updated tests for 'session.created' events to verify the emission of 'session_lifecycle' messages.
    • Added tests to confirm that 'auth_status' messages are emitted prior to 'result' messages for 'provider_auth' errors.
  • src/adapters/opencode/opencode-session.ts
    • Implemented logic to emit an 'auth_status' message before a 'result' message when a 'provider_auth' error occurs.
  • src/core/types/unified-message.ts
    • Defined a new TypeScript type, 'SessionLifecycleSubtype', to enumerate canonical session lifecycle event subtypes.
  • src/e2e/codex-adapter.e2e.test.ts
    • Removed assertions for the 'metadata.done' flag in various E2E tests.
    • Updated test descriptions and expectations to reflect the change from a 'done' flag to a 'completed' status for tool progress.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This is an excellent pull request that successfully closes several protocol gaps across metadata normalization, status inference, authentication flow, and session lifecycle events. The changes are well-implemented and consistently applied across the OpenCode, Codex, and ACP adapters. I particularly appreciate the new tests that cover the new logic, such as the turnRunningEmitted flag in the ACP session and the new lifecycle events. The documentation updates are also clear and comprehensive. The code quality is high, and I have no concerns with merging these changes.

- Add canonical `error` key to OpenCode error metadata for consumer mapper
- Emit `auth_status` before `provider_auth` errors in OpenCode (mirrors ACP)
- Add `status: "running"` to OpenCode busy status for router compatibility
- Remove unused `done: true` metadata from Codex adapter (3 locations)
- Add `turnRunningEmitted` flag to ACP session for status_change(running)
- Define `SessionLifecycleSubtype` type for canonical lifecycle events
- Map OpenCode session.created/deleted/message.part.removed to session_lifecycle
- Emit session_lifecycle(session_created) on Codex thread/started
- Document all 12 remaining drops with categories and future work items
@teng-lin teng-lin force-pushed the fix/protocol-gaps-v3 branch from 3972832 to 27f5f12 Compare February 21, 2026 21:59
…le changes

E2e tests now expect:
- ACP/Gemini: status_change(running) before first agent_message_chunk
- OpenCode: session.created/session.deleted emit session_lifecycle
- OpenCode: message.part.removed emits session_lifecycle
@teng-lin teng-lin merged commit b2f2bc6 into main Feb 21, 2026
7 checks passed
@teng-lin teng-lin deleted the fix/protocol-gaps-v3 branch February 21, 2026 22:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant