Skip to content

fix(tickets): the drawer reads a file's link again when a read brought none CU-86agmkyyu - #3350

Merged
oleksandr-blip merged 6 commits into
mainfrom
fix/help-center-upload-links
Dec 4, 2026
Merged

oleksandr-blip merged 6 commits into
mainfrom
fix/help-center-upload-links

Conversation

@oleksandr-blip

@oleksandr-blip oleksandr-blip commented Dec 4, 2026 •

Copy link
Copy Markdown
Contributor

The library side of the Help Center upload fix in flamingo-stack/multi-platform-hub#2088, under Attachment Support (Images + Any File Type). With #2088 the hub keeps a ticket's HubSpot files as references and signs them on each read of the timeline, within a 2 s budget, keeping no link it failed to sign. In the live check of #2088, the drawer's first read, about 20 s after the ticket was created, brought the file without a link: a chip with no thumbnail and no Download button. Nothing read the timeline again while the drawer stayed open, so the chip stayed that way until the card was reopened, the tab was shown again or the ticket stream reconnected.

The drawer reads again while a file has no link

  • useTicketEngagements: a read that brings a file without a link is followed by up to three more, 2, 4 and 8 seconds apart. A read in which every file has its link stops them. The hook schedules them itself, from the query cache on each result of the query: refetchInterval's reads carry nothing that sets them apart from the others, and the retry cap below needs that.
  • The count lives on the query, not the component: a WeakMap keyed by the TanStack Query, counted from its dataUpdateCount + errorUpdateCount. So drawers open on the ticket together share it, a drawer reopened while a read is on its way keeps it, and a read that a newer one replaced (a stream invalidation cancels the read in flight) does not move it. The query has gcTime: 0, so a drawer opened after the last one closed starts over.
  • Failed reads count toward the three, so a run of errors stops as well. A re-read carries a fetch meta that the hook's retry checks: it is not retried, so a run sends at most three requests. Every read that sends its own request (the first load, a ticket-stream invalidation, a focus, mount or reconnect refetch, a read after a run) keeps the host's retry, read from queryClient.defaultQueryOptions({ queryKey }): global and per-key defaults, query-core's three in the browser when nothing is set (the hub sets three).
  • A re-read due while the tab is hidden, the device is offline or another read is on its way is not sent; the next result (the focus or reconnect refetch, the read in flight) schedules the one after it.
  • A file starts the three over when it comes without a link for the first time (e.g. a new reply whose file the hub could not sign yet), and when it loses its link again on a read after a run is over (a stream event, the tab shown again). Never during a run, so a file that keeps losing and getting its link cannot extend one.
  • A file that keeps coming without a link does not start them over: it costs three extra reads each time the drawer opens.
  • Files are told apart by their id, as the hub signs them (once per id per read).
  • The rules are a pure nextRelink(budget, unlinked, results) in relink-budget.ts, beside the hook; scheduleRelink keeps only the WeakMap keyed by the query, the timer and its guard.

Not in this PR

  • Hub side: on a ticket whose HubSpot copy is stale, each read of the timeline starts its own background refresh (only the cold start is coalesced). So each re-read can start one more, queued behind HubSpot's 8 requests a second.

Checks

  • New use-ticket-engagements.test.tsx, 32 tests on a default QueryClient:
    • the delays and their boundaries, the stop after three, one unlinked file among several messages and within one message;
    • the same file losing its link again, a new file after the three ran out, a file losing its link again after and during a run beside one that never gets it;
    • a replaced read, a drawer reopened while a read was on its way, a drawer opened after the last one closed, two drawers open together and one of them closing, a closed drawer, other queries' results, a client with its own queryKeyHashFn;
    • one request per failed re-read; the first load retried as the client's default, retry: 1, a retry function, retry: false and per-key defaults say;
    • a stream read during a run retried, also past a re-read's due time, after a failed re-read and when it replaces a re-read on its way; no re-read while the tab is hidden or the device is offline, and the focus or reconnect read after it retried; a read after a run retried.
  • New relink-budget.test.ts, 9 table tests on nextRelink that render nothing: the 2/4/8 s waits and the stop, the budget dropped once every file is linked, a new file during and after a run, a relapse during a run (its last read included) and after it, the wait picked from the result count, the same result twice (two drawers), the given budget left unchanged.
  • Of the hook tests, 22 fail on main; the 10 that pass assert that nothing reads again or that a read keeps the client's retry. 6 fail on ef3e1ba, the head before the re-reads got their own timer.
  • 36 hand mutants over the hook and relink-budget.ts (no mutation tool in this package): 33 killed. The 3 survivors are equivalent: one stops marking unlinked files a second time, which the loop before it already marks; one drops the idle check, and query-core then joins the read in flight without a request of its own; one schedules on every update of the query, and an update without a result comes during a read whose result schedules again.
  • npm run type-check, npm run lint:types, the fast ESLint pass and Prettier, on the changed files: clean. vitest src/components/tickets: 4 files, 54 tests pass.
  • Live check on the hub preview of Use nickname in log event instead of hostname #2088, on this PR's 8fc1a9b build (before the retry cap): with the first read's links nulled in the page, the re-read 2.6 s later brought them, the thumbnail and Download button appeared, and no further read followed. Not run again since.

Change-Set: fix-help-center-upload-links

Change set flamingo-stack/openframe-oss-lib#3350: these pull requests are one change, reviewed together.

  • flamingo-stack/openframe-oss-lib#3350 (this pull request): fix(tickets): the drawer reads a file's link again when a read brought none CU-86agmkyyu · landed
  • …and 1 pull request not visible

Linked work

  • …and 1 linked item not shown here

Linked by the Depends-On / Change-Set lines in these descriptions; this block is maintained by the hub.

…t none CU-86agmkyyu

The hub signs a ticket's HubSpot files on each read of the timeline, under a
2 s budget, and keeps no link it failed to sign. A read that misses the budget
returns the file without a link, and the drawer then draws a chip it can
neither show nor download. Nothing read the timeline again while the drawer
stayed open, so the chip kept no link until the card was reopened, the tab
was shown again or the ticket stream reconnected.

A read that brings a file without a link is now followed by up to three more,
2, 4 and 8 seconds apart. The count lives on the query, so every drawer on the
ticket shares it and a read that a newer one replaced does not move it.
Failed reads count toward the three. A file not seen before without a link
starts the three over; one that keeps coming without a link does not.
@oleksandr-blip oleksandr-blip added the build Run the PR builds and publish snapshots (Java, npm preview); stays on until removed label Dec 4, 2026
@flamingo

flamingo Bot commented Dec 4, 2026 •

Copy link
Copy Markdown
Contributor

🦩 flamingo Code Review

✅ Tests and checks passed on this commit (8 lanes).

2 findings: 🔴 0 action required · 🟠 0 recommended · 🔵 2 informational

Advisory: findings do not block the merge.

Rules cited: LOGIC-001 · 1 defect outside any rule

Files Lines Languages Tests Checks 🔴 Action required 🟠 Recommended 🔵 Informational
2 +665 / -2 TypeScript (1 npm lane) ✅ 30 / 30 green ✅ 7 / 7 passed 0 0 2

🔵 Informational (2)

# Where Finding Flagged by
1 use-ticket-engagements.ts:64 Re-link scheduling state machine lives inside the hook's file with module-level mutable state instead of a plain module (Minor) LOGIC-001
2 use-ticket-engagements.ts:56 No test pins two drawers open on one ticket at once Tests and mutation

✅ What this change does well

  • The new use-ticket-engagements.test.tsx exercises the relink budget precisely, exact delay boundaries (1_999/1 ms), exhaustion after three re-reads, and interaction with stream invalidation, without rendering UI.
  • scheduleRelink guards the re-read on query.isActive(), idle fetch status, focus and online state in use-ticket-engagements.ts, so hidden or offline tabs do not generate background HubSpot reads.
  • The relink re-read is tagged with RELINK_META and excluded from retries, bounding a run to three extra requests.
  • use-ticket-engagements.ts marks only the re-reads with a fetch meta that its retry checks, so every request the host sends itself keeps the host's retry policy, resolved through defaultQueryOptions with per-key defaults.
  • use-ticket-engagements.test.tsx runs on a default QueryClient with fake timers and pins the delays at their boundaries, failed and replaced reads, the hidden tab, offline and a custom queryKeyHashFn; 20 of its 30 tests fail on main.

Inline comments: 2 new

2 possible problems checked and ruled out
  • openframe-frontend-core/src/components/tickets/hooks/use-ticket-engagements.ts:180 Pending relink timer is never cancelled when the last drawer unmounts: use-ticket-engagements.ts:180-192 returns only the cache unsubscribe; the setTimeout at line 85 is cleared only by the next scheduleRelink call, so a pending relink timer (up to 8s) survives unmount keeping the query object alive. The inner guard (query.isActive(), line 87) prevents the actual fetch, so impact is a short-lived leak / test cross-talk, real but small.
  • openframe-frontend-core/src/components/tickets/hooks/use-ticket-engagements.ts:98 hostRetries re-implements react-query's retry-policy resolution instead of letting the client decide: hostRetries deliberately resolves the host client's own retry option and only suppresses retries for relink reads; SSOT-001's 'shared helper re-implemented' names hub/design-system exports, not reading a third-party library's option. On its own merits this is a design preference, not a defect (use-ticket-engagements.ts:98-104 behaves correctly).

🧪 Tests and mutation

Tests per lane

Language Project Command Status Counts Time
TypeScript (npm) openframe-frontend-core npx vitest related --run src/components/tickets/hooks/__tests__/use-ticket-engagements.test.tsx src/components/tickets/hooks/use-ticket-engagements.ts ✅ passed 30 run, 0 failures 7.9 s

Checks

Check Kind Language Project Status Time
lint lint TypeScript (npm) openframe-frontend-core ✅ passed 2.2 s
lint:config-smoke lint TypeScript (npm) openframe-frontend-core ✅ passed 0.7 s
lint:cycles lint TypeScript (npm) openframe-frontend-core ✅ passed 752.6 s
lint:types lint TypeScript (npm) openframe-frontend-core ✅ passed (4 findings on lines this change did not touch) 48 s
type-check typecheck TypeScript (npm) openframe-frontend-core ✅ passed 2.1 s
format format TypeScript (npm) openframe-frontend-core ✅ passed 10.4 s
OpenGrep security TypeScript (OpenGrep) . ✅ passed 12.2 s

Docker is installed but not running (start Docker Desktop or colima start): the test services were not started and a test that starts containers fails for the environment, not the code.

The vitest lane ran the 30 tests of use-ticket-engagements.test.tsx: all pass.

Lint:types held 4 errors, all in openframe-message-attachments.test.tsx, which this change does not touch.

No Stryker in openframe-frontend-core, so mutation is a gap; the PR reports 30 hand mutants, 27 killed, the 3 survivors equivalent.

1 gap (not tested here):

  • TypeScript (npm) openframe-frontend-core: no mutation testing (no Stryker configured: mutation coverage is a gap to report)
🤖 Prompt for AI agents: fix every finding
Address these code-review findings on pull request #3350 of flamingo-stack/openframe-oss-lib, most important first.
For each one, make the minimal change that resolves it and do not refactor unrelated code.
If you can show a finding is wrong, skip it and say why.

1. [Informational] openframe-frontend-core/src/components/tickets/hooks/use-ticket-engagements.ts:64 Re-link scheduling state machine lives inside the hook's file with module-level mutable state instead of a plain module
   LOGIC-001 requires logic beyond a few lines (here: a budget/backoff state machine over per-file link state, a result counter, a run-restart rule and a timer) to live in a plain TypeScript module next to the hook, as pure functions or a reducer, each testable without rendering. The change instead adds `scheduleRelink` plus a module-level mutable `relinkBudgets` WeakMap directly in `use-ticket-engagements.ts` (lines 32-96), with the transition logic (`runOver`, `startsOver`, `budget.since`, `budget.files`) mutating that map in place and firing a `setTimeout` in the same function. As a result the only way the new tests can exercise any of these transitions is `renderHook` (see the added `__tests__/use-ticket-engagements.test.tsx`, which drives 500+ lines of timer/react-query choreography to assert a backoff table).
2. [Informational] openframe-frontend-core/src/components/tickets/hooks/use-ticket-engagements.ts:56 No test pins two drawers open on one ticket at once
   The JSDoc says drawers open on the ticket together share the count, and each hook instance subscribes to the query cache, so every result runs scheduleRelink once per open drawer. The suite renders one drawer at a time. A throwaway test with two drawers on one client gave one run (4 requests, none after) and kept the run going after one drawer closed, so the code holds today; nothing keeps it that way.

Next: commit a suggestion, or hand a comment's prompt to your coding agent. React 👍 on a finding that helped and 👎 on one that is wrong: the reviewer learns from both.

Review again. New commits are not reviewed until you ask:

  • Review the new commits: only what was pushed since this review
  • Review the whole diff again: everything, including what was already reviewed

Or comment @flamingo-review (new commits) or @flamingo-review full (everything). Add the flamingo-review-always label to review every push.

Updated 2026-12-04 17:03 UTC · reviewed from Oleksandr Koltunov's machine

@flamingo

flamingo Bot commented Dec 4, 2026 •

Copy link
Copy Markdown
Contributor

🦩 flamingo Code Review / security

✅ No findings on the current head.

Advisory: findings do not block the merge.

Files Lines 🔴 Action required 🟠 Recommended 🔵 Informational
2 +665 / -2 0 0 0
1 possible problem checked and ruled out
  • openframe-frontend-core/src/components/tickets/hooks/use-ticket-engagements.ts:71 Response-content-driven re-read loop: an unlinked attachment id the hub has not shown before restarts the 2/4/8 s re-read run indefinitely: The doc comment the diff itself adds (use-ticket-engagements.ts:58, "A file starts the count over when it first comes without a link") states that a newly-unlinked file id restarting the 2/4/8 s run is the intended contract, so lines 74-80 implement the documented design, not a bug; each re-read is further gated on query.isActive(), fetchStatus === 'idle', focus and online (lines 86-91), so it is…

Review again. New commits are not reviewed until you ask:

  • Security-check the new commits: only what was pushed since this security review
  • Security-check the whole diff again: everything, including what was already checked

Or comment @flamingo-review security (new commits) or @flamingo-review security full (everything). Add the flamingo-security-review-always label to security-review every push.

Updated 2026-12-04 17:08 UTC · reviewed from Oleksandr Koltunov's machine

… CU-86agmkyyu

The re-read budget remembered every file it had seen without a link for as
long as any file on the ticket stayed without one. So beside a file that
never gets a link, a file that got its link and lost it on a later read (a
stream event, a reopened tab) was read again no more.

A file now starts the re-reads over when it loses its link again after a run
is over. During a run it does not, so a file that keeps losing and getting
its link cannot extend one.

The tests call act() without awaiting a synchronous callback, which the
type-aware lint pass (lint:types) requires.

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

Two small follow-ups on the re-read logic.

…client's retries CU-86agmkyyu

A failed re-read was retried by the host's QueryClient (three times in the
browser by default) before it counted, so three re-reads could send twelve
requests. A read during a run is no longer retried; the first load and any
read after a run keep the client's own retry, its per-key defaults included.

The tests run on a default QueryClient now, and the contract moves into
one JSDoc on relinkInterval.
…agmkyyu

ef3e1ba turned the retries off for every read during a run, so a read the
re-reads did not send (a stream invalidation, a refetch on focus, mount or
reconnect) lost the client's retries too. refetchInterval's reads carry
nothing that sets them apart from the others.

The re-reads now run on a timer of their own, scheduled from the query
cache on each result, and carry a fetch meta that the retry option checks:
a re-read is not retried, and every read that sends its own request keeps
the client's retry. A re-read is not sent while the tab is hidden, the
device is offline or another read is on its way. The query hash comes from
the client, so a host's queryKeyHashFn is honoured.
…-86agmkyyu

The JSDoc says drawers open on the ticket together share the count, and
each drawer subscribes to the query cache, so every result schedules the
re-reads once per drawer. Two tests now pin it: two drawers send one run
of three re-reads, and closing one keeps the other's run going.
…ook CU-86agmkyyu

LOGIC-001: the budget's transition (a file new or relapsed after a run
starts the count over, the wait follows the result count) is now
nextRelink in relink-budget.ts, from the previous budget, the files
without a link and the result count to the next budget and wait. It
builds a new budget instead of editing the one it was given.
scheduleRelink keeps the WeakMap keyed by the query, the timer and its
guard.

relink-budget.test.ts covers the transition without rendering: the
delays, the drop once every file is linked, a restart during and after
a run and the run it starts, a relapse during the run and on its last
read, the same result passed twice, and the budget left as it was.
@oleksandr-blip
oleksandr-blip added this pull request to the merge queue Dec 4, 2026
Merged via the queue into main with commit 02e08e7 Dec 4, 2026
23 checks passed
@oleksandr-blip
oleksandr-blip deleted the fix/help-center-upload-links branch December 4, 2026 18:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

build Run the PR builds and publish snapshots (Java, npm preview); stays on until removed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants