Skip to content

fix(review): a review asks again when the output under review changed - #939

Open
gshost1 wants to merge 1 commit into
scaleapi:mainfrom
gshost1:fix/review-asks-again-when-output-changed
Open

gshost1 wants to merge 1 commit into
scaleapi:mainfrom
gshost1:fix/review-asks-again-when-output-changed

Conversation

@gshost1

@gshost1 gshost1 commented Nov 27, 2026 •

Copy link
Copy Markdown

What and why

A review's decision now holds for the output it was given on. ReviewStore.put_awaiting stores a sha256 of the upstream summary with the record (upstream_digest). Registered again with a different upstream, the review replaces its record with a new awaiting one that carries the new output. The same output, or a call without upstream, keeps a recorded decision, as before. ReviewTaskStep and the signature of put_awaiting are unchanged.

A retry_config span that covers a review re-runs the agent on a fresh world. The review then found the first attempt's decision under the same (instance_id, step_id) and went on at once. The retried output was collected while review_decisions credited an operator who never saw it, and the stored review still showed the first output. A review that retries itself (an abort regenerates the output) aborted the new output on the old abort, and a resume of the same instance from before the review reused the old decision too. Keying on the run's attempt epoch instead doesn't work: every re-register of the instance bumps it, so a resume at the review would ask again about the same output.

Closes #938

How it was tested

  • tst/unit/task_step/retry_test.py, with the real scheduler, instance store and review store; the operator uses list_awaiting and set_decision, as the hub would:
    • test_a_review_the_retry_re_runs_waits_for_a_decision_on_the_new_output, test_a_review_that_regenerates_a_rejected_output_asks_about_the_new_one and test_a_resume_from_before_the_review_asks_about_the_new_output fail on main and pass with the fix.
    • test_a_resume_at_the_review_keeps_the_decision_given_on_its_output passes on main and with the fix. It fails if the re-open keys on the attempt epoch.
  • tst/unit/task_step/test_review.py::test_a_decision_stands_for_the_output_it_was_given_on: the same output keeps the decision; a new one awaits with its own upstream.
  • tst/unit/task_step with tst/unit/config/test_reset_config.py: 4701 passed (main: 4696). tst/integration/task_step/review_store_test.py: 3 passed, unchanged. Full tst/unit and packages/agentenv-protocol/tests: 19905 passed, 8 skipped (main: 19900). The 2 test_mcp_cli_builder.py codegen tests fail on main too, in an environment whose system python3 lacks httpx. ruff check clean; check_plugin_api.py: no break to the plugin surface.

Risks

  • A record written before this change has no upstream_digest, so a re-register over it keeps its decision, as today (Ne doesn't match an absent field), until the store's 7-day TTL removes it. Stores without TTL support, such as the local SQLite one, keep it.
  • The output is compared through the summary the record holds: the last prompt response trimmed to 4000 characters, or its bounded structured output. A re-run whose summary comes out the same keeps the decision, even if something else it produced, such as a file, differs.
  • The record gains one field. A hub that reads the collection can ignore it.

Confidence Score: 3/5 · Block merging until operator decisions are tied to the output the operator saw.RetriggerView in GreptileConfidence Score: 3/5

Block merging until operator decisions are tied to the output the operator saw.

FindingsFix All in CursorFindings

  1. P1 Security Old approval accepts new output ▶
Fix with agent prompt
### Issue 1
src/agent_env/task_step/review_store.py:79-82
An operator can open output A, then submit their decision after the review times out and a retry registers output B. This replacement keeps the same identifiers, so the delayed `set_decision(..., CONTINUE)` approves B instead. `set_decision` checks only the identifiers and `AWAITING`, and the worker accepts the decision without checking the output. The task then continues with output the operator never saw.

Require the displayed review's digest or generation when saving a decision, and reject stale submissions.

**How this was verified:** Changed output replaces the record under the same identifiers, while the decision write and worker poll never compare the output's digest.

---

For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.

Summary

The PR stores an upstream_digest and reopens a review when its summarized output changes.

  • Reviews ask again when the output changes.

Diagram

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A[Register output] --> B{Existing digest differs?}
    B -->|No| C[Keep existing decision]
    B -->|Yes| D[Replace with awaiting review]
    D --> E[Operator submits decision]
    E --> F[Worker continues or aborts]
    G[Delayed decision for old output] --> E
Loading

Reviews (1) · Last reviewed commit: "fix(review): a review asks again when th..." · Reviewed by Greptile

A review's decision is keyed by (instance_id, step_id), which a span retry or a resume keeps. put_awaiting ignored the duplicate, so the re-run review went on with the first output's decision. It now stores a digest of the upstream summary and replaces the record when that differs; the same output keeps its decision.
@gshost1
gshost1 requested a review from a team as a code owner November 27, 2026 18:52
Comment on lines +79 to +82
if upstream is not None:
filt = Filter.of(instance_id=instance_id, step_id=step_id)
filt = filt.where("upstream_digest", Ne(digest))
self._doc_store.replace(REVIEWS_COLLECTION, filt, doc)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 security Old approval accepts new output

An operator can open output A, then submit their decision after the review times out and a retry registers output B. This replacement keeps the same identifiers, so the delayed set_decision(..., CONTINUE) approves B instead. set_decision checks only the identifiers and AWAITING, and the worker accepts the decision without checking the output. The task then continues with output the operator never saw.

Require the displayed review's digest or generation when saving a decision, and reject stale submissions.

How this was verified: Changed output replaces the record under the same identifiers, while the decision write and worker poll never compare the output's digest.

Knowledge Base Used: Task-step context and execution

Prompt To Fix With AI
This is a comment left during a code review.
Path: src/agent_env/task_step/review_store.py
Line: 79-82

Comment:
**Old approval accepts new output**

An operator can open output A, then submit their decision after the review times out and a retry registers output B. This replacement keeps the same identifiers, so the delayed `set_decision(..., CONTINUE)` approves B instead. `set_decision` checks only the identifiers and `AWAITING`, and the worker accepts the decision without checking the output. The task then continues with output the operator never saw.

Require the displayed review's digest or generation when saving a decision, and reject stale submissions.

**How this was verified:** Changed output replaces the record under the same identifiers, while the decision write and worker poll never compare the output's digest.

**Knowledge Base Used:** [Task-step context and execution](https://app.greptile.com/-/switch-tenant?tenant=scale-ai&next=%2Fcustom-context%2Fknowledge-base%2Fscaleapi%2Fagentenv-framework%2F-%2Fdocs%2Ftask-step-execution.md)

---

For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.

Fix in Cursor Fix in Claude Code Fix in Codex

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

A review step that a retry_config re-runs goes on with the first attempt's decision, so the operator never sees the retried output

1 participant