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
1 change: 1 addition & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ jobs:
- vcpkg.json
- .github/workflows/ci.yml
- .github/workflows/tests.yml
- .github/workflows/memory-comment.yml
- .github/workflows/nightly.yml
- .github/actions/setup-sdk-deps/**
- .github/actions/setup-capture/**
Expand Down
100 changes: 100 additions & 0 deletions .github/workflows/memory-comment.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
# Copyright 2026 LiveKit, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

name: Memory results comment

on:
workflow_run:
workflows: [CI]
types: [completed]

# Keep write access out of the build jobs, including builds of fork PRs.
# This workflow never checks out or executes code from the triggering run.
permissions:
actions: read
contents: read
pull-requests: write

concurrency:
group: memory-results-${{ github.event.workflow_run.head_repository.full_name }}-${{ github.event.workflow_run.head_branch }}
cancel-in-progress: false

jobs:
comment:
if: github.event.workflow_run.event == 'pull_request'
runs-on: ubuntu-24.04
steps:
- name: Find memory report
id: report
uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9.0.0
with:
script: |
const run = context.payload.workflow_run;
const artifacts = await github.paginate(github.rest.actions.listWorkflowRunArtifacts, {
...context.repo, run_id: run.id
});
const artifact = artifacts.find(item =>
item.name === `memory-tester-report-${run.run_attempt}` && !item.expired);
if (artifact) core.setOutput('artifact-id', artifact.id);

- name: Download memory report
if: steps.report.outputs.artifact-id != ''
uses: actions/download-artifact@9000827ccba6bdab643e8b6fd33ac0654aef8333 # v8.0.2
with:
artifact-ids: ${{ steps.report.outputs.artifact-id }}
merge-multiple: true
path: ${{ runner.temp }}/memory-results
github-token: ${{ github.token }}
run-id: ${{ github.event.workflow_run.id }}

- name: Update PR comment
if: steps.report.outputs.artifact-id != ''
uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9.0.0
with:
script: |
const fs = require('node:fs');
const run = context.payload.workflow_run;
// Resolve the PR through GitHub, never through downloaded metadata.
// The workflow_run pull_requests array can be empty for fork PRs.
const pulls = await github.paginate(github.rest.repos.listPullRequestsAssociatedWithCommit, {
...context.repo, commit_sha: run.head_sha
});
const marker = '<!-- livekit-memory-results -->';
const report = fs.readFileSync(`${process.env.RUNNER_TEMP}/memory-results/memory-tester-report.md`, 'utf8');
if (report.length > 32000) throw new Error('Memory report is too large');
const needsAttention = /:x: (FAIL|ERROR)|:warning: ADVISORY/.test(report);
for (const pull of pulls) {
const { data: current } = await github.rest.pulls.get({
...context.repo, pull_number: pull.number
});
if (current.state !== 'open' || current.head.sha !== run.head_sha ||
current.base.repo.full_name !== `${context.repo.owner}/${context.repo.repo}`) continue;
const comments = await github.paginate(github.rest.issues.listComments, {
...context.repo, issue_number: pull.number
});
const existing = comments.find(comment =>
comment.user.login === 'github-actions[bot]' && comment.body?.startsWith(marker));
// A delayed completion or rerun must not replace a newer result.
const previous = existing?.body.match(/<!-- run:(\d+) attempt:(\d+) -->/);
if (previous && (Number(previous[1]) > run.id ||
(Number(previous[1]) === run.id && Number(previous[2]) > run.run_attempt))) continue;
const body = `${marker}\n<!-- run:${run.id} attempt:${run.run_attempt} -->\n` +
`${needsAttention ? '⚠️ Memory checks need attention.' : '✅ Memory checks passed.'}\n\n` +
`[CI run](${run.html_url}/attempts/${run.run_attempt}) · Commit ${run.head_sha}\n\n${report}`;
if (existing) {
await github.rest.issues.updateComment({ ...context.repo, comment_id: existing.id, body });
} else {
await github.rest.issues.createComment({ ...context.repo, issue_number: pull.number, body });
}
}
24 changes: 23 additions & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -457,22 +457,44 @@ jobs:
--gtest_output=xml:${{ env.BUILD_DIR }}/integration-test-results.xml

- name: Run memory tester
id: memory
if: matrix.name == 'ubuntu-24.04-x64' && inputs.build_type == 'release'
timeout-minutes: 10
shell: bash
run: |
set -euo pipefail
export MEMORY_TESTER_REPORT="$RUNNER_TEMP/memory-tester-report.md"
source scripts/set-test-tokens.sh
scripts/memory-tester.sh \
--build-dir "${{ env.BUILD_DIR }}" \
--scenario all \
--iterations 100 \
--warmup 20 \
--max-rss-growth-mib 24 \
--max-thread-growth 2 \
--max-thread-growth 10 \
--advisory-max-rss-growth-mib 8 \
--advisory-max-thread-growth 0

- name: Summarize memory results
if: always() && steps.memory.outcome != 'skipped' && steps.memory.outcome != ''
shell: bash
env:
MEMORY_OUTCOME: ${{ steps.memory.outcome }}
run: |
report="$RUNNER_TEMP/memory-tester-report.md"
if [[ "$MEMORY_OUTCOME" != 'success' ]]; then
echo ':x: FAIL — memory tester did not complete successfully. See the run logs.' >> "$report"
fi
cat "$report" >> "$GITHUB_STEP_SUMMARY"

- name: Upload memory results
if: always() && steps.memory.outcome != 'skipped' && steps.memory.outcome != ''
uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2
with:
name: memory-tester-report-${{ github.run_attempt }}
path: ${{ runner.temp }}/memory-tester-report.md
retention-days: ${{ inputs.artifact_retention_days }}

- name: Run stress tests
if: matrix.e2e-testing && inputs.run_stress_tests
timeout-minutes: ${{ inputs.stress_timeout_minutes }}
Expand Down
6 changes: 3 additions & 3 deletions docs/testing.md
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ Each scenario reports process RSS and thread count at cycle 0, after warmup
cycle 20, and after final cycle 100. Checkpoint sampling waits for the thread
count to remain stable for 500 ms so short-lived teardown work does not cause a
false failure. The gate applies to warmup-to-final growth. CI fails above its
blocking limits of 24 MiB RSS or two threads, which protects against large
blocking limits of 24 MiB RSS or 10 threads, which protects against large
customer-impacting regressions while allowing for allocator and dependency
variation. It also emits a non-blocking advisory above 8 MiB RSS or zero
threads. If threads grow, the tester reports when the final sustained growth
Expand All @@ -236,11 +236,11 @@ tokens before running any scenario:
source scripts/set-test-tokens.sh
scripts/memory-tester.sh --scenario audio-track \
--iterations 100 --warmup 20 \
--max-rss-growth-mib 24 --max-thread-growth 2 \
--max-rss-growth-mib 24 --max-thread-growth 10 \
--advisory-max-rss-growth-mib 8 --advisory-max-thread-growth 0
scripts/memory-tester.sh --scenario video-track \
--iterations 100 --warmup 20 \
--max-rss-growth-mib 24 --max-thread-growth 2 \
--max-rss-growth-mib 24 --max-thread-growth 10 \
--advisory-max-rss-growth-mib 8 --advisory-max-thread-growth 0
```

Expand Down
14 changes: 8 additions & 6 deletions scripts/memory-tester.sh
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ Environment:
MEMORY_TESTER_MAX_THREAD_GROWTH,
MEMORY_TESTER_ADVISORY_MAX_RSS_GROWTH_MIB,
MEMORY_TESTER_ADVISORY_MAX_THREAD_GROWTH, MALLOC_ARENA_MAX.
MEMORY_TESTER_REPORT overrides the GITHUB_STEP_SUMMARY report destination.
All scenarios require LIVEKIT_URL and LIVEKIT_TOKEN_A.
EOF
}
Expand All @@ -63,6 +64,7 @@ max_rss_growth_mib="${MEMORY_TESTER_MAX_RSS_GROWTH_MIB:-8}"
max_thread_growth="${MEMORY_TESTER_MAX_THREAD_GROWTH:-0}"
advisory_max_rss_growth_mib="${MEMORY_TESTER_ADVISORY_MAX_RSS_GROWTH_MIB:-}"
advisory_max_thread_growth="${MEMORY_TESTER_ADVISORY_MAX_THREAD_GROWTH:-}"
summary_file="${MEMORY_TESTER_REPORT:-${GITHUB_STEP_SUMMARY:-}}"

while (($#)); do
case "$1" in
Expand Down Expand Up @@ -131,7 +133,7 @@ for current_scenario in "${scenarios[@]}"; do
fi
done

if [[ -n "${GITHUB_STEP_SUMMARY:-}" ]]; then
if [[ -n "${summary_file}" ]]; then
{
echo "## Memory tester results"
echo
Expand All @@ -142,7 +144,7 @@ if [[ -n "${GITHUB_STEP_SUMMARY:-}" ]]; then
echo
echo "| Scenario | RSS 0→${warmup} | RSS ${warmup}→${iterations} | Threads 0→${warmup} | Threads ${warmup}→${iterations} | Status |"
echo "|---|---:|---:|---:|---:|---|"
} >> "${GITHUB_STEP_SUMMARY}"
} >> "${summary_file}"
fi

report_regex='memory tester: scenario=([a-z-]+), RSS 0 ([0-9]+\.[0-9]+) -> warmup ([0-9]+\.[0-9]+) MiB \((-?[0-9]+\.[0-9]+) MiB\) -> final ([0-9]+\.[0-9]+) MiB \((-?[0-9]+\.[0-9]+) MiB\), threads 0 ([0-9]+) -> warmup ([0-9]+) \((-?[0-9]+)\) -> final ([0-9]+) \((-?[0-9]+)\), verdict=(PASS|FAIL), advisory=(PASS|FAIL)'
Expand Down Expand Up @@ -186,7 +188,7 @@ for current_scenario in "${scenarios[@]}"; do
fi
fi

if [[ -n "${GITHUB_STEP_SUMMARY:-}" ]]; then
if [[ -n "${summary_file}" ]]; then
if [[ "${BASH_REMATCH[12]}" == "FAIL" ]]; then
verdict=":x: FAIL"
elif [[ "${advisory_exceeded}" == "true" ]]; then
Expand All @@ -199,12 +201,12 @@ for current_scenario in "${scenarios[@]}"; do
thread_warmup_growth="$(format_growth "${BASH_REMATCH[9]}")"
thread_final_growth="$(format_growth "${BASH_REMATCH[11]}")"
echo "| ${BASH_REMATCH[1]} | ${rss_warmup_growth} MiB | ${rss_final_growth} MiB | ${thread_warmup_growth} | ${thread_final_growth} | ${verdict} |" \
>> "${GITHUB_STEP_SUMMARY}"
>> "${summary_file}"
fi
else
echo "ERROR: ${current_scenario} did not produce a memory report." >&2
if [[ -n "${GITHUB_STEP_SUMMARY:-}" ]]; then
echo "| ${current_scenario} | — | — | — | — | :x: ERROR |" >> "${GITHUB_STEP_SUMMARY}"
if [[ -n "${summary_file}" ]]; then
echo "| ${current_scenario} | — | — | — | — | :x: ERROR |" >> "${summary_file}"
fi
status=1
fi
Expand Down
Loading