Skip to content
Open
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
5 changes: 5 additions & 0 deletions .github/workflows/review.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ on:
description: Codex session this run continues; one per PR, or per branch for pushes, by default.
type: string
default: ""
session-ref-prefix:
description: Store session snapshots under `refs/<prefix>/<hash>` instead of Actions artifacts; empty keeps artifacts, for example `agent-sessions`.
type: string
default: ""
broker:
description: Service that exchanges the job's OIDC token for an installation token of the App and relays webhooks.
type: string
Expand Down Expand Up @@ -94,6 +98,7 @@ jobs:
codex-auth: ${{ secrets.codex-auth }}
service-tier: ${{ inputs.service-tier }}
session-key: ${{ inputs.session-key }}
session-ref-prefix: ${{ inputs.session-ref-prefix }}
broker: ${{ inputs.broker }}
encrypt-snapshots: ${{ inputs.encrypt-snapshots }}
shared-uv-cache: ${{ inputs.shared-uv-cache }}
Expand Down
8 changes: 5 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -105,13 +105,15 @@ Each run seeds the webhook that started it into its event stream in the same sha
- Completed checks on the reviewed head wake a review that waits for CI; the review's own check runs and suites never do.
- The review decides when a pull request is safe to merge, using CI results it trusts and running the checks that matter when CI is missing or flaky. It leaves work that is still moving, such as recent pushes or an open draft, to the author. The action merges only when the verdict says so and the head has not moved since.

The tool and stop hooks record consumed context locally. The action checkpoints these receipts with the review session after publishing the checks, PR review and reactions successfully. Session snapshots are Actions artifacts shared across trigger refs. When no artifact exists, the action can resume from a legacy cache visible to the trigger. Queued runs fetch the current PR head and skip consumed activity only when that head also has a saved publication checkpoint. Receiving an event alone never marks it consumed, and a forked review starts its own checkpoint. Receipt deduplication is independent of the transport: the action neither saves a replay cursor nor sends `Last-Event-ID`.
The tool and stop hooks record consumed context locally. The action checkpoints these receipts with the review session after publishing the checks, PR review and reactions successfully. Session snapshots are Actions artifacts shared across trigger refs, or custom git refs when `session-ref-prefix` is set (see below). When no artifact exists, the action can resume from a legacy cache visible to the trigger. Queued runs fetch the current PR head and skip consumed activity only when that head also has a saved publication checkpoint. Receiving an event alone never marks it consumed, and a forked review starts its own checkpoint. Receipt deduplication is independent of the transport: the action neither saves a replay cursor nor sends `Last-Event-ID`.

New session snapshots expire after 1 day by default. When using the reusable workflow, set the repository Actions variable `REVIEW_SESSION_RETENTION_DAYS` to a positive whole number of days to keep them longer. Direct action callers can set `session-retention-days`. GitHub caps the requested retention at the repository limit. Invalid values warn and fall back to 1 day.
New session artifacts expire after 1 day by default. When using the reusable workflow, set the repository Actions variable `REVIEW_SESSION_RETENTION_DAYS` to a positive whole number of days to keep them longer. Direct action callers can set `session-retention-days`. GitHub caps the requested retention at the repository limit. Invalid values warn and fall back to 1 day.

In a private repository, setting `session-ref-prefix` (for example `agent-sessions`) moves session snapshots from Actions artifacts to custom git refs at `refs/agent-sessions/<hash>`. Each changed snapshot appends a commit that contains the complete session as raw files: rollouts are split into 16 MiB chunks with a manifest of paths, sizes and SHA-256 digests, and the next run reassembles and verifies them before Codex resumes. Nothing is pruned, so earlier tool output stays available to search on later runs. Restore reads the ref at depth 1; when the ref is absent the action falls back to an artifact, then the legacy cache. These are not branches: pushing a custom ref does not trigger `push` workflows, but anyone with read access to the repository can fetch it. Git must resolve both fetch and push to the checked repository’s HTTPS URL. The action checks repository visibility before restoring and again before saving; this cannot protect snapshots already pushed if you later make the repository public. Do not make a repository containing these snapshots public. `encrypt-snapshots` is not supported in this mode yet, and `session-retention-days` applies only to artifact snapshots. Ref history grows with every save; changing the prefix starts a new namespace while leaving the old refs untouched. Removing the input switches back to artifact storage. The next run restores the latest available artifact or legacy cache, and starts fresh if both have expired. Progress saved only in the ref stays there.

To shorten retention for `agent-debug-events`, set the repository Actions variable `REVIEW_DEBUG_RETENTION_DAYS` to a positive whole number of days (for example, `7`). Direct action callers can set the `debug-retention-days` input. An invalid value skips the debug upload.

Session saves clear reasoning bodies from superseded context windows in an archive-only copy. Every saved thread keeps its required compaction checkpoint, guardian state and later records, including parent history still needed by an earlier fork. The cleanup keeps record identities, byte offsets and ordinals intact by replacing removed bodies with JSON whitespace; compressed artifacts shrink while uncompressed file lengths stay the same. Histories without a proven boundary stay intact. Old reasoning is no longer available for rewind or transcript inspection after restoring a cleaned snapshot. The running session and separately archived debug events are unchanged.
Artifact saves clear reasoning bodies from superseded context windows in an archive-only copy. Every saved thread keeps its required compaction checkpoint, guardian state and later records, including parent history still needed by an earlier fork. The cleanup keeps record identities, byte offsets and ordinals intact by replacing removed bodies with JSON whitespace; compressed artifacts shrink while uncompressed file lengths stay the same. Histories without a proven boundary stay intact. Old reasoning is no longer available for rewind or transcript inspection after restoring a cleaned snapshot. The running session and separately archived debug events are unchanged.

Anyone with read access to the repository can download its session and debug artifacts, which contain Codex conversations and tool output. Set `encrypt-snapshots` to have the action encrypt each artifact with AES-256-GCM; it is off by default, and needs a broker that serves `/snapshot-key`. The key comes from the broker, which derives it from the repository's numeric ID and its own secret: renaming the repository, reinstalling the App, or switching the provider or the model leaves older snapshots readable, while another repository's key cannot open them. If the current session fails authentication, the run stops before extraction. Restore the original key or delete the unreadable snapshot to resume reviews. A child review can start fresh if it cannot restore the parent session. Snapshots saved before encryption restore as they were, and the next save of that session replaces the plaintext one, which pruning then removes like any older snapshot; archives under the pre-rename `code-review-session-*` name remain downloadable until retention expires. To remove one sooner, delete the plaintext artifact from its workflow run after verifying the replacement. Restores follow the archive's own marker rather than the input, so turning `encrypt-snapshots` off stops new encryption without stranding what an earlier run encrypted. [GitHub artifact access](https://docs.github.com/en/actions/how-tos/manage-workflow-runs/download-workflow-artifacts)

Expand Down
113 changes: 106 additions & 7 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ inputs:
default: "1"
session-key:
description: Codex session this review continues; one per PR, or per branch for pushes, by default.
session-ref-prefix:
description: Store session snapshots under `refs/<prefix>/<hash>` in this repository instead of Actions artifacts. Empty keeps artifacts; for example `agent-sessions`. The ref namespace is configurable through this prefix.
default: ""
service-tier:
description: Provider service tier for reviews, such as `ultrafast` where the model advertises it; `default` or empty sends none.
setup:
Expand Down Expand Up @@ -84,6 +87,21 @@ runs:
done ) >> "$RUNNER_TEMP/token.err" 2>&1 &
echo "TOKEN_PID=$!" >> "$GITHUB_ENV"

- name: Validate the session storage mode
if: steps.app-token.outputs.skip != 'true' && inputs.session-ref-prefix != ''
shell: bash
env:
ENCRYPT_SNAPSHOTS: ${{ inputs.encrypt-snapshots }}
GH_CONFIG_DIR: ${{ runner.temp }}/gh
run: |
encryption=$(printf '%s' "$ENCRYPT_SNAPSHOTS" | tr '[:upper:]' '[:lower:]' | tr -d '[:space:]')
case "$encryption" in
true) echo "::error::encrypt-snapshots is not supported with session-ref-prefix yet"; exit 1 ;;
false) ;;
*) echo "::error::encrypt-snapshots must be true or false"; exit 1 ;;
esac
bash "$GITHUB_ACTION_PATH/scripts/require-private-session-repo.sh"

- name: Resolve the review target
if: steps.app-token.outputs.skip != 'true'
shell: bash
Expand Down Expand Up @@ -177,9 +195,32 @@ runs:
with:
bun-version: ${{ inputs.bun-version }}

- name: Find the session snapshot ref
id: ref-snapshot
if: steps.app-token.outputs.skip != 'true' && (inputs.session-ref-prefix != '' && env.SKIP != 'true')
shell: bash
env:
SESSION_REF_PREFIX: ${{ inputs.session-ref-prefix }}
SESSION_REF_REMOTE: ''
SESSION_REF_TOKEN: ''
GH_CONFIG_DIR: ${{ runner.temp }}/gh
run: bash "$GITHUB_ACTION_PATH/scripts/session-ref.sh" find "$SESSION_KEY"

- name: Restore the session snapshot from its ref
id: restore-session-ref
if: steps.app-token.outputs.skip != 'true' && (steps.ref-snapshot.outputs.commit)
shell: bash
env:
SESSION_REF_PREFIX: ${{ inputs.session-ref-prefix }}
SESSION_REF_REMOTE: ''
SESSION_REF_TOKEN: ''
GH_CONFIG_DIR: ${{ runner.temp }}/gh
run: bash "$GITHUB_ACTION_PATH/scripts/session-ref.sh" restore "$SESSION_KEY" "$CODEX_HOME"

- name: Find codex session snapshot
id: snapshot
if: steps.app-token.outputs.skip != 'true' && (env.SKIP != 'true')
# When the ref is absent, fall back to a snapshot saved before this storage moved out of artifacts.
if: steps.app-token.outputs.skip != 'true' && (env.SKIP != 'true' && (!steps.ref-snapshot.outputs.commit && (inputs.session-ref-prefix == '' || steps.ref-snapshot.outcome == 'success')))
shell: bash
env:
GH_TOKEN: ${{ github.token }}
Expand Down Expand Up @@ -344,9 +385,47 @@ runs:
bash "$GITHUB_ACTION_PATH/scripts/subscribe.sh" >> "$RUNNER_TEMP/sse.err" 2>&1 &
echo "SSE_PID=$!" >> "$GITHUB_ENV"

- name: Find the session to fork in refs
id: fork-ref-snapshot
if: steps.app-token.outputs.skip != 'true' && (inputs.session-ref-prefix != '' && steps.check.outputs.fork-key && !steps.snapshot.outputs.id && !steps.ref-snapshot.outputs.commit && !steps.session-cache.outputs.cache-matched-key && env.SKIP != 'true')
shell: bash
env:
SESSION_REF_PREFIX: ${{ inputs.session-ref-prefix }}
SESSION_REF_REMOTE: ''
SESSION_REF_TOKEN: ''
GH_CONFIG_DIR: ${{ runner.temp }}/gh
FORK_KEY: ${{ steps.check.outputs.fork-key }}
run: bash "$GITHUB_ACTION_PATH/scripts/session-ref.sh" find "$FORK_KEY"

- name: Restore the session to fork from its ref
id: restore-fork-ref
if: steps.app-token.outputs.skip != 'true' && (steps.fork-ref-snapshot.outputs.commit)
continue-on-error: true
shell: bash
env:
SESSION_REF_PREFIX: ${{ inputs.session-ref-prefix }}
SESSION_REF_REMOTE: ''
SESSION_REF_TOKEN: ''
GH_CONFIG_DIR: ${{ runner.temp }}/gh
FORK_KEY: ${{ steps.check.outputs.fork-key }}
run: bash "$GITHUB_ACTION_PATH/scripts/session-ref.sh" restore "$FORK_KEY" "$CODEX_HOME/fork"

- name: Verify the session to fork from its ref
id: verify-fork-ref
if: steps.app-token.outputs.skip != 'true' && (steps.restore-fork-ref.outcome == 'success')
shell: bash
run: |
if [ -d "$CODEX_HOME/fork/sessions" ] && [ -s "$CODEX_HOME/fork/last-thread-id" ]; then
echo "restored=true" >> "$GITHUB_OUTPUT"
else
rm -rf "$CODEX_HOME/fork"
echo "::warning::Could not restore the session to fork. This review starts without it."
fi

- name: Find the session to fork
id: fork-snapshot
if: steps.app-token.outputs.skip != 'true' && (steps.check.outputs.fork-key && !steps.snapshot.outputs.id && !steps.session-cache.outputs.cache-matched-key && env.SKIP != 'true')
# When the fork's ref is absent, fall back to a snapshot saved before this storage moved out of artifacts.
if: steps.app-token.outputs.skip != 'true' && (steps.check.outputs.fork-key && !steps.snapshot.outputs.id && !steps.session-cache.outputs.cache-matched-key && !steps.fork-ref-snapshot.outputs.commit && (inputs.session-ref-prefix == '' || steps.fork-ref-snapshot.outcome == 'success') && env.SKIP != 'true')
shell: bash
env:
GH_TOKEN: ${{ github.token }}
Expand Down Expand Up @@ -524,7 +603,7 @@ runs:
# Only the optional CI-name lookup uses this token; the reviewer keeps the App identity.
REVIEW_ACTIONS_TOKEN: ${{ github.token }}
# Without the empty-string fallback, a failed restore check sets FORK_KEY to "false", which run-review.sh treats as a session key.
FORK_KEY: ${{ ((steps.decrypt-fork.outputs.restored == 'true' || steps.verify-fork.outputs.restored == 'true') && steps.check.outputs.fork-key) || '' }}
FORK_KEY: ${{ ((steps.decrypt-fork.outputs.restored == 'true' || steps.verify-fork.outputs.restored == 'true' || steps.verify-fork-ref.outputs.restored == 'true') && steps.check.outputs.fork-key) || '' }}
JOB_CHECK_RUN_ID: ${{ job.check_run_id }}
TRIGGER_SENDER: ${{ github.event.sender.login || 'unknown' }}
TRIGGER_TYPE: ${{ github.event.sender.type || 'unknown' }}
Expand Down Expand Up @@ -585,7 +664,7 @@ runs:

- name: Archive codex session
id: encrypt-session
if: steps.app-token.outputs.skip != 'true' && (env.SKIP != 'true' || env.RECORDED_SKIP == 'true')
if: steps.app-token.outputs.skip != 'true' && (inputs.session-ref-prefix == '' && (env.SKIP != 'true' || env.RECORDED_SKIP == 'true'))
# Losing the key must not fail a review that is already published; the older snapshot stays restore-able.
continue-on-error: true
shell: bash
Expand All @@ -603,9 +682,25 @@ runs:
bash "$GITHUB_ACTION_PATH/scripts/snapshot.sh" save "$RUNNER_TEMP/snapshot.bin" "$CODEX_HOME"
printf 'retention-days=%s\n' "$retention_days" >> "$GITHUB_OUTPUT"

- name: Save the session snapshot to its ref
id: save-session-ref
if: steps.app-token.outputs.skip != 'true' && (inputs.session-ref-prefix != '' && (env.SKIP != 'true' || env.RECORDED_SKIP == 'true'))
# An append failure must not discard a completed review.
continue-on-error: true
shell: bash
env:
SESSION_REF_PREFIX: ${{ inputs.session-ref-prefix }}
SESSION_REF_REMOTE: ''
SESSION_REF_TOKEN: ''
SESSION_REF_BASE: ${{ steps.restore-session-ref.outputs.commit }}
GH_CONFIG_DIR: ${{ runner.temp }}/gh
run: |
bash "$GITHUB_ACTION_PATH/scripts/require-private-session-repo.sh" &&
bash "$GITHUB_ACTION_PATH/scripts/session-ref.sh" save "$SESSION_KEY"

- name: Save codex session
id: save-session
if: steps.app-token.outputs.skip != 'true' && (steps.encrypt-session.outcome == 'success')
if: steps.app-token.outputs.skip != 'true' && (inputs.session-ref-prefix == '' && steps.encrypt-session.outcome == 'success')
# An upload failure must not discard a completed review.
continue-on-error: true
uses: actions/upload-artifact@v7
Expand All @@ -618,7 +713,7 @@ runs:
retention-days: ${{ steps.encrypt-session.outputs.retention-days }}

- name: Drop older session snapshots
if: steps.app-token.outputs.skip != 'true' && (steps.save-session.outputs.artifact-id)
if: steps.app-token.outputs.skip != 'true' && (inputs.session-ref-prefix == '' && steps.save-session.outputs.artifact-id)
continue-on-error: true
shell: bash
env:
Expand All @@ -640,6 +735,7 @@ runs:
env:
GH_CONFIG_DIR: ${{ runner.temp }}/gh
SNAPSHOT_ID: ${{ steps.save-session.outputs.artifact-id }}
SAVED_REF: ${{ steps.save-session-ref.outputs.commit }}
run: |
[ -n "$CODEX_HOME" ] || exit 0
opened=$(if [ -f "$RUNNER_TEMP/forked-prs" ]; then cat "$RUNNER_TEMP/forked-prs"; fi) || exit 1
Expand All @@ -649,7 +745,10 @@ runs:
# A draft this run opened can only fork the session it was written into; drafts an earlier run left pending were already waiting after a save.
if [ -n "$(printf '%s' "$opened" | sed '/^$/d')" ]; then
listed=false
[ -z "$SNAPSHOT_ID" ] || listed=$(GH_TOKEN=${{ github.token }} bash "$GITHUB_ACTION_PATH/scripts/retry.sh" gh api "repos/${{ github.repository }}/actions/artifacts/$SNAPSHOT_ID" --jq '.expired == false' </dev/null) || listed=false
# A successful ref push is the saved snapshot's own proof; append-only refs cannot expire.
if [ -n "$SAVED_REF" ]; then listed=true
else [ -z "$SNAPSHOT_ID" ] || listed=$(GH_TOKEN=${{ github.token }} bash "$GITHUB_ACTION_PATH/scripts/retry.sh" gh api "repos/${{ github.repository }}/actions/artifacts/$SNAPSHOT_ID" --jq '.expired == false' </dev/null) || listed=false
fi
[ "$listed" = true ] || { echo "::warning::The session snapshot is unavailable, so drafts this run opened stay draft."; pending=$(comm -23 <(printf '%s\n' "$pending") <(printf '%s\n' "$opened" | sed '/^$/d' | sort -u)); [ -n "$pending" ] || exit 0; }
fi
left=
Expand Down
Loading
Loading