Repository navigation
refactor(history): unchain the whole-file build and correct its docs - #45362
Conversation
UX Review (Opus 5.5) — ⏭️ skippedRevision |
First Principles Review (Opus 5.5) — ✅ PASSPremise-level review of First-Principles-Verdict: PASS Nothing blocks. The one code edit binds the same two locals, and the docstring, comment and spec edits match the code on this head. What this change shipsInventory (4 items) — 4 justifiedIntent: make the code that rewrites transcript metadata easier to read correctly, with no change in behaviour. This is a FIX to readability and docs.
[FIRST-PRINCIPLES-REVIEWED] d449176 Description read[DESCRIPTION-READ] d4d33aabd2cad2d8331bda8d34b8993e91e24804ce8fd9ce9909478ac32269c8 That sha256 names the PR description this verdict read. Recompute it with |
Design Review (Opus 5.5) — ✅ PASSDesign-level review of Design-Verdict: PASS Nothing blocks: the code change binds the same two values on both branches, and everything else is docstrings, a comment and one line of spec text. [DESIGN-REVIEWED] d449176 Description read[DESCRIPTION-READ] 05a3dcbb7f8a5e64ac9ae76a8ecd7875a602bc68970956421551cc04fb94f62c That sha256 names everything this verdict read: the PR description, plus the 1 evidence file(s) the workflow collected from it and handed this review. It covers that evidence because the media strip replaces every attachment URL with the same placeholder, so an edit swapping one attachment for another would leave the description's captured text identical while what this review judged changed. Recompute it with |
Opus 5.5 Review — ✅ no blocking findingsReviewed Verdict parsed from the review's SHA-scoped output markers for commit False positive or not applicable? A repository writer can comment: |
GPT 6.1 Review — ✅ no blocking findingsGPT 6.1 completed its review of This comment is updated in place on each push. Review detailsNo findings. False positive or not applicable? A repository writer can comment: |
|
The red Tracked in #45371, which needs a product decision. No rerun: the failure is deterministic. This PR waits for that fix and rebases onto it. |
_whole_file_build tested `text is not None` twice, once for `lines` and again around a chained ternary for `head`. One if/else now binds `head` and `rest` together; the values are unchanged on both paths (None and [] for an absent file, line 0 or "" and the rows after it otherwise). Two docstrings and a comment in the same file did not match the code: - _stage_streamed: the documented return paired "None when build wrote nothing" with a real digest. When build writes nothing, and when the rows change between the count and the copy, it returns (None, _UNREAD), and the caller judges again under the lock. - the inline comment on that return said "as the whole-file pass always did"; it now says what the caller does with the result. - the module docstring named only compaction and rotation, leaving out rewrite_transcript and the two metadata-line rewrite helpers. The history spec's module map carried the same short list and is updated with it.
d48d6fe to
d449176
Compare
|
Rebased onto |
KiroCrewCaptain
left a comment
There was a problem hiding this comment.
I reviewed head d449176. The one code change rewrites the chained ternary in the whole-file metadata build as an if/else. It binds the same head and remaining rows for an absent file, an empty file and a normal transcript, so history output, row order and handling of damaged lines do not change. The other edits are docstrings, one comment and one line of the spec. I checked them against the module's actual return paths and definitions, and they are accurate. CI on this head is green across the Linux and Windows backend shards, coverage, lint and type checks, so nothing blocks.
|
Green-age re-check, no push. |
Problem / Motivation
Goal: Make
history_rewrite.py's whole-file metadata build test for an absent transcript once instead of twice, and make the module's docstrings and the history spec's module map describe what the module does today, with no change to any transcript write.Part of the module-by-module backend simplification sweep. The detector's one new actionable site this run is the chained ternary in
history_rewrite._whole_file_build. Every other site in the queue is one the sweep leaves alone: a keystone file, a test-pinned ternary, or a site an earlier run already declined. So this PR takes that site plus the stale prose in the same file:_whole_file_buildteststext is not Nonetwice: once to buildlines, and again in a chained ternary forhead((lines[0] if lines else "") if text is not None else None)._stage_streamed's docstring says it returns "(staged name or None when build wrote nothing, digest of the bytes it was built from)". When build writes nothing, the second item is_UNREAD, not a digest. The same(None, _UNREAD)pair comes back when the rows change between the count and the copy.rewrite_transcriptand the metadata-line rewrites (rewrite_metadata_line,rewrite_head_streaming), whichhistory_marker.pyandhistory_projection.pyimport from it.Nothing is broken at runtime. This is a readability cleanup.
Why it matters
rewrite_metadata_linedecides whether to publish an unlocked staged copy or rebuild under the lock from_stage_streamed's result. A docstring that promises a digest where the code returns the never-matching_UNREADmisleads a reader working on that decision. A module summary that lists only compaction and rotation sends a reader looking for the metadata-line rewrites to the wrong place.Not a goal
diagnostics.py,safety_override_grant.py,sandbox_plan.py,tool_permission.py).rewrite_transcript's docstring sentence that every history-store rename over a transcript goes through it. The metadata-line paths rename throughpublish_replacementandatomic_writedirectly. The history spec's "Durable replace" paragraph makes the matching claim, and correcting the two together is a spec change of its own.lines[:]copy in_maybe_rotate, and any other code in this file.What changed (motivation → approach → change)
No transcript byte, lock, sync, digest compare or archive step changes.
_whole_file_buildlines = ... if text is not None else [], thenhead = (lines[0] if lines else "") if text is not None else None, thenrest = lines[1:]if text is None: head = None; rest = [],else:split once,head = lines[0] if lines else "",rest = lines[1:]NonegivesNoneand[]both ways; a string gives the samelines[0](or"") andlines[1:]. The test is stillis None, so""takes the string branch as before. Nothing after the block readslines._stage_streameddocstring(staged name or None when build wrote nothing, digest ...)(staged name, digest ...), or(None, _UNREAD)when build wrote nothing or the rows changed between the count and the copy; either way the caller judges again under the lockreturnstatements.return None, _UNREADstagedleftNone,rewrite_metadata_line's locked branch calls_whole_file_buildagain.docs/system-specs/modules/history.mdmodule maprewrite_transcriptand the two metadata-line rewrite helpers,rewrite_metadata_lineandrewrite_head_streaminghistory_projection's unsynced metadata write andhome_path_rewritereplace a transcript themselves.restcarries alist[str]annotation because its first assignment is an empty list.head's first assignment isNone, so mypy reads it asstr | Nonefrom the laterstrassignment with no annotation.Backwards compatibility
Compatible:
_whole_file_buildreturns the same bytes for every input, and every other hunk is a docstring, a comment or spec text.Removes nothing: no name, signature, import or behaviour is removed; the module-level names are identical before and after.
Tests
No new tests: the change preserves behaviour. I did not run tests locally, because this host's standing rule leaves the suites to CI. Existing tests reach both branches of
_whole_file_build:text is None:test_update_metadata_still_upserts_a_missing_transcriptintest/test_history_locking_remediation_locked_section.py(update_metadataon a transcript that does not exist).test_a_row_with_a_carriage_return_takes_the_whole_file_path(a row the chunked copy refuses) andtest_the_fallback_frees_the_stale_staged_copy_before_writing(the rebuild under the lock), same file.No test reads this module's source or docstrings, or the edited spec line.
The diff touches nothing under
website/,.github/orscripts/, so the frontend suites do not run.Static gates run locally on this head (flake8, isort, and the black, subprocess-encoding, comment-history, brand, harness-parity, line-cap, docs-lint, per-file-coverage self-test and vendor-manifest checks) all exit 0. mypy is left to CI under the same host rule.
Before opening, five read-only reviewers (AUTOSDE and CI contracts, behaviour, imports, security and boot path, comment accuracy) looked at the diff. The first four found nothing: both branches of
_whole_file_buildbind the same values, no import or module-level name changed, and no lock, digest compare, sync or archive step changed. The comment reviewer found two Low issues, and an independent refuter confirmed each. First, the first draft of the module docstring and the spec line said the module owns "the rewrites that replace a transcript file", which other modules also do. Second, the commit message called all three edits docstrings and called the incomplete module docstring false. Both are fixed here, and a verifier checked them closed. Nothing was dropped as a false positive.Manual verification
N/A — unit coverage sufficient: the one code change rebinds two locals to the same values, and the rest is docstrings, a comment and one spec line.
Real-machine verification
N/A -- the diff rebinds two locals to identical values and edits docstrings, a comment and spec text; nothing behaves differently on any host.
Screenshots / video
Why no screenshot: backend-only readability change in the transcript rewrite module; no frontend or rendered surface changes.
Related Issues
Part of #16523
Checklist
feat|fix|docs|style|refactor|perf|test|chore|ci|build|revert: ...); PR Hygiene does not count commitsContribution License Agreement
Accepted under the project's Apache-2.0 license.