Skip to content

fix(osm): keep OSM/OSL timeout alive across non-consuming events - #866

Open
yekingyan wants to merge 3 commits into
rmk-rs:mainfrom
yekingyan:fix/osm-osl-timeout-non-consuming
Open

fix(osm): keep OSM/OSL timeout alive across non-consuming events#866
yekingyan wants to merge 3 commits into
rmk-rs:mainfrom
yekingyan:fix/osm-osl-timeout-non-consuming

Conversation

@yekingyan

@yekingyan yekingyan commented May 29, 2026

Copy link
Copy Markdown
Contributor

Problem

The OSM/OSL release path waited with a single select(timeout, next_event).
The first event arriving during the timeout cancelled the wait permanently,
so the one-shot got stuck in Single and never auto-released. A typical
trigger is the release event of a layer key (a non-consuming event).

Additionally, when a consuming event was already sitting in unprocessed_events
(dequeued from the channel before entering the wait), the subscriber would
never deliver it again, causing the OSM to hang indefinitely (e.g. fast
Ctrl+Shift+P sequences).

Fix

Replace the single select with a deadline loop: non-consuming events are
pushed to the queue and we keep waiting for the remaining time, while a
consuming event breaks out (OSM: press in quick_release mode, release
otherwise; OSL: press).

Before entering the loop, check whether unprocessed_events already contains
a consuming event and skip the await entirely if so.

Test

Added test_osm_timeout_not_cancelled_by_non_consuming_event: an OSL press
interrupts the OSM timeout; after the timeout elapses the OSM must have
auto-released, so the later layer-1 key is sent without the modifier.
Red before the fix, green after.

@github-actions

github-actions Bot commented May 29, 2026

Copy link
Copy Markdown

Size Report

Example main PR Diff .text .data .bss
use_config/nrf52832_ble 394.8 KiB 395.1 KiB +0.06% ⬆️ +244 0 0
use_config/nrf52840_ble 443.3 KiB 443.5 KiB +0.05% ⬆️ +244 0 0
use_config/nrf52840_ble_split (central) 492.5 KiB 492.8 KiB +0.06% ⬆️ +312 0 0
use_config/nrf52840_ble_split (peripheral) 316.9 KiB 316.9 KiB +0.00% ⬆️ +4 0 0
use_config/pi_pico_w_ble 667.9 KiB 668.2 KiB +0.04% ⬆️ +284 0 0
use_config/rp2040 148.5 KiB 148.9 KiB +0.24% ⬆️ +372 0 0
use_config/rp2040_split (central) 162.1 KiB 162.4 KiB +0.20% ⬆️ +340 0 0
use_config/rp2040_split (peripheral) 27.8 KiB 27.8 KiB +0.00% 0 0 0
use_config/stm32f1 63.0 KiB 63.2 KiB +0.40% ⬆️ +264 0 0
use_config/stm32h7 100.0 KiB 100.3 KiB +0.26% ⬆️ +272 0 0
use_rust/nrf52832_ble 382.2 KiB 382.4 KiB +0.06% ⬆️ +256 0 0
use_rust/nrf52840_ble 438.6 KiB 438.8 KiB +0.04% ⬆️ +220 0 0
use_rust/nrf52840_ble_split (central) 501.8 KiB 502.1 KiB +0.05% ⬆️ +264 0 0
use_rust/nrf52840_ble_split (peripheral) 313.3 KiB 313.3 KiB +0.00% 0 0 0
use_rust/pi_pico_w_ble 668.2 KiB 668.5 KiB +0.04% ⬆️ +280 0 0
use_rust/rp2040 148.0 KiB 148.4 KiB +0.24% ⬆️ +376 0 0
use_rust/rp2040_split (central) 160.8 KiB 161.1 KiB +0.20% ⬆️ +340 0 0
use_rust/rp2040_split (peripheral) 28.1 KiB 28.1 KiB +0.00% 0 0 0
use_rust/stm32f1 62.9 KiB 63.2 KiB +0.40% ⬆️ +260 0 0
use_rust/stm32h7 122.3 KiB 122.5 KiB +0.19% ⬆️ +248 0 0
use_config/nrf52832_ble — 394.8 KiB → 395.1 KiB (+0.06% ⬆️)

cargo size (PR):

   text	   data	    bss	    dec	    hex	filename
 365204	   4588	  34760	 404552	  62c48	rmk-nrf52832

cargo size (main):

   text	   data	    bss	    dec	    hex	filename
 364960	   4588	  34760	 404308	  62b54	rmk-nrf52832

Bloaty diff (PR vs main):

    FILE SIZE        VM SIZE    
 --------------  -------------- 
  +0.1% +1.30Ki  [ = ]       0    .debug_info
  +0.0% +1.03Ki  [ = ]       0    .debug_str
  +0.1%    +244  +0.1%    +244    .text
  +0.1%    +235  [ = ]       0    .debug_line
  +0.0%    +130  [ = ]       0    .strtab
  +0.0%     +96  [ = ]       0    .debug_ranges
  +0.1%     +64  [ = ]       0    .symtab
  +0.1%     +48  [ = ]       0    .debug_frame
  +0.0%     +16  [ = ]       0    .debug_aranges
 -29.6%     -21  [ = ]       0    [Unmapped]
  -0.0%    -183  [ = ]       0    .debug_loc
  +0.0% +2.94Ki  +0.1%    +244    TOTAL
use_config/nrf52840_ble — 443.3 KiB → 443.5 KiB (+0.05% ⬆️)

cargo size (PR):

   text	   data	    bss	    dec	    hex	filename
 398168	   4596	  51416	 454180	  6ee24	rmk-nrf52840

cargo size (main):

   text	   data	    bss	    dec	    hex	filename
 397924	   4596	  51416	 453936	  6ed30	rmk-nrf52840

Bloaty diff (PR vs main):

    FILE SIZE        VM SIZE    
 --------------  -------------- 
  +0.1% +2.18Ki  [ = ]       0    .debug_str
  +0.1%    +244  +0.1%    +244    .text
  +0.1%    +192  [ = ]       0    .debug_ranges
  +0.1%     +96  [ = ]       0    .symtab
  +0.0%     +57  [ = ]       0    .strtab
  +0.7%     +55  [ = ]       0    .debug_abbrev
  +0.0%     +37  [ = ]       0    .debug_line
  +0.1%     +36  [ = ]       0    .debug_frame
  +0.0%     +16  [ = ]       0    .debug_aranges
   +17%     +10  [ = ]       0    [Unmapped]
  -0.0%    -602  [ = ]       0    .debug_info
  -0.1%    -929  [ = ]       0    .debug_loc
  +0.0% +1.41Ki  +0.1%    +244    TOTAL
use_config/nrf52840_ble_split (central) — 492.5 KiB → 492.8 KiB (+0.06% ⬆️)

cargo size (PR):

   text	   data	    bss	    dec	    hex	filename
 453140	   4652	  46808	 504600	  7b318	central

cargo size (main):

   text	   data	    bss	    dec	    hex	filename
 452828	   4652	  46808	 504288	  7b1e0	central

Bloaty diff (PR vs main):

    FILE SIZE        VM SIZE    
 --------------  -------------- 
  +0.1% +2.84Ki  [ = ]       0    .debug_str
  +0.1% +2.19Ki  [ = ]       0    .debug_info
  +0.1%    +312  +0.1%    +312    .text
  +0.1%    +282  [ = ]       0    .debug_line
  +0.1%    +136  [ = ]       0    .debug_ranges
  +0.0%    +135  [ = ]       0    .strtab
  +0.1%     +96  [ = ]       0    .symtab
  +0.1%     +48  [ = ]       0    .debug_frame
  +0.0%     +16  [ = ]       0    .debug_aranges
  +9.5%      +4  [ = ]       0    [Unmapped]
  -0.0%     -49  [ = ]       0    .debug_loc
  +0.1% +5.98Ki  +0.1%    +312    TOTAL
use_config/nrf52840_ble_split (peripheral) — 316.9 KiB → 316.9 KiB (+0.00% ⬆️)

cargo size (PR):

   text	   data	    bss	    dec	    hex	filename
 292936	   4468	  27152	 324556	  4f3cc	peripheral

cargo size (main):

   text	   data	    bss	    dec	    hex	filename
 292932	   4468	  27152	 324552	  4f3c8	peripheral

Bloaty diff (PR vs main):

    FILE SIZE        VM SIZE    
 --------------  -------------- 
  +0.0%      +4  +0.0%      +4    .text
  +0.0%      +2  [ = ]       0    .debug_line
  -0.0%      -1  [ = ]       0    .strtab
  -0.0%     -32  [ = ]       0    .debug_loc
  -0.0%    -775  [ = ]       0    .debug_info
  -0.1% -2.56Ki  [ = ]       0    .debug_str
  -0.1% -3.35Ki  +0.0%      +4    TOTAL
use_config/pi_pico_w_ble — 667.9 KiB → 668.2 KiB (+0.04% ⬆️)

cargo size (PR):

   text	   data	    bss	    dec	    hex	filename
 629652	      0	  54604	 684256	  a70e0	rmk-pi-pico-w

cargo size (main):

   text	   data	    bss	    dec	    hex	filename
 629368	      0	  54604	 683972	  a6fc4	rmk-pi-pico-w

Bloaty diff (PR vs main):

    FILE SIZE        VM SIZE    
 --------------  -------------- 
  +0.0%    +864  [ = ]       0    .debug_str
  +0.0%    +637  [ = ]       0    .debug_info
  +0.1%    +284  +0.1%    +284    .text
  +0.0%    +153  [ = ]       0    .debug_line
  +0.0%    +107  [ = ]       0    .strtab
  +0.1%     +32  [ = ]       0    .debug_frame
  +0.0%     +32  [ = ]       0    .symtab
  +0.0%      +8  [ = ]       0    .debug_aranges
  +0.0%      +8  [ = ]       0    .debug_ranges
   +10%      +6  [ = ]       0    [Unmapped]
  -0.1% -1.56Ki  [ = ]       0    .debug_loc
  +0.0%    +532  +0.0%    +284    TOTAL
use_config/rp2040 — 148.5 KiB → 148.9 KiB (+0.24% ⬆️)

cargo size (PR):

   text	   data	    bss	    dec	    hex	filename
 136904	      0	  15540	 152444	  2537c	rmk-rp2040

cargo size (main):

   text	   data	    bss	    dec	    hex	filename
 136532	      0	  15540	 152072	  25208	rmk-rp2040

Bloaty diff (PR vs main):

    FILE SIZE        VM SIZE    
 --------------  -------------- 
  +0.2% +1.54Ki  [ = ]       0    .debug_info
  +0.0%    +561  [ = ]       0    .debug_str
  +0.3%    +372  +0.3%    +372    .text
  +0.1%    +167  [ = ]       0    .debug_line
  +0.1%     +92  [ = ]       0    .strtab
  +0.2%     +32  [ = ]       0    .debug_frame
  +0.0%      +8  [ = ]       0    .debug_aranges
 -39.3%     -24  [ = ]       0    [Unmapped]
  -0.1%     -32  [ = ]       0    .symtab
  -0.0%     -40  [ = ]       0    .debug_ranges
  -0.2%    -580  [ = ]       0    .debug_loc
  +0.1% +2.09Ki  +0.2%    +372    TOTAL
use_config/rp2040_split (central) — 162.1 KiB → 162.4 KiB (+0.20% ⬆️)

cargo size (PR):

   text	   data	    bss	    dec	    hex	filename
 149912	      0	  16388	 166300	  2899c	central

cargo size (main):

   text	   data	    bss	    dec	    hex	filename
 149572	      0	  16388	 165960	  28848	central

Bloaty diff (PR vs main):

    FILE SIZE        VM SIZE    
 --------------  -------------- 
  +0.1% +1.06Ki  [ = ]       0    .debug_info
  +0.0%    +537  [ = ]       0    .debug_str
  +0.3%    +340  +0.3%    +340    .text
  +0.1%    +106  [ = ]       0    .strtab
  +0.2%     +32  [ = ]       0    .debug_frame
  +0.1%     +32  [ = ]       0    .symtab
   +29%     +12  [ = ]       0    [Unmapped]
  +0.0%      +8  [ = ]       0    .debug_aranges
  -0.0%     -16  [ = ]       0    .debug_ranges
  -0.0%     -55  [ = ]       0    .debug_line
  -0.2%    -807  [ = ]       0    .debug_loc
  +0.0% +1.25Ki  +0.2%    +340    TOTAL
use_config/rp2040_split (peripheral) — 27.8 KiB → 27.8 KiB (+0.00%)

cargo size (PR):

   text	   data	    bss	    dec	    hex	filename
  25596	     60	   2796	  28452	   6f24	peripheral

cargo size (main):

   text	   data	    bss	    dec	    hex	filename
  25596	     60	   2796	  28452	   6f24	peripheral

Bloaty diff (PR vs main):

    FILE SIZE        VM SIZE    
 --------------  -------------- 
  +0.0%      +6  [ = ]       0    .debug_str
  +0.0%      +2  [ = ]       0    .strtab
  +0.0%      +8  [ = ]       0    TOTAL
use_config/stm32f1 — 63.0 KiB → 63.2 KiB (+0.40% ⬆️)

cargo size (PR):

   text	   data	    bss	    dec	    hex	filename
  57220	     28	   7520	  64768	   fd00	rmk-stm32f1

cargo size (main):

   text	   data	    bss	    dec	    hex	filename
  56956	     28	   7520	  64504	   fbf8	rmk-stm32f1

Bloaty diff (PR vs main):

    FILE SIZE        VM SIZE    
 --------------  -------------- 
  +0.2% +1.13Ki  [ = ]       0    .debug_info
  +0.8%    +328  [ = ]       0    .debug_ranges
  +0.5%    +264  +0.5%    +264    .text
  +0.2%    +201  [ = ]       0    .debug_line
  +0.6%    +180  [ = ]       0    .strtab
  +0.6%    +128  [ = ]       0    .symtab
  +0.6%     +80  [ = ]       0    .debug_frame
  +0.0%     +78  [ = ]       0    .debug_str
  +0.5%     +32  [ = ]       0    .debug_aranges
 -16.4%      -9  [ = ]       0    [Unmapped]
  -0.0%     -37  [ = ]       0    .debug_loc
  +0.1% +2.34Ki  +0.4%    +264    TOTAL
use_config/stm32h7 — 100.0 KiB → 100.3 KiB (+0.26% ⬆️)

cargo size (PR):

   text	   data	    bss	    dec	    hex	filename
  92672	    268	   9760	 102700	  1912c	rmk-stm32h7

cargo size (main):

   text	   data	    bss	    dec	    hex	filename
  92400	    268	   9760	 102428	  1901c	rmk-stm32h7

Bloaty diff (PR vs main):

    FILE SIZE        VM SIZE    
 --------------  -------------- 
  +0.2% +1.48Ki  [ = ]       0    .debug_info
  +0.1% +1.21Ki  [ = ]       0    .debug_str
  +0.5%    +352  [ = ]       0    .debug_ranges
  +0.3%    +341  [ = ]       0    .debug_line
  +0.3%    +272  +0.3%    +272    .text
  +0.1%    +214  [ = ]       0    .debug_loc
  +0.3%    +180  [ = ]       0    .strtab
  +0.5%    +128  [ = ]       0    .symtab
  +0.5%     +80  [ = ]       0    .debug_frame
  +0.1%     +32  [ = ]       0    .debug_aranges
   +33%     +17  [ = ]       0    [Unmapped]
  +0.1% +4.27Ki  +0.3%    +272    TOTAL
use_rust/nrf52832_ble — 382.2 KiB → 382.4 KiB (+0.06% ⬆️)

cargo size (PR):

   text	   data	    bss	    dec	    hex	filename
 353276	   4588	  33744	 391608	  5f9b8	rmk-nrf52832

cargo size (main):

   text	   data	    bss	    dec	    hex	filename
 353020	   4588	  33744	 391352	  5f8b8	rmk-nrf52832

Bloaty diff (PR vs main):

    FILE SIZE        VM SIZE    
 --------------  -------------- 
  +0.0% +1.12Ki  [ = ]       0    .debug_str
  +0.1%    +974  [ = ]       0    .debug_info
  +0.1%    +259  [ = ]       0    .debug_line
  +0.1%    +256  +0.1%    +256    .text
  +0.1%    +130  [ = ]       0    .strtab
  +0.1%    +112  [ = ]       0    .debug_ranges
  +0.1%     +64  [ = ]       0    .symtab
  +0.1%     +48  [ = ]       0    .debug_frame
  +0.0%     +16  [ = ]       0    .debug_aranges
  +2.6%      +1  [ = ]       0    [Unmapped]
  -0.2%     -18  [ = ]       0    .debug_abbrev
  -0.0%    -305  [ = ]       0    .debug_loc
  +0.0% +2.62Ki  +0.1%    +256    TOTAL
use_rust/nrf52840_ble — 438.6 KiB → 438.8 KiB (+0.04% ⬆️)

cargo size (PR):

   text	   data	    bss	    dec	    hex	filename
 397804	   4596	  46904	 449304	  6db18	rmk-nrf52840

cargo size (main):

   text	   data	    bss	    dec	    hex	filename
 397584	   4596	  46904	 449084	  6da3c	rmk-nrf52840

Bloaty diff (PR vs main):

    FILE SIZE        VM SIZE    
 --------------  -------------- 
  +0.1% +1.48Ki  [ = ]       0    .debug_info
  +0.0%    +892  [ = ]       0    .debug_str
  +0.0%    +337  [ = ]       0    .debug_loc
  +0.1%    +322  [ = ]       0    .debug_line
  +0.1%    +220  +0.1%    +220    .text
  +0.1%    +160  [ = ]       0    .debug_ranges
  +0.1%     +96  [ = ]       0    .symtab
  +0.0%     +36  [ = ]       0    .strtab
  +0.0%     +16  [ = ]       0    .debug_frame
   +20%      +9  [ = ]       0    [Unmapped]
  +0.0%      +8  [ = ]       0    .debug_aranges
  +0.0% +3.53Ki  +0.0%    +220    TOTAL
use_rust/nrf52840_ble_split (central) — 501.8 KiB → 502.1 KiB (+0.05% ⬆️)

cargo size (PR):

   text	   data	    bss	    dec	    hex	filename
 456948	   4652	  52552	 514152	  7d868	central

cargo size (main):

   text	   data	    bss	    dec	    hex	filename
 456684	   4652	  52552	 513888	  7d760	central

Bloaty diff (PR vs main):

    FILE SIZE        VM SIZE    
 --------------  -------------- 
  +0.1% +1.64Ki  [ = ]       0    .debug_info
  +0.1%    +402  [ = ]       0    .debug_line
  +0.1%    +264  +0.1%    +264    .text
  +0.1%    +136  [ = ]       0    .debug_ranges
  +0.0%     +64  [ = ]       0    .symtab
  +0.0%     +49  [ = ]       0    .strtab
  +0.1%     +32  [ = ]       0    .debug_frame
  +0.0%     +16  [ = ]       0    .debug_aranges
  -5.5%      -3  [ = ]       0    [Unmapped]
  -0.0%    -136  [ = ]       0    .debug_loc
  -0.0%    -159  [ = ]       0    .debug_str
  +0.0% +2.29Ki  +0.1%    +264    TOTAL
use_rust/nrf52840_ble_split (peripheral) — 313.3 KiB → 313.3 KiB (+0.00%)

cargo size (PR):

   text	   data	    bss	    dec	    hex	filename
 290920	   4468	  25400	 320788	  4e514	peripheral

cargo size (main):

   text	   data	    bss	    dec	    hex	filename
 290920	   4468	  25400	 320788	  4e514	peripheral

Bloaty diff (PR vs main):

    FILE SIZE        VM SIZE    
 --------------  -------------- 
  +0.0%     +67  [ = ]       0    .debug_str
  +0.0%      +3  [ = ]       0    .debug_line
  +1.9%      +1  [ = ]       0    [Unmapped]
  -0.0%      -1  [ = ]       0    .strtab
  -0.0%    -170  [ = ]       0    .debug_info
  -0.0%    -100  [ = ]       0    TOTAL
use_rust/pi_pico_w_ble — 668.2 KiB → 668.5 KiB (+0.04% ⬆️)

cargo size (PR):

   text	   data	    bss	    dec	    hex	filename
 629816	      0	  54748	 684564	  a7214	rmk-pi-pico-w

cargo size (main):

   text	   data	    bss	    dec	    hex	filename
 629536	      0	  54748	 684284	  a70fc	rmk-pi-pico-w

Bloaty diff (PR vs main):

    FILE SIZE        VM SIZE    
 --------------  -------------- 
  +0.0%    +426  [ = ]       0    .debug_str
  +0.1%    +280  +0.1%    +280    .text
  +0.0%    +115  [ = ]       0    .debug_info
  +0.0%    +106  [ = ]       0    .strtab
  +0.1%     +32  [ = ]       0    .debug_frame
  +0.0%     +32  [ = ]       0    .symtab
  +0.0%     +15  [ = ]       0    .debug_line
   +23%     +11  [ = ]       0    [Unmapped]
  +0.0%      +8  [ = ]       0    .debug_aranges
  +0.0%      +8  [ = ]       0    .debug_ranges
  -0.1% -1.59Ki  [ = ]       0    .debug_loc
  -0.0%    -600  +0.0%    +280    TOTAL
use_rust/rp2040 — 148.0 KiB → 148.4 KiB (+0.24% ⬆️)

cargo size (PR):

   text	   data	    bss	    dec	    hex	filename
 136560	      0	  15412	 151972	  251a4	rmk-rp2040

cargo size (main):

   text	   data	    bss	    dec	    hex	filename
 136184	      0	  15412	 151596	  2502c	rmk-rp2040

Bloaty diff (PR vs main):

    FILE SIZE        VM SIZE    
 --------------  -------------- 
  +0.2% +1.73Ki  [ = ]       0    .debug_info
  +0.1%    +875  [ = ]       0    .debug_str
  +0.3%    +376  +0.3%    +376    .text
  +0.2%    +266  [ = ]       0    .debug_line
  +0.1%     +92  [ = ]       0    .strtab
  +0.2%     +32  [ = ]       0    .debug_frame
  +0.0%      +8  [ = ]       0    .debug_aranges
  +8.3%      +5  [ = ]       0    [Unmapped]
  -0.1%     -32  [ = ]       0    .symtab
  -0.0%     -40  [ = ]       0    .debug_ranges
  -0.2%    -580  [ = ]       0    .debug_loc
  +0.1% +2.71Ki  +0.2%    +376    TOTAL
use_rust/rp2040_split (central) — 160.8 KiB → 161.1 KiB (+0.20% ⬆️)

cargo size (PR):

   text	   data	    bss	    dec	    hex	filename
 148796	      0	  16172	 164968	  28468	central

cargo size (main):

   text	   data	    bss	    dec	    hex	filename
 148456	      0	  16172	 164628	  28314	central

Bloaty diff (PR vs main):

    FILE SIZE        VM SIZE    
 --------------  -------------- 
  +0.1%    +999  [ = ]       0    .debug_info
  +0.0%    +715  [ = ]       0    .debug_str
  +0.3%    +340  +0.3%    +340    .text
  +0.1%    +106  [ = ]       0    .strtab
  +0.0%     +51  [ = ]       0    .debug_line
  +0.2%     +32  [ = ]       0    .debug_frame
  +0.1%     +32  [ = ]       0    .symtab
   +34%     +14  [ = ]       0    [Unmapped]
  +0.0%      +8  [ = ]       0    .debug_aranges
  -0.0%     -16  [ = ]       0    .debug_ranges
  -0.2%    -785  [ = ]       0    .debug_loc
  +0.0% +1.46Ki  +0.2%    +340    TOTAL
use_rust/rp2040_split (peripheral) — 28.1 KiB → 28.1 KiB (+0.00%)

cargo size (PR):

   text	   data	    bss	    dec	    hex	filename
  25656	     60	   3060	  28776	   7068	peripheral

cargo size (main):

   text	   data	    bss	    dec	    hex	filename
  25656	     60	   3060	  28776	   7068	peripheral

Bloaty diff (PR vs main):

    FILE SIZE        VM SIZE    
 --------------  -------------- 
  +0.0%      +2  [ = ]       0    .debug_str
  +0.0%      +1  [ = ]       0    .strtab
  -4.8%      -3  [ = ]       0    [Unmapped]
  [ = ]       0  [ = ]       0    TOTAL
use_rust/stm32f1 — 62.9 KiB → 63.2 KiB (+0.40% ⬆️)

cargo size (PR):

   text	   data	    bss	    dec	    hex	filename
  57156	     28	   7496	  64680	   fca8	rmk-stm32f1

cargo size (main):

   text	   data	    bss	    dec	    hex	filename
  56896	     28	   7496	  64420	   fba4	rmk-stm32f1

Bloaty diff (PR vs main):

    FILE SIZE        VM SIZE    
 --------------  -------------- 
  +0.2%    +866  [ = ]       0    .debug_info
  +0.1%    +466  [ = ]       0    .debug_str
  +0.8%    +328  [ = ]       0    .debug_ranges
  +0.5%    +260  +0.5%    +260    .text
  +0.6%    +180  [ = ]       0    .strtab
  +0.2%    +165  [ = ]       0    .debug_line
  +0.6%    +128  [ = ]       0    .symtab
  +0.6%     +80  [ = ]       0    .debug_frame
  +0.7%     +32  [ = ]       0    .debug_aranges
  -0.0%     -37  [ = ]       0    .debug_loc
  +0.1% +2.41Ki  +0.4%    +260    TOTAL
use_rust/stm32h7 — 122.3 KiB → 122.5 KiB (+0.19% ⬆️)

cargo size (PR):

   text	   data	    bss	    dec	    hex	filename
 109440	    324	  15692	 125456	  1ea10	rmk-stm32h7

cargo size (main):

   text	   data	    bss	    dec	    hex	filename
 109192	    324	  15692	 125208	  1e918	rmk-stm32h7

Bloaty diff (PR vs main):

    FILE SIZE        VM SIZE    
 --------------  -------------- 
  +0.1% +1.05Ki  [ = ]       0    .debug_info
  +0.2%    +248  +0.2%    +248    .text
  +0.2%    +192  [ = ]       0    .debug_ranges
  +0.1%    +133  [ = ]       0    .debug_line
  +0.1%     +80  [ = ]       0    .strtab
  +0.1%     +16  [ = ]       0    .debug_frame
 -32.3%     -21  [ = ]       0    [Unmapped]
  -0.0%     -95  [ = ]       0    .debug_loc
  -0.0%    -112  [ = ]       0    .debug_str
  +0.0% +1.48Ki  +0.2%    +248    TOTAL

@yekingyan
yekingyan force-pushed the fix/osm-osl-timeout-non-consuming branch from 7c1d906 to c74a484 Compare May 29, 2026 15:02
Comment thread rmk/tests/keyboard_one_shot_test.rs Outdated
@yekingyan
yekingyan force-pushed the fix/osm-osl-timeout-non-consuming branch from f48b908 to 2fd78c1 Compare June 12, 2026 14:28
The OSM/OSL release path used a single select(timeout, next_event), so the
first event arriving during the timeout cancelled the wait permanently,
leaving the one-shot stuck in Single (never auto-released). A typical
trigger is the release event of a layer key.

Replace the single select with a deadline loop: non-consuming events are
pushed to the queue and we keep waiting for the remaining time, while a
consuming event (OSM: press in quick_release mode, release otherwise;
OSL: press) breaks out.

Additionally, check unprocessed_events before entering the await loop —
if a consuming event was already dequeued from the channel, the subscriber
would never see it, causing the OSM to hang indefinitely.
@yekingyan
yekingyan force-pushed the fix/osm-osl-timeout-non-consuming branch from 20a9693 to 055fd99 Compare June 12, 2026 14:51
@HaoboGu
HaoboGu requested a review from jpds June 12, 2026 16:07
Comment thread rmk/src/keyboard/oneshot.rs Outdated
match select(timeout, self.keyboard_event_subscriber.next_message_pure()).await {
Either::First(_) => {
// Timeout, deactivate layer
self.keymap.deactivate_layer(layer_num);

@HaoboGu HaoboGu Jun 13, 2026

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Should layer_num be l in OneShotState::Initial(l) | OneShotState::Single(l)?

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.

Should layer_num be l in OneShotState::Initial(l) | OneShotState::Single(l)?

Good catch — should be l.

Just pushed a fix (0610cb4c) that uses the match-bound l instead of the outer layer_num parameter.

They're numerically equal on every current call path, so there's no behavior change today, but l is the semantically correct value and it's more robust if that invariant ever changes.

…aram

In the OSL release path, the Initial(l) | Single(l) arm was calling
self.keymap.deactivate_layer(layer_num) using the outer function
parameter instead of the layer number l bound by the match arm.

Currently these happen to be numerically equal on the only call path,
but relying on that is fragile and semantically wrong: the deactivated
layer should always be the one actually stored in osl_state, not the
layer passed into this invocation of process_action_osl.

Addresses review comment from @HaoboGu on PR rmk-rs#866.
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.

3 participants