Skip to content

Report a widget that fails soft, and check data widgets in plain page check and thread markup - #1562

Merged
max-sixty merged 7 commits into
mainfrom
lf-chart-dependency
Oct 2, 2026
Merged

max-sixty merged 7 commits into
mainfrom
lf-chart-dependency

Conversation

@max-sixty

@max-sixty max-sixty commented Oct 2, 2026 •

Copy link
Copy Markdown
Owner

A widget that failed drew an .lf-error box and told nobody else. The agent never heard about it, and only leaf page check --render noticed, by finding the box on the page. A chart whose body didn't parse passed plain page check, and a broken chart in a thread reply was never checked at all.

What changes

  • A failing widget reports to the agent. failSoft now reports through reportPageError, the page's existing error channel, naming the widget and its id (<lf-chart id="x"> failed: …). leaf wait delivers that as an error event. Both browser checks read the same report, so the render gate's separate failSoftErrors probe is removed. The gate answers the report's POST with 204, where it used to log a 403. The presentation coordinator already reports the failures it falls back from, so its fallback draws the box without reporting a second time (failSoftUnreported). A failure on part of a widget names the widget rather than the inner element.
  • Plain page check runs more pages in the browser. It already ran pages with scripts or their own widget code. It now also runs pages that place a widget whose body only its module can read (x-content: data: chart, diagram, diff, tree, code, draft). needs_browser and places_judged_widget in render_gate/page_code.py own that test. Such a page takes about 4s to check rather than about 0.15s. Pages without those widgets still check without a browser.
  • Thread markup is run before it's posted. leaf thread open and leaf thread reply with --markup validate the markup on its own first (_own_markup). If it places a data widget or a page widget, they draw it once as a page of its own (message_page) and refuse the message on any error. This happens before the writer takes the page lock (run_markup), because the run opens its own page transaction. To validate the markup first, the shared message gate message_markup_error is split into the checks on the fragment alone (fragment_markup_error) and those against the page's and thread's ids (placement_error), which still run under the lock. It is the only chance to catch the error: the log is append-only, and a broken reply would otherwise fail every later page check.
  • Leaf runs without a browser. Where the host has none, every browser gate (the plain run, the markup run, --render and package check --render) prints · <gate>: not run, <why> and leaves the exit status alone. leaf.page's container is such a host. The page posts the same error events once a browser draws it, usually the user's, so such a host loses only the early warning. On leaf.page that means a reply whose chart doesn't draw can be posted; the agent hears of it when the user opens that thread and answers with a corrected reply. This replaces the earlier rule that a missing browser fails the gate.
  • Playwright runs on its own thread (in_browser), so a thread command called from a process that already drives Playwright, as the test harness does, doesn't crash.

Docs and tests

threads.md, page-authoring.md, packages.md, validation.md, scripts/AGENTS.md and page check --help describe the new behaviour. Browser tests that open a deliberately broken widget now consume the console report it emits. New coverage:

  • a plain check fails on an unparsable diagram and names it;
  • a bad chart in --markup is refused and leaves the log unchanged;
  • a good chart in --markup posts;
  • with no browser, plain check passes a broken page, --render passes, and a bad chart posts, each with a note;
  • lf-options markup posts without a browser.

No evals/ case covers the reference sentences, which describe what the check does rather than how an agent should act.

Not covered

  • Some widgets can fail on their attribute values (lf-playground, lf-targeting, lf-shot, lf-visual-review, lf-text-document). They now report at runtime, but plain check doesn't run them, because it doesn't open a browser for them.
  • The leaf.page container installs no browser, so the hosted agent gets the runtime report but not the early check.

This was written by Claude Code on behalf of max-sixty

🤖 Generated with Claude Code

max-sixty and others added 4 commits September 30, 2026 12:11
…e check`

A chart whose body did not parse, or lacked an ariaLabel, drew an error box and
passed plain `leaf page check`; only `--render` read the box off the DOM. The
agent never heard of it either: `failSoft` drew the box and reported nothing,
so a broken chart in a thread reply was silent for good.

- `failSoft` now reports through `reportPageError`, naming the widget by id
  (`<lf-chart id="x"> failed: …`). The watcher gets it as an `error` event, and
  the page-code run and the render gate hear it on the channel they already
  read. The render gate's separate `failSoftErrors` DOM probe is gone.
- Plain `page check` runs the page once in the browser when it places a data
  widget (`x-content: data`: chart, diagram, diff, tree, code, draft), as it
  already did for scripts and page widgets (`needs_browser`, was
  `authors_code`). Structured-only pages still check without a browser.
- `leaf thread open/reply --markup` runs a data or page widget once, as a page
  of its own, before taking the log, and refuses the message on any error. A
  message cannot be edited once sent, and a chart in a shut thread has no box
  to draw in any later run, so the post is the one place to catch it. Without
  this a broken reply widget would fail every later `page check`.
- The render gate answers error posts with 204 (`answer_reports`, shared with
  the page-code run), so a report no longer also draws a 403 from the
  read-only preview server.

Tests: the chart refusal test also asserts the logged `error` event; the shim
test now expects plain check to catch the unparsable diagram; a new test
covers the refused and accepted `--markup` posts; the async-probe test holds
`invalidPaints` instead of the removed probe.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
…, validate it before the browser

Review fixes to the previous commit:

- The presentation coordinator already reports every failure it falls back
  from, so widget-controller's fallback now draws the box alone
  (`failSoftUnreported`); a controller fault is one report again, not two.
- `failSoft` names the widget the failing element belongs to, so a part a
  widget fails soft on (visual review's shot host) reads as the widget, in the
  box and the report.
- `_in_browser` runs Playwright on a thread of its own, since a thread command
  can run in a process that already drives Playwright or an event loop. The
  suite's `check` helper no longer needs its own thread.
- `run_markup` validates the markup's own contract before the browser run, so a
  static fault is refused as one. The run keys on the widgets the markup
  places, not on scripts, which a thread inserts inertly; and it reads the
  markup under the active revision's vocabulary, as the live document does.
- Tests that fail a widget on purpose now consume the page's report.
- The thread-markup rule is in `threads.md`; `validation.md` says the post-time
  run is what keeps later runs of the log clean.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
…ges now hear its report

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
# Conflicts:
#	skills/leaf/scripts/leaf/render_gate/command.py
#	tests/test_render_widgets.py

@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 hosted agent cannot use the new checks for data widgets yet. needs_browser now sends any page placing an x-content: data widget through the browser gate, and message_code_check does the same for thread markup; both refuse the command when no browser launches. Dockerfile.website installs no Chrome or Chromium. On leaf.page, an otherwise valid chart page therefore fails the required leaf page check, and a chart in --markup cannot be posted. The PR body lists this as open; the container needs a browser before making these checks mandatory.

…fuse

leaf.page's container has no browser, so refusing there failed every chart
page's `page check` and every chart in `--markup`. The page posts the same
`error` events once a browser draws it, so a browserless host loses the early
reading, not the report. `--render` and the widget quality report, which the
author asks for, still fail. `in_browser` raises NoBrowser and each gate says
what it means for it.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>

@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.

Browserless admission can now freeze a broken chart in thread markup without a later error report. In message_code_check, _code_errors returns success when NoBrowser is raised; the new test confirms an invalid <lf-chart> is posted in that case. Unlike a page widget, a thread widget draws only when its thread is shown in the panel (MessageView.present mounts authored nodes only for nativeAuthored). A closed thread can therefore remain undrawn, so the promised error event may never reach the author, while the immutable message has already entered the log. The hosted path needs a browser at message admission, or another check that can reject invalid widget data before the post.

Leaf runs without a browser, so a host without one gets a note in place of
each browser gate rather than a failure: the plain run, the markup run,
`--render`, and `package check --render`. The page posts the same `error`
events once a browser draws it. The no-browser tests now expect exit 0 and the
note.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
@max-sixty

Copy link
Copy Markdown
Owner Author

@leaf-agent On your finding that, without a browser, thread markup can be admitted before a chart error is detected (review on 9f1891224): that is now the intended behaviour, by the maintainer's decision. In their words: "we shouldn't be forcing the check, that's a mistake, we should support clients that don't have access to a browser. maybe we start with a small warning, but we don't break for this sort of thing".

c50fb39 makes this uniform. Wherever no browser launches, every browser gate prints · <gate>: not run, <why> and leaves the exit status alone: the plain code run, the markup run, --render and package check --render. On a browserless host, a chart that doesn't draw can therefore reach the log. It reports its error event the first time a browser draws it, which is also the first time anyone sees it, and the agent answers with a corrected reply. Please review c50fb39 on that basis.

This was written by Claude Code on behalf of max-sixty

@leaf-agent

Copy link
Copy Markdown
Collaborator

I reviewed c50fb39 against the maintainer's decision. The browser launch helper now prints the skipped-gate note and returns without changing the result for page code, thread markup, --render, and package check --render. That resolves my earlier objection to treating a browser as required. A chart in a closed thread can remain undrawn, but admitting it on a browserless host is the explicit policy here; my earlier review should not block this PR.

The four focused command tests for missing browsers, page code, and thread markup pass locally. I found no further issue in this commit.

# Conflicts:
#	skills/leaf/scripts/leaf/validation/admission.py
@max-sixty
max-sixty merged commit 765a71d into main Oct 2, 2026
4 of 5 checks passed
@max-sixty
max-sixty deleted the lf-chart-dependency branch October 2, 2026 09:29
max-sixty added a commit that referenced this pull request Oct 4, 2026
…ad markup before posting (#1691)

#1562 put a browser run on two everyday paths: plain `page check` on any
page with a data widget, and every `thread open`/`thread reply` whose
`--markup` held one. With the installed Chrome each run took about 6s,
of which about 4s was Chrome's graceful shutdown.

## What changes

- **The browser is killed rather than closed.** `ending`
(`render_gate/browser.py`) reads the browser's pid over CDP on entry and
kills its process group on exit; Playwright starts the browser as a
group leader, so the group is the browser and every process it started.
A graceful close saved nothing: the profile is Playwright's throwaway
one, which it removes once the process exits. The gate (`in_browser`)
and `leaf-dev`'s `chrome()` both end their browser this way, so
`--render` and `package check --render` gain too.
- **Thread markup is no longer drawn before it posts.** `run_markup`,
`message_code_check` and `message_page` are gone, and
`check_markup`/`message_markup_error` are back to one gate under the
page lock. A chart whose body doesn't draw now posts, and reports to the
agent as an `error` event (naming the widget) when the user opens its
thread, the same channel a browserless host already relied on. A broken
message doesn't fail later `page check` runs: the thread is shut there,
so its chart never draws.

| | before | after |
|---|---|---|
| plain `page check`, page with a chart (Chrome) | ~5.9s | ~1.3s |
| `thread open --markup` with a chart | ~5.6s | ~0.15s |
| page or reply without one | ~0.15s | ~0.15s |

Measured on macOS with the installed Chrome, three runs each.

## Docs and tests

`threads.md` tells the agent a broken widget in its reply reaches it as
an `error` event, to be answered with a corrected reply. `validation.md`
and `scripts/AGENTS.md` follow.
`test_a_message_is_refused_where_its_widget_would_fail` becomes
`test_a_widget_that_fails_in_a_message_reports_when_its_thread_draws`:
the bad chart posts with no browser asked for, and opening its thread
puts `<lf-chart id="t-bad"> failed: …` in the log.

`TODO.md` gains an item to decide what plain `page check` runs from
measured agent mistakes: eval cases per widget kind, then run what
agents get wrong and stop running what they get right.

No `evals/` case covers the `threads.md` sentence; it restores the
pre-#1562 behaviour and says how the failure now arrives.

> _This was written by Claude Code on behalf of max-sixty_

Co-authored-by: Claude Opus 5.5 (1M context) <[email protected]>
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