Skip to content

Batch 673: dryrun trace caps its writes and counts its shared patch (BACKLOG #6824, #6825) - #3253

Merged
wshallwshall merged 15 commits into
mainfrom
b673/trace-group-2
Nov 24, 2026
Merged

wshallwshall merged 15 commits into
mainfrom
b673/trace-group-2

Conversation

@wshallwshall

Copy link
Copy Markdown
Collaborator

Batch 673 (pipeline), dryrun_trace group 2. Its base PR 3237 (#6822, #6823) has merged, and this branch merged origin/main normally after it. git diff origin/main... touches only dryrun_trace.py, its test file and two changelog fragments.

BACKLOG #6824 -- traced writes are bounded

  • Verdict: REAL. A failing test showed that past _MAX_EVENTS, _writes_by_line kept every later write.
  • Fix:
    • record_write drops writes past the event cap and sets truncated.
    • A per-invocation _MAX_WRITES of 5000 also applies. Past it the invocation gets writes_truncated, and truncated too, which the IDE test bench reads (traceView.ts, testBenchWebview.ts).
    • Writes with no latched frame are kept as on main, and they count against the cap.
    • Adds changelog.d/6824.fixed.md.
  • Behaviour change, by design of the fix: once one invocation reaches 5000 kept writes, its writes on later lines are dropped where main emitted them. The trace is flagged truncated. The IDE's inline write views (liveDebug.ts, stepsModel.ts) read neither flag, so there a capped list can look complete. That IDE reading is open finding 1.
  • Proposed banner: CLOSED. REAL; trace writes are capped per event budget and per invocation, and a capped trace is flagged truncated, with a failing test plus fix.

BACKLOG #6825 -- concurrent traces no longer restore Message._write under each other

  • Verdict: REAL. A failing two-thread test showed one trace's exit restoring the patch while another was running.
  • Fix: a lock-guarded holder count; the first entry installs the patch and the last exit restores it. Unit and end-to-end concurrency tests. Adds changelog.d/6825.fixed.md.
  • Proposed banner: CLOSED. REAL; the shared write patch is held by count, so one trace's exit no longer unpatches a concurrent trace, with a failing test plus fix.

Checks (Builder): ruff check and format, both mypy package legs, mypy on tests/test_dryrun_trace.py, the changelog fragment check. pytest on test_dryrun_trace, test_accepts_seam, test_copy_on_send, test_dryrun_snapshot_parity, test_data_never_becomes_structure and test_cli: 564 passed. Full suite not run. Read the pytest legs and the tests mypy leg.

QA: xhigh. Rounds: 2 + 3 unrepaired. Tag: xhigh effort -> 10 inline angles -> dedup (no verify) -> sweep -> <=15 findings (round-525b615052, round-4aa8008e8c, round-11061c491c, round-df23aac5f8, round-c26ef5f793). The unrepaired rounds led to Manager-directed repairs: a write-dropping regression was reverted, and writes with no latched frame were restored. The head, 596566c2, is comment and changelog text only, and no review round ran on it.

Open findings, to file under R2:

  1. The IDE inline write views should read writes_truncated (or truncated), and ADR 0072 section 3 does not name writes_truncated.
  2. On main, writes made before a multi-line target latches, and wrapper writes made after the target returns, are never emitted and set no flag. They now also spend the write budget.
  3. A write is recorded before it is applied, so a raising __len__ on a str subclass can error only the traced run. This predates the change.
  4. The holder-count leak window is narrowed, not closed. The patch restores the import-time _write, not the method installed before the first entry. A design that installs the patch once would remove both problems.
  5. Kept writes hold their path strings unbounded; only the count is capped.
  6. Tests: b_done.wait is unasserted; there is no teardown on the module-global state; one test bounds by _MAX_EVENTS, not _MAX_WRITES.
  7. Line tracing continues after the event cap, and the event-cap check is duplicated in _finalize and record_write.
  8. On free-threaded 3.14t, child threads inherit a recorder that is not thread-safe.
  9. The cap semantics are stated in three places (SDS-3.5).

… huge ints

Under show_phi=True, _safe_value passed a NaN/Infinity float through, so the
CLI's json.dumps wrote the bare tokens NaN/Infinity, which RFC 8259 rejects,
and an int past the 4300-digit int-to-str limit made json.dumps raise
ValueError. A non-finite float is now repr'd ("nan", "inf", "-inf") and an int
longer than the 120-character value cap becomes "<int: too large>", found by
comparison so the conversion that raises never runs.

BACKLOG #6822 (Argon RC-S08-37). Verdict: real defect; the new test failed
before the fix.

Proposed PR title: dryrun trace: --show-phi values stay valid JSON for NaN,
Infinity and huge ints (BACKLOG #6822)
Proposed banner: CLOSED -- fixed: _safe_value renders non-finite floats and
over-cap ints as strings under --show-phi; failing test plus fix.
Check numbers by type() and call no subclass hook (no abs, repr or comparison
on a user subclass), tag non-finite floats as "<float: nan>" etc., keep an
over-cap int's 120-character prefix like a long string and use the
placeholder only past the int-to-str digit limit, fix the positive-boundary
off-by-one, and give the changelog fragment the bullet format the checker
requires. Tests add the hostile-subclass case, the untraced-disposition
comparison, the positive boundary and the real CLI serializer.

BACKLOG #6822

Proposed PR title: dryrun trace: --show-phi values stay valid JSON for NaN,
Infinity and huge ints (BACKLOG #6822)
Proposed banner: CLOSED -- fixed: _safe_value renders non-finite floats and
over-cap ints as strings under --show-phi; failing test plus fix.
_sends_from walked any non-Iterator iterable. An object whose __iter__
returns a stored generator is single-pass but not an Iterator, so the
trace observer exhausted it before dryrun._partition ran: the traced
run read FILTERED with zero deliveries where the untraced run delivered
(reproduced by the new test before the fix). The Handler half now walks
the same re-iterable allowlist as the Router half and declares any
other iterable return with lazy_result.

BACKLOG #6823

Proposed banner: FIXED - traced dry run walks only re-iterable Handler
containers; a single-pass iterable of Sends is declared lazy_result and
no longer drained (test + fix).
Review round 1: a list subclass with a single-pass __iter__, or one that
is its own Iterator, passed isinstance(result, list) and was still
drained. Walk only the exact builtin types, derive the Handler's
lazy_result from the one predicate, and fix the docstrings that still
described the removed Iterator guard.

BACKLOG #6823
Review round 2: drop the dead Iterator check on the Handler path and
correct the changelog and comment that said the Handler walks the
allowlist "as the Router half already did" (the Router half still uses
isinstance, so a container subclass there is reported, not fixed here).

BACKLOG #6823

Proposed banner: FIXED - traced dry run walks a Handler return only
when its exact type is list/tuple/set/frozenset; a single-pass iterable
of Sends (or a single-pass container subclass) is declared lazy_result
and no longer drained (test + fix). Open findings in the PR body.
Manager follow-up on review round 3. The exact-container test now uses
identity, so no user metaclass __eq__ runs in the observer.
CONNECTIONS.md and USER-GUIDE.md define the Handler's lazy_result as
shipped, ADR 0072 gains a dated amendment naming gate 1b and the
removed Iterator guard, and the changelog states the str/bytes
exclusion.

BACKLOG #6823

Proposed banner: FIXED - traced dry run walks a Handler return only
when its exact type is list/tuple/set/frozenset; a single-pass iterable
of Sends (or a single-pass container subclass) is declared lazy_result
and no longer drained (test + fix; docs and ADR 0072 amended). Open
findings in the PR body.
Text only. CONNECTIONS.md and USER-GUIDE.md now say plainly that a bare
return Send(...) still gets its per-invocation sends. The ADR 0072
Status line and README index row note the 2026-11-24 amendment, which
now says it supersedes section 3 and gate 1b on the Handler half. The
dryrun_trace module docstring and _Recorder comment describe the wider
Handler lazy_result.

BACKLOG #6823
After an invocation reached _MAX_EVENTS, _finalize stopped popping
_writes_by_line while record_write kept appending every Message write, so
a long mutating loop grew the recorder without bound. record_write now
drops a write once the event cap is reached, and past a new per-invocation
_MAX_WRITES cap that also bounds a helper's writes landing on one traced
line. Either marks the invocation truncated; _finalize clears writes that
can no longer be emitted.

BACKLOG #6824
_patched_message_writes overwrote and restored the class-global
Message._write with no count or lock, so when two threads traced at once
the first to finish restored the original under the other, which then
recorded no writes. A lock-guarded holder count now installs the patch on
the first entry and restores it on the last exit.

BACKLOG #6825
- The write cap marks writes_truncated, not truncated, which the IDE reads
  as short line coverage.
- A write is recorded only after Message._write accepts it, so refused
  writes spend no budget.
- No write is kept without a latched frame; the dead clear() is gone.
- The patch holder count is taken inside the try, released only if held.
- Tests: refused write, end-to-end concurrent traces, holder count.

BACKLOG #6824, #6825

Proposed vault banners:
#6824: FIXED (batch 673, branch b673/trace-group-2). Adjudicated a real
defect by failing test: past _MAX_EVENTS, record_write kept every write in
_writes_by_line. Writes are dropped past the event cap (truncated) and a
new 5,000-write cap (writes_truncated).
#6825: FIXED (batch 673, branch b673/trace-group-2). Adjudicated a real
defect by failing test: a second trace exiting restored Message._write
under the first. A lock-guarded holder count now restores on the last exit.
- Record a write before Message._write again, so a write that raises still
  shows on the failing line; round 1's reorder had hidden it.
- Keep no write once the traced frame has returned (no open line).
- Document the event and write caps in the module docstring; fix the
  changelog's write-cap wording.
- Thread tests re-raise worker errors and fail on a hung worker.

BACKLOG #6824, #6825

Proposed vault banners:
#6824: FIXED (batch 673, branch b673/trace-group-2). Adjudicated a real
defect by failing test: past _MAX_EVENTS, record_write kept every write in
_writes_by_line. Writes are dropped past the event cap (truncated), with
no open line, and past a new 5,000-write cap (writes_truncated).
#6825: FIXED (batch 673, branch b673/trace-group-2). Adjudicated a real
defect by failing test: a second trace exiting restored Message._write
under the first. A lock-guarded holder count now restores on the last exit.
The round-2 guard on _last_line dropped writes made after a handled
in-frame exception, with no flag. It is reverted with its test. The
holder-count comment now says the leak window is narrowed, not closed,
and the changelog says the write cap counts kept writes.

BACKLOG #6824, #6825

Proposed vault banners:
#6824: FIXED (batch 673, branch b673/trace-group-2). Adjudicated a real
defect by failing test: past _MAX_EVENTS, record_write kept every write in
_writes_by_line. Writes are dropped past the event cap (truncated) and
past a new 5,000-kept-write cap (writes_truncated).
#6825: FIXED (batch 673, branch b673/trace-group-2). Adjudicated a real
defect by failing test: a second trace exiting restored Message._write
under the first. A lock-guarded holder count now restores on the last exit.
# Conflicts:
#	messagefoundry/pipeline/dryrun_trace.py
A write with no latched frame is keyed to the def line again, as on main,
so a wrapper's write before a one-line target is emitted; it now counts
against _MAX_WRITES. The write cap also sets truncated, the only key the
IDE reads (traceView.ts, testBenchWebview.ts), so a capped trace never
looks complete. Comment reason corrected; new wrapper test.

BACKLOG #6824

Proposed vault banners:
#6824: FIXED (batch 673, branch b673/trace-group-2). Adjudicated a real
defect by failing test: past _MAX_EVENTS, record_write kept every write in
_writes_by_line. Writes are dropped past the event cap and past a new
5,000-kept-write cap; either sets truncated, the second also
writes_truncated.
#6825: FIXED (batch 673, branch b673/trace-group-2). Adjudicated a real
defect by failing test: a second trace exiting restored Message._write
under the first. A lock-guarded holder count now restores on the last exit.
Text only. The write-cap comment says the test bench shows its event-cap
message and the inline views read neither flag. The changelog headline is
narrowed to writes past the event cap and names, at least, the kept
writes that are never emitted.

BACKLOG #6824
@wshallwshall wshallwshall added the qa Builder QA record posted; not a merge gate label Nov 24, 2026
@wshallwshall

Copy link
Copy Markdown
Collaborator Author

QA: level xhigh. Rounds: 2 + 3 unrepaired. Tag: xhigh effort -> 10 inline angles -> dedup (no verify) -> sweep -> <=15 findings (last round round-c26ef5f793, on 746098f). The head, 596566c, is text only and was not reviewed. Lander: ready to merge. The batch 673 Manager opened this PR; see the body for the R2 findings.

@wshallwshall

Copy link
Copy Markdown
Collaborator Author

Lander: enqueuing at pinned head 596566c. QA round-c26ef5f793 (exit 0) covers the branch; the head adds text only. Finding 1, the IDE inline views ignoring the truncated flag past 5000 writes, I rule ORDINARY: a disclosed display gap in a dev tool, on a path that was unbounded before this PR, which weakens no control. Findings 1-9 (ORDINARY or MAIN) are queued for filing under R2.

@wshallwshall
wshallwshall added this pull request to the merge queue Nov 24, 2026
Merged via the queue into main with commit c959ec8 Nov 24, 2026
64 checks passed
@wshallwshall
wshallwshall deleted the b673/trace-group-2 branch November 24, 2026 17:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

qa Builder QA record posted; not a merge gate

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant