Skip to content

fix(fork): a Petal's digest card goes away once you answer it - #380

Merged
NoahHendrickson merged 2 commits into
customfrom
t3/dismiss-petal-digest-on-reply
Nov 19, 2026
Merged

NoahHendrickson merged 2 commits into
customfrom
t3/dismiss-petal-digest-on-reply

Conversation

@NoahHendrickson

@NoahHendrickson NoahHendrickson commented Nov 19, 2026 •

Copy link
Copy Markdown
Owner

Answering a Petal's Needs you ask left its digest card up: Reply only quoted the ask into the composer, so the digest never learned the answer went out. Approval asks like "OK to push and open a PR?" also had no one-click answer unless the Petal happened to write one.

Digest hides answered asks. One atom per bot (useAnsweredBotDigestAsks) derives the conversation's run revision (botDigestRevision) and the owner messages that quote an ask (> ask, written only through quoteBotDigestAsk). It holds while assistant text streams, so the digest never redraws at stream rate. The digest re-reads whenever any run starts or settles. A pure reducer (nextBotDigestRead, kept per bot across remounts) records which quoting messages had settled when the digest in hand was read. An ask stays hidden until a read lands under the revision that settled its answer, and comes back only if the Petal kept it. Answer buttons mark their message id in a shared atom until the conversation holds it, or the send fails. The "Sent" label is gone, since the card now leaves instead. A message with no run (imported) never hides an ask. The digest draws nothing until the conversation loads.

One-click approvals. The seeded Petal rules now require every approval or yes-or-no ask to end with answers after an arrow, links before it, the yes naming the action: OK to push and open a PR? https://github.com/…/pull/21 → Open PR | Hold. BOT_RULES_VERSION goes 4 → 5, so existing Petals get the new rules through refreshBotRules.

Tests: botDigestSections.test.ts covers quote extraction (including a null run and a cancelled run), the revision for earlier runs behind a queued one, the read reducer (a moved revision, refresh in flight, a failed refresh, a fresh read), and pending answers. The forkBots guard follows the new rule text. vp run check:changed and the fork lint ratchet pass. Not exercised in a running app.

Reviewed with sol-loop: 5 rounds with gpt-6.2-sol on high. Sol verdict: changes, one item open after round 5: an answered ask flashing back after leaving and returning mid-refresh. It is fixed in the follow-up commit along with the review findings, but that commit was not re-reviewed by Sol.

Done by Claude Opus 5.5 in Claude Code (T3 Code).

🤖 Generated with Claude Code

Replying to a Needs you ask (Reply then send, or an answer button) now hides
its card until the run that reads the answer settles and the digest is read
again; it comes back only if the Petal keeps the ask. Petal rules (v5) also
require approval and yes-or-no asks to end with one-click answers, e.g.
`→ Open PR | Hold`.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@github-actions github-actions Bot added vouch:trusted Author is trusted by repo permissions or the VOUCHED list. size:L labels Nov 19, 2026

@NoahHendrickson NoahHendrickson left a comment

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

Reviewed head 56dd0f30f82b22549f46e8f32f5ef40879a75475 against base 1e977aad7f621854f75b2732fc942a4de6aa055d. The inline findings cover a duplicate-answer window and two cases where an ask can stay hidden after its answer is withdrawn or fails. I traced the state transitions in source and ran git diff --check.

Comment thread apps/web/src/custom/bots/BotDigest.tsx Outdated
}>(() => ({
revision,
readAt: AsyncResult.isSuccess(result) ? result.timestamp : null,
asks: NO_ASKS,

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

[P2] Keep answered asks hidden across a thread switch. Answer an ask, switch threads while the Petal is working, then return after the run settles. The file query can still expose its cached digest while the refresh runs. This mount starts with an empty held.asks, and awaitedBotDigestAsks skips the now-settled reply, so the old card becomes actionable again until the read completes. On a slow connection the owner can submit a duplicate approval. Carry the hold across mounts or associate the cached digest with the run revision it was read under.

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

Fixed in 8047a77. The read state (revision, read time, and which quoting messages had settled when it landed) is kept per bot outside the component (readByBot in useAnsweredBotDigestAsks.ts). Coming back after the run settled, the moved revision marks the cached digest stale, so the answered ask stays hidden until the refetch lands.

Comment thread apps/web/src/custom/bots/BotDigest.tsx Outdated
setHeld({ revision, readAt, asks: new Set([...held.asks, ...awaited]) });
} else if (fresh) setHeld({ revision, readAt, asks: awaited });
else if ([...awaited].some((source) => !held.asks.has(source))) {
setHeld({ ...held, asks: new Set([...held.asks, ...awaited]) });

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

[P2] Restore an ask when its queued reply is edited away. Queue an answer and use Edit queued message to replace the quoted reply with an unrelated prompt. The message edit removes the ask from awaited without changing any run status, so it triggers no digest refresh. held.asks keeps the old match and the card stays hidden until another run transition, which may never come for a held queue. Retain the prior match only when a refresh is needed to account for a settling run.

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

Fixed in 8047a77. Hidden asks are now derived every render from the current quoting messages (answeredBotDigestAsks), with no held ask strings, so editing the quote out of a queued message brings the ask back right away.

Comment thread apps/web/src/custom/bots/BotDigest.tsx Outdated
answers.delete(item.source);
return { ...previous, answers };
});
setSentFor((previous) => new Map([...previous].filter(([, id]) => id !== messageId)));

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

[P3] Restore the card if a send fails after the digest remounts. If the owner leaves and returns before the send fails, the new mount initializes its sentFor from the pending entry. The failure callback still updates the old instance's state. Even if it clears sentByBot, the new instance never observes the cleared map, and no projected message will retire the failed ID. The error toast tells the owner to try again while the card is still hidden. Store pending sends in shared state that the mounted digest subscribes to.

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

Fixed in 8047a77. Pending button answers live in a shared atom (pendingAnswersAtom, keep-alive per bot), and a failed send clears its entry there, so a digest mounted since sees the ask come back.

@NoahHendrickson NoahHendrickson left a comment

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

Code review of 56dd0f3: one finding (performance).

The answered-ask logic holds up as far as I traced it: the > ${item.source} quote matches what awaitedBotDigestAsks extracts, owner messages get the queued run's id at creation, and revisionedQuery refetches on each new revision string, so a read lands under the settled revision. The remount flash is the open item the PR already describes.

I only read the code; I did not run the tests (no node_modules in the review worktree).

Comment thread apps/web/src/custom/bots/BotDigest.tsx Outdated
: NO_DIGEST;
// The bot rewrites its digest during a turn, so each run it starts or ends reads it again.
const revision = bot.latestRun === null ? null : `${bot.latestRun.runId}:${bot.latestRun.status}`;
const conversation = useQuietThreadProjection(botRef);

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

Performance: the digest now re-renders on every streamed assistant chunk while the Petal works.

useQuietThreadProjection only holds through text streamed into turn items. sameThreadStructure (packages/client-runtime/src/state/threadDetail.ts:235) compares messages by reference, and the adapters stream assistant text as message.updated too. For example, ClaudeAdapterV2 emits message.updated from its delta coalescer every ~50ms (publishAssistantArtifacts, ~L8548), and the client upserts it into a new messages array (orchestrationV2Projection.ts:405). So while the bot writes a reply, this structure changes on every chunk.

Before this PR, BotDigestAsksFor only read the quiet shell, so it didn't redraw during streaming. Now each chunk re-runs the whole render: awaitedBotDigestAsks over every message (Petal threads are long-lived), the delivered scan for each pending answer, parseBotDigest(contents), the line resolution, and the card subtree. All of that runs on the thread the user is looking at, at stream rate.

Suggested fix: derive the two values this component needs, botDigestRevision(runs) and the awaited set (plus whether pending message ids are present), in a small atom or selector. It should only change when runs or a user message changes, and its result should be stable (for example a joined string key, or the same Set when the contents match), so assistant streaming never reaches this component.

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

Fixed in 8047a77. The digest no longer reads the quiet projection. One atom per bot (conversationAtom in useAnsweredBotDigestAsks.ts) derives the run revision and the quoting owner messages, and keeps its previous value unless one of them changes, so assistant streaming never reaches the component.

@NoahHendrickson NoahHendrickson left a comment

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

Code-quality review of 56dd0f30f82b22549f46e8f32f5ef40879a75475. Changes requested, not approved.

The behavior is right and the seeded-rules part (botSeedFiles.ts, the version bump, the guard) is fine. The problem is how BotDigestAsksFor decides whether to hide an answered ask. The PR makes that decision with three overlapping mechanisms, each with its own lifetime and cleanup:

  1. sentFor: a module-global sentByBot map, mirrored into component state through a write-through setter, plus a cleanup during render that scans every conversation message for each entry.
  2. awaited: derived from the projection.
  3. held (revision, readAt, asks): a three-branch setHeld that runs during render, plus a fresh flag that flips which set applies.

Then open filters on all three. This is the hardest logic in the PR, and it sits inline in a component that already owns the query, dismissal, paging, answer/reply and rendering. The part most likely to break (held/fresh) has no tests: botDigestSections.test.ts only covers awaitedBotDigestAsks and botDigestRevision. The PR description itself still lists an open remount flash. That is what this kind of state tends to produce.

1. Store facts and derive the asks (main ask)

The real rule is simple. Hide ask X when an owner message quotes X and the run reading that message had not settled when the digest in hand was read. So the state you need is "which runs had settled as of the last fresh read" (ReadonlySet<RunId>), not a set of ask strings that gets merged, swapped and reset.

  • Keep { revision, readAt, settledRunIds }. When the revision changes, record it so that earlier reads count as stale, and keep settledRunIds. When a new read lands under the same revision and is not waiting, set settledRunIds to the currently settled ids.
  • hidden = answeredBotDigestAsks(messages, settledRunIds): one pure function and one set.

Settled sets only grow, so today's awaited is always a subset of that set. That makes awaited, held.asks, fresh, the union branch, hidden = fresh ? NO_ASKS : held.asks and NO_ASKS all go away, and the filter becomes !hidden.has(item.source). Put the transition in botDigestSections.ts as a pure nextDigestRead(prev, { revision, readAt, waiting, settledRunIds }) and test it there. That reducer is the part that needs tests.

2. Delete the conversation === null fallback

The fallback keeps a second revision scheme alive (${runId}:${status} from the shell next to botDigestRevision). When the conversation loads, the scheme switch moves the revision, which costs an extra refetch and a pointless trip through the hold logic. It also does not protect anything: while conversation is null, awaited is empty, so already-answered asks render anyway. Wait for the conversation before rendering asks, or before rendering at all. That removes the ternary, conversation?.…, ?? false and conversation === null ? NO_ASKS : …, and it likely narrows the remount flash Sol flagged.

3. Fold pending sends into the same computation

sentFor now lives only from the click until the projection holds the message, so the module-global map, the mirrored state and the cleanup during render are a lot of machinery for a window that usually lasts milliseconds. The doc comment on sentByBot ("before the bot answers") is also out of date now. Treat a pending send as a pending owner message, { id, text }, and merge it with the projection's messages, deduped by id. It then feeds the same answered-asks function as #1. delivered, the cleanup branch during render and the separate !sentFor.has(...) filter go away. Stale entries are harmless once they dedupe by id, and they can be pruned in answer().

4. Make the quote format one helper

The > ${item.source}\n\n format is written in two places in BotDigest.tsx (answer, reply) and parsed a third time in awaitedBotDigestAsks, with no shared definition. Put quoteBotDigestAsk(source) next to the parser so that writing and reading the quote cannot drift apart.

5. Smaller boundary notes

  • awaitedBotDigestAsks treats a user message with runId === null as awaited forever (the test asserts this for "Pick a day?"). V1-imported messages also carry a null runId (LegacyV1ThreadImporter). If null means "not yet assigned", say so. Otherwise the default should be "not awaited", so an ask can never be hidden for good.
  • botDigestRevision is a fingerprint built from counts (len:begun:settled:lastStatus). It only stays collision-free because run statuses move forward. runs.map((r) => ${r.id}:${r.status}).join() is obviously correct and costs no more. If you keep the counts, add a one-line comment on why they are enough.

No file crosses 1k lines (BotDigest.tsx is 380). I would still pull #1 to #3 into a useAnsweredBotDigestAsks hook, or the pure helpers, so BotDigestAsksFor goes back to rendering.

Comment thread apps/web/src/custom/bots/BotDigest.tsx Outdated
// revision moves, even one landing in that same render, predates it.
const readAt = AsyncResult.isSuccess(result) ? result.timestamp : held.readAt;
const fresh = held.revision === revision && !result.waiting && held.readAt !== readAt;
if (held.revision !== revision) {

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

There are three state transitions during render here, over ask strings, plus the fresh flag that picks which set wins. If held stored the settled run ids as of the last fresh read, and the asks were derived from them, this block becomes a single pure reducer in botDigestSections.ts and awaited/hidden/NO_ASKS all collapse into one set. It also gives the logic a test, which it has none of today.

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

Done in 8047a77, as suggested. The read state stores the quoting messages whose runs had settled as of the last fresh read. nextBotDigestRead is a pure reducer in botDigestSections.ts with tests, and answeredBotDigestAsks is the single set the filter uses.

Comment thread apps/web/src/custom/bots/BotDigest.tsx Outdated
const conversation = useQuietThreadProjection(botRef);
// The bot rewrites its digest during a turn, so each run it starts or ends reads it again: read
// off the conversation, so a read never lands before the answers it settles.
const revision =

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

This keeps a second revision scheme alive only for the pre-load window, and in that window awaited is empty anyway, so answered asks show regardless. Can we gate on conversation !== null and delete this branch, along with the conversation?. / ?? false / conversation === null ? NO_ASKS paths further down?

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

Done in 8047a77. The shell fallback is gone. BotDigestAsks draws nothing until the conversation loads, and the revision comes only from botDigestRevision.

Comment thread apps/web/src/custom/bots/BotDigest.tsx Outdated
const NO_ANSWERS: SentAnswers = new Map();
/** Each bot's sent answers outlive its digest's mount, so leaving the conversation and coming back
before the bot answers cannot offer the same ask twice. */
const sentByBot = new Map<string, SentAnswers>();

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

This now lives only from the click until the projection holds the message, so the module map, the mirrored state and the cleanup during render are heavy for that window, and the comment above is out of date. Can we merge pending sends into the projection's messages (deduped by id) and feed them to the same answered-asks function?

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

Done in 8047a77. sentByBot, the mirrored state and the cleanup during render are gone. Pending sends are { messageId -> ask } in a shared atom, deduped against the quoting messages by id inside answeredBotDigestAsks, and pruned in markBotDigestAnswer.

for (let at = projection.messages.length - 1; at >= 0; at -= 1) {
const message = projection.messages[at]!;
if (message.role !== "user") continue;
const status = message.runId === null ? undefined : runs.get(message.runId);

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

A user message with a null runId counts as awaited forever. V1-imported user messages also carry runId: null. If null means "not yet assigned", say so here. Otherwise skip null runIds, so an ask can never be hidden for good. This is also the function that should own quoteBotDigestAsk, since BotDigest.tsx writes the > source format in two places.

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

Both done in 8047a77. A message with a null runId is skipped (botDigestQuotes), so it can never hide an ask for good, with a test row. quoteBotDigestAsk lives next to the parser, and both answer and reply use it.

…atom

Review on #380: the digest redrew at stream rate (the quiet projection's
messages move with every assistant chunk), and hiding answered asks took
three overlapping mechanisms with no tests on the hardest part.

- One atom per bot keeps the run revision and the owner messages that quote
  an ask, holding while assistant text streams.
- The read in hand is a pure reducer (nextBotDigestRead) over the quoting
  messages whose runs had settled when it landed, kept per bot across
  remounts, so returning mid-refresh no longer flashes an answered ask.
- Pending button answers live in a shared atom, so a send that fails after
  the digest remounted still brings the ask back.
- An edited queued reply that drops its quote shows the ask again at once;
  a message with no run (imported) never hides one.
- quoteBotDigestAsk is the one place the `> ask` quote is written; the
  shell-revision fallback is gone and the digest waits for the conversation.

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

Copy link
Copy Markdown
Owner Author

Addressed the reviews in 8047a77; replies are inline. On the code-quality review's boundary note about botDigestRevision: I kept the counts rather than joining every run's id and status, since the atom recomputes it on each structure change during streaming. A comment now says why counts are enough (a run's status only moves forward). The answered-asks logic now lives in useAnsweredBotDigestAsks.ts plus pure helpers in botDigestSections.ts, so BotDigestAsksFor is back to querying and rendering.

@NoahHendrickson
NoahHendrickson merged commit dea2c69 into custom Nov 19, 2026
31 checks passed
@NoahHendrickson
NoahHendrickson deleted the t3/dismiss-petal-digest-on-reply branch November 19, 2026 16:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:L vouch:trusted Author is trusted by repo permissions or the VOUCHED list.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants