Skip to content
14 changes: 14 additions & 0 deletions .github/scripts/historical-recovery-timezone-callers.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/usr/bin/env bash
# Disposable historical RED overlays only. New physical-send timezone guards
# call recovery helpers absent in those baselines. Pin the pre-guard callers;
# never replace the causal recovery implementation or selected test fixtures.
set -euo pipefail
timezone_callers=aa8e596e6d6f3e4648d6beba73b39b240dd5357a
git fetch --no-tags --depth=1 origin "$timezone_callers"
for target in backend/internal/service/openai_request_timezone_egress.go backend/internal/service/openai_ws_client.go; do
git restore --source="$timezone_callers" -- "$target"
expected=$(git rev-parse "$timezone_callers:$target")
actual=$(git hash-object "$target")
test "$expected" = "$actual"
printf 'timezone compatibility caller baseline=%s path=%s expected=%s actual=%s\n' "$timezone_callers" "$target" "$expected" "$actual"
done
24 changes: 16 additions & 8 deletions .github/workflows/issue715-agent-recovery.yml
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,10 @@ jobs:
set -euo pipefail
git rev-parse HEAD
original=6df0cd5bb0ce4d774d34004008f9dd661d236468
bash .github/scripts/historical-recovery-timezone-callers.sh
targets=(backend/internal/service/openai_codex_model_metadata.go backend/internal/service/openai_codex_models_service.go backend/internal/service/openai_excel_bps_models_manifest.go)
git fetch --no-tags --depth=1 origin "$original"
trap 'git restore --source=HEAD -- "${targets[@]}"; git diff --exit-code' EXIT
trap 'git restore --source=HEAD -- "${targets[@]}" backend/internal/service/openai_request_timezone_egress.go backend/internal/service/openai_ws_client.go; git diff --exit-code' EXIT
git restore --source="$original" -- "${targets[@]}"
for target in "${targets[@]}"; do
expected=$(git rev-parse "$original:$target")
Expand Down Expand Up @@ -97,6 +98,7 @@ jobs:
set -euo pipefail
git rev-parse HEAD
original=6df0cd5bb0ce4d774d34004008f9dd661d236468
bash .github/scripts/historical-recovery-timezone-callers.sh
targets=(backend/internal/handler/openai_gateway_handler.go backend/internal/service/openai_account_scheduler.go backend/internal/service/openai_gateway_forward.go backend/internal/service/openai_gateway_response_handling.go backend/internal/service/openai_gateway_service.go backend/internal/service/openai_ws_forwarder_ingress.go backend/internal/service/openai_ws_v2_passthrough_adapter.go backend/internal/service/openai_ws_http_bridge.go backend/internal/service/openai_ws_pool.go)
added=(backend/internal/service/openai_agent_message_recovery.go backend/internal/service/openai_agent_message_recovery_cache.go backend/internal/service/openai_agent_message_delivery.go backend/internal/repository/gateway_cache_agent_recovery.go backend/internal/repository/gateway_cache_agent_shadow_epoch.go backend/internal/service/openai_ws_agent_recovery.go backend/internal/service/openai_agent_message_recovery_wait.go backend/internal/service/openai_ws_search_activation.go backend/internal/service/openai_409_omit_history.go backend/internal/service/openai_409_readable_shadow.go backend/internal/repository/gateway_cache_readable_shadow.go backend/internal/service/openai_400_omit_history.go backend/internal/service/openai_history_omission.go)
# The exact original gateway struct predates analysis admission state.
Expand All @@ -117,7 +119,7 @@ jobs:
git fetch --no-tags --depth=1 origin "$original"
git fetch --no-tags --depth=1 origin "$analysis_compat"
git fetch --no-tags --depth=1 origin "$billing_compat"
trap 'git restore --source=HEAD -- "${targets[@]}" "${added[@]}" "$analysis_leaf" "$billing_leaf" "${weekly_leaves[@]}"; git diff --exit-code' EXIT
trap 'git restore --source=HEAD -- "${targets[@]}" "${added[@]}" "$analysis_leaf" "$billing_leaf" "${weekly_leaves[@]}" backend/internal/service/openai_request_timezone_egress.go backend/internal/service/openai_ws_client.go; git diff --exit-code' EXIT
git restore --source="$original" -- "${targets[@]}"
git restore --source="$analysis_compat" -- "$analysis_leaf"
git restore --source="$billing_compat" -- "$billing_leaf"
Expand Down Expand Up @@ -173,9 +175,10 @@ jobs:
set -euo pipefail
git rev-parse HEAD
original=18b7c0a4f5f4306a9c92f9715f08164f520df457
bash .github/scripts/historical-recovery-timezone-callers.sh
target=backend/internal/service/openai_gateway_response_handling.go
git fetch --no-tags --depth=1 origin "$original"
trap 'git restore --source=HEAD -- "$target"; git diff --exit-code' EXIT
trap 'git restore --source=HEAD -- "$target" backend/internal/service/openai_request_timezone_egress.go backend/internal/service/openai_ws_client.go; git diff --exit-code' EXIT
git restore --source="$original" -- "$target"
expected=$(git rev-parse "$original:$target")
actual=$(git hash-object "$target")
Expand Down Expand Up @@ -209,9 +212,10 @@ jobs:
set -euo pipefail
git rev-parse HEAD
original=b6d780f1a4fee66c2930219dfe9e400b8f0279de
bash .github/scripts/historical-recovery-timezone-callers.sh
target=backend/internal/service/openai_gateway_response_handling.go
git fetch --no-tags --depth=1 origin "$original"
trap 'git restore --source=HEAD -- "$target"; git diff --exit-code' EXIT
trap 'git restore --source=HEAD -- "$target" backend/internal/service/openai_request_timezone_egress.go backend/internal/service/openai_ws_client.go; git diff --exit-code' EXIT
git restore --source="$original" -- "$target"
expected=$(git rev-parse "$original:$target")
actual=$(git hash-object "$target")
Expand Down Expand Up @@ -245,6 +249,7 @@ jobs:
set -euo pipefail
git rev-parse HEAD
original=242f5b0892a59d95005099e6294262b066bd2f8b
bash .github/scripts/historical-recovery-timezone-callers.sh
targets=(backend/internal/service/openai_agent_message_recovery.go backend/internal/service/openai_agent_message_recovery_cache.go backend/internal/repository/gateway_cache_agent_recovery.go backend/internal/service/openai_gateway_forward.go backend/internal/service/openai_gateway_response_handling.go)
added=backend/internal/service/openai_agent_message_delivery.go
ws_original=a575df898ccd0876c4c0eb1559da38cedfdfe99d
Expand All @@ -263,7 +268,7 @@ jobs:
git fetch --no-tags --depth=1 origin "$original"
git fetch --no-tags --depth=1 origin "$ws_original"
git fetch --no-tags --depth=1 origin "$scheduler_compat"
trap 'git restore --source=HEAD -- "${targets[@]}" "$added" "${ws_targets[@]}" "${ws_added[@]}" "$scheduler_leaf" "$wait_added" "${omission_added[@]}"; git diff --exit-code' EXIT
trap 'git restore --source=HEAD -- "${targets[@]}" "$added" "${ws_targets[@]}" "${ws_added[@]}" "$scheduler_leaf" "$wait_added" "${omission_added[@]}" backend/internal/service/openai_request_timezone_egress.go backend/internal/service/openai_ws_client.go; git diff --exit-code' EXIT
git restore --source="$original" -- "${targets[@]}"
git restore --source="$ws_original" -- "${ws_targets[@]}"
git restore --source="$scheduler_compat" -- "$scheduler_leaf"
Expand Down Expand Up @@ -312,9 +317,10 @@ jobs:
set -euo pipefail
git rev-parse HEAD
original=d91d890049a9bd8bd0e414f30b0cb3b5bcc0f06e
bash .github/scripts/historical-recovery-timezone-callers.sh
target=backend/internal/service/openai_ws_forwarder_ingress.go
git fetch --no-tags --depth=1 origin "$original"
trap 'git restore --source=HEAD -- "$target"; git diff --exit-code' EXIT
trap 'git restore --source=HEAD -- "$target" backend/internal/service/openai_request_timezone_egress.go backend/internal/service/openai_ws_client.go; git diff --exit-code' EXIT
git restore --source="$original" -- "$target"
expected=$(git rev-parse "$original:$target")
actual=$(git hash-object "$target")
Expand Down Expand Up @@ -347,14 +353,15 @@ jobs:
set -euo pipefail
git rev-parse HEAD
original=e7f54240d83765c90a98e961ad5e33b0fa35ab56
bash .github/scripts/historical-recovery-timezone-callers.sh
target=backend/internal/service/openai_ws_agent_recovery.go
caller=backend/internal/service/openai_ws_forwarder_ingress.go
passthrough=backend/internal/service/openai_ws_v2_passthrough_adapter.go
git fetch --no-tags --depth=1 origin "$original"
# Manager fields and readable-payload methods live together. Restore
# both transport callers with that manager; retain candidate tests and
# standalone admission/principal helpers required by current HTTP.
trap 'git restore --source=HEAD -- "$target" "$caller" "$passthrough"; git diff --exit-code' EXIT
trap 'git restore --source=HEAD -- "$target" "$caller" "$passthrough" backend/internal/service/openai_request_timezone_egress.go backend/internal/service/openai_ws_client.go; git diff --exit-code' EXIT
git restore --source="$original" -- "$target" "$caller" "$passthrough"
expected=$(git rev-parse "$original:$target")
actual=$(git hash-object "$target")
Expand Down Expand Up @@ -426,13 +433,14 @@ jobs:
set -euo pipefail
git rev-parse HEAD
original=a575df898ccd0876c4c0eb1559da38cedfdfe99d
bash .github/scripts/historical-recovery-timezone-callers.sh
targets=(backend/internal/handler/openai_gateway_handler.go backend/internal/service/openai_ws_forwarder_ingress.go backend/internal/service/openai_ws_v2_passthrough_adapter.go backend/internal/service/openai_ws_http_bridge.go backend/internal/service/openai_ws_pool.go)
# Search activation references fields absent in this pool. Retain the
# standalone recovery helpers needed by current HTTP code; the pinned
# pre-WS handler/transports never call them or publish WS ownership.
added=(backend/internal/service/openai_ws_search_activation.go)
git fetch --no-tags --depth=1 origin "$original"
trap 'git restore --source=HEAD -- "${targets[@]}" "${added[@]}"; git diff --exit-code' EXIT
trap 'git restore --source=HEAD -- "${targets[@]}" "${added[@]}" backend/internal/service/openai_request_timezone_egress.go backend/internal/service/openai_ws_client.go; git diff --exit-code' EXIT
git restore --source="$original" -- "${targets[@]}"
rm -- "${added[@]}"
for target in "${targets[@]}"; do
Expand Down
89 changes: 89 additions & 0 deletions .github/workflows/rebuilt-request-dispatch.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
name: Rebuilt request dispatch
on:
pull_request:
paths:
- 'backend/internal/service/openai_409_omit_history*'
- 'backend/internal/service/openai_agent_message_recovery.go'
- 'backend/internal/service/openai_gateway_forward.go'
- 'backend/internal/service/openai_account_scheduler.go'
- 'backend/internal/service/openai_request_timezone_egress*'
- 'backend/internal/service/openai_ws_client.go'
- 'backend/internal/service/openai_responses_namespace.go'
- 'backend/internal/handler/openai_409_*'
- 'backend/internal/handler/openai_gateway_handler.go'
- '.github/workflows/rebuilt-request-dispatch.yml'
permissions:
contents: read
jobs:
behavior:
runs-on: ubuntu-latest
timeout-minutes: 25
strategy:
fail-fast: false
matrix:
phase: [RED, GREEN]
steps:
- uses: actions/checkout@v6
with:
ref: ${{ github.event.pull_request.head.sha }}
fetch-depth: 0
- uses: actions/setup-go@v6
with:
go-version-file: backend/go.mod
cache-dependency-path: backend/go.sum
- name: Install isolated Redis fixture
run: |
bash .github/scripts/ci-ubuntu-mirrors.sh
sudo apt-get update
sudo apt-get install -y --no-install-recommends redis-server
- name: Restore release implementation for RED
if: matrix.phase == 'RED'
run: |
set -euo pipefail
baseline=aa8e596e6d6f3e4648d6beba73b39b240dd5357a
for target in backend/internal/handler/openai_gateway_handler.go backend/internal/service/openai_409_omit_history.go backend/internal/service/openai_account_scheduler.go backend/internal/service/openai_agent_message_recovery.go backend/internal/service/openai_gateway_forward.go backend/internal/service/openai_request_timezone_egress.go backend/internal/service/openai_ws_client.go backend/internal/service/openai_responses_namespace.go; do
git show "$baseline:$target" > "$target"
done
- name: Same network and tool-loop regressions
env:
PHASE: ${{ matrix.phase }}
run: |
set -euo pipefail
set +e
(cd backend && go test -race -json -tags=unit ./internal/service ./internal/handler -run '^TestOpenAI409(HTTPProjectionAndPassthrough|WSInitialWithoutPointer|PhysicalTimezonePreservesReadableTask|NamespaceProjectionPreservesNumbers)$' -count=1 -timeout=10m) > "$RUNNER_TEMP/dispatch.jsonl" 2>&1
result=$?
set -e
cat "$RUNNER_TEMP/dispatch.jsonl"
python3 - "$PHASE" "$result" "$RUNNER_TEMP/dispatch.jsonl" <<'PY'
import json,sys
phase,result,path=sys.argv[1:]
raw=open(path).read()
for invalid in ('[build failed]', 'undefined:', 'panic:', 'WARNING: DATA RACE', 'no tests to run'):
assert invalid not in raw, invalid
events=[]
for line in raw.splitlines():
try: events.append(json.loads(line))
except ValueError: pass
terminals={e['Test']:e['Action'] for e in events if 'Test' in e and e.get('Action') in ('pass','fail','skip')}
assert terminals and 'skip' not in terminals.values(), terminals
expected=[
'TestOpenAI409HTTPProjectionAndPassthrough/oauth/stream=false/internal_metadata',
'TestOpenAI409HTTPProjectionAndPassthrough/oauth/stream=true/message_namespace',
'TestOpenAI409HTTPProjectionAndPassthrough/apikey/stream=true/passthrough',
'TestOpenAI409PhysicalTimezonePreservesReadableTask/http/preserved=true',
'TestOpenAI409PhysicalTimezonePreservesReadableTask/ws/preserved=true',
]
if phase=='GREEN':
assert int(result)==0 and set(terminals.values())=={'pass'}, terminals
assert all(terminals.get(t)=='pass' for t in expected)
assert len([t for t,v in terminals.items() if t.startswith('TestOpenAI409WSInitialWithoutPointer/') and t.count('/')==2 and v=='pass'])==15
else:
assert int(result)!=0
assert all(terminals.get(t)=='fail' for t in expected), terminals
assert any(t.startswith('TestOpenAI409WSInitialWithoutPointer/') and t.count('/')==2 and v=='fail' for t,v in terminals.items()), terminals
PY
- uses: actions/upload-artifact@v7
if: always()
with:
name: rebuilt-dispatch-${{ matrix.phase }}-${{ github.event.pull_request.head.sha }}
path: ${{ runner.temp }}/dispatch.jsonl
53 changes: 53 additions & 0 deletions backend/internal/handler/openai_409_http_rebuild_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,21 @@ func TestOpenAI409HTTPRebuildOwnerCooldown(t *testing.T) {
}
}

func TestOpenAI409HTTPProjectionAndPassthrough(t *testing.T) {
for _, accountType := range []string{service.AccountTypeAPIKey, service.AccountTypeOAuth} {
for _, stream := range []bool{false, true} {
for _, shape := range []string{"message_namespace", "internal_metadata", "tool_schema_null", "passthrough"} {
if shape == "passthrough" && accountType != service.AccountTypeAPIKey {
continue
}
t.Run(fmt.Sprintf("%s/stream=%t/%s", accountType, stream, shape), func(t *testing.T) {
runHTTPRebuildFixture(t, accountType, stream, shape, "completed", "", "")
})
}
}
}
}

func TestOpenAI409HTTPControlNormalization(t *testing.T) {
for _, stream := range []bool{false, true} {
for _, accountType := range []string{service.AccountTypeAPIKey, service.AccountTypeOAuth} {
Expand Down Expand Up @@ -522,6 +537,12 @@ func runHTTPRebuildFixture(t *testing.T, accountType string, stream bool, pointe
gjson.GetBytes(body, "stream").Bool() && gjson.GetBytes(body, "store").Type == gjson.False &&
gjson.GetBytes(body, `input.#(role==system)`).Type == gjson.Null
}
if pointer == "message_namespace" {
valid = valid && !gjson.GetBytes(body, "input.0.namespace").Exists()
}
if pointer == "internal_metadata" && accountType == service.AccountTypeOAuth {
valid = valid && !gjson.GetBytes(body, "input.0.internal_chat_message_metadata_passthrough").Exists()
}
if n == 3 {
valid = valid && httpRebuildToolPair(body, "run_tests", httpRebuildCheck)
}
Expand Down Expand Up @@ -561,6 +582,9 @@ func runHTTPRebuildFixture(t *testing.T, accountType string, stream bool, pointe
for i, label := range []string{"A", "B"} {
accounts[i].Credentials = map[string]any{"base_url": provider.URL, "api_key": "fixture-rebuild-" + label, "access_token": "fixture-rebuild-" + label, "chatgpt_account_id": "fixture-chatgpt-" + label}
}
if pointer == "passthrough" {
accounts[1].Extra = map[string]any{"openai_passthrough": true, "openai_responses_mode": "force_responses"}
}
settings := service.NewSettingService(&omit409SettingsRepo{enabled: boundary != "strict"}, cfg)
usage := &readable409UsageRepo{}
h := newOpenAIResponsesFailoverTestHandlerWithUsage(t, transport, repository.NewGatewayCache(clients()), settings, usage, accounts...)
Expand Down Expand Up @@ -612,6 +636,35 @@ func runHTTPRebuildFixture(t *testing.T, accountType string, stream bool, pointe
delete(body, "tools")
body["parallel_tool_calls"] = true
}
if previous.Exists() {
history = append([]string(nil), history...)
if pointer == "passthrough" && previous.Get("id").String() == "resp_rebuild_B" {
filtered := history[:0]
for _, item := range history {
if item != httpRebuildAgentA {
filtered = append(filtered, item)
}
}
history = filtered // only B's established opaque owner remains
}
var field string
switch pointer {
case "message_namespace":
field = "namespace"
case "internal_metadata":
field = "internal_chat_message_metadata_passthrough"
}
if field != "" {
updated, err := sjson.Set(history[0], field, "fixture-output-metadata")
require.NoError(t, err)
history[0] = updated
}
if pointer == "tool_schema_null" {
declarations := httpRebuildToolDefinitions()
declarations[0].(map[string]any)["parameters"].(map[string]any)["type"] = nil
body["tools"] = declarations
}
}
body["input"] = json.RawMessage("[" + strings.Join(history, ",") + "]")
if previous.Exists() && (pointer == "previous" || boundary == "pointer_only") {
body["previous_response_id"] = previous.Get("id").String()
Expand Down
Loading
Loading