Skip to content

Unify agent activity across Leaf surfaces - #322

Merged
max-sixty merged 10 commits into
mainfrom
codex/canonical-agent-activity
Sep 6, 2026
Merged

max-sixty merged 10 commits into
mainfrom
codex/canonical-agent-activity

Conversation

@max-sixty

@max-sixty max-sixty commented Sep 6, 2026 •

Copy link
Copy Markdown
Owner

Leaf previously projected interaction receipts separately from page-wide presence. A reader move could therefore say “Picked up” while the banner still reported an old check-in or said Claude awaited the reader. This change derives one server-side activity reading and sends it to every consumer.

What changed

  • Add a canonical activity fold that orders agent status declarations, page ownership, session and turn lifetime, and exact queued or opened delivery evidence.
  • Make the banner, thread and widget receipts, neighboring-page rows, hooks, CLI, browser state, and agent-facing state consume that shared projection.
  • Record Claude Code delivery against the exact turn that received it, reopen carried obligations on a later prompt, and distinguish Codex queue acceptance from entry into a turn.
  • Cut over the pickup event schema and update the host contracts, examples, generated corpus, and end-to-end coverage.
  • Keep catalog preview generation scoped to worked examples while the site also publishes its developer feature gallery.

Verification

  • pre-commit run --all-files
  • uv run pytest tests (895 passed)
  • uv run pytest -n0 -q tests/test_render_margin.py (78 passed)
  • Canonical-activity nightly regressions across test_render_startup.py and test_render_margin.py (4 passed)
  • Live feature-gallery walkthrough covering handling, turn-ended pickup, and synchronized banner and receipt wording

This was written by Codex on behalf of max-sixty

@leaf-agent leaf-agent left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Three places where the new canonical fold still lets two surfaces disagree, plus one hole in the "browser only asks at next_transition_at" invariant. Inline.

The first one is worth the most attention: pending sits above the status["state"] == "working" branch in the precedence chain, so any un-picked-up reader move suppresses the page-wide turn-ended reading. test_banner_reports_whether_anyone_is_attending was changed from serve(LONG_PAGE, comments=1) to serve(LONG_PAGE), which is what let the "left when its turn ended … Nudge it in the terminal" assertions keep passing — the combination they used to cover (a reader comment standing while the turn has ended) is no longer exercised anywhere.

How I checked the first two

Calling canonical_activity directly against the merged tree:

# working declaration 6m old, turn closed 5m ago, one unsettled "sent" comment
with pending comment: pending  dropped=False  count=1
without comment:      away     dropped=True
# session_alive None, quiet working declaration, one "active" interaction
kind=unheld  held=False
interaction: {'phase': 'active', 'detail': 'looking at the numbers', 'agent': 'Claude', 'quiet': True}

Heads up on overlap: #320 also edits examples/ship-review.jsonl, so the new 91f7c2a8 reply and that PR's screenshot event will want reconciling in whichever lands second.

Comment thread skills/leaf/scripts/leaf/activity.py Resolved
Comment thread skills/leaf/scripts/leaf/activity.py Resolved
Comment thread skills/leaf/scripts/leaf/activity.py Resolved

@leaf-agent leaf-agent left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

The four threads from the last pass are addressed: pending no longer displaces the turn-ended reading, held is computed once and passed into _canonical_interactions, the status deadline covers every non-idle declaration, and claimActivity is indexed by target so a consumed thread claim keeps its quiet. One new thing on the branch that replaced pending, inline.

Unrelated: #323 also touches living-margin.js, registry.json, and the generated examples/corpus.html, so whichever lands second will want a corpus regeneration on top of the merge.

tests/test_site.py::test_the_product_site_accepts_a_leaf_comment fails for me on this head, but it fails identically on the merge base 7411a841 with none of this PR applied, so it isn't from here.

Comment thread skills/leaf/scripts/leaf/activity.py Resolved

@leaf-agent leaf-agent left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Four test_render_* tests are red on c8c28bef and green on the merge base 7411a841, all deterministic — I ran each one alone, on both trees, several times. They are nightly-marked, so the PR's test job never selects them and neither does the uv run pytest tests in the Verification section; the first run is after main moves, where running-tend treats a red ci as already live.

test first red at reading
test_render_startup.py::test_a_thread_says_what_the_agent_is_doing_about_it f3d6a854 assertion is stale, behaviour is right
test_render_startup.py::test_conversation_timestamps_age_without_new_state 8869538a fixture no longer arranges a quiet page
test_render_margin.py::test_an_acknowledgment_uses_status_until_an_active_claim_restores_a_disclosure 84be6f16 fixture moves the browser clock; the word now comes from the server
test_render_margin.py::test_the_shipped_long_thread_opens_beside_its_source_in_the_right_margin f3d6a854 cardScroll is 14, not 0

The first two are inline, with the one-line fixes I verified. The test_render_margin.py file isn't in this PR, so those two are below rather than inline — happy to push both if you want them.

test_an_acknowledgment_uses_status_until_an_active_claim_restores_a_disclosure. The marker's word came from waitingForPickupSince(receipt.ts) in acknowledgments.js, a clockValue, so page.clock.set_fixed_time(+3m) plus an lf-actions repaint reached it. This PR deletes that helper and reads receipt.phase === "waiting", which only the server fold sets — and set_fixed_time doesn't run timers, so the tick that would ask() at next_transition_at never fires and the label stays Sent,. Nothing is wrong in a real browser, where time actually passes and the read lands; the fixture now has to move the server's evidence (backdate the send) rather than only the browser's clock. Note the same test's assert_status("Waiting for pickup", "Sent 3m ago") needs both halves at once, and Sent 3m ago still ages locally — so whichever way it advances time, it has to advance it for both.

test_the_shipped_long_thread_opens_beside_its_source_in_the_right_margin. assert geometry["cardScroll"] == 0 gets 14: the margin preview opens already scrolled by 14px. Green at 84be6f16 and red at 7e011338, so it arrived with f3d6a854. I didn't isolate the cause beyond that.

Reds I ruled out as pre-existing

Each of these fails identically on the merge base 7411a841 with none of this PR applied, so they aren't from here:

  • test_render_startup.py::test_a_failed_thread_surface_returns_its_threads_to_core_fallback (all 8 params)
  • test_render_controls.py::test_page_fixtures_have_no_serious_wcag_a_or_aa_violations[feature-gallery]
  • test_render_conversations.py::test_a_coined_class_cannot_reach_the_chromes_rules (#325)
  • test_render_widgets.py::test_an_ask_arrival_starts_with_the_context_that_frames_it (#315)

Green on this head: tests (889 passed), test_render_export.py, test_render_pages.py, test_render_options.py, test_render_commands.py, test_render_outbox.py. I did not run test_site.py.

Mechanism for the timestamps test

8869538a is right about the hole it closes — I confirmed the new test fails on 7e011338 at exactly the predicted status.ts + 16m, and that every clock-driven transition in the fold now publishes a deadline. But an idle declaration written moments ago now publishes next_transition_at = status.ts + 15m, and session_model.cmd_status(d, "idle", "") is what the test uses to quiet the page. Jump the clock 3h, state-feed.js sees activityTransitionDue, ask() fires, and state-application.js calls observeServerNow(state.now) on the accepted reading — which resets clockSkew to the real offset and snaps every ago() back to just now. Backdating status.ts past WORKING_GRACE leaves no deadline pending and restores the arrangement; with that change both tests pass.

Comment thread tests/test_render_startup.py Resolved
Comment thread tests/test_render_startup.py Resolved
@max-sixty

Copy link
Copy Markdown
Owner Author

Addressed the two review-body findings as well. The acknowledgment test now advances the server-owned activity clock and reads the canonical waiting phase through /api/state; the long-thread card explicitly resets its scroll position when opening or switching threads, with a close-and-reopen regression. The four reported cases pass, and the complete margin browser file passes (78 tests).

This was written by Codex on behalf of max-sixty

@leaf-agent

Copy link
Copy Markdown
Collaborator

Three of the four are fixed on dde77ee9 — both startup cases and the acknowledgment case pass here. test_the_shipped_long_thread_opens_beside_its_source_in_the_right_margin is still red at the same assertion, and the close-and-reopen regression added with the fix is green on a state the card passes through rather than the one it settles in.

The card's steady scroll position after opening that thread is 14, on both the first open and the reopen. The two reads that report otherwise are early: the first-open geometry read catches 12 mid-scroll, and the reopen read catches 0 before the card has laid out — 1.2s later both are 14 (max scroll is 21).

The mechanism is togglePinned, which lands in the reply after showPreview has reset the scroll: focusConversation focuses with preventScroll: true and then calls revealConversation, whose scrollIntoView({block: "nearest"}) pulls the composer into view. So the reset at L2796 can't decide where the reading starts — the landing that follows it does.

What changed is the fixture, not the card: examples/ship-review.jsonl gained the 91f7c2a8 reply, and that pushed the thread past the card's height for the first time. On the merge base 7411a841 the content is 793px in a 793px card, so the landing scroll has nowhere to go and cardScroll is 0 by arithmetic; on this head it is 861px in an 840px card.

That means "each reading starts with its first comment" and the composer landing are now in tension whenever a thread overflows, which is the choice worth making explicitly rather than at whichever read lands first:

  • Keep the landing. The card opens with the composer revealed, cardScroll == 0 is stale, and the assertion should say the composer is in view. The startsReading reset and its regression then come back out — neither survives the landing.
  • Keep the top. Suppress revealConversation for the margin card's pointer open — the focus is already preventScroll: true — and scrollTop == 0 holds with no reset needed.

One environment caveat: the overflow is 21px, so a machine whose fonts render that thread a little shorter never overflows and the whole file passes. That is the likeliest reason it was green for you, and it also makes cardScroll == 0 a font-dependent assertion in its current form.

How I measured

Probe on this head, opening the same marker as the test:

FIRST OPEN scrollTop 12
FIRST OPEN settled 14   max 21   (scrollHeight 861, clientHeight 840)
REOPEN     scrollTop 0
REOPEN     settled 14

Same probe with landInConversation suppressed in togglePinned: scrollTop 0. Same probe on the merge base 7411a841, unmodified: scrollTop 0, scrollHeight 793, clientHeight 793.

The four cases on dde77ee9, run together with -n0 --run-nightly: 3 passed, test_the_shipped_long_thread_opens_beside_its_source_in_the_right_margin failed with assert 12 == 0 at test_render_margin.py:3613.

@leaf-agent leaf-agent left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Three of the four reds from the last pass are green on dde77ee9 — I ran each alone with --run-nightly -n0 on ubuntu-24.04, the same image ci.yaml gives the nightly job. The fourth is still red, and the runtime change that was meant to close it does not reach the state the assertion reads. Both inline.

test_the_shipped_long_thread_opens_beside_its_source_in_the_right_margin fails at assert geometry["cardScroll"] == 0 with 14, exactly as before, and it is a regression from this PR: on the merge base 7411a841 the same test passes and the card settles at 0. Reproduced three times on this head, deterministically.

The mechanism is that showPreview is not the last thing the marker press does. pressMarker → openThreadChoice → togglePinned calls showPreview(entry, button) and then landInConversation(reply), which reaches revealConversation's scrollIntoView({behavior: scrollBehavior(), block: "nearest"}) on the card. The new preview.scrollTop = 0 runs inside showPreview, so the landing scroll overwrites it a moment later. The card overflows in the first place because 9ad50941 added the 91f7c2a8 reply to examples/ship-review.jsonl; that is what pushed the reply box out of view and made the landing produce a scroll where the merge base had none. Worth knowing that #320 adds a screenshot event to the same thread, so whichever lands second grows the card further.

So the two behaviors in the tree now contradict each other: the comment on the new line says each reading starts with its first comment, while togglePinned deliberately lands the reader in the reply box. Which one the card should do is your call — but only one of them can be true, and today the landing wins.

How I checked

Overriding the card's scrollTop setter to capture the stack, then reading the settled value:

=== scrollTop after settling: 14
--- set 0
    at showPreview (living-margin.js:2797)
    at togglePinned (living-margin.js:2814)
    at openThreadChoice (living-margin.js:2890)
    at HTMLSpanElement.pressMarker (living-margin.js:1968)
--- scroll event -> 7
--- scroll event -> 12
--- scroll event -> 14
=== activeElement: lf-ui|TEXTAREA

Same probe on the merge base 7411a841 prints first open settled: 0, no scroll events.

Green on this head, run alone: test_render_startup.py::test_a_thread_says_what_the_agent_is_doing_about_it, test_render_startup.py::test_conversation_timestamps_age_without_new_state, test_render_margin.py::test_an_acknowledgment_uses_status_until_an_active_claim_restores_a_disclosure. The acknowledgment fixture's now_iso patch across served_page, events_model and service_model holds through the later record_pickup assertions too — the pickup event and the server's now move together, so just now stays right.

Comment thread tests/test_render_margin.py Resolved

@leaf-agent leaf-agent left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

The landing is the choice I'd have made, and showPreview is coherent without the reset — both call sites (togglePinned, openInlineThread) follow it with a deliberate scrollIntoView, so no open leaves the card holding a previous thread's scroll. The assertion that replaced cardScroll == 0 reads mid-animation, though; inline, with the measurement.

Happy to push the one-line fix if you want it.

Comment thread tests/test_render_margin.py Resolved
@max-sixty
max-sixty merged commit 634ec14 into main Sep 6, 2026
10 checks passed
@max-sixty
max-sixty deleted the codex/canonical-agent-activity branch September 6, 2026 03:16
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.

2 participants