Skip to content

Preserve review summaries when check refreshes a PR - #1099

Closed
eowca wants to merge 4 commits into
mainfrom
lean178/1003-preserve-pr-body
Closed

eowca wants to merge 4 commits into
mainfrom
lean178/1003-preserve-pr-body

Conversation

@eowca

@eowca eowca commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

Preserve review summaries when check refreshes a PR

Context and goal

  • Goal: Concurrent local PR updates preserve review summaries, checks, and unrelated prose.
  • Problem: Two writers can read the same old body and the last write erases sections written by the first.
  • Context: GitHub replaces the whole PR body on each update.

Closes #1003

Acceptance

  • Local check, review, and PR refreshes read the body inside the same lock used for the corresponding update.
  • A delayed check retains both the newly written review summary and unrelated body text.

Notes

Use the existing task state directory for the lock. Keep check execution, reviewer dispatch, and Git push outside the lock.

Base

main @ f717ea4

Validation

Recorded for 2bebc1db8a14

  • uv run --group dev ruff check src tests: exit 0
  • uv run --group dev tach check: exit 0
  • uv run --python 3.14 python scripts/check_architecture_docs.py: exit 0
  • scripts/size_budget.sh: exit 0
  • uv run --group dev pytest -q: exit 0

Review

  • primary, claude, 2bebc1d, approve

Open in [code]smith · Need help on this PR? Tag @codesmith-bot with what you need.

Co-Authored-By: Codex <noreply@openai.com>

@loopzero-feder-positronics loopzero-feder-positronics Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

loopzero primary review by claude on 2bebc1db8a14b615423814b9e266d05be18c70b7, 37.6s: approve (0 critical, 0 important, 2 suggestion)

Settings per native call (launch configuration and CLI claims, not backend attestation):

  • Call 1: requested model claude-opus-5-5 (effort medium); CLI-reported model claude-opus-5-5 (effort unknown); configured model claude-opus-5-5 (effort medium)
Raw reviewer output
{"duration_api_ms":34713,"stop_reason":"tool_use","session_id":"e4353003-4c85-42b6-a4e2-84cc9aeb0467","total_cost_usd":0.27217,"usage":{"input_tokens":14,"cache_creation_input_tokens":22321,"cache_read_input_tokens":123330,"output_tokens":3444,"output_tokens_details":{"thinking_tokens":1844},"server_tool_use":{"web_search_requests":0,"web_fetch_requests":0},"service_tier":"standard","cache_creation":{"ephemeral_1h_input_tokens":22321,"ephemeral_5m_input_tokens":0},"inference_geo":"global","iterations":[{"input_tokens":2,"output_tokens":733,"cache_read_input_tokens":26479,"cache_creation_input_tokens":1644,"cache_creation":{"ephemeral_5m_input_tokens":0,"ephemeral_1h_input_tokens":1644},"type":"message"}],"speed":"standard","fallback_credit":null},"modelUsage":{"claude-opus-5-5":{"inputTokens":14,"outputTokens":3444,"cacheReadInputTokens":123330,"cacheCreationInputTokens":22321,"webSearchRequests":0,"costUSD":0.27217,"contextWindow":1000000,"maxOutputTokens":128000,"thinkingTokens":1844,"cacheCreationEphemeral5mInputTokens":0,"cacheCreationEphemeral1hInputTokens":22321,"canonicalModel":"claude-opus-5-5","provider":"firstParty","costBasis":"list"}},"permission_denials":[],"terminal_reason":"completed","fast_mode_state":"off","fast_mode_disabled_reason":"sdk_opt_in_required","subagent_stats":{"spawned":0,"requested":{"background":0,"foreground":0,"unset":0},"started_in_background":0,"max_depth":0,"spawned_by_subagents":0,"completed":0,"failed":0,"killed":{"parent":0,"user":0,"system":0},"refused":{"depth_limit":0,"concurrency_limit":0,"budget":0},"by_type":{}},"safety_stops":0,"is_error":false,"num_turns":9,"subtype":"success","api_error_status":null,"result":"{\"verdict\":\"approve\",\"findings\":[{\"severity\":\"suggestion\",\"path\":\"tests/test_cli.py\",\"line\":420,\"title\":\"Delayed-check test checks the re-read, not the lock\",\"body\":\"`delay` runs `review` all the way through before it calls the real `_update_pr_checks`, so the check never actually overlaps with the review. The test would still pass if `_lock_task_state` were a no-op, because it only shows that the check reads the live body again before writing. That re-read does cover the acceptance criterion about a delayed check, but nothing tests the serialization. Smallest fix: add a focused test that holds `_lock_task_state(wt)` (for example from a thread or a second process). It should assert that `_update_pr_checks` / the review append does not call `pr_view`/`pr_for_branch` until the lock is released.\"},{\"severity\":\"suggestion\",\"path\":\"src/loopzero/cli.py\",\"line\":637,\"title\":\"Body built before the push is now only used for validation and draft creation\",\"body\":\"For an existing open PR, `existing`/`body` at lines 637-638 are now discarded and rebuilt from `live.body` inside the lock (line 662). Building it early still has a purpose: it raises on malformed markers or an oversized body before the push, and the create-draft path uses it. A short comment saying so would stop a later cleanup from removing it, or from going back to reusing the stale `body` in the update branch.\"}]}","structured_output":{"verdict":"approve","findings":[{"severity":"suggestion","path":"tests/test_cli.py","line":420,"title":"Delayed-check test checks the re-read, not the lock","body":"`delay` runs `review` all the way through before it calls the real `_update_pr_checks`, so the check never actually overlaps with the review. The test would still pass if `_lock_task_state` were a no-op, because it only shows that the check reads the live body again before writing. That re-read does cover the acceptance criterion about a delayed check, but nothing tests the serialization. Smallest fix: add a focused test that holds `_lock_task_state(wt)` (for example from a thread or a second process). It should assert that `_update_pr_checks` / the review append does not call `pr_view`/`pr_for_branch` until the lock is released."},{"severity":"suggestion","path":"src/loopzero/cli.py","line":637,"title":"Body built before the push is now only used for validation and draft creation","body":"For an existing open PR, `existing`/`body` at lines 637-638 are now discarded and rebuilt from `live.body` inside the lock (line 662). Building it early still has a purpose: it raises on malformed markers or an oversized body before the push, and the create-draft path uses it. A short comment saying so would stop a later cleanup from removing it, or from going back to reusing the stale `body` in the update branch."}]},"ttft_ms":2414,"type":"result","duration_ms":35884,"uuid":"78d8d8f1-7ecb-445b-ba65-3539ff7386e9","ttft_stream_ms":1682,"time_to_request_ms":718,"first_content_frame_ms":1682,"queued_turn_count":0,"result_index":0}

Comment thread tests/test_cli.py
assert text in updated


def test_delayed_check_preserves_review_summary(wt, gh, fake_bin, capsys, monkeypatch):

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

suggestion: Delayed-check test checks the re-read, not the lock

delay runs review all the way through before it calls the real _update_pr_checks, so the check never actually overlaps with the review. The test would still pass if _lock_task_state were a no-op, because it only shows that the check reads the live body again before writing. That re-read does cover the acceptance criterion about a delayed check, but nothing tests the serialization. Smallest fix: add a focused test that holds _lock_task_state(wt) (for example from a thread or a second process). It should assert that _update_pr_checks / the review append does not call pr_view/pr_for_branch until the lock is released.

Comment thread src/loopzero/cli.py
"run `loopzero start <new-task-slug>` for a new task"
)
existing = _sync_task_narrative(wt, pr.body or "") if pr is not None else None
existing = _sync_task_narrative(wt, pr.body) if pr is not None else None

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

suggestion: Body built before the push is now only used for validation and draft creation

For an existing open PR, existing/body at lines 637-638 are now discarded and rebuilt from live.body inside the lock (line 662). Building it early still has a purpose: it raises on malformed markers or an oversized body before the push, and the create-draft path uses it. A short comment saying so would stop a later cleanup from removing it, or from going back to reusing the stale body in the update branch.

eowca and others added 3 commits November 26, 2026 00:29
Architecture-Review: unchanged; keep the approved body serialization and combine it with main’s timeout handling.

Co-Authored-By: Codex <noreply@openai.com>
Keep the shared task-state lock and main’s receipt publication guard. Preserve the fresh PR body read and update the test call expectations for the new branch-history lookup.

Architecture-Review: unchanged; the integration preserves both documented uses of the task-state lock.
Co-Authored-By: Codex <noreply@openai.com>
@eowca

eowca commented Nov 26, 2026

Copy link
Copy Markdown
Contributor Author

Conflict resolution at e935bf9d retains the shared lock, the stale-receipt guard, and the fresh PR body read. All 24 focused tests and the full sandboxed loopzero check passed against a4fa1690. loopzero review refused the delta because it would include conflicts resolved in merges after the reviewed commit. loopzero ready confirms this head lacks current review and hosted eligibility. Issue #1003 remains open pending an authorized fresh-review path.

@eowca

eowca commented Nov 26, 2026

Copy link
Copy Markdown
Contributor Author

Superseded by #1230. The replacement carries this PR’s reviewed diff and the merge resolution tested at e935bf9d. It retains the closing reference for #1003 and will receive fresh review.

@eowca eowca closed this Nov 26, 2026
mergify Bot pushed a commit that referenced this pull request Nov 26, 2026
* Serialize updates to the pull request body

Carry forward the reviewed change and tested merge resolution from #1099.

Co-Authored-By: Codex <noreply@openai.com>

* Integrate receipt identity with serialized PR updates

Carry the already-landed receipt rendering change from #1160 into the delta. Keep the check lookup and write under the shared lock and render from the freshly read PR when publishing.

Architecture-Review: unchanged; receipt verification and serialized body updates retain their documented behavior.
Co-Authored-By: Codex <noreply@openai.com>

---------

Co-authored-by: eowca <4008965+eowca@users.noreply.github.com>
Co-authored-by: Codex <noreply@openai.com>
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.

Preserve PR sections during overlapping Loop Zero updates

1 participant