Skip to content

Add start/stop timer buttons to the Chronos report header - #86690

Merged
tgolen merged 16 commits into
mainfrom
tgolen-chronos-startstop
Apr 6, 2026
Merged

tgolen merged 16 commits into
mainfrom
tgolen-chronos-startstop

Conversation

@tgolen

@tgolen tgolen commented Mar 30, 2026 •

Copy link
Copy Markdown
Contributor

Explanation of Change

This PR adds some buttons to the header of the chat with chronos@expensify.com. There is a "Start Timer" and a "Stop Timer" button.

In order to easily determine which button to show, the code looks at the chat history and which commands have been previously sent.

Fixed Issues

$ #86742

Tests

  1. Open a chat with chronos@expensify.com
  2. Say "hi" and if you are prompted to setup time tracking goals, fill those out
  3. Verify there is a "Start Timer" button in the report header
  4. Click "Start Timer" and verify that the phrase "start" is sent in the Chronos chat and Chronos responds saying you started a timer
  5. Verify there is now a "Stop Timer" button in the report header
  6. Click "Stop Timer" and verify that the phrase "stop" is sent in the Chronos chat and Chronos responds saying you stopped a timer
  • Verify that no errors appear in the JS console

Offline tests

Doesn't really work offline, because it requires Chronos responses.

QA Steps

Same as tests

  • Verify that no errors appear in the JS console

PR Author Checklist

  • I linked the correct issue in the ### Fixed Issues section above
  • I wrote clear testing steps that cover the changes made in this PR
    • I added steps for local testing in the Tests section
    • I added steps for the expected offline behavior in the Offline steps section
    • I added steps for Staging and/or Production testing in the QA steps section
    • I added steps to cover failure scenarios (i.e. verify an input displays the correct error message if the entered data is not correct)
    • I turned off my network connection and tested it while offline to ensure it matches the expected behavior (i.e. verify the default avatar icon is displayed if app is offline)
    • I tested this PR with a High Traffic account against the staging or production API to ensure there are no regressions (e.g. long loading states that impact usability).
  • I included screenshots or videos for tests on all platforms
  • I ran the tests on all platforms & verified they passed on:
    • Android: Native
    • Android: mWeb Chrome
    • iOS: Native
    • iOS: mWeb Safari
    • MacOS: Chrome / Safari
  • I verified there are no console errors (if there's a console error not related to the PR, report it or open an issue for it to be fixed)
  • I followed proper code patterns (see Reviewing the code)
    • I verified that any callback methods that were added or modified are named for what the method does and never what callback they handle (i.e. toggleReport and not onIconClick)
    • I verified that comments were added to code that is not self explanatory
    • I verified that any new or modified comments were clear, correct English, and explained "why" the code was doing something instead of only explaining "what" the code was doing.
    • I verified any copy / text shown in the product is localized by adding it to src/languages/* files and using the translation method
      • If any non-english text was added/modified, I used JaimeGPT to get English > Spanish translation. I then posted it in #expensify-open-source and it was approved by an internal Expensify engineer. Link to Slack message:
    • I verified all numbers, amounts, dates and phone numbers shown in the product are using the localization methods
    • I verified any copy / text that was added to the app is grammatically correct in English. It adheres to proper capitalization guidelines (note: only the first word of header/labels should be capitalized), and is either coming verbatim from figma or has been approved by marketing (in order to get marketing approval, ask the Bug Zero team member to add the Waiting for copy label to the issue)
    • I verified proper file naming conventions were followed for any new files or renamed files. All non-platform specific files are named after what they export and are not named "index.js". All platform-specific files are named for the platform the code supports as outlined in the README.
    • I verified the JSDocs style guidelines (in STYLE.md) were followed
  • If a new code pattern is added I verified it was agreed to be used by multiple Expensify engineers
  • I followed the guidelines as stated in the Review Guidelines
  • I tested other components that can be impacted by my changes (i.e. if the PR modifies a shared library or component like Avatar, I verified the components using Avatar are working as expected)
  • I verified all code is DRY (the PR doesn't include any logic written more than once, with the exception of tests)
  • I verified any variables that can be defined as constants (ie. in CONST.ts or at the top of the file that uses the constant) are defined as such
  • I verified that if a function's arguments changed that all usages have also been updated correctly
  • If any new file was added I verified that:
    • The file has a description of what it does and/or why is needed at the top of the file if the code is not self explanatory
  • If a new CSS style is added I verified that:
    • A similar style doesn't already exist
    • The style can't be created with an existing StyleUtils function (i.e. StyleUtils.getBackgroundAndBorderStyle(theme.componentBG))
  • If new assets were added or existing ones were modified, I verified that:
    • The assets are optimized and compressed (for SVG files, run npm run compress-svg)
    • The assets load correctly across all supported platforms.
  • If the PR modifies code that runs when editing or sending messages, I tested and verified there is no unexpected behavior for all supported markdown - URLs, single line code, code blocks, quotes, headings, bold, strikethrough, and italic.
  • If the PR modifies a generic component, I tested and verified that those changes do not break usages of that component in the rest of the App (i.e. if a shared library or component like Avatar is modified, I verified that Avatar is working as expected in all cases)
  • If the PR modifies a component related to any of the existing Storybook stories, I tested and verified all stories for that component are still working as expected.
  • If the PR modifies a component or page that can be accessed by a direct deeplink, I verified that the code functions as expected when the deeplink is used - from a logged in and logged out account.
  • If the PR modifies the UI (e.g. new buttons, new UI components, changing the padding/spacing/sizing, moving components, etc) or modifies the form input styles:
    • I verified that all the inputs inside a form are aligned with each other.
    • I added Design label and/or tagged @Expensify/design so the design team can review the changes.
  • If a new page is added, I verified it's using the ScrollView component to make it scrollable when more elements are added to the page.
  • I added unit tests for any new feature or bug fix in this PR to help automatically prevent regressions in this user flow.
  • If the main branch was merged into this PR after a review, I tested again and verified the outcome was still expected according to the Test steps.
  • I verified that similar component doesn't exist in the codebase
  • I verified that all props are defined accurately and each prop has a /** comment above it */
  • I verified that each file is named correctly
  • I verified that each component has a clear name that is non-ambiguous and the purpose of the component can be inferred from the name alone
  • I verified that the only data being stored in component state is data necessary for rendering and nothing else
  • In component if we are not using the full Onyx data that we loaded, I've added the proper selector in order to ensure the component only re-renders when the data it is using changes
  • For Class Components, any internal methods passed to components event handlers are bound to this properly so there are no scoping issues (i.e. for onClick={this.submit} the method this.submit should be bound to this in the constructor)
  • I verified that component internal methods bound to this are necessary to be bound (i.e. avoid this.submit = this.submit.bind(this); if this.submit is never passed to a component event handler like onClick)
  • I verified that all JSX used for rendering exists in the render method
  • I verified that each component has the minimum amount of code necessary for its purpose, and it is broken down into smaller components in order to separate concerns and functions

Screenshots/Videos

Android: Native
Android: mWeb Chrome
iOS: Native
iOS: mWeb Safari
MacOS: Chrome / Safari image

@tgolen tgolen self-assigned this Mar 30, 2026
@OSBotify

Copy link
Copy Markdown
Contributor

🦜 Polyglot Parrot! 🦜

Squawk! Looks like you added some shiny new English strings. Allow me to parrot them back to you in other tongues:

View the translation diff
diff --git a/src/languages/ja.ts b/src/languages/ja.ts
index b2986305..bcf2fe74 100644
--- a/src/languages/ja.ts
+++ b/src/languages/ja.ts
@@ -7522,7 +7522,7 @@ ${reportName}
         oooEventSummaryFullDay: (summary: string, dayCount: number, date: string) => `${summary}(${date} までの ${dayCount} ${dayCount === 1 ? '日' : '日数'} 分)`,
         oooEventSummaryPartialDay: (summary: string, timePeriod: string, date: string) => `${date}の${timePeriod}の${summary}`,
         startTimer: 'タイマー開始',
-        stopTimer: 'タイマー停止',
+        stopTimer: 'タイマーを停止',
     },
     footer: {
         features: '機能',
diff --git a/src/languages/pl.ts b/src/languages/pl.ts
index b194c494..6557c590 100644
--- a/src/languages/pl.ts
+++ b/src/languages/pl.ts
@@ -7580,8 +7580,8 @@ Wymagaj szczegółów wydatków, takich jak paragony i opisy, ustawiaj limity i
     chronos: {
         oooEventSummaryFullDay: (summary: string, dayCount: number, date: string) => `${summary} za ${dayCount} ${dayCount === 1 ? 'dzień' : 'dni'} do ${date}`,
         oooEventSummaryPartialDay: (summary: string, timePeriod: string, date: string) => `${summary} z ${timePeriod} z dnia ${date}`,
-        startTimer: 'Uruchom timer',
-        stopTimer: 'Zatrzymaj timer',
+        startTimer: 'Startuj licznik',
+        stopTimer: 'Zatrzymaj licznik czasu',
     },
     footer: {
         features: 'Funkcje',
diff --git a/src/languages/zh-hans.ts b/src/languages/zh-hans.ts
index 30672141..d6528f75 100644
--- a/src/languages/zh-hans.ts
+++ b/src/languages/zh-hans.ts
@@ -7393,7 +7393,7 @@ ${reportName}
         oooEventSummaryFullDay: (summary: string, dayCount: number, date: string) => `${summary},共计 ${dayCount} ${dayCount === 1 ? '天' : '天'},截至 ${date}`,
         oooEventSummaryPartialDay: (summary: string, timePeriod: string, date: string) => `${summary},时间范围:${timePeriod},日期:${date}`,
         startTimer: '开始计时',
-        stopTimer: '停止计时',
+        stopTimer: '停止计时器',
     },
     footer: {
         features: '功能',

Note

You can apply these changes to your branch by copying the patch to your clipboard, then running pbpaste | git apply 😉

View workflow run

@codecov

codecov Bot commented Mar 30, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Looks like you've decreased code coverage for some files. Please write tests to increase, or at least maintain, the existing level of code coverage. See our documentation here for how to interpret this table.

Files with missing lines Coverage Δ
src/CONST/index.ts 93.65% <ø> (-1.52%) ⬇️
...equestReportView/MoneyRequestReportActionsList.tsx 56.01% <ø> (-1.72%) ⬇️
src/libs/ReportActionsUtils.ts 55.77% <ø> (-0.22%) ⬇️
src/pages/inbox/HeaderView.tsx 97.84% <100.00%> (+0.04%) ⬆️
src/pages/inbox/report/PureReportActionItem.tsx 57.63% <ø> (+0.19%) ⬆️
src/pages/inbox/report/ReportActionsList.tsx 77.25% <ø> (-1.96%) ⬇️
src/libs/ChronosUtils.ts 97.43% <97.43%> (ø)
src/components/ChronosTimerHeaderButton.tsx 0.00% <0.00%> (ø)
... and 368 files with indirect coverage changes

@tgolen

tgolen commented Mar 30, 2026

Copy link
Copy Markdown
Contributor Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: bb45a41161

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread src/libs/ReportActionsUtils.ts Outdated
Comment on lines +989 to +990
const CHRONOS_TIMER_COMMAND_STOP_REGEX = /stop(?:ped|ping)?(?:\snow)?/i;
const CHRONOS_TIMER_COMMAND_START_REGEX = /start(?:ed|ing)?(?:\snow)?/i;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Restrict Chronos command matching to standalone commands

isChronosStartOrStopMessage() uses unanchored regexes, so any comment containing substrings like "starting", "nonstop", or "kickstart" is treated as a timer command. getLatestUserChronosTimerCommand() then uses that match to infer timer state, which can flip the header button to the wrong action and send the opposite command on click in normal conversations with Chronos. Match against whole-command text (or at least word-bounded tokens) to avoid false positives.

Useful? React with 👍 / 👎.

@tgolen tgolen changed the title WIP adding start/stop buttons Add start/stop timer buttons to the Chronos report header Mar 31, 2026
@tgolen
tgolen marked this pull request as ready for review March 31, 2026 16:35
@tgolen
tgolen requested review from a team as code owners March 31, 2026 16:35
@melvin-bot
melvin-bot Bot requested review from ahmedGaber93 and joekaufmanexpensify and removed request for a team March 31, 2026 16:35
@melvin-bot

melvin-bot Bot commented Mar 31, 2026

Copy link
Copy Markdown

@ahmedGaber93 Please copy/paste the Reviewer Checklist from here into a new comment on this PR and complete it. If you have the K2 extension, you can simply click: [this button]

@melvin-bot
melvin-bot Bot removed the request for review from a team March 31, 2026 16:35

const reportActionsOnyxKey = `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${report.reportID}` as OnyxKey;
const [sortedVisibleReportActions = getEmptyArray<OnyxTypes.ReportAction>()] = useOnyx<OnyxKey, OnyxTypes.ReportAction[]>(
reportActionsOnyxKey,

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.

❌ PERF-11 (docs)

The useOnyx selector on REPORT_ACTIONS returns a full ReportAction[] array via getSortedReportActionsForDisplay. Onyx runs deepEqual on the selector output to decide whether to re-render, and comparing an entire array of report actions is expensive. Additionally, the selector closes over visibleReportActionsData (the entire VISIBLE_REPORT_ACTIONS for ALL reports), meaning any change to visible actions in ANY report triggers re-execution of this expensive selector.

The component only needs to know whether the timer is running (a boolean). Compute the final boolean directly in the selector instead of returning the full array:

const [isTimerRunning] = useOnyx<OnyxKey, boolean>(
    reportActionsOnyxKey,
    {
        selector: (reportActions: unknown): boolean => {
            const sorted = getSortedReportActionsForDisplay(
                reportActions as OnyxEntry<ReportActions>,
                canPerformWriteAction,
                false,
                visibleReportActionsData,
                report.reportID,
            );
            return isChronosTimerRunningFromVisibleActions(sorted, currentUserAccountID);
        },
    },
    [canPerformWriteAction, visibleReportActionsData, report.reportID, currentUserAccountID],
);

This reduces deepEqual to a trivial boolean comparison and eliminates the intermediate array allocation.


Please rate this suggestion with 👍 or 👎 to help us improve! Reactions are used to monitor reviewer efficiency.

notifyReportID: report.reportID,
ancestors,
text: isTimerRunning ? 'stop' : 'start',
timezoneParam: timezoneParam ?? CONST.DEFAULT_TIME_ZONE,

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.

❌ CONSISTENCY-2 (docs)

The literal strings 'stop' and 'start' are timer command strings sent as chat messages and also matched by the regexes in ReportActionsUtils.ts. These are domain-specific command values that should be defined as named constants to avoid typos and maintain a single source of truth.

Define constants in CONST, for example:

// In CONST
CHRONOS: {
    TIMER_COMMAND: {
        START: 'start',
        STOP: 'stop',
    },
},

Then use them in the component:

text: isTimerRunning ? CONST.CHRONOS.TIMER_COMMAND.STOP : CONST.CHRONOS.TIMER_COMMAND.START,

And in ReportActionsUtils.ts for comparing return values:

return getLatestUserChronosTimerCommand(...) === CONST.CHRONOS.TIMER_COMMAND.START;

Please rate this suggestion with 👍 or 👎 to help us improve! Reactions are used to monitor reviewer efficiency.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 1ee5f2337b

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread src/libs/ReportActionsUtils.ts Outdated
Comment on lines +990 to +991
const CHRONOS_TIMER_COMMAND_STOP_REGEX = /\bstop(?:ped|ping)?(?:\s+now)?\b/i;
const CHRONOS_TIMER_COMMAND_START_REGEX = /\bstart(?:ed|ing)?(?:\s+now)?\b/i;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Anchor Chronos timer command matching to whole message

The new command patterns still match any message that contains start/stop as a standalone word, so normal conversation like “I will start later” is interpreted as a timer command and flips the header button state incorrectly. That can make the next tap send the opposite action from what the user expects. Fresh evidence: the new unit test intentionally treats "stop then start" as a valid command, which confirms matching is not restricted to command-only input.

Useful? React with 👍 / 👎.

@tgolen

tgolen commented Apr 2, 2026

Copy link
Copy Markdown
Contributor Author

Thanks @ahmedGaber93, that's a good idea! I've added support for those now.

@ahmedGaber93

Copy link
Copy Markdown
Contributor

@tgolen I recently noticed from Chronos replay that any sentence containing start or stop is treated as a command.

Screenshot 2026-04-02 at 5 19 22 PM

So all these sentences trigger start/stop tracking:

start - start now - started now - started at - have started - I have started
please start - let's start

Some typos also works: stoped - stopped
question also work: should we start now?

Should we handle those here?

@ahmedGaber93

Copy link
Copy Markdown
Contributor

I also found that on a new account (first time chat with chronos), commands don’t work until the user answers questions like “How many hours per week?”. So sending start doesn’t trigger tracking. Should we update the button text accordingly?

20260402180137315.mp4

@tgolen

tgolen commented Apr 2, 2026

Copy link
Copy Markdown
Contributor Author

Thanks @ahmedGaber93 I think both of those things are fine to leave as-is for now. This is just a simple feature built for internal use mostly, so I don't think those will really become a factor.

@melvin-bot
melvin-bot Bot requested a review from roryabraham April 2, 2026 22:11
@melvin-bot

melvin-bot Bot commented Apr 2, 2026

Copy link
Copy Markdown

@roryabraham Please copy/paste the Reviewer Checklist from here into a new comment on this PR and complete it. If you have the K2 extension, you can simply click: [this button]

@ahmedGaber93

Copy link
Copy Markdown
Contributor

@tgolen All yours!

roryabraham
roryabraham previously approved these changes Apr 3, 2026

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

No blockers. Not sure the adding button will cause people to use manual time tracking if they aren't already, but I suppose it doesn't hurt.

Comment thread src/libs/ReportActionsUtils.ts Resolved
@tgolen
tgolen merged commit 20aa657 into main Apr 6, 2026
37 of 38 checks passed
@tgolen
tgolen deleted the tgolen-chronos-startstop branch April 6, 2026 14:29
@melvin-bot melvin-bot Bot added the Emergency label Apr 6, 2026
@melvin-bot

melvin-bot Bot commented Apr 6, 2026

Copy link
Copy Markdown

@tgolen looks like this was merged without a test passing. Please add a note explaining why this was done and remove the Emergency label if this is not an emergency.

@github-actions

github-actions Bot commented Apr 6, 2026

Copy link
Copy Markdown
Contributor

🚧 @tgolen has triggered a test Expensify/App build. You can view the workflow run here.

@tgolen

tgolen commented Apr 6, 2026

Copy link
Copy Markdown
Contributor Author

Oops, I did not see that. There was a TypeScript error. I will put up a PR to fix that.

@OSBotify

OSBotify commented Apr 7, 2026

Copy link
Copy Markdown
Contributor

🚀 Deployed to staging by https://github.com/tgolen in version: 9.3.53-0 🚀

platform result
🕸 web 🕸 success ✅
🤖 android 🤖 failure ❌
🍎 iOS 🍎 failure ❌

Bundle Size Analysis (Sentry):

@MelvinBot

Copy link
Copy Markdown
Contributor

After reviewing the PR changes and the existing help site articles under App/docs/articles, no changes are required to the help site.

Here's my reasoning:

  • No existing Chronos article exists — There is no help site article covering the Chronos chat or timer commands (chronos@expensify.com). Since the underlying Chronos timer feature (typing "start"/"stop" in the chat) already existed before this PR and was never documented, this PR simply adds convenience buttons for an undocumented feature.
  • The existing time tracking article (new-expensify/workspaces/Enable-Time-Tracking-and-Set-a-Default-Hourly-Rate.md) covers workspace-level Time Tracking settings (enabling the feature, setting hourly rates). The Chronos timer is a separate concept — it's a 1:1 chat with chronos@expensify.com for personal time tracking, not the workspace Time Tracking feature.
  • The change is self-explanatory in the UI — The buttons are labeled "Start Timer" and "Stop Timer" and appear directly in the Chronos chat header. No documentation is needed for users to understand them.

If you'd like a new help site article created specifically for the Chronos timer feature (covering both the chat commands and these new buttons), let me know and I can draft one.

@OSBotify

OSBotify commented Apr 7, 2026

Copy link
Copy Markdown
Contributor

🚀 Deployed to staging by https://github.com/tgolen in version: 9.3.53-0 🚀

platform result
🕸 web 🕸 success ✅
🤖 android 🤖 failure ❌
🍎 iOS 🍎 failure ❌

Bundle Size Analysis (Sentry):

@OSBotify

OSBotify commented Apr 7, 2026

Copy link
Copy Markdown
Contributor

🚀 Deployed to production by https://github.com/roryabraham in version: 9.3.53-7 🚀

platform result
🕸 web 🕸 success ✅
🤖 android 🤖 success ✅
🍎 iOS 🍎 success ✅

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.

7 participants