-
Notifications
You must be signed in to change notification settings - Fork 0
feat: configurable foreground waits with background completion #206
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
maxirmx
wants to merge
6
commits into
main
Choose a base branch
from
xxx-branch
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+2,051
−257
Open
Changes from 5 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
4b6f3d8
feat: configurable foreground waits with background completion
maxirmx ee7e6be
Fix shutdown and delivery recovery review findings
maxirmx 9b9a5f2
Add CancelPendingRequests method to backend test
maxirmx a0b7f64
address review
maxirmx 4aac8f2
Merge branch 'xxx-branch' of github.com:maxirmx/fuelflux into xxx-branch
maxirmx ce50b95
fix review thread findings
Copilot File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -47,6 +47,7 @@ | |
| # build | ||
| build/ | ||
| build-*/ | ||
| out/ | ||
| _codeql_build_dir/ | ||
| _codeql_detected_source_root | ||
|
|
||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,131 @@ | ||
| # Foreground backend waits and durable reporting | ||
|
|
||
| Set `fuelflux::timing::kForegroundBackendWaitTimeout` in | ||
| [`include/timing_config.h`](../include/timing_config.h) and rebuild. The default | ||
| is `std::chrono::seconds{5}`; a non-positive value fails compilation. This one | ||
| setting controls authorization cache fallback, the slow-connection warning, | ||
| and release of both refuel and intake transmission screens on every connection | ||
| type. HTTP connection/total deadlines and DNS deadlines remain independent. | ||
|
|
||
| ## Authorization | ||
|
|
||
| Each attempt captures saved user and tank values, pending-card protection, and | ||
| writable local report-storage availability before starting its independent | ||
| backend session. The general user/tank snapshot comes from one cache generation. | ||
| The captured values stay unchanged for that attempt even if synchronization or | ||
| report delivery finishes meanwhile. | ||
|
|
||
| The display initially shows `Проверка...` / `Ожидайте`. An online result received | ||
| before the foreground deadline follows the existing allowance, role, and tank | ||
| selection checks. A network failure can use the captured snapshot; a definitive | ||
| authorization denial cannot. | ||
|
|
||
| When the foreground deadline expires, usable saved data automatically continues | ||
| through the existing cache authorization checks. Otherwise the display shows | ||
| `Медленное соединение`, `Ожидайте или`, and the keyboard profile's Cancel prompt | ||
| (`Нажмите ОТМЕНА (B)` for legacy, `Нажмите ОТМЕНА` for VID). The warning uses small | ||
| text lines so it fits the ST7565 as well as the larger ILI9488. Cancel immediately | ||
| returns to the welcome screen. Cancel before the warning retains its former | ||
| behavior. | ||
|
|
||
| Attempts have independent IDs and sessions. Abandonment signals transport | ||
| cancellation, including cancellable c-ares DNS waits on the GSM build. The | ||
| controller accepts an attempt's result only while that attempt is current. | ||
| A late successful unused session is closed asynchronously; it cannot update | ||
| the active session or cache. | ||
|
|
||
| ## Reports and subsequent operations | ||
|
|
||
| Before enabling another operation, the controller stores the completed payload | ||
| and a protected per-card user/tank snapshot in one SQLite transaction, deducting | ||
| the refuel volume exactly once. Intake preserves the allowance. A persistence | ||
| failure shows `Ошибка записи` and enters the error procedure instead of showing | ||
| successful completion with an unrecorded transaction. | ||
|
|
||
| The transmission screen remains until delivery resolves or the foreground wait | ||
| expires. The existing completion screen retains the final volume and accepts a | ||
| new card or PIN. Screen release does not send the report again. The delivery | ||
| coordinator owns the reporting backend session, so the new operation cannot | ||
| reuse or close it. | ||
|
|
||
| A card with queued or in-flight reports immediately uses its protected snapshot | ||
| and locally reduced allowance, even when the general cache lacks its tanks. | ||
| Different cards authorize normally. Late delivery changes only its matching | ||
| report and attempt IDs. Network failures schedule retries; definitive rejections | ||
| move the unchanged payload to `dead_messages` and resolve that report. Once no | ||
| pending reports remain for the card, its next operation attempts online | ||
| authorization normally. | ||
|
|
||
| Authorization has a bounded worker and queue. A separate single delivery worker | ||
| coordinates both new reports and retries, with one active sender and ordered | ||
| delivery within each card. At most one additional original session is retained; | ||
| other queued reports obtain an independent session when selected. Controller | ||
| state and display transitions remain on the controller loop. Shutdown cancels | ||
| active network work and joins the owned workers. At process exit the shared | ||
| token-cleanup worker is also cancelled and joined before DNS/logging teardown. | ||
| The same cleanup order applies when the application enters permanent failure. | ||
|
|
||
| Controller startup and shutdown synchronize event-loop ownership, including a | ||
| thread that has been launched but has not entered `run()` yet. Exceptions release | ||
| that ownership too. `shutdown()` returns `false` if an active controller action | ||
| does not exit within `kShutdownDeadline`; it leaves live state and peripherals | ||
| intact so the caller can retry after the action exits. Destruction while the loop | ||
| is still live terminates the process. The application also exits with failure on | ||
| a shutdown timeout, allowing the service supervisor to restart it instead of | ||
| freeing state under a hung peripheral call. Independent/cancellable backend | ||
| sessions are required by `Controller` and checked at construction; synchronous | ||
| backend adapters may still be used directly by synchronization/delivery callers. | ||
|
|
||
| ## Persistence and compatibility | ||
|
|
||
| The `backlog` schema now has stable increasing report IDs, delivery attempt IDs, | ||
| queued/in-flight status, retry eligibility, and a payload interpretation flag. | ||
| Startup migrates legacy implicit rowids in order without changing payloads. | ||
| Legacy payloads retain their existing tank-mapping interpretation. New payloads | ||
| capture the backend tank ID and transaction timestamp once; retries do not | ||
| remap tanks or replace timestamps. | ||
|
|
||
| `card_report_state` stores the reduced allowance and saved user/tanks separately | ||
| from cache generations. Report acknowledgements and retries never deduct again. | ||
| Interrupted deliveries are recovered for retry at coordinator startup. Protected | ||
| card data and pending-card restrictions therefore survive restart. | ||
| If startup recovery cannot write to SQLite, the worker retries recovery before | ||
| sending any report. Recovery clears the in-flight marker; only the next delivery | ||
| claim increments the attempt ID. Old completions are rejected both before that | ||
| claim and after it. | ||
|
|
||
| Canonical delivery checks the method's user role and payload shape. It does not | ||
| compare an already-recorded transaction with a later server allowance or remap | ||
| its tank: those values may have changed since dispensing, and doing so would | ||
| incorrectly suppress or alter a retry. | ||
|
|
||
| Synchronization records resolved snapshot revisions before fetching server | ||
| data and may release protection only if those revisions remain unchanged and | ||
| the card still has no pending reports after the cache commit. A server fetch | ||
| started while reports were pending cannot restore an older allowance. A fresh | ||
| successful online authorization refreshes resolved protection and its revision, | ||
| so an older synchronization fetch cannot undo that authorization either. | ||
|
|
||
| Backend deduplication remains unverified. Network-failure retries are preserved. | ||
| A timeout can occur after the server accounted for a report but before its reply | ||
| arrived; stable local IDs and exclusive sending cannot prevent duplicate server | ||
| accounting in that case. Exactly-once accounting requires backend support for | ||
| an idempotency key or equivalent reconciliation protocol. The local report ID | ||
| is not sent as an undocumented backend field. | ||
|
|
||
| ## Verification | ||
|
|
||
| `foreground_backend_test.cpp` exercises configurable waits, early/late results, | ||
| cache fallback, missing-cache cancellation, same/different-card continuation, | ||
| refuel/intake delivery, rejection, storage failures, and shutdown. | ||
| `report_delivery_test.cpp` covers atomic deductions, snapshot protection, stable | ||
| payloads, attempt matching, per-card ordering, migration, and restart recovery. | ||
| Backend tests include cancellation of an already-sent HTTP authorization; | ||
| c-ares cancellation tests are enabled in `USE_CARES` builds. Display tests check | ||
| the Russian warning and both Cancel labels against the small display's width. | ||
|
|
||
| Run `ctest --test-dir <build-directory> --output-on-failure`. The Windows console | ||
| suite and Linux container build with `TARGET_SIM800C=ON` have been exercised. | ||
| The Linux checks include cancellation while waiting for a deliberately withheld | ||
| DNS reply and while waiting for another resolver call. Physical displays and | ||
| the modem still require validation on the target hardware. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| #pragma once | ||
|
|
||
| #include "backend.h" | ||
| #include <optional> | ||
|
|
||
| namespace fuelflux { | ||
|
|
||
| // A value copy: it must not change when synchronization flips cache tables. | ||
| struct AuthorizationSnapshot { | ||
| UserInfo user; | ||
| std::vector<BackendTankInfo> tanks; | ||
| }; | ||
|
|
||
| struct ProtectedCardSnapshot { | ||
| AuthorizationSnapshot authorization; | ||
| bool pending = false; | ||
| }; | ||
|
|
||
| struct SavedAuthorizationState { | ||
| std::optional<AuthorizationSnapshot> saved; | ||
| bool reportStorageAvailable = false; | ||
| bool pendingReports = true; // Fail closed if storage cannot be read. | ||
| }; | ||
|
|
||
| } // namespace fuelflux |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.