Skip to content

feat(app-sdk): ChatEmbed re-reads its slot on a host push signal - #21109

Merged
bolichen97 merged 2 commits into
mainfrom
feat/chatembed-ws-push
Oct 28, 2026
Merged

bolichen97 merged 2 commits into
mainfrom
feat/chatembed-ws-push

Conversation

@buluoray

@buluoray buluoray commented Oct 16, 2026 •

Copy link
Copy Markdown
Contributor

Problem / Motivation

Goal: An app's embedded chat (ChatEmbed) shows a streaming reply as it is written, like the dashboard chat, instead of catching up once per poll.

ChatEmbed learns about new rows only from its poll: one read per second while a turn runs, one every five seconds when idle. A reply in a Spec Builder chat therefore arrives in one-second jumps, and a new message or approval on an idle slot can take up to five seconds to appear. The dashboard chat, mounted on the same session, updates live from /api/ws.

Why it matters

Every app that embeds a chat looks laggier than the dashboard for the same session, and the idle poll is the floor on how fast a person sees an approval card in an app. A live update also lets the poll back off while nothing changes, so an idle open embed reads a third as often (once per 15 s, not once per 5 s). While a reply streams it reads more: up to four since-cursor delta reads a second, not one, each carrying only the rows after the held cursor.

Not a goal

  • Rendering chat_* frame payloads inside ChatEmbed. Rows still come only from the slot read.
  • Live updates for slots the app does not own (slots:user, slots:all, slots:app:<name> visibility). Those keep polling.
  • A real event bridge for useAppEvents (AppHost's subscribeFn is unchanged).
  • Any server-side change to /api/ws, the event scope gate, or the slot-detail read.

What changed (motivation → approach → change)

Goal → push the change, not the content. The RFC's P5-f row (docs/request-for-change/rfc-chat-core-extraction.md) chose the since-cursor poll over the WebSocket stream because folding chat_* frames needs a store-free copy of the chat frame reducer and a slots:* event grant. Both costs come from sending frame CONTENT to the app. A content-free "this slot changed" signal needs neither: the embed answers it with the same incremental read it already makes, so the read's checks (permissions.api, deny_app_slot_access) keep deciding what the app sees. The session list already works this way (mc:app:slots in hooks/websocket/slotList.ts).

How app event access is gated today: an app token's /api/ws socket receives slot-scoped events for slots it owns with no declaration (ws_event_scope._slot_visible); wider scopes need slots:*. In-host apps do not hold an app token: they run in the dashboard and fetch with the dashboard user's session, and AppHost's subscribeFn delivers nothing from the socket. So the boundary for this change is client-side, and it is drawn at exactly the gateway's no-declaration set.

  • app-sdk/slotPush.ts (new): the SlotPush seam on the SDK context — watch(slotKey, {onChange, onConnection}) and connected(slotKey), both live only while the socket is up AND the slot is the watching app's — and an internal useSlotPush(). Neither the hook nor the SlotPush types are on the public barrel. AppScopedApiProvider / AppApiProvider take it as an optional slotPush prop. A host that passes none (the vendored iframe SDK, session controls) is unchanged.
  • utils/appSlotPush.ts (new): the dashboard's provider. useWebSocket feeds it every decoded frame; markGatewayConnected/markGatewayDisconnected feed it the connection flag. It signals an app only for a frame in SLOT_CHANGE_FRAMES whose slot's ChatSlot.app is that app, ownership read at each delivery. slot_title is in the set (the embed header shows the read's title) and is read from key, as the gateway gate reads it. The signal has no arguments.
  • ChatEmbed: a signal re-reads at once; signals during an in-flight read collapse into one trailing read, at least 250 ms after the last, joining (not aborting) an in-flight request. Each connect, reconnects included, re-reads once. While the page is hidden (React Query's focusManager) or the host tab is inactive (info.active === false) no push read is sent: signals only mark one read pending, sent once both are visible. The poll itself pauses only for a hidden page; an inactive host tab keeps its cadence, as on main. While the channel is up and reads succeed the poll is a 5 s / 15 s backstop. A failing read ignores the channel and keeps the 1 s / 5 s cadence and the outage back-off, so the stalled-connection notice still appears 10 s into an outage even when the socket is up (a deleted session or lost access fails the read, not the socket).
  • AppHost and SpecBuilderPage pass useAppSlotPush(<app>). Spec Builder's slots are app-owned, so it gets live updates. IncidentChat passes none: its incident slot is created by the generic POST /api/chat and is unowned, so it keeps the full 1 s / 5 s poll. Any embed on a slot the host does not signal keeps that cadence, since connected(slotKey) reads false for it.
  • Docs: docs/app-kit/api-reference.md (Live updates, polling), docs/system-specs/modules/app-kit-platform.md (new ChatEmbed live updates section), history.md (the delta read's caller), the RFC table.

No new permission is needed: the provider never signals outside the gateway's own-slot default, and test/test_app_slot_push_frames.py pins that set against ws_event_scope.

Backwards compatibility

Compatible: slotPush is an optional new prop and context field; without it every embed polls exactly as on main, and no API, permission, or wire format changes.

Removes nothing: the poll, its cadence without a channel, the stall notice and the read path all remain. With a live channel, push adds reads while the slot changes, and the poll slows to the 5 s / 15 s backstop while it does not.

Tests

  • website/src/test/ChatEmbed.pushRead.test.tsx: a signal re-reads before the poll would; ten signals during an in-flight read give one trailing read; the idle poll is 15 s while the channel is up and 5 s once it drops; reconnect re-reads once; no host channel polls at 5 s; a failing read under a live channel still shows the stalled notice within EMBED_STALL_MS; a slot that becomes signalled after mount moves to the 15 s backstop with no reconnect; a hidden page sends zero reads under 20 signals and a reconnect, then one catch-up read on focus; a read scheduled just before the page hides is held until focus returns; an inactive host tab sends zero reads, then one when it turns active; focus returning with nothing pending sends nothing; embedPollInterval unit cases. Mutations checked: letting pushed override the error cadence reddens the stall test and its unit case; removing the in-flight coalescing reddens the burst test; removing the focusManager subscription reddens the two hidden-page tests, removing the visibility check in the timer callback reddens the held-read test, and removing the host-active flush reddens the inactive-tab test.
  • website/src/test/appSlotPush.test.ts: own slot signalled with no payload; a slot_title frame signals through key, and key is not read for frames that use slot; another app's slot, an unowned slot and an unlisted slot are not; ownership change stops signalling; non-change frames and malformed frames ignored; unwatch; connectivity fan-out including repeated true; the socket router calls it before its switch. Mutation checked: dropping the ownership comparison reddens two cases.
  • website/src/hooks/websocket/gatewayConnectivity.test.tsx: the connect/disconnect helpers move the push flag too.
  • test/test_app_slot_push_frames.py: every name in the client's SLOT_CHANGE_FRAMES is slot-scoped and outside the subagent family in ws_event_scope, and the gateway admits each for an own slot with no declaration and refuses it for another app's or a person's slot; slot_title is in the set and is checked with its slot in key.

Local: scoped frontend suite 12224/12224, tsc, full eslint src/, i18n:check, jscpd, build, docs lint, comment-history, file-line-cap, feature-map gates pass. The backend related run on this host had 74 failures in unrelated modules (test_file_explorer_app.py, test_design_tweak_devproc.py, steering/skill projection) that read host paths; this diff adds no backend source.

Manual verification

Not done in a running dashboard; behaviour is covered by the unit tests above. Checked on the backend: a slot made by get_or_create_slot(app="spec-builder") (the Spec Builder runtime's call) is in serialize_slots() with app: "spec-builder", which is what the provider's ownership check reads from dashboard.slots. Unverified end to end: that a Spec Builder chat in a live dashboard streams visibly faster.

Screenshots / video

Why no screenshot: nothing on screen changes shape or style; the embed shows the same rows sooner, which a still image cannot show and the unit tests pin by read timing.

Related Issues

Closes #24130

Refs the chat-core extraction RFC, phase P5-f (docs/request-for-change/rfc-chat-core-extraction.md).

Checklist

  • At most two commits (one is the norm), with a Conventional Commits title (feat|fix|docs|style|refactor|perf|test|chore|ci|build|revert: ...)
  • Existing tests pass and new tests added for new functionality
  • Self-review completed; code follows project style guidelines
  • Documentation updated (if applicable)
  • No secrets, credentials, or internal references in the diff

Contribution License Agreement

Contributions are accepted under the project's Apache-2.0 license; see the Licensing section of CONTRIBUTING.md.

@buluoray
buluoray requested review from a team and KiroCrewCaptain as code owners October 16, 2026 06:40
@buluoray
buluoray requested a review from bolichen97 October 16, 2026 06:40
@github-actions github-actions Bot added the readiness: checking Automated validation is still running label Oct 16, 2026
@github-actions

github-actions Bot commented Oct 16, 2026 •

Copy link
Copy Markdown
Contributor

UX Review (Opus 5.5) — ✅ PASS

UX-level review of d5825caad3baea65781f2a2316680fb4b759b681 — updated in place on each push. A BLOCK verdict blocks PR readiness; PASS does not.

UX-Verdict: PASS

Nothing to check. The diff only changes when ChatEmbed re-reads its slot. It adds or changes no control, label, string or layout, so the missing blind read leaves no gap.

[UX-REVIEWED] d5825ca

Description read

[DESCRIPTION-READ] 0606d879ce93355c3b57d83b6c8f87032ecb6592f8bc9d1536fd6946c29111db

That sha256 names everything this verdict read: the PR description, plus the 3 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 16, 2026 •

Copy link
Copy Markdown
Contributor

First Principles Review (Opus 5.5) — ✅ PASS

Premise-level review of d5825caad3baea65781f2a2316680fb4b759b681 — 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 does not.

First-Principles-Verdict: PASS

Nothing blocks. The one open question is whether the base RFC covers "push over poll". It is listed as partial, and this diff adds its own row to it.

Notes

  • Item 3 — inherited: the PR changes how often every embed polls on an app-owned slot. Its record is a row this diff adds to rfc-chat-core-extraction.md ("ChatEmbed push: … the poll becomes a backstop"). The base P5-f row says the poll was "Chosen over the WebSocket stream". That choice was about frame content, so whether it also rules out a content-free signal is a judgement call, which makes this a note and not trigger (c).
Inventory (7 items) — 6 justified

Intent: an app's embedded chat should show a streaming reply live, the way the dashboard does. This is an ADDITION.

  1. An embed on an app-owned slot re-reads as soon as the dashboard socket reports a change — justified
  2. Bursts of signals collapse into one read in flight plus one trailing read, at least 250 ms apart — justified
  3. While the socket is up, polling slows to every 5 s while a turn runs and every 15 s when idle (was 1 s / 5 s) — inherited (RFC row added by this PR)
  4. Each reconnect triggers one catch-up read — justified
  5. No push reads while the page is hidden or the host tab is inactive; one held read is sent when it becomes visible again — justified
  6. Spec Builder and AppHost apps get push; IncidentChat and the iframe SDK keep polling — justified
  7. New internal slotPush provider prop and context field, kept off the public barrel — justified

[FIRST-PRINCIPLES-REVIEWED] d5825ca

Description read

[DESCRIPTION-READ] 9b789ab3b6c47d236ddba5b6ab37708380e91c0ae60d8d12518adea884c24ef4

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 16, 2026 •

Copy link
Copy Markdown
Contributor

Design Review (Opus 5.5) — ✅ PASS

Design-level review of d5825caad3baea65781f2a2316680fb4b759b681 — updated in place on each push. A BLOCK verdict blocks PR readiness; PASS does not.

Design-Verdict: PASS

Nothing blocks. The signal carries no content, ownership is checked against the gateway's own-slot set, and any slot that is not signalled falls back to the existing poll.

Notes

  • Ownership comes from store.getState().dashboard.slots. If that list ever drops app-owned slots (a filter or pagination), the embed quietly goes back to 1 s / 5 s polling instead of failing. Nothing tests that list against Spec Builder's slots.

[DESIGN-REVIEWED] d5825ca

Description read

[DESCRIPTION-READ] 2194a6610fdefcf86ff4b46a43806687a9cad3718933ac6ecc435072abc1364e

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 16, 2026 •

Copy link
Copy Markdown
Contributor

Opus 5.5 Review — ✅ no blocking findings

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

Review details

No findings.

Notes:

  • chat_thinking is in SLOT_CHANGE_FRAMES, but thinking is broadcast-only and the slot-detail read never includes it. During a thinking phase the embed therefore re-reads up to every 250 ms, and those reads cannot return a change.

[OPUS-REVIEWED] d5825ca

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

False positive or not applicable? A repository writer can comment:
/ai-review override fable d5825caad3baea65781f2a2316680fb4b759b681 false-positive: <reason, 20 to 500 characters>

@github-actions

github-actions Bot commented Oct 16, 2026 •

Copy link
Copy Markdown
Contributor

GPT 6.1 Review — ✅ no blocking findings

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

This comment is updated in place on each push.

Review details

No findings.
[GPT-REVIEWED] d5825ca

False positive or not applicable? A repository writer can comment:
/ai-review override gpt d5825caad3baea65781f2a2316680fb4b759b681 false-positive: <reason, 20 to 500 characters>

@github-actions github-actions Bot added readiness: action required A blocking check or review needs attention and removed readiness: checking Automated validation is still running labels Oct 16, 2026
@buluoray
buluoray force-pushed the feat/chatembed-ws-push branch from 25bdcdf to 50621c9 Compare October 16, 2026 07:25
@buluoray

Copy link
Copy Markdown
Contributor Author

Review dispositions for 25bdcdfd91, all fixed in 50621c9a57 (rebased onto main 9b99f5fbcc):

Opus BLOCKING — useSlotPush on the barrel but not in the vendor stub. Fixed by the subtraction First Principles also asked for: the value export is gone from app-sdk/index.ts, so the stub needs no entry and chatProtocolBoundary.test.ts passes. Only export type { SlotPush, SlotPushWatcher } stays, because AppApiProvider (public) takes a slotPush prop and an author must be able to name its type. The useSlotPush() line is removed from api-reference.md.

Opus FINDING / Design CONCERNS — "socket up" read as "my slot is covered". Fixed at the source as Design suggested: SlotPush.connected(slotKey) and each watcher's onConnection now report live only while the socket is up AND ownerOf(slotKey) === app (utils/appSlotPush.ts liveFor). ChatEmbed also re-reads connected(slotKey) at each poll tick, so a slot that changes hands, or is not listed yet, moves to the full 1 s / 5 s cadence on the next tick. Tests: appSlotPush.test.ts "reads a slot the app does not own, or one not listed yet, as not live" (reddens when liveFor drops the owner check) and ChatEmbed.pushRead.test.tsx "keeps the normal cadence for a slot the host does not signal…" plus "returns to the normal cadence when the slot stops being signalled mid-life" (reddens when the tick-time read is reverted to the mount-time state). Spec and API reference updated.

First Principles item 8 — IncidentChat wiring that never fires. Removed: IncidentChat.tsx is back to main's text.

First Principles item 5 — barrel export with no consumer. Removed as above (types kept, reason given).

CI reds on the old head: Backend Lint was black on my new test file (fixed). Frontend Tests (3) / Frontend Coverage Merge / Coverage Gate were the boundary test above (fixed). Backend Tests (3.12, 6) and (Windows) (6) failed test_chat_fork_error_codes.py::test_the_ratchet_can_actually_fail (27 vs 26); that file and chat_fork.py are outside this diff, it passes on main, and main fixed it in #21075 — the rebase carries that in.

@github-actions github-actions Bot added readiness: checking Automated validation is still running and removed readiness: action required A blocking check or review needs attention labels Oct 16, 2026
@buluoray
buluoray force-pushed the feat/chatembed-ws-push branch from 50621c9 to fc492c5 Compare October 16, 2026 08:22
@buluoray

Copy link
Copy Markdown
Contributor Author

First Principles on 50621c9a57, both fixed in fc492c5770:

  • Item 6: the SlotPush/SlotPushWatcher type re-export is removed from app-sdk/index.ts. Nothing on the public barrel names the push seam now.
  • Item 10: app-kit-platform.md now lists only AppHost and SpecBuilderPage as hosts that pass slotPush, and names IncidentChat among those that pass none.

E2E (stub ACP backend, offline) on 50621c9a57 failed two member-memory.spec.ts specs after the stub gateway exited -14 at 722s; no member-memory or gateway source is in this diff. Its one re-run was spent on that head; the new head runs it fresh.

@buluoray

Copy link
Copy Markdown
Contributor Author

First Principles on fc492c5770 (items 2, 3, 5: the backstop cadence) — kept, no push:

  • In the Goal, not beside it. The task this PR implements asks for push with a fall back to the since-cursor poll when the socket is unavailable or drops. Polling at full rate while push is up is not a fallback, it is two read paths running at once. Items 2, 3 and 5 are that fallback contract: slow the poll while the slot is signalled (2), re-read once when the channel comes back because changes made while it was down were never signalled (3), and never let a live socket slow the outage path, so the fix: flag a chat embed whose poll keeps failing as stale #19899 stall notice still lands at 10 s (5).
  • Cost, stated as arithmetic, not a measurement. A running embed on main reads its slot 60 times a minute; with push it reads once per signal batch (at most every 250 ms during a stream, then nothing) plus a 5 s backstop, so 12 a minute when nothing changes. Idle: 12 → 4 a minute. Each read is a gateway GET /api/chat/slots/{slot}. I have not profiled the gateway side; this is the read count only.
  • Missed-frame risk. SLOT_CHANGE_FRAMES is not hand-kept in isolation: test/test_app_slot_push_frames.py pins every entry against the gateway's own event gate. A frame type outside the set falls to the backstop (5 s running / 15 s idle), and that is the documented bound in app-kit-platform.md.

If the owner prefers push as an extra on top of the unchanged poll, the subtraction listed in the verdict is mechanical and I can make it; until then this stays as the brief specified.

@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 16, 2026

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

REQUEST_CHANGES at fc492c5.

Blocking: a renamed or auto-titled slot now shows its old title for longer. SLOT_CHANGE_FRAMES leaves out slot_title, but the embed header renders shown?.title from the slot read. While the channel is up, the idle poll is 15 s, so the title can lag up to 15 s where main lags 5 s. Smallest fix: add slot_title to the set, and read data.key when data.slot is absent in noteAppSlotFrame. slot_title carries its slot in key (ws_event_scope.py). Add a case to appSlotPush.test.ts and let test_app_slot_push_frames.py pin the new entry.

Also needs a reply on this head:

  1. Design Watch: a streamed reply can drive about 4 slot reads per second per embed (250 ms gap), against 1 per second on main. The description still says push makes an open embed cost less. State the streaming cost and why it is acceptable, or tune the gap.
  2. Design punchline: confirm that Spec Builder slots appear in dashboard.slots with app set. The backend does create them with app=spec-builder, but nothing shows the store list carries it.
  3. UX punchline: the body says a live Spec Builder stream was never checked. A short manual check, or a reply saying why it is not needed, clears it.

The First Principles backstop concern has a reasoned reply. Whether to keep the slower backstop is the owner's call. All checks on this head are green.

— crew-pr-reviewer (r107)

@github-actions github-actions Bot added readiness: action required A blocking check or review needs attention and removed readiness: passed Eligible automated validation passed for the current revision labels Oct 16, 2026

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

Not ready yet. The push seam is a good shape: the signal carries nothing, the slot read stays the only permission gate, and test_app_slot_push_frames.py pins the frame set against ws_event_scope.

Head reviewed: fc492c5. Bots read: Design PASS, First Principles CONCERNS, UX PASS, Opus no blocking, GPT no blocking, readiness action required.

🔴 0 must-fix · 🟡 1 should-fix (inline, on ChatEmbed.tsx).

I agree with the open slot_title point from the earlier review on this head. I checked it: ws_event_scope.py reads the slot from key for slot_title, and noteAppSlotFrame reads only data.slot, so both the set and the key lookup need the change. The Design Watch item (about 4 reads per second per embed while streaming) and the unverified live Spec Builder check also still need a reply on this head.

Verified: every frame in SLOT_CHANGE_FRAMES is slot-scoped in the gateway gate and carries slot; ownership is read at delivery; no file hits the security path list; main does not contain this change.

Comment thread website/src/app-sdk/ChatEmbed.tsx Outdated
refetchInterval: (query) => embedPollInterval(
query.state,
embedOutageMs(failureRunsRef.current, `${String(query.queryKey[1])}:${String(query.queryKey[2])}`, query.state),
pushLive && (slotPush?.connected(slotKey) ?? false),

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.

🟡 A slot that is listed after the embed mounts never moves to the backstop cadence.

pushLive is set from connected(slotKey) at mount and is changed again only by onConnection, which fires only when the socket goes up or down. If the slot is not yet in dashboard.slots at mount (for example a spec chat created just before the embed renders), pushLive is false. When the slot list later carries it, connected(slotKey) turns true, but pushLive && connected(slotKey) stays false until the next reconnect. Push signals still arrive, so nothing breaks, but the poll keeps its 1 s / 5 s cadence on top of the push reads.

      pushLive && (slotPush?.connected(slotKey) ?? false),

Why it matters: the spec section added here says the embed reads connected(slotKey) again at each tick and moves cadence on the next tick. That holds for a slot that leaves the app, not for one that arrives. A new chat is a common Spec Builder path, so the lower idle cost does not apply there.

Suggestion: use slotPush?.connected(slotKey) ?? false alone for the cadence, and keep pushLive only as the state that makes a connection change re-render. Add a case beside "returns to the normal cadence when the slot stops being signalled mid-life" where the slot becomes signalled after mount and the idle poll moves to 15 s. If Spec Builder always has the slot in the list before the embed mounts, say so and I will withdraw this.
Rule: SAGE description and diff fidelity; docs/system-specs/modules/app-kit-platform.md (ChatEmbed live updates)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

🤖 Kiro Crew Auto-Pipeline [operator: buluoray#ce473fca]: Fixed in 64f921b. The poll cadence now reads slotPush?.connected(slotKey) alone at each tick, so a slot listed after mount moves to the 15 s backstop with no reconnect. The pushLive state only re-renders on a connection change. New test: "moves to the backstop once a slot listed after mount becomes signalled" (red before the fix). The spec sentence is updated.

@buluoray
buluoray force-pushed the feat/chatembed-ws-push branch from fc492c5 to 64f921b Compare October 18, 2026 05:41
@github-actions github-actions Bot added readiness: checking Automated validation is still running and removed readiness: action required A blocking check or review needs attention labels Oct 18, 2026
@buluoray

Copy link
Copy Markdown
Contributor Author

🤖 Kiro Crew Auto-Pipeline [operator: buluoray#ce473fca]: Reply to @iamwhatever's review (r107, at fc492c5) and @bolichen97's review, now on head 64f921b (rebased onto current main, still two commits).

Blocking: slot_title (fixed). Checked: push_slot_title broadcasts {"_type": "slot_title", "key": ..., "title": ...} (state.py), the gate reads the slot from key for it, and the embed header renders the read's title. SLOT_CHANGE_FRAMES now holds slot_title, and a new KEY_SLOT_FRAMES set makes noteAppSlotFrame read key when slot is absent, for that frame only, as the gate does. Tests: appSlotPush.test.ts gains "signals a title change, which names its slot in key" (red before the fix) and "does not read key as the slot for frames that name it in slot". test_app_slot_push_frames.py now asserts slot_title is in the set, pins KEY_SLOT_FRAMES == ["slot_title"], and checks the gate for each frame with the slot in the same field the client reads (24 passed). The spec section says the same.

Design Watch: streaming read rate (cost stated, gap kept). While a reply streams, one embed reads up to 4 times a second, not once. Each read is the since-cursor delta: only the rows after the held cursor. Idle, an embed reads once per 15 s, not once per 5 s. The 250 ms gap is the cost of the PR's goal, showing a reply as it is written. A 1 s gap would make streaming no faster than the poll. The PR body no longer says an open embed simply costs less. It now states both rates, and the spec section records the cost.

Design punchline: Spec Builder slots in dashboard.slots with app (measured). The Spec Builder runtime makes its slot with state.get_or_create_slot(name=slot_key, app=APP_NAME) and stamps slot._app = APP_NAME. SlotProjection.to_dict emits "app": slot._app, and ChatSlot.app is typed on the client. I ran it: a DashboardState built from the test helper, a slot from get_or_create_slot(name="spec-probe", app="spec-builder"), then serialize_slots(dashboard_user=True) → listed: 1, app: spec-builder.

UX punchline: live Spec Builder stream (not run; reason). I did not run a live dashboard on this host. Push changes only when the embed reads. What it reads and renders is the same read and the same rows as without push. That timing is pinned by ChatEmbed.pushRead.test.tsx. The one live input the path depends on is the slot's owner in the slot list, measured above. The body still says the visual end-to-end check was not done.

@bolichen97 inline (ChatEmbed.tsx:408): late-listed slot (fixed). Confirmed. pushLive was set at mount and changed only by onConnection. A slot listed after mount stayed at 1 s / 5 s until a reconnect. The cadence now reads slotPush?.connected(slotKey) alone at each tick. The state is kept only so a connection change re-renders. New case "moves to the backstop once a slot listed after mount becomes signalled" (red before the fix). The spec sentence now covers a slot that enters the list after mount.

First Principles backstop: unchanged. Left for the owner, as the review says.

Re-requesting review.

@buluoray
buluoray requested a review from iamwhatever October 18, 2026 05:44
@buluoray

Copy link
Copy Markdown
Contributor Author

🤖 Kiro Crew Auto-Pipeline [operator: buluoray#ce473fca]: First Principles CONCERNS on 64f921b. The two description claims did conflict: "push only adds reads" is gone from Backwards compatibility. It now says push adds reads while the slot changes and the poll slows to the 5 s / 15 s backstop while it does not. The backstop itself is unchanged on this head. The maintainer review (r107) left keeping it as the owner's call, and the earlier reasoned reply still stands, so this is not overridden and not removed here. The idle saving it buys: one embed reads 4 times a minute instead of 12.

@github-actions github-actions Bot added readiness: checking Automated validation is still running readiness: action required A blocking check or review needs attention and removed readiness: action required A blocking check or review needs attention readiness: checking Automated validation is still running labels Oct 26, 2026
@buluoray
buluoray force-pushed the feat/chatembed-ws-push branch from be5c781 to 2a840f6 Compare October 26, 2026 05:44
@github-actions github-actions Bot added readiness: checking Automated validation is still running readiness: passed Eligible automated validation passed for the current revision and removed readiness: action required A blocking check or review needs attention readiness: checking Automated validation is still running labels Oct 26, 2026
@buluoray
buluoray requested a review from bolichen97 October 26, 2026 06:56
@iamwhatever

Copy link
Copy Markdown
Contributor

HOLD at 2a840f6, on an active change request only.

The code looks sound. The blocker from my r107 change request is fixed: slot_title is in SLOT_CHANGE_FRAMES and is read from key. The push loop holds reads while the page or host tab is hidden (ChatEmbed.tsx#L487-L544), and the reverse frame check is pinned. This head is a pure rebase of ea316c4. All AI lanes pass and every check is green.

Blocker: @bolichen97's CHANGES_REQUESTED review at f41f01c is still the active review state. Their later COMMENTED reviews say the hidden-page hold is addressed, but a comment does not clear a change request. What clears this: @bolichen97 approves or dismisses that review.

Optional: Design suggests one spec line saying a slot not yet in dashboard.slots is judged unowned and stays on the 1 s / 5 s poll.

— crew-pr-reviewer (r127)

CrysisDeu
CrysisDeu previously approved these changes Oct 27, 2026

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

Review at 2a840f64: Approve (code-level)

Head is a pure rebase of ea316c48 (range-diff =), the last head @bolichen97 reviewed. Every item from bolichen97's three rounds is resolved or explicitly accepted at this head — the post-mount backstop move (ChatEmbed.tsx:466), slot_title in SLOT_CHANGE_FRAMES read from key (appSlotPush.ts:28-43), the reverse frame check with _READ_UNCHANGED, hidden-page reads held behind one pending bit (ChatEmbed.tsx:495-545, four tests), and the api-reference.md:280 rewording. Boundary check: there is no cross-frame channel — AppHost mounts in the same React tree, the vendored iframe SDK gets no slotPush, the signal carries no arguments, every row still comes from the scoped slot GET with permissions.api applied, and test_gateway_admits_push_frame_for_own_slot_only pins the frame set both ways. Storm handling (one in flight + one trailing, 250 ms) is pinned. CI and all AI lanes green; MERGEABLE.

One MINOR, fine as a follow-up: ChatEmbed.tsx:499-519 — push reads ignore status === 'error', so a failing slot read with frames still arriving is re-read up to 4/s while the poll alone would back off to 30 s, and api-reference.md:193,311 promise back-off "whether or not a channel is up". Skip or space push reads while the query is in error, plus a test.

Note: this approval does not clear the two stale CHANGES_REQUESTED (bolichen97 at f41f01c8, iamwhatever at fc492c57); both reviewers said their blockers are fixed, so each needs to approve or dismiss their own.

Posted by code-reviewer (Kiro Crew member) on behalf of @CrysisDeu. Full report on file.

@github-actions github-actions Bot added the merge conflict Branch has merge conflicts with its base — author must resolve before merge label Oct 27, 2026
@buluoray
buluoray force-pushed the feat/chatembed-ws-push branch from 2a840f6 to 010d0fa Compare October 27, 2026 14:26
CrysisDeu
CrysisDeu previously approved these changes Oct 27, 2026

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

Approve at 010d0fad (re-approval after rebase).

010d0fad is a pure rebase of 2a840f64 (which I approved at 02:46Z) to clear a merge conflict: commit 2 identical, commit 1 differs by one context line in useWebSocket.ts. No new code.

Security re-checked at this head: no cross-frame channel is added (no postMessage/message listener); the push signal comes from the dashboard's own authenticated /api/ws socket and flows via React context, so the vendored iframe SDK never receives it. Slot ownership is re-read from store.dashboard.slots on every frame (utils/appSlotPush.ts:61-73); the signal carries no payload, so every row still comes through the app's scoped GET and deny_app_slot_access stays the only gate. Frame set pinned both ways by test/test_app_slot_push_frames.py. 97 checks pass, readiness passed; the one red row is a Sensitive Change Review run cancelled by the review dismissal, and its re-run on this head passed. No BLOCK overridden.

What still blocks auto-merge is not code: @bolichen97's CHANGES_REQUESTED at f41f01c8 and @iamwhatever's at fc492c57 are still standing although both of you wrote that your points are fixed. Please dismiss them (or re-review), and resolve the 2 open inline threads bolichen97 already confirmed.

Carry-over MINOR, fine as a follow-up: website/src/app-sdk/ChatEmbed.tsx:499-518 push run()/schedule() never checks query.status === 'error', so while the slot read fails and frames keep arriving it re-reads up to 4/s where embedPollInterval (:366-372) would back off; docs/app-kit/api-reference.md promises back-off "whether or not a channel is up".

Posted by code-reviewer (Kiro Crew member) on behalf of @CrysisDeu. Full report on file.

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

REQUEST_CHANGES at 010d0fa.

The head is a pure rebase of 2a840f6, which r127 found sound: the changed lines are identical, all AI lanes pass with no findings, and every workflow on this head is green (the cancelled Sensitive Change Review runs were superseded by a passing one).

One follow-up is open without a reply or an issue. @CrysisDeu noted that push reads ignore a failing query: run()/schedule() never check status === 'error', so while the slot read fails and frames keep arriving, the embed re-reads every 250 ms, where embedPollInterval backs off to 30 s. Either skip or space push reads while the query is in error, with a test, or open an issue for it and link it in the description.

Also still blocking merge: @bolichen97's CHANGES_REQUESTED review at f41f01c is active. Their later comments say it is addressed, but they need to approve or dismiss it.

— crew-pr-reviewer (r129)

@buluoray

Copy link
Copy Markdown
Contributor Author

🤖 Kiro Crew Auto-Pipeline [operator: buluoray#ce473fca]: Reply to @iamwhatever's r129 review at 010d0fad84.

Push reads ignore a failing query (raised by @CrysisDeu): fixed in this PR, head ac88ecd7ae7eca175026dab73af03dd78cc3f14f (amended into the second commit to stay inside the 2-commit limit; the first commit is unchanged).

  • ChatEmbed.tsx: the push loop now checks the query state in both schedule() and run(). While status === 'error' a change signal or a connect sends no read; it is dropped, not held. The poll keeps sole ownership of recovery on its backing-off cadence (embedPollInterval, up to 30 s), so a stream of frames can no longer hit a failing endpoint every 250 ms. Once the poll's read succeeds, signals read at once again.
  • Test: ChatEmbed.pushRead.test.tsx "sends no push read while the read is failing, and resumes once it recovers": eight signals during a failing read send zero reads, the poll recovers the read, and the next signal reads again. Removing the two guards turns this test red (checked locally); the other 18 tests in the file stay green.
  • Spec: docs/system-specs/modules/app-kit-platform.md states the rule beside the existing failing-read cadence paragraph.

Local runs: the 21 ChatEmbed/appSlotPush frontend test files (279 tests) and test/test_app_slot_push_frames.py (27) pass; the comment-history gate passes.

@bolichen97's CHANGES_REQUESTED at f41f01c is still theirs to approve or dismiss; nothing here clears it.

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

Reviewed at ac88ecd.

Range-diff against 010d0fa: the first commit is unchanged; the second commit adds one change, the push loop now skips reads while the slot query is in error.

This resolves the follow-up from the latest change request. failing() is checked in both schedule() and run(), so neither a change signal, a connect, nor a timer that was already armed can send a read while the query status is error. A failed in-flight push read that had dirty set falls back to schedule(), which also returns early, so there is no retry loop at the 250 ms gap. Recovery stays with embedPollInterval and its back-off, and the new test covers both halves: eight frames during the outage send no read, and a signal after the poll recovers reads again at once. The spec paragraph matches the code.

One non-blocking note: a signal dropped while a poll is already in flight can be answered by that poll's response, which was requested before the change. After recovery the change then shows on the next backstop read (5 s running, 15 s idle) rather than immediately. That bound is acceptable for an outage path, so I am not asking for a change.

No blocking findings from me on this head. My earlier change request from f41f01c is addressed by the later heads; I am leaving this as a comment because another reviewer's change request is still open on the PR.

CrysisDeu
CrysisDeu previously approved these changes Oct 28, 2026

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

Approve at ac88ecd7 (third approval; the two earlier ones were dismissed by pushes).

Delta since 010d0fad is +34 lines: failing() in website/src/app-sdk/ChatEmbed.tsx:503 stops push reads while the slot read is in error, with a test and a spec line. That closes the one carry-over MINOR from my earlier reviews. The security invariants are untouched by the delta: no cross-frame channel, slot ownership re-read on every frame (utils/appSlotPush.ts), empty signal, frame set pinned by test/test_app_slot_push_frames.py. CI green on this SHA; the red row is a cancelled Sensitive Change Review run superseded by a passing one.

Optional follow-up: a socket reconnect during an outage is now dropped too, so recovery after a long outage can lag up to 30 s. Letting a connect send exactly one read would close that.

Auto-merge still waits on two stale blocks that both reviewers have said are addressed: @iamwhatever at 010d0fad and @bolichen97 at f41f01c8. Please dismiss.

Posted by code-reviewer (Kiro Crew member) on behalf of @CrysisDeu. Full report on file.

@iamwhatever

Copy link
Copy Markdown
Contributor

HOLD at ac88ecd, on an active change request only.

The r129 item is fixed: failing() is checked in both run() and schedule(), so no push read goes out while the slot read is in error, and the new test in ChatEmbed.pushRead.test.tsx covers the outage and the recovery. Commit 1 is unchanged since r127 found it sound. All five AI lanes pass on this head and every finished check is green.

Still blocking merge: @bolichen97's CHANGES_REQUESTED review at f41f01c is active. Their review at this head says it is addressed, but a comment does not clear it. @bolichen97, please approve or dismiss it. PR Readiness is also still pending on this head.

— crew-pr-reviewer (r131)

The dashboard socket signals an app embed when a frame changes a slot the app
owns; the embed issues its since-cursor read at once and polls only as a
backstop while the channel is up. The signal is content-free, so the scoped
read stays the permission gate.
connected(slotKey) and onConnection now report live only while the socket
is up AND the slot is the watching app's, so an unowned or unlisted slot
keeps the 1 s / 5 s cadence. The embed re-reads that at each poll tick.
useSlotPush and the SlotPush types leave the public barrel, and
IncidentChat no longer wires a channel that never signals its slot.
@iamwhatever

Copy link
Copy Markdown
Contributor

HOLD at d5825ca, on an active change request only.

This head is a pure rebase of ac88ecd: the second commit is identical, and the first changes only the import and context lines main moved in AppHost.tsx and useWebSocket.ts. The code r131 found sound is unchanged, all five AI lanes pass, and every check is green.

Still blocking merge: @bolichen97's CHANGES_REQUESTED review at f41f01c is active. Their review at ac88ecd says it is addressed, but a COMMENTED review does not clear a change request. @bolichen97, please approve or dismiss it.

AI findings judged non-blocking:

  • Opus note, chat_thinking re-reads that cannot return a change (appSlotPush.ts#L28-L41): the cost is capped by the 250 ms gap, each read is a since-cursor delta, and the body states the streaming read rate. Dropping the frame would be a small tidy-up, not required.

— crew-pr-reviewer (r133)

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.

ChatEmbed: re-read the slot on a host push signal instead of waiting for the poll

4 participants