Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
98 changes: 98 additions & 0 deletions .github/scripts/issue817-race-gate.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
#!/usr/bin/env bash
# Remote CI only. Diagnostics never replace the first race regression result.
set -euo pipefail
label="$1"
checkout="$2"
regression="$3"
evidence="$checkout/evidence"
binary="$RUNNER_TEMP/issue817-$label-$GITHUB_RUN_ID.test"
mkdir -p "$evidence"
go version > "$evidence/toolchain.txt"
go env GOOS GOARCH CGO_ENABLED GOEXPERIMENT >> "$evidence/toolchain.txt"
uname -a > "$evidence/kernel.txt"
ldd --version > "$evidence/libc.txt" 2>&1
printf 'go test -c -race -tags=integration ./internal/repository -o %q\n' "$binary" > "$evidence/command.txt"
printf 'cd %q && %q -test.run %q -test.count=1 -test.v=true -test.timeout=10m\n' "$checkout/backend/internal/repository" "$binary" "$regression" >> "$evidence/command.txt"
if ! (cd "$checkout/backend" && go test -c -race -tags=integration ./internal/repository -o "$binary") > "$evidence/build.log" 2>&1; then
cat "$evidence/build.log"
exit 1
fi
go version -m "$binary" > "$evidence/binary-modules.txt"
go tool buildid "$binary" > "$evidence/binary-buildid.txt"
sha256sum "$binary" > "$evidence/binary-before.sha256"
ulimit -c 0
export GOTRACEBACK=crash
set +e
(cd "$checkout/backend/internal/repository" && "$binary" -test.run "$regression" -test.count=1 -test.v=true -test.timeout=10m) > "$evidence/regression.log" 2>&1
result=$?
set -e
cat "$evidence/regression.log"
printf '%s\n' "$result" > "$evidence/regression-exit.txt"
sha256sum "$binary" > "$evidence/binary-after.sha256"
cmp "$evidence/binary-before.sha256" "$evidence/binary-after.sha256"

if [ "$result" -eq 139 ]; then
# Live first-signal capture avoids trusting the old core/executable mismatch.
# Keep ASLR enabled as in the uninstrumented invocation. Never print frame
# arguments, locals, the environment, memory dumps or raw core files.
set +e
(cd "$checkout/backend/internal/repository" && timeout --kill-after=5s 90s gdb -nx -batch \
-iex 'set auto-load off' -iex 'set print frame-arguments none' \
-ex 'set pagination off' -ex 'set confirm off' \
-ex 'set disable-randomization off' -ex 'handle SIGSEGV stop print nopass' \
-ex run -ex 'p $_siginfo' -ex 'info registers pc sp' \
-ex 'x/8i $pc' -ex 'info sharedlibrary' -ex 'thread apply all bt' \
--args "$binary" -test.run "$regression" -test.count=1 -test.v=true -test.timeout=60s) > "$evidence/first-signal.txt" 2>&1
debugger_result=$?
# This still enters the exact TestMain but selects no product tests. It is
# a startup comparison only, and cannot satisfy either RED or GREEN.
(cd "$checkout/backend/internal/repository" && timeout --kill-after=5s 60s "$binary" -test.run '^$' -test.count=1 -test.v=true -test.timeout=45s) > "$evidence/startup-only.log" 2>&1
startup_result=$?
set -e
printf '%s\n' "$debugger_result" > "$evidence/debugger-exit.txt"
printf '%s\n' "$startup_result" > "$evidence/startup-only-exit.txt"

# Independent stdlib-only race binary exercises the observed os/exec+timer
# startup path without importing application code. A pass is not exoneration.
cat > "$RUNNER_TEMP/issue817-startup.go" <<'GO'
package main

import (
"context"
"fmt"
"os/exec"
"sync"
"time"
)

func main() {
var workers sync.WaitGroup
for i := 0; i < 4; i++ {
workers.Add(1)
go func() { defer workers.Done(); for j := 0; j < 20; j++ { <-time.After(time.Millisecond) } }()
}
for _, args := range [][]string{{"info"}, {"image", "inspect", "postgres:18.1-alpine3.23"}} {
fmt.Println("stdlib startup before docker", args[0])
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
err := exec.CommandContext(ctx, "docker", args...).Run()
cancel()
fmt.Println("stdlib startup after docker", args[0], "error:", err)
}
workers.Wait()
}
GO
set +e
go build -race -o "$RUNNER_TEMP/issue817-startup" "$RUNNER_TEMP/issue817-startup.go" > "$evidence/stdlib-build.log" 2>&1
smoke_build=$?
if [ "$smoke_build" -eq 0 ]; then
timeout --kill-after=5s 45s "$RUNNER_TEMP/issue817-startup" > "$evidence/stdlib-startup.log" 2>&1
printf '%s\n' "$?" > "$evidence/stdlib-startup-exit.txt"
fi
set -e
printf '%s\n' "$smoke_build" > "$evidence/stdlib-build-exit.txt"
sha256sum "$binary" > "$evidence/binary-after-diagnostics.sha256"
cmp "$evidence/binary-before.sha256" "$evidence/binary-after-diagnostics.sha256"
fi
printf 'passed\n' > "$evidence/binary-identity-ok.txt"
# Even a successful debugger/startup comparison cannot turn a crash into GREEN.
exit "$result"
33 changes: 33 additions & 0 deletions .github/scripts/issue817-validate-evidence.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#!/usr/bin/env bash
# Remote CI evidence gate. Expected RED failures never excuse forbidden errors.
set -euo pipefail
behavior="$1"
first_result="$2"
log="$3"
test -r "$log"
if grep -Eq 'build failed|setup failed|undefined:|syntax error:|no tests to run|panic:|--- SKIP:|WARNING: DATA RACE|race detected during execution|Segmentation fault|segmentation fault|core dumped' "$log"; then
echo 'Rejected forbidden error in regression evidence' >&2
exit 1
fi
for child in never_run previous_completed_run; do
name="TestIssue817QuotaSkipPreservesPending5xxExecution/$child"
if [ "$behavior" = red ]; then
test "$first_result" -ne 0
grep -F -- "--- FAIL: $name" "$log"
# Attribute the expected 1/actual 0 probe failure to each child's own
# execution section, rather than accepting one global diagnostic match.
awk -v name="$name" '
$1 == "===" && $2 == "RUN" { selected = ($3 == name) }
selected && /expected:[[:space:]]*1([[:space:]]|$)/ { expected = 1 }
selected && /actual[[:space:]]*:[[:space:]]*0([[:space:]]|$)/ { actual = 1 }
selected && /pending 5xx signal must execute after quota-skipped cron before acknowledgement/ { diagnostic = 1 }
END { exit !(expected && actual && diagnostic) }
' "$log"
elif [ "$behavior" = green ]; then
test "$first_result" -eq 0
grep -F -- "--- PASS: $name" "$log"
else
echo 'Unknown evidence behavior' >&2
exit 1
fi
done
182 changes: 182 additions & 0 deletions .github/workflows/issue817-quota-skip-followup.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,182 @@
name: Issue817 quota skip pending 5xx

on:
push:
branches: [fix/issue817-quota-skip-followup-20261113]
pull_request:
paths:
- 'backend/internal/repository/quality_template_quota.go'
- 'backend/internal/repository/quality_quota_5xx_integration_test.go'
- 'backend/internal/repository/integration_harness_test.go'
- 'backend/internal/service/quality_quota_integration_helper.go'
- '.github/scripts/issue817-race-gate.sh'
- '.github/scripts/issue817-validate-evidence.sh'
- '.github/workflows/issue817-quota-skip-followup.yml'

permissions:
contents: read

concurrency:
group: issue817-skip-${{ github.event_name }}-${{ github.ref }}
cancel-in-progress: true

jobs:
pending-5xx:
runs-on: ubuntu-latest
timeout-minutes: 25
strategy:
fail-fast: false
matrix:
behavior: [red, green]
# Provision services outside the race binary: the captured startup SIGSEGV
# occurred in TestMain's Docker subprocess path, before any product test.
services:
postgres:
image: postgres:18.1-alpine3.23
env:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
POSTGRES_DB: sub2api_test
ports:
- 5432:5432
options: >-
--health-cmd "pg_isready -U postgres -d sub2api_test"
--health-interval 5s
--health-timeout 5s
--health-retries 12
redis:
image: redis:8.4-alpine
ports:
- 6379:6379
options: >-
--health-cmd "redis-cli ping"
--health-interval 5s
--health-timeout 5s
--health-retries 12
env:
SUB2API_TEST_POSTGRES_DSN: 'host=127.0.0.1 port=5432 dbname=sub2api_test user=postgres password=postgres sslmode=disable TimeZone=UTC'
SUB2API_TEST_REDIS_URL: 'redis://127.0.0.1:6379/0'
steps:
- uses: actions/checkout@v6
with:
ref: ${{ github.event.pull_request.head.sha || github.sha }}
path: ${{ matrix.behavior }}
- name: Record exact candidate and baseline blob
working-directory: ${{ matrix.behavior }}
env:
EXPECTED_HEAD: ${{ github.event.pull_request.head.sha || github.sha }}
BEHAVIOR: ${{ matrix.behavior }}
shell: bash
run: |
set -euo pipefail
mkdir -p evidence
git rev-parse HEAD | tee evidence/head.txt
test "$(git rev-parse HEAD)" = "$EXPECTED_HEAD"
if [ "$BEHAVIOR" = red ]; then
original=c424f8217da12cd4fb8d10aeaf1c4f2592c3f286
source=backend/internal/repository/quality_template_quota.go
git fetch --no-tags --depth=1 origin "$original"
git rev-parse "$original:$source" | tee evidence/original-blob.txt
# Only the isolated RED checkout receives the old production blob.
git show "$original:$source" > "$source"
fi
- name: Reject contaminated RED evidence before running product regressions
working-directory: ${{ matrix.behavior }}
shell: bash
run: |
set -euo pipefail
cat > evidence/gate-valid-red.log <<'LOG'
=== RUN TestIssue817QuotaSkipPreservesPending5xxExecution/never_run
expected: 1
actual : 0
Messages: pending 5xx signal must execute after quota-skipped cron before acknowledgement
=== RUN TestIssue817QuotaSkipPreservesPending5xxExecution/previous_completed_run
expected: 1
actual : 0
Messages: pending 5xx signal must execute after quota-skipped cron before acknowledgement
--- FAIL: TestIssue817QuotaSkipPreservesPending5xxExecution
--- FAIL: TestIssue817QuotaSkipPreservesPending5xxExecution/never_run
--- FAIL: TestIssue817QuotaSkipPreservesPending5xxExecution/previous_completed_run
LOG
validator=.github/scripts/issue817-validate-evidence.sh
bash "$validator" red 1 evidence/gate-valid-red.log
for forbidden in 'WARNING: DATA RACE' 'panic: injected' 'Segmentation fault' '--- SKIP: injected' '[build failed]' 'no tests to run'; do
cp evidence/gate-valid-red.log evidence/gate-contaminated-red.log
printf '%s\n' "$forbidden" >> evidence/gate-contaminated-red.log
if bash "$validator" red 1 evidence/gate-contaminated-red.log; then
echo "Gate wrongly accepted forbidden evidence: $forbidden" >&2
exit 1
fi
done
# Both FAIL labels still exist; only the second child's diagnosis is
# missing. A first-child-only global grep would wrongly accept this.
awk '/=== RUN.*previous_completed_run/ { second=1 } second && /Messages:/ { next } { print }' evidence/gate-valid-red.log > evidence/gate-missing-second-diagnostic.log
if bash "$validator" red 1 evidence/gate-missing-second-diagnostic.log; then
echo 'Gate wrongly accepted a missing second-child diagnostic' >&2
exit 1
fi
if bash "$validator" red 0 evidence/gate-valid-red.log; then
echo 'Gate wrongly accepted a zero first RED exit' >&2
exit 1
fi
echo 'Evidence gate synthetic rejection regressions passed'
- uses: actions/setup-go@v6
with:
go-version-file: ${{ matrix.behavior }}/backend/go.mod
cache-dependency-path: ${{ matrix.behavior }}/backend/go.sum
- name: Prepare live first-signal startup diagnostics
working-directory: ${{ matrix.behavior }}
shell: bash
run: |
set -euo pipefail
if ! command -v gdb >/dev/null; then
bash .github/scripts/ci-ubuntu-mirrors.sh
sudo apt-get update
sudo apt-get install -y --no-install-recommends gdb
fi
uname -a > evidence/kernel.txt
go version > evidence/toolchain.txt
- name: Real PostgreSQL plan and existing Redis trigger worker
working-directory: ${{ matrix.behavior }}
env:
CI: 'true'
BEHAVIOR: ${{ matrix.behavior }}
shell: bash
run: |
set -euo pipefail
set +e
bash .github/scripts/issue817-race-gate.sh "$BEHAVIOR" "$PWD" '^TestIssue817QuotaSkipPreservesPending5xxExecution$' > evidence/pending-5xx.log 2>&1
result=$?
set -e
cat evidence/pending-5xx.log
test "$(cat evidence/binary-identity-ok.txt)" = passed
bash .github/scripts/issue817-validate-evidence.sh "$BEHAVIOR" "$result" evidence/pending-5xx.log
- name: Retained exact lease, 401, ownership, manual and trigger contracts
if: matrix.behavior == 'green'
working-directory: green/backend
env:
CI: 'true'
shell: bash
run: |
set -euo pipefail
go test -race -tags=integration ./internal/repository -run '^(TestIssue817QuotaSkipPreserves401AndOwnership|TestIssue817QuotaSkipRetainsActualIsolationOwnership|TestIssue817ManualTriggerIsOneShotAndLeaseFenced|TestQuality5xxClaimKeepsCronAndCoalescesScheduledRun|TestQuality5xxFinishConsumesCrossedCronWithoutOverwritingEdits|TestQualityRetestRestBlocksEveryClaimUntilDeadline)$' -count=1 -v -timeout=10m 2>&1 | tee ../evidence/retained-contracts.log
if grep -Eq 'no tests to run|--- SKIP:|panic:|WARNING: DATA RACE|race detected during execution' ../evidence/retained-contracts.log; then
exit 1
fi
for required in \
TestIssue817QuotaSkipPreserves401AndOwnership \
TestIssue817QuotaSkipRetainsActualIsolationOwnership \
TestIssue817ManualTriggerIsOneShotAndLeaseFenced \
TestQuality5xxClaimKeepsCronAndCoalescesScheduledRun \
TestQuality5xxFinishConsumesCrossedCronWithoutOverwritingEdits \
TestQualityRetestRestBlocksEveryClaimUntilDeadline; do
grep -F -- "--- PASS: $required (" ../evidence/retained-contracts.log
done
- uses: actions/upload-artifact@v7
if: always()
with:
name: issue817-skip-${{ matrix.behavior }}-${{ github.event_name }}-${{ github.run_id }}
path: |
${{ matrix.behavior }}/evidence/
evidence/
if-no-files-found: error
Loading
Loading