Skip to content

fix(context): report a failed background-context injection instead of swallowing it - #20748

Merged
chenmingwei23 merged 2 commits into
mainfrom
replace/12666
Oct 15, 2026
Merged

chenmingwei23 merged 2 commits into
mainfrom
replace/12666

Conversation

@iamwhatever

@iamwhatever iamwhatever commented Oct 15, 2026 •

Copy link
Copy Markdown
Contributor

Problem / Motivation

Goal: When the artifact companion chat or the Papyrus co-author could not be told which document it is holding, the user sees a notice in that chat column instead of nothing (or a false save error).

Opening the artifact companion chat, or the Papyrus co-author, silently POSTs
/api/chat/slots/<slot>/context so the agent is told which document it is holding. Both
posts were fire-and-forget (.catch(() => undefined)). When that POST was rejected the
panel still opened looking ready, so the user typed "summarize this" against an agent that
had never been told what "this" was.

On the artifact page the failure was worse than silent: it was routed through the page's
SAVE-error channel, so a background enqueue failure told a user with a dirty editor buffer
that their work had not been written.

Why it matters

The failure is invisible at exactly the moment the user acts on it. They get a confident
but unanchored answer and no reason to suspect the attach step, which is the one thing
they cannot see. The misrouted save error is worse: it reports data loss that did not
happen, on a page holding unsaved edits.

Not a goal

What changed (motivation → approach → change)

Symptom: a rejected context POST left no user-visible trace on either surface (and on the
artifact page surfaced as a save failure). Root cause: the POST had no result handling at
all — a bare .catch swallowing every rejection, and no state to render one.

Each surface now owns a notice in its own chat column, mounted beside the composer its
copy names, and retracts it when the newest inject for the current session succeeds (a superseded session's late result is ignored; the Papyrus notice also clears when the paper changes). The artifact notice distinguishes
a first attach from a staleness refresh: a failed refresh means only the newest version is
missing, not that nothing was shared, and labelling that "not attached" was itself wrong.

The POST is routed through useMutation, like every other write on these pages, rather
than a bare promise chain. A memory-only claim map is held before the request so an
open/close/reopen inside the request window cannot inject twice; a rejected post releases
the claim so the next open retries instead of recording a delivered baseline. The claim is
deliberately not persisted — a resolved POST is not a durable-write acknowledgment, so a
claim outliving the page could suppress a nudge for an entry that was never stored.

Both posts gain maxAge (3600s). Without a TTL a dormant slot accumulates entries against
_MAX_CONTEXT_PER_SOURCE (10) and every later post answers 429.

ArtifactChatPanel loses its fixed calc(100vh - 240px) height for flex. With the notice
above it in the same column, a fixed height put the composer past the fold whenever both
mounted.

Carried onto current main from fork PR #12666 by @rnoack1. Conflict resolution: PapyrusPage.tsx keeps main's chatWidth (from #11881) in place of the fork's CHAT_PANEL_WIDTH; ArtifactDetailPage.tsx keeps main's edit-token / save-conflict state beside the new context-notice state. The new bn/hi/ru strings were moved to the informal register (তুমি / तुम / ты) that the diff-scoped style gates require.

Backwards compatibility

Compatible: no request field is added or removed, no validator is tightened, and no existing key changes meaning. Both posts keep ephemeral: true; they gain maxAge (3600s), an existing optional parameter of POST /api/chat/slots/{slot}/context that main already accepts.

Removes nothing: the diff only adds a notice and result handling to a post whose failure was previously dropped.

Tests

Website only; no Python source is touched.

  • ArtifactDetailPage.companionChat.test.tsx — the notice appears on a rejected inject and is titled for the context failure rather than the save failure; it is taken down with the panel so it never names an absent composer; it mounts inside the chat column, not at page top; the panel carries no fixed height; a first failed share is never relabelled as a staleness failure; a user turn or a non-user row does not retract it. A superseded session's late success does not clear the current session's notice (fails on the previous head). "Nothing more happens" checks flush effects inside act() instead of sleeping.
  • ArtifactDetailPageCoverage.test.tsx — a stale session re-open nudges rather than taking a silent baseline; the stale body names the version.
  • PapyrusPageCoverage.test.tsx — the paper's identity is handed over silently; a rejected push renders the notice.
  • papyrusResizeAria.test.tsx — reads the sized column box via closest('[style*="width"]'), since the panel now sits in a flex-1 child beside the notice.

Manual verification

Run locally on this branch, rebased on current main:

  • npm run typecheck — clean.
  • vitest run on the three touched test files plus src/i18n with I18N_BASE_REF=origin/main — all pass (the bn/hi/ru register gates included).
  • npm run build — green.
  • Both capture harnesses this PR adds — exit 0 (they assert the notice renders with its own title, never via the save-error channel).

Screenshots / video

Before = current main build; after = this branch. Same fixtures: the /context post answers 500.

Artifact companion chat, resume nudge failed:

before: artifact chat, no notice

after: artifact chat, context notice above the panel

Papyrus co-author, first share failed:

before: papyrus co-author, no notice

after: papyrus co-author, context notice above the panel

More frames

429 context_not_queued path (same copy, pins the refusal path):

after: queue full

First injection on a new bound session (first-share title, not the staleness title):

before: first injection

after: first injection

Related Issues

Fixes #20737
Replaces #12666 (thanks @rnoack1 — original fix and harnesses are theirs; authorship kept on the commit).

Pattern harvest

Rule candidate: review-prompt
Pattern: a background write whose only failure handling is .catch(() => undefined) — the
user acts on the assumption it succeeded, and where the surface has an unrelated error
channel in scope, the rejection gets rendered as that channel's failure instead, so the
report is not merely absent but wrong.

Checklist

  • At most two commits (one is the norm), with a Conventional Commits title
  • Existing tests pass and new tests added for new functionality
  • Self-review completed; code follows project style guidelines
  • Documentation updated (if applicable) — N/A, no user-facing doc surface
  • No secrets, credentials, or internal references in the diff

Contribution License Agreement

Contributions are accepted under the project's Apache-2.0 license.

… swallowing it

Both companion surfaces posted their context fire-and-forget, so a rejected inject
left the panel looking ready while the agent had never been told which document it held.

Carried from fork PR #12666 onto current main: conflicts in PapyrusPage.tsx
(main renamed CHAT_PANEL_WIDTH to chatWidth) and ArtifactDetailPage.tsx (kept
main edit-token state beside the new context-notice state); bn/hi/ru copy moved
to the informal register the style gates require.

Fixes #20737

Co-authored-by: cixuuz <26782336+cixuuz@users.noreply.github.com>
Co-authored-by: rnoack1 <69695077+rnoack1@users.noreply.github.com>
@github-actions github-actions Bot added the readiness: checking Automated validation is still running label Oct 15, 2026
@github-actions

github-actions Bot commented Oct 15, 2026 •

Copy link
Copy Markdown
Contributor

Design Review (Opus 5.5) — ✅ PASS

Design-level review of 9274dd4321fe2553c49ba1b07ca883d29a417ec9 — updated in place on each push. A BLOCK verdict blocks PR readiness; PASS/CONCERNS are advisory.

Design-Verdict: PASS

Check one thing before merge: the chat column's fixed h-[calc(100vh-240px)] dropped the old minHeight: 480, so on a short viewport the composer can shrink to unusable.

[DESIGN-REVIEWED] 9274dd4

Description read

[DESCRIPTION-READ] e83d4a6bb77d27ae96ef6e9a25ab35f8dfd7297e3361a8573288fd76311a2893

That sha256 names everything this verdict read: the PR description, plus the 1 evidence file(s) the workflow collected from it and handed this review. It covers that evidence because the media strip replaces every attachment URL with the same placeholder, so an edit swapping one attachment for another would leave the description's captured text identical while what this review judged changed. Recompute it with .github/scripts/pr-description-capture.sh over the same inputs; if it differs, the description or that evidence changed after this verdict was formed and any finding drawn from either is unproven.

@github-actions

github-actions Bot commented Oct 15, 2026 •

Copy link
Copy Markdown
Contributor

First Principles Review (Opus 5.5) — 🟡 CONCERNS

Premise-level review of 9274dd4321fe2553c49ba1b07ca883d29a417ec9 — why this exists and whether the shipped surface is the smallest honest version. Updated in place on each push. A BLOCK verdict blocks PR readiness; PASS/CONCERNS are advisory.

First-Principles-Verdict: CONCERNS

The description's "false save error" harm is not on main: the removed lines are a bare .catch(() => undefined), carried over from fork #12666.

Not justified as shipped

  • Item 2 — inherited: the description says the failure "was routed through the page's SAVE-error channel". But both removed artifact hunks read api.chatSlotContext(...).catch(() => undefined), and neither calls setSaveError. The save-channel defect belongs to the fork's base, not to main. The capture-harness assertion rendered through the SAVE-error channel guards against a path main never had.
    Clears when: a main-side reproduction of the save-error routing is shown, or that claim and the matching 'Save failed' assertion are removed.
  • Item 6 — rides along: the mounts the chat panel on mobile test and its comment describe "a !isMobile gate". The removed JSX {panel === 'chat' && ( has no such gate, so the test pins a defect this PR does not fix.
    Subtraction: delete the test and the "EVERY breakpoint" comment.
    Clears when: the deletion is made, or a base commit carrying the gate is cited.

What this change ships

Inventory (8 items) — 5 justified

Intent: a user opening a document chat learns when the agent was never told which document it holds. FIX.

  1. The artifact companion chat shows a notice in its column when the context share fails — justified
  2. The failure no longer appears as a save error — inherited: not a main defect
  3. The Papyrus co-author shows a notice in its column when the paper share fails — justified
  4. The artifact notice is titled differently for a first share and for a stale-version refresh — justified
  5. A failed share frees the claim, so the next open retries — justified
  6. A mobile chat-panel test for a gate main lacks — rides along
  7. Both context posts now expire after one hour (maxAge 3600) — rides along
  8. The chat panel height comes from flex instead of a fixed calc, plus two capture harnesses — justified

[FIRST-PRINCIPLES-REVIEWED] 9274dd4

Description read

[DESCRIPTION-READ] 4808e10eb59af38c10311f835aa847ef11281188118b814996c0ec635fa26260

That sha256 names the PR description this verdict read. Recompute it with .github/scripts/pr-description-capture.sh; if it differs, the description changed after this verdict was formed and any finding drawn from the description is unproven.

@github-actions

github-actions Bot commented Oct 15, 2026 •

Copy link
Copy Markdown
Contributor

UX Review (Opus 5.5) — 🟡 CONCERNS

UX-level review of 9274dd4321fe2553c49ba1b07ca883d29a417ec9 — updated in place on each push. A BLOCK verdict blocks PR readiness; PASS/CONCERNS are advisory.

UX-Verdict: CONCERNS

The first-share notice tells the user to "mention the artifact in your next message" while the panel under it has no session and no message box.

Watch

  • The notice's fix can't be done in the no-session state. In shot-07, "Mention the artifact in your next message…" sits above "No active session for this artifact." and a "Start chat" button, with no composer anywhere. The blind reader said: "there's no chat and no message box… I'd wonder whether clicking Start chat clears the warning or keeps it." This shows on every failed first share where the panel hasn't picked up the new session. The user is told to do something they can't do yet. Smallest fix: don't show the notice until there is a session to type into, or give this state its own line: "Start a chat, then mention the artifact."
  • "Mention" doesn't say what to type. The reader, on all three notices: "I'm not sure what 'mention the artifact' means: do I type its name? Is there a special way to mention it?" This is the only way to recover, so every failure carries the doubt, and the reader added that they'd be "unsure whether I had actually fixed the problem." Put the document's name in the copy.

Suggestions

  • In chat_context_not_attached, chat_context_stale_not_attached and context_not_attached, replace the vague "the artifact" / "the paper" with the actual name: Mention "{{title}}" in your next message….
  • Shorten the second sentence of all three bodies from "You can dismiss this once you've mentioned it." to "Dismiss once you've mentioned it." so the action comes first.

[UX-REVIEWED] 9274dd4

Description read

[DESCRIPTION-READ] aeac26a6c8b9b3d51cf2a203c8a3507db606dc72a93760177da94871d1d21de4

That sha256 names everything this verdict read: the PR description, plus the 10 evidence file(s) the workflow collected from it and handed this review. It covers that evidence because the media strip replaces every attachment URL with the same placeholder, so an edit swapping one attachment for another would leave the description's captured text identical while what this review judged changed. Recompute it with .github/scripts/pr-description-capture.sh over the same inputs; if it differs, the description or that evidence changed after this verdict was formed and any finding drawn from either is unproven.

@github-actions

github-actions Bot commented Oct 15, 2026 •

Copy link
Copy Markdown
Contributor

Opus 5.5 Review — ✅ no blocking findings

Reviewed 9274dd4321fe2553c49ba1b07ca883d29a417ec9 — this comment is updated in place on each push.

Review details

No findings block this merge; one advisory finding.

FINDING — website/src/pages/ArtifactDetailPage.tsx:1520 — onError checks only vars.slug !== slug, with none of the newest-slot and version guard that onSuccess and the Papyrus sibling's seq check have. Scenario: a resume nudge for slot A is still in flight when "New chat" archives A and creates B, and B's injection succeeds. A's POST then fails late and runs setContextError(contextFailureMessage(...)). The new session B shows "couldn't share" even though its own context was delivered, and the notice stays until the user dismisses it. → Fix: after releaseInjectedVersion, set the notice only when high.slug === slug && high.slotKey === vars.slotKey && vars.version >= high.version, using const high = latestInjectedRequest.current.

[OPUS-REVIEWED] 9274dd4

Verdict parsed from the review's SHA-scoped output markers for commit 9274dd4321fe2553c49ba1b07ca883d29a417ec9.

False positive or not applicable? A repository writer can comment:
/ai-review override fable 9274dd4321fe2553c49ba1b07ca883d29a417ec9: <one-sentence reason>

@github-actions

github-actions Bot commented Oct 15, 2026 •

Copy link
Copy Markdown
Contributor

GPT 6.1 Review — ✅ no blocking findings

GPT 6.1 completed its review of 9274dd4321fe2553c49ba1b07ca883d29a417ec9 and found no blocking issues.

This comment is updated in place on each push.

Review details

No findings.
[GPT-REVIEWED] 9274dd4

False positive or not applicable? A repository writer can comment:
/ai-review override gpt 9274dd4321fe2553c49ba1b07ca883d29a417ec9: <one-sentence reason>

Keep both context posts ephemeral (the durable flag was a no-op on main),
collapse the duplicate claim-map helpers into the ref, drop two tests that
never checked what they named, replace six promise-sleeps with an act()
flush, and read the sized co-author column in papyrusResizeAria now that
the panel sits beside the notice.

Scope the notice retraction to the newest request on the current slot
(artifact) or the newest push (Papyrus), so a superseded session late
success cannot clear the current failure; clear the Papyrus notice when
the paper changes.

Co-authored-by: rnoack1 <69695077+rnoack1@users.noreply.github.com>
@iamwhatever
iamwhatever marked this pull request as ready for review October 15, 2026 10:37
@iamwhatever
iamwhatever requested review from a team and KiroCrewCaptain as code owners October 15, 2026 10:37
@github-actions github-actions Bot added readiness: passed Eligible automated validation passed for the current revision and removed readiness: checking Automated validation is still running labels Oct 15, 2026

@chenmingwei23 chenmingwei23 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Batch approval: readiness: passed, no merge conflict, checks green.

@chenmingwei23
chenmingwei23 merged commit bedd559 into main Oct 15, 2026
106 checks passed
@chenmingwei23
chenmingwei23 deleted the replace/12666 branch October 15, 2026 15:42
@github-actions github-actions Bot removed the readiness: passed Eligible automated validation passed for the current revision label Oct 15, 2026
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.

Artifact and Papyrus chats hide a failed document-context attach

3 participants