Skip to content

Commit edc49bd

Browse files
authored
chore(app-server): preserve protocol event types on turns (#14)
1 parent a6402b3 commit edc49bd

8 files changed

Lines changed: 336 additions & 152 deletions

File tree

.github/workflows/codex-autoreview.yml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,18 @@ jobs:
2525
- uses: actions/checkout@v4
2626
with:
2727
fetch-depth: 0
28+
- name: Install Codex binary fetch dependencies
29+
run: python3 -m pip install zstandard
30+
- name: Fetch bundled codex binary
31+
env:
32+
CODEX_BINARY_RELEASE_TAG: ${{ vars.CODEX_BINARY_RELEASE_TAG || 'rust-v0.122.0' }}
33+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
34+
run: |
35+
set -euo pipefail
36+
python3 scripts/fetch_codex_binary.py \
37+
--release-tag "$CODEX_BINARY_RELEASE_TAG" \
38+
--target-triple x86_64-unknown-linux-musl
39+
test -x codex/vendor/x86_64-unknown-linux-musl/codex/codex
2840
- name: Codex autonomous review
2941
uses: gersmann/codex-review-action@v1
3042
with:
@@ -44,6 +56,18 @@ jobs:
4456
- uses: actions/checkout@v4
4557
with:
4658
fetch-depth: 0
59+
- name: Install Codex binary fetch dependencies
60+
run: python3 -m pip install zstandard
61+
- name: Fetch bundled codex binary
62+
env:
63+
CODEX_BINARY_RELEASE_TAG: ${{ vars.CODEX_BINARY_RELEASE_TAG || 'rust-v0.122.0' }}
64+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
65+
run: |
66+
set -euo pipefail
67+
python3 scripts/fetch_codex_binary.py \
68+
--release-tag "$CODEX_BINARY_RELEASE_TAG" \
69+
--target-triple x86_64-unknown-linux-musl
70+
test -x codex/vendor/x86_64-unknown-linux-musl/codex/codex
4771
- name: Codex autonomous edits
4872
uses: gersmann/codex-review-action@v1
4973
with:

codex/app_server/_protocol_helpers.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@
1212
from codex.protocol import types as protocol
1313

1414
type RequestHandler[RequestT: BaseModel] = Callable[[RequestT], object | Awaitable[object]]
15-
Notification = BaseModel
15+
type Notification = protocol.ServerNotificationValue | GenericNotification
16+
type ServerRequest = protocol.ServerRequestValue | GenericServerRequest
1617

1718

1819
def method_name(message: BaseModel) -> str:
@@ -123,7 +124,7 @@ def parse_notification(message: JsonObject, *, strict: bool) -> Notification:
123124
raise AppServerProtocolError(_notification_error_message(message)) from exc
124125

125126

126-
def parse_server_request(message: JsonObject, *, strict: bool) -> BaseModel:
127+
def parse_server_request(message: JsonObject, *, strict: bool) -> ServerRequest:
127128
method = message.get("method")
128129
try:
129130
return protocol.ServerRequest.model_validate(message).root
@@ -151,16 +152,21 @@ def _build_known_methods(*, root_model: type[BaseModel]) -> frozenset[str]:
151152
root_field = getattr(root_model, "model_fields", {}).get("root")
152153
if root_field is None:
153154
return frozenset()
155+
annotation = _unwrap_type_alias(root_field.annotation)
154156
methods = {
155157
method
156-
for candidate in get_args(root_field.annotation)
158+
for candidate in get_args(annotation)
157159
if isinstance(candidate, type) and issubclass(candidate, BaseModel)
158160
for method in [_candidate_method_literal(candidate)]
159161
if method is not None
160162
}
161163
return frozenset(methods)
162164

163165

166+
def _unwrap_type_alias(annotation: object) -> object:
167+
return getattr(annotation, "__value__", annotation)
168+
169+
164170
def _candidate_method_literal(candidate: type[BaseModel]) -> str | None:
165171
model_fields = getattr(candidate, "model_fields", None)
166172
if not isinstance(model_fields, dict) or "method" not in model_fields:

0 commit comments

Comments
 (0)