Skip to content

TD-5443: Code feed: symlink loops on Python 3.13+, the frame cap as sent, full-length lines - #303

Merged
captcrock merged 3 commits into
mainfrom
td/5443-code-feed-followups
Dec 3, 2026
Merged

captcrock merged 3 commits into
mainfrom
td/5443-code-feed-followups

Conversation

@captcrock

Copy link
Copy Markdown
Contributor

Three small follow-ups from TD-5440's review of the Code feed, plus the gaps an independent review of the first commit found.

What changes

  1. Symlink loops read "a symlink loop" on every Python. On 3.13 and later, Path.resolve() no longer raises on a loop; it returns a half-resolved path. So the open failed with ELOOP, or a loop that led outside the folder read "points outside the feed folder". A strict resolve now names it on 3.11 through 3.14.
  2. The 4 MiB frame cap measures the frame as it is sent. That means json.dumps' spaced separators, the problems list, and room for the "left out" lines. The feed is now redacted when it is read, so the scrub on the way out (which can lengthen text, e.g. ab://a@ to ab://[REDACTED]@) no longer changes its size.
  3. 400 valid lines of exactly 16,384 B give 200 milestones, not 199 and a wrong "inside a long line" problem. The read budget counts each line's newline. When the budget does stop a read, the problem says so ("read stopped after its last 3.125 MiB; older lines left out"). Blank lines no longer take a milestone's place, and a line is measured with its spaces.

Docs: docs/code-feed.md and the TD-5443 backlog entry.

Before / after

Case main 4322ea8 this branch
Loop that leads outside the folder, Python 3.14 "points outside the feed folder" "a symlink loop"
Near-cap frame, measured as sent 8,805 B over 4 MiB under
Frame with secret-shaped text 89,414 B over 4 MiB (seen on the first commit) 49,536 B under
400 lines of 16,384 B 199 milestones + a wrong problem 200 milestones, no problem
Lines with a blank line between them fewer than 200 milestones 200

New tests fail on the old code: 6 on 3.11 and 8 on 3.14 against main. Against the first commit, the review-round tests fail 5 on 3.11 and 6 on 3.14. tests/test_code_feed.py: 55 passed on 3.11 and on 3.14.

One existing test changed: test_one_huge_line_is_read_in_bounded_time_and_left_out. Only its expected message changed, from "3 MiB inside a long line; that line and anything older left out" to "3.125 MiB; older lines left out". Both parts are what item 3 fixes.

Cost

Redacting at read time makes read_feed about ten times slower:

  • a 352 KB feed: 4.5 ms to 43.7 ms;
  • a 100-card near-cap feed: 72 ms to 713 ms (medians).

It runs off the event loop and only when the folder changes. A cheaper exact check would mean the push skipping its scrub for an already-redacted feed, which is a reply-path policy change, so it's left for the reviewer to decide.

Tests that fail at random on main too (not caused by this change)

I ran the full core suite twice on this branch on a heavily loaded shared machine (load average 40 to 70). Each run had 2 failures out of 10,256, and they were different tests each time. None of the failing tests touch the Code feed. Checked against main 4322ea8 under the same load, with main and branch runs taking turns:

Test Full runs on this branch main 4322ea8 this branch, outside the full runs
tests/test_newer_data_read_only.py::test_nothing_in_a_newer_folder_changes (a leftover .sessions.json.*.tmp) failed in run 2 failed 2 of 60 paired runs; 0 of 30 alone failed 1 of 13 paired runs; 0 of 30 alone
tests/test_skip_all.py::TestSkipAllWire::test_setup_state_defaults_off (assert 0 > 0) failed in run 2 not seen failing by name: 0 of 60 paired runs (one more main failure, in 38 paired runs of these two, wasn't recorded by name); 0 of 30 alone 0 of 13 paired runs; 0 of 30 alone
tests/test_benchmarks.py::test_no_regression[daemon_cold_start] (a timing ceiling) failed in run 1 fails every run under this load (3 of 3 paired, plus the whole file twice) the same
tests/test_picker_groups.py::TestOverTheWire::test_setup_state_names_every_models_section_and_each_slot (a socket answered HTTP 404) failed in run 1 passes 20 of 20 alone passes 20 of 20 alone

Summary lines on main 4322ea8, the run-1 pair:

FAILED tests/test_benchmarks.py::test_no_regression[daemon_cold_start]
1 failed, 1 passed in 3.06s

Evidence logs (kept locally): td5443-core-pytest-full-830f850c.log, td5443-core-pytest-full-830f850c-run2.log, td5443-two-tests-main-vs-branch.log, td5443-picker-repeat.log, td5443-run2-failures-main-vs-branch.log. CI on a clean runner is the reference.

Checks

  • ruff, ruff format and mypy are clean (445 source files).
  • release_scan --git: 0 hits.

Independent review

A fresh reviewer agent reviewed the first commit with read-only access and no access to my conclusions. The outside review lanes timed out or weren't available. Each finding was reproduced before it was fixed:

  • A loop leading outside the folder on 3.13+: fixed (item 1).
  • Redaction growing the frame past the cap: fixed (item 2).
  • Two budget inputs, trailing spaces and a line still being written: fixed (item 3), along with the older blank-line case.
  • Doc wording: fixed.

Kept as they are, with reasons:

  • The small over-drop from reserving room for the "left out" lines: it's bounded by two short lines, and it's what guarantees the cap.
  • The monkeypatched ELOOP test: it covers the error mapping, and a real-loop test now covers the actual behaviour.

🤖 Generated with Claude Code

https://claude.ai/code/session_01SPdoY5jgXgTw6gUHBMBngR

captcrock and others added 3 commits December 2, 2026 22:29
…ent, full-length lines

- A symlink loop is "a symlink loop" on every Python (3.13+ raise OSError ELOOP).
- The frame cap measures the frame as it is sent: json.dumps' separators and the
  problems list, with room for the lines that say what was left out.
- The events read budget counts each line's newline, so 200 full-length lines fit;
  the budget message is exact (3.125 MiB).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01SPdoY5jgXgTw6gUHBMBngR
…size check, honest cut message

- A strict resolve names a symlink loop on every Python, also one that leads
  outside the folder (3.13+ resolve() left it half resolved).
- The feed is redacted when read, so the scrub on the way out no longer grows it
  past the size the fit measured.
- The read-budget problem says what happened, without claiming a long line;
  blank lines no longer take a milestone's place; a line is measured with its spaces.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01SPdoY5jgXgTw6gUHBMBngR
The blank-line fix re-read one more 64 KiB block per pass and re-joined,
re-split and re-decoded everything read so far, so a tail of blank lines
was quadratic: 3 MiB of newlines took 5-7 s per read, and a watcher with
a writer still appending used 84% of a core. When blank lines leave the
first pass short, it now reads the rest of the budget in one go and
processes once. A test with 4 KiB blocks and 2 MiB of newlines took 65.7 s
before and passes in about a second now.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@captcrock

Copy link
Copy Markdown
Contributor Author

Manager review: the three follow-ups pass, and the cost is acceptable (read_feed runs only when the folder changes; idle watcher 0.0–0.1% of a core). One blocker found and fixed in 0415364: a tail of blank lines was re-read one block per pass, quadratically (3 MiB of newlines took 5–7 s per read; 84% of a core with a writer appending). It now reads the rest of the budget in one go after a short first pass, at most two passes; a new test took 65.7 s before and ~1 s now. Low, not fixed here: the PR body's "55 passed" for test_code_feed.py is 50 (now 51); card/event text is cut before it is scrubbed, so a token split by the 4,000-character cut can show a fragment (older, also on main). Optional follow-up: cache the scrubbed wire frames per change.

@captcrock
captcrock merged commit 3837191 into main Dec 3, 2026
10 checks passed
@captcrock
captcrock deleted the td/5443-code-feed-followups branch December 3, 2026 03:14
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.

1 participant