diff --git a/.github/scripts/prepare-replay-red-fixtures.sh b/.github/scripts/prepare-replay-red-fixtures.sh index f5ce3a18a2fb..72a45caa89d0 100644 --- a/.github/scripts/prepare-replay-red-fixtures.sh +++ b/.github/scripts/prepare-replay-red-fixtures.sh @@ -54,8 +54,40 @@ if ! git -C "$tree" grep -q 'func (a \*Account) IsExcelBPSSearchEnabled' "$basel exit 1 fi exclude_absent_fixture backend/internal/service/openai_excel_bps_search_test.go "$contract" + # PR872 added independent search diagnostics/race fixtures which also use + # that absent API and the excluded search fixture helper. Keep them in every + # candidate GREEN; only isolate proven post-baseline files in this old RED. + for target in backend/internal/service/openai_excel_bps_search_diagnostics_test.go backend/internal/service/openai_excel_bps_search_race_test.go; do + if git -C "$tree" cat-file -e "$candidate:$target" 2>/dev/null; then + exclude_absent_fixture "$target" "$contract" + fi + done fi # Later mixed-owner proofs/diagnostics share the restored recovery struct. script_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" bash "$script_dir/prepare-ws-owner-red-fixtures.sh" "$baseline" "$tree" "$candidate" + +# PR874 creation-only OAuth policy is absent in historical recovery sources. +# Keep the selected recovery tests untouched and all candidate GREEN fixtures; +# adapt only these unrelated service fixtures to the exact old Account API. +contract=backend/internal/service/account.go +if ! git -C "$tree" grep -q 'InitialAPIKeyDisposition' "$baseline" -- "$contract"; then + target=backend/internal/service/oauth_apikey_disposition_test.go + if git -C "$tree" cat-file -e "$candidate:$target" 2>/dev/null; then + exclude_absent_fixture "$target" "$contract" + fi + target=backend/internal/service/openai_plugin_account_directory_test.go + expected_contract=$(git -C "$tree" rev-parse "$baseline:$contract") + test "$(git -C "$tree" hash-object "$contract")" = "$expected_contract" + candidate_blob=$(git -C "$tree" rev-parse "$candidate:$target") + test "$(git -C "$tree" hash-object "$target")" = "$candidate_blob" + if git -C "$tree" cat-file -e "$baseline:$target" 2>/dev/null; then + expected=$(git -C "$tree" rev-parse "$baseline:$target") + git -C "$tree" show "$baseline:$target" > "$tree/$target" + test "$(git -C "$tree" hash-object "$target")" = "$expected" + printf 'historical plugin fixture path=%s candidate_blob=%s baseline_blob=%s contract_blob=%s\n' "$target" "$candidate_blob" "$expected" "$expected_contract" + else + exclude_absent_fixture "$target" "$contract" + fi +fi diff --git a/.github/workflows/encrypted-history-400.yml b/.github/workflows/encrypted-history-400.yml index 4d7b48ca56d2..10283624b576 100644 --- a/.github/workflows/encrypted-history-400.yml +++ b/.github/workflows/encrypted-history-400.yml @@ -43,6 +43,7 @@ jobs: git rev-parse HEAD go test -race -json -p 2 -tags=unit ./internal/service ./internal/handler ./internal/handler/admin -run '^Test(OpenAI400|OpenAI409|OmitOpenAIHistorical|ForwardEncryptedContentSSERetry|UpdateSettingsOpenAI400|UpdateSettingsOpenAI409)' -count=1 -timeout=5m settings: + # The pinned Playwright 1.56.1 browser packages support Ubuntu 24.04. runs-on: ubuntu-24.04 timeout-minutes: 15 steps: diff --git a/.github/workflows/free-fast-customer-cost-details.yml b/.github/workflows/free-fast-customer-cost-details.yml index 6719b7a02664..abcc058e9f20 100644 --- a/.github/workflows/free-fast-customer-cost-details.yml +++ b/.github/workflows/free-fast-customer-cost-details.yml @@ -118,6 +118,7 @@ jobs: frontend: env: NODE_OPTIONS: --max-old-space-size=4096 + # Playwright 1.56.1 has no Chromium package for Ubuntu 26.04. runs-on: ubuntu-24.04 timeout-minutes: 25 steps: diff --git a/.github/workflows/future-shadow.yml b/.github/workflows/future-shadow.yml index a95928ff2a51..d80454597afb 100644 --- a/.github/workflows/future-shadow.yml +++ b/.github/workflows/future-shadow.yml @@ -90,7 +90,9 @@ jobs: while IFS= read -r target; do case "$target" in *_test.go) continue ;; esac if git cat-file -e "$BASELINE_SHA:$target" 2>/dev/null; then + mkdir -p -- "$(dirname -- "$target")" git show "$BASELINE_SHA:$target" > "$target" + git add -N -- "$target" test "$(git hash-object "$target")" = "$(git rev-parse "$BASELINE_SHA:$target")" else rm -- "$target" diff --git a/.github/workflows/http-task-rebuild.yml b/.github/workflows/http-task-rebuild.yml index 909da77756a0..5d351bdde9d9 100644 --- a/.github/workflows/http-task-rebuild.yml +++ b/.github/workflows/http-task-rebuild.yml @@ -96,7 +96,9 @@ jobs: while IFS= read -r target; do case "$target" in *_test.go) continue ;; esac if git cat-file -e "$BASELINE_SHA:$target" 2>/dev/null; then + mkdir -p -- "$(dirname -- "$target")" git show "$BASELINE_SHA:$target" > "$target" + git add -N -- "$target" expected=$(git rev-parse "$BASELINE_SHA:$target") test "$(git hash-object "$target")" = "$expected" echo "$target baseline=$expected" >> "$RUNNER_TEMP/http-task-evidence/red-blobs.txt" @@ -211,7 +213,9 @@ jobs: while IFS= read -r target; do case "$target" in *_test.go) continue ;; esac if git cat-file -e "$REVIEW_BASELINE:$target" 2>/dev/null; then + mkdir -p -- "$(dirname -- "$target")" git show "$REVIEW_BASELINE:$target" > "$target" + git add -N -- "$target" else rm -- "$target" fi diff --git a/.github/workflows/shadow-review-repair.yml b/.github/workflows/shadow-review-repair.yml index cfc637b0b53b..38db493e00e2 100644 --- a/.github/workflows/shadow-review-repair.yml +++ b/.github/workflows/shadow-review-repair.yml @@ -81,7 +81,9 @@ jobs: while IFS= read -r target; do case "$target" in *_test.go) continue ;; esac if git cat-file -e "$BASELINE_SHA:$target" 2>/dev/null; then + mkdir -p -- "$(dirname -- "$target")" git show "$BASELINE_SHA:$target" > "$target" + git add -N -- "$target" test "$(git hash-object "$target")" = "$(git rev-parse "$BASELINE_SHA:$target")" else rm -- "$target" @@ -154,7 +156,9 @@ jobs: while IFS= read -r target; do case "$target" in *_test.go) continue ;; esac if git cat-file -e "$baseline:$target" 2>/dev/null; then + mkdir -p -- "$(dirname -- "$tested_tree/$target")" git show "$baseline:$target" > "$tested_tree/$target" + git -C "$tested_tree" add -N -- "$target" test "$(git hash-object "$tested_tree/$target")" = "$(git rev-parse "$baseline:$target")" else rm -- "$tested_tree/$target" diff --git a/backend/internal/service/openai_recovery_subreason.go b/backend/internal/service/openai_recovery_subreason.go index 24b0652947a8..c311b08c04f6 100644 --- a/backend/internal/service/openai_recovery_subreason.go +++ b/backend/internal/service/openai_recovery_subreason.go @@ -11,7 +11,8 @@ func safeOpenAIRecoverySubreason(value string) string { "tool_invalid", "tool_incomplete", "tool_duplicate", "tool_unpaired", "tool_history_unsupported", "shadow_record_changed", "shadow_epoch_changed", "shadow_fence_changed", "shadow_fence_invalid", "shadow_store_unavailable", "input_invalid", "input_integrity", "controls_integrity", "readable_intent_missing", - "http_projection_source", "apikey_projection_source", "oauth_projection_source": + "http_projection_source", "apikey_projection_source", "oauth_projection_source", + "ws_body_unreadable", "ws_readable_source", "ws_projection_integrity", "ws_previous_removed": return value default: return "unknown" diff --git a/backend/internal/service/openai_ws_agent_recovery.go b/backend/internal/service/openai_ws_agent_recovery.go index a3a2487b344c..a68528173054 100644 --- a/backend/internal/service/openai_ws_agent_recovery.go +++ b/backend/internal/service/openai_ws_agent_recovery.go @@ -11,9 +11,11 @@ import ( "sync/atomic" "time" + "github.com/Wei-Shaw/sub2api/internal/pkg/logger" coderws "github.com/coder/websocket" "github.com/gin-gonic/gin" "github.com/tidwall/gjson" + "go.uber.org/zap" ) type openAIWSAgentRecoveryKey struct{} @@ -258,12 +260,12 @@ func (r *openAIWSAgentRecovery) begin(account *Account, source, payload []byte, // bridge payload and accidentally granting a transformed opaque item. reader, err := req.GetBody() if err != nil { - return openAIAgentRecoveryError("wire_changed") + return openAIWSWireRefusal(r.ctx, "ws_body_unreadable", source, payload) } actual, err := io.ReadAll(reader) _ = reader.Close() if err != nil { - return openAIAgentRecoveryError("wire_changed") + return openAIWSWireRefusal(r.ctx, "ws_body_unreadable", source, payload) } payload = actual } @@ -297,7 +299,7 @@ func (r *openAIWSAgentRecovery) begin(account *Account, source, payload []byte, } if r.readable != nil { if openAIAgentRecoveryInputDigest(source) != r.readableSource || openAI409ControlsDigest(source) != r.readableControls { - return openAIAgentRecoveryError("wire_changed") + return openAIWSWireRefusal(ctx, "ws_readable_source", source, payload) } ctx = context.WithValue(ctx, openAIAgentRecoveryContextKey{}, r.readable) if mode == "http_bridge" && account.IsOpenAIApiKey() { @@ -348,7 +350,7 @@ func (r *openAIWSAgentRecovery) begin(account *Account, source, payload []byte, gjson.GetBytes(source, "store").Type != gjson.False || gjson.GetBytes(payload, "previous_response_id").Exists() || proof.sourceInput != openAIAgentRecoveryInputDigest(source) || proof.sourceControls != openAI409ControlsDigest(source) || proof.input != openAIAgentRecoveryInputDigest(payload) || proof.controls != openAI409ControlsDigest(payload) { - return openAIAgentRecoveryError("wire_changed") + return openAIWSWireRefusal(ctx, "ws_projection_integrity", source, payload) } // Recheck the original pointer on the actual selected account before // allowing its HTTP representation to omit that pointer. @@ -374,7 +376,7 @@ func (r *openAIWSAgentRecovery) begin(account *Account, source, payload []byte, } if !projected && !r.request.omittedHistory && previous != "" && (r.request.owner != nil || r.request.disableOwnerBinding || r.request.previousResponseID != "") && gjson.GetBytes(payload, "previous_response_id").String() != previous { - return openAIAgentRecoveryError("wire_changed") + return openAIWSWireRefusal(ctx, "ws_previous_removed", source, payload) } if err := r.service.checkOpenAIAgentRecoveryAccount(ctx, account); err != nil { if r.request.hasCompletedMixedOwners() { @@ -561,3 +563,38 @@ func (r *openAIWSAgentRecovery) write(payload []byte, write func() error) error func openAIWSAgentRecoveryClose(err error) error { return NewOpenAIWSClientCloseError(coderws.StatusPolicyViolation, "agent task continuation is unavailable; original task was preserved", err) } + +// Fixed field-presence/count metadata only. Never log response IDs, hashes, +// input text, tool content, headers, credentials or arbitrary JSON keys. +func openAIWSWireRefusal(ctx context.Context, stage string, source, payload []byte) error { + sourceInput, wireInput := gjson.GetBytes(source, "input"), gjson.GetBytes(payload, "input") + inputKind := "absent" + switch { + case sourceInput.IsArray(): + inputKind = "array" + case sourceInput.Type == gjson.String: + inputKind = "string" + case sourceInput.Exists(): + inputKind = "other" + } + storeKind := "absent" + switch gjson.GetBytes(source, "store").Type { + case gjson.True: + storeKind = "true" + case gjson.False: + storeKind = "false" + default: + if gjson.GetBytes(source, "store").Exists() { + storeKind = "other" + } + } + logger.FromContext(ctx).Warn("openai.encrypted_history_409_refused", zap.String("stage", stage), + zap.String("source_input_kind", inputKind), zap.String("source_store", storeKind), + zap.Int("source_input_items", len(sourceInput.Array())), zap.Int("wire_input_items", len(wireInput.Array())), + zap.Bool("source_previous_present", gjson.GetBytes(source, "previous_response_id").String() != ""), + zap.Bool("wire_previous_present", gjson.GetBytes(payload, "previous_response_id").String() != ""), + zap.Bool("source_model_present", gjson.GetBytes(source, "model").String() != ""), + zap.Bool("input_changed", openAIAgentRecoveryInputDigest(source) != openAIAgentRecoveryInputDigest(payload)), + zap.Bool("controls_changed", openAI409ControlsDigest(source) != openAI409ControlsDigest(payload))) + return openAIRecoveryDiagnosticError("wire_changed", stage, openAIAgentRecoveryFromContext(ctx)) +} diff --git a/backend/internal/service/openai_ws_plaintext_owner_test.go b/backend/internal/service/openai_ws_plaintext_owner_test.go index 91ba3bd8eef7..7b419692b8bd 100644 --- a/backend/internal/service/openai_ws_plaintext_owner_test.go +++ b/backend/internal/service/openai_ws_plaintext_owner_test.go @@ -116,6 +116,12 @@ func TestOpenAIWSPlaintextBridgeProjectionGuards(t *testing.T) { require.Empty(t, manager.request.previousResponseID) } else { require.Error(t, err, "changed projection must never authorize an upstream write") + if change != "owner" && change != "unproven" { + var recovery *OpenAIAgentRecoveryError + require.ErrorAs(t, err, &recovery) + require.Equal(t, "ws_projection_integrity", recovery.InternalSubreason()) + require.Equal(t, "encrypted_agent_recovery_wire_changed", recovery.ClientCode()) + } } }) }