Skip to content

TD-5444: Code feed: scrub before the cut; scrubbed frames made once per change - #305

Merged
captcrock merged 2 commits into
mainfrom
td/5444-code-feed-scrub-then-cut
Dec 3, 2026
Merged

captcrock merged 2 commits into
mainfrom
td/5444-code-feed-scrub-then-cut

Conversation

@captcrock

Copy link
Copy Markdown
Contributor

Two follow-ups to the Code feed, from TD-5443's review.

What changes

  1. Scrub before the cut. Card text over 4,000 characters and event text over 2,000 were cut first and scrubbed later. A token that straddled the cut was then no longer a token the scrubber knew, and its first 20 characters showed. Text over its cap is now scrubbed, then cut. Text that fits is scrubbed once, with the whole feed, as before.

  2. Scrubbed frames made once per change. The watcher keeps the current feed's scrubbed frames in two kinds:

    • a window's frame, with the folder's path;
    • a phone's or another computer's frame, without it.

    It empties them when the same fingerprint the watcher already uses says the folder changed. The push and get_code_feed share them, and a feed that is no longer the current one is never cached.

    Every reply still goes through the reply funnel's scrub, unchanged. The cache saves only the off-loop scrubs that built each frame.

Docs: the TD-5444 backlog entry.

Before / after

Case main 3837191 this branch
A GitHub-style token straddling the card cut (in where, now, next, needs_you) or the event cut its first 20 characters show scrubbed whole
Frames built for push + a window's get + a phone's get 4 scrubs (1.45–1.66 s) 2 scrubs (0.86–0.91 s)

New tests that fail on main's code (9):

  • the 5 straddle tests;
  • 3 cache tests: once per kind of frame; a feed that is no longer current is not cached; push and get share the frames;
  • the edited test below.

tests/test_code_feed.py passes on this branch.

One existing test changed: test_the_push_serializes_off_the_event_loop. It slowed scrub_wire_json where the daemon used to call it. The frame is now built in code_feed, so the test slows it there instead. The assertion is the same.

Cost

Scrubbing the cut text before the cut costs a second scrub of that text only. Medians, interleaved with main, on a loaded machine:

  • A copy of a real feed (352 KB, 7 cards, 200 events): read_feed went from 42–45 ms to 51–53 ms.
  • A near-cap feed (100 cards, each text field just under its 4,000 cap; 200 events, each 8,000 characters, over its 2,000 cap): from 336–484 ms to 600–755 ms.

read_feed runs off the event loop and only when the folder changes.

An earlier version scrubbed every field twice and roughly doubled read_feed. The review round replaced it.

Merging with #304

This branch and #304 (TD-5445) both start from main 3837191. Whichever merges second conflicts in core/tests/test_code_feed.py and docs/tst-desk-backlog.md; core/tstd/code_feed.py merges cleanly. I'll rebase this branch once #304 is merged, rerun the tests and push.

Full suite

On 9d5b03dd, on a heavily loaded shared machine (load average 35 to 50): 6 failed, 10,336 passed, 13 skipped, 4 deselected. None of the 6 is in the Code feed.

I reran the 6 on their own, three times on this branch and three times with main's code_feed.py and daemon.py in place of this branch's (the only source files it changes):

  • This branch: run 1, all passed; run 2, test_remote_approve.py::TestDoubleResolve::test_second_client_cannot_flip_an_approve failed; run 3, test_audit_set_aside_errors.py::test_concurrent_set_asides_keep_one_file_one_note_and_every_row failed.
  • Main's code: run 1, test_audit_set_aside_errors… and test_drain.py::test_shutdown_gives_an_open_turn_a_short_settle failed; runs 2 and 3, all passed.

test_second_client_cannot_flip_an_approve failed 3 of 33 times on this branch and 0 of 33 on main's code, counting the 3 runs above plus single runs. Each failure was TimeoutError: daemon did not bind, the test's 2.5 s wait for a fresh daemon to listen. That count leans against this branch, though it doesn't settle it. I found no link:

  • nothing this PR changes runs before the daemon binds;
  • the time to bind, measured 24 times on each side and interleaved, is the same: medians 0.24–0.39 s on this branch and 0.22–0.35 s on main, longest 0.71 s and 0.74 s.

CI on a clean runner is the reference. I'll look again if it fails there.

Checks

  • ruff, ruff format and mypy: clean.
  • release_scan --git: 0 hits.

Independent review

A fresh reviewer agent reviewed the branch with read-only access and no access to my conclusions.

What it checked:

  • Scrubbing before the cut holds. It fuzzed 15 secret shapes across every cut field and every offset: 0 leaks on the branch, against 1,200 with the old cut-first code.
  • The cache is correct. The frames are tied to the current feed, emptied with the fingerprint, and the window's and phone's frames are kept apart.

Its findings, each reproduced before acting:

  • My wording overclaimed: each reply is still scrubbed again by the reply funnel, so only the off-loop scrubs are saved. Fixed in the code comments, the test and the backlog. The funnel's scrub is kept, with no exceptions.
  • A likely CI flake in the stale-feed test (two same-size writes about 1 ms apart): fixed, the sizes now differ.
  • A private key in a bad ts showed in the problem reason. This is older than this change and is fixed separately in TD-5445: Code feed: a problem reason never echoes a value #304.

The funnel's on-loop scrub of a near-cap get_code_feed reply was measured separately at 255–339 ms (stalls up to 786 ms for a heavier reply). That gets its own ticket and is not changed here.

🤖 Generated with Claude Code

https://claude.ai/code/session_01SPdoY5jgXgTw6gUHBMBngR

…er change

Text over its cap (a card's 4,000/200-character fields, an event's 2,000-
character text and 200-character source) is scrubbed before it is cut: a
secret split by the cut, or a private key that lost its END line to it, was
no longer one the scrubber knew, and part of it showed.

The watcher keeps the current feed's scrubbed frames, one for a window and
one for a phone or another computer, emptied when its fingerprint changes;
the push and get_code_feed share them. Every reply still goes through the
reply funnel's scrub.

Rebased onto TD-5445 (#304) as one commit.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01SPdoY5jgXgTw6gUHBMBngR
@captcrock
captcrock force-pushed the td/5444-code-feed-scrub-then-cut branch from 9d5b03d to 554e8d0 Compare December 3, 2026 07:17
…rames

The watcher noted nothing about register_secret_value, so a value registered
after the frames were made went out raw in the next push (main scrubs at push
time). The frames are now kept with the number of registered secrets, emptied
when it grows, and a frame scrubbed while one was being registered isn't kept.
The backlog names every cut: 4,000, 2,000, 200 and 64 characters.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01SPdoY5jgXgTw6gUHBMBngR
@captcrock
captcrock merged commit b44efde into main Dec 3, 2026
10 checks passed
@captcrock
captcrock deleted the td/5444-code-feed-scrub-then-cut branch December 3, 2026 07:37
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