Skip to content

Optimize: settings file keys address what the server's keys name - #2437

Merged
utkarshdalal merged 3 commits into
masterfrom
optimize-settings-file-addressing
Nov 16, 2026
Merged

utkarshdalal merged 3 commits into
masterfrom
optimize-settings-file-addressing

Conversation

@utkarshdalal

@utkarshdalal utkarshdalal commented Nov 16, 2026 •

Copy link
Copy Markdown
Owner

Description

Optimize settings files: the writer now addresses each key in the same notation the server's keys use, and edits only the value's characters. Also two judging and ladder fixes found on a device.

Settings file writer (ConfigFormats.kt)

  • Every format flattens the file into key -> value entries. An op writes the entry it names by replacing only the characters of that value, so comments, declarations, quoting, attribute order, spacing, encodings and line endings (including a lone \r) stay as they were. XML and JSON are no longer re-serialized.
  • XML: a child is keyed tag[v] by the first of name, Name, id, Id, key, Key it carries. Before, only Name counted, so a selector keyed by id missed and a new element the game ignores was appended. Unkeyed siblings are counted per tag (tag, tag[1], ...), so tag[N] is no longer read as Name="N". A key without @attr is the element's text, else its one non-keying attribute, else its value attribute. Before, it always wrote the text. Values are read and written as they are in the file, and malformed files no longer fail to parse.
  • XML, missing parts: a missing attribute is added to its element. A missing element, along with any missing blocks above it, is added with all the attributes the step writes on it, as the last child of its parent and indented like the file. It is keyed by the attribute the file's other elements of that tag use. An element that can only be addressed by its value (the attribute name is not in the key) or by position is never added.
  • INI: an op's section and key address Section.key, so a section whose name contains a dot is found. Repeated keys: the last occurrence is read and written. A key with an empty section is not added above the first header of a file that has no keys there.
  • JSON: strict JSON is edited in place. A new member takes its siblings' indentation and separator. A file that is not strict JSON (trailing commas and the like) is addressed as structured text instead of failing the step.
  • Structured text (cfg): nested blocks prefix their entries (Block.name). A name that repeats is name#2 from its second occurrence (it was counted from zero). bind lines, -flag value pairs, "key" "value", Name(value) and seta lines are covered. Unkeyed lines and flags without a value are never written. A key that is not a full path matches the only entry whose path ends with it.
  • applyVerified now also checks that no other key changed and none appeared.
  • An op that cannot be written is skipped and counted with the step's skipped ops, instead of failing the whole step. This covers a key that is missing and cannot be added where the game reads it, and a value that cannot be stored there. Ops that only work together, such as the attributes of one new element, are checked as a group. A kept step re-check skips such keys the same way.

Judging: a start without the game window (OptimizeJudge.kt, OptimizeController.kt)

  • A session under two minutes that never showed the game's window and left no fatal fingerprint is no result. It is reported as not_comparable with judge_reason no_window, and the step stays pending and is tried again on the next launch.
  • It counts as a crash (judge_reason no_window) only on the second such start in a row with the step applied, and only when the game's latest session without a step on trial did show its window. If starts fail without the step too, the step is not blamed; after three such starts it is judged not comparable.
  • A crash after the window was seen is judged as before.

Ladder: rungs the app refuses (OptimizeLocalState.kt, OptimizeController.kt)

  • A settings step number is one level of the game's ladder in every phase, so a rung on a level the ladder already kept, tried or skipped is still refused.
  • A rung the app refuses as a repeat is now kept in the ladder's skipped list (rung id, version, reason repeat) and sent as ladder.skipped with the next request, which is asked for right away. Before, the refusal was not sent, so the same rung could be offered again on every launch and nothing was applied.

Where a settings file is, and when it is not there (OptimizeApplier.kt, OptimizeModels.kt, EngineHint.kt)

  • An engine_file lever may carry path_alternatives: other places the same file can be. The first of path and the alternatives that leads to an existing file is written.
  • A file that is at none of them is not a failure: its ops count as skipped. A rung whose settings files are all missing goes into the tried list as file_missing (the outcome is no_op with apply.missing_files), and the next rung is asked for in the same launch.
  • The Unreal project name (from <Project>-Win64-Shipping.exe and its folder) is sent as engine_meta.project.

After-cards follow the next answer (OptimizeController.kt, OptimizeRules.kt, OptimizeCardDialog.kt)

  • A helped or no-change card still waiting takes its choices from the next-rung answer the app asks for at exit: exhausted turns it into the end card (keep or undo all); no_rule or not_settings drops "Keep going" (helped: keep or undo; no change: stop here). A card already on screen is updated in place. Existing strings only.

Store ids, the exit question for throttled sessions, external power (OptimizeIdentity.kt, OptimizeServer.kt, OptimizeModels.kt)

  • The next-rung game block carries the store's other ids next to store_id: epic_namespace and epic_app_name for Epic games (from the Epic library row), amazon_sku for Amazon games. Each is null when the row does not have it; other stores send none of them. Amazon's store_id was already its product id.
  • A session long enough for a thermal reading in which the device throttled (the session's own throttle onset) now sends the exit dry-run even when the local rules say it ran fine, and even when this rules build was already asked for the game. The first card follows the server's answer; with no answer, or one without show_card, the local decision stands as before. The user's own holds still come first.
  • Sessions carry on_external_power (true when the device was on external power at the session's start or exit, null when neither was read) in the metrics, outcome before/after and the stored run.

Tests: OptimizeFileAddressingTest covers path alternatives, missing files and the after-card choices; EngineHintTest the Unreal project name. Tests: ConfigFormatsTest has a test per addressing rule, all on small synthetic files. OptimizeJudgeTest covers the no-window starts. OptimizeStateTest covers skipped rungs and step numbers across phases. OptimizeOfferTest covers the store ids per store; OptimizeServerTest runs a hot session at its target (660 s at 59.5 fps under a 60 cap, hot most of the session) through the local verdict to the exit question and the card, and the external power field.

Recording

The helped and no-change cards lose "Keep going" when the server has nothing next; no new screens. Not recorded yet.

Type of Change

  • Bug fix
  • Performance / stability improvement
  • Compatibility improvements
  • Other (requires prior approval)

Checklist

  • If I have access to #code-changes, I have discussed this change there and it has been green-lighted. If I do not have access, I have still provided clear context in this PR. If I skip both, I accept that this change may face delays in review, may not be reviewed at all, or may be closed.
  • This change aligns with the current project scope (core functionality, stability, or performance). If not, it has been explicitly approved beforehand.
  • I have attached a recording of the change.
  • I have read and agree to the contribution guidelines in CONTRIBUTING.md.

Summary by cubic

Settings file ops now address keys exactly as the server names them, so each edit replaces only that value's characters and keeps comments, quoting, attribute order, indentation, and line endings intact. Also fixes judging of starts that never reach the game window, stops repeated ladder rungs from being offered again, finds settings files at alternate paths, and sends store ids and throttled-session verdicts to the server.

Settings file editing and server exchange

  • Every format flattens the file into key→value entries; an op writes only the value it names, and unwritable ops are skipped instead of failing the step.
  • XML children are keyed by name/Name/id/Id/key/Key, unkeyed siblings counted per tag; INI keys are Section.key with the last repeat written.
  • JSON is edited in place (non-strict JSON falls back to structured text), which covers block paths, name#2 repeats, bind, flags, and Name(value). Missing elements are added keyed like the file's own, and applyVerified confirms no other key changed.
  • When a file is not at its path, its path_alternatives are tried in order; a missing file's ops count as skipped, and a rung with all its files missing goes into the tried list as file_missing.
  • The Unreal project name, read from <Project>-Win64-Shipping.exe, is sent as engine_meta.project; Epic games add epic_namespace and epic_app_name, and Amazon games amazon_sku, to the next-rung game block.
  • A long session in which the device throttled asks the exit dry-run even when the local rules said it ran fine or this rules build was already asked; sessions also carry on_external_power.

Judging and ladder

  • A start without the game window is reported as not_comparable with no_window and stays pending; it counts as a crash only when it repeats while the game's last unstepped session showed the window.
  • A rung refused as a repeat is recorded in the ladder's skipped list and sent with the next request, so it is not offered again.
  • A helped or no-change card still waiting takes its choices from the next-rung answer at exit: exhausted shows the end card, no_rule or not_settings drops "Keep going", and an already-shown card updates in place.

Written for commit 0b31ed8. Summary will update on new commits.

View guided diff Turn on auto-fix

Summary by CodeRabbit

  • New Features
    • Configuration changes now preserve existing formatting and avoid overwriting settings that cannot be safely updated.
    • Optimization can use alternate settings-file locations, report when required files are missing, and offer clearer choices when no further changes are available.
    • Optimization decisions better account for sessions where the game window does not appear, and can include additional game and store information in reports.
    • Exit-time optimization checks now account for throttled sessions.

Every format flattens the file into key -> value entries and an op edits the
characters of the value it names, so the rest of the file keeps its bytes.
XML children are keyed by name/Name/id/Id/key/Key, unkeyed siblings are
counted per tag, a key without @attr is the text, the one non-keying
attribute or the value attribute; missing elements are added keyed like the
file's own. INI keys are Section.key with the last repeat written; JSON is
edited in place and falls back to structured text; structured text has block
paths and name#2 repeats. An op that cannot be written is skipped instead of
failing the step.

A start that never showed the game window is no result, not a crash of the
pending step, unless it repeats. A rung refused as a repeat is listed in
ladder.skipped so it is not offered again.
@coderabbitai

coderabbitai Bot commented Nov 16, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

Caution

Review failed

The pull request is closed.

Walkthrough

The change updates configuration parsing and editing, file-operation handling, optimization ladder state, game metadata, and session evaluation. It also updates related tests and the card dialog actions.

Changes: Optimization configuration and session flow

Layer / File(s) Summary
Verified configuration edits
app/src/main/java/app/gamenative/optimize/ConfigFormats.kt, app/src/test/java/app/gamenative/optimize/ConfigFormatsTest.kt
INI, JSON, XML, and CFG formats now edit localized text ranges. Verified application checks that untouched entries remain unchanged. Tests cover preservation, editing, and refusal cases.
Game and engine metadata
app/src/main/java/app/gamenative/optimize/EngineHint.kt, OptimizeIdentity.kt, OptimizeModels.kt, OptimizeController.kt, app/src/test/java/app/gamenative/optimize/EngineHintTest.kt, OptimizeOfferTest.kt
Engine hints can include an Unreal project name. Game request data can include Epic namespace and app name or Amazon SKU when available.
File selection and missing-file outcomes
app/src/main/java/app/gamenative/optimize/OptimizeModels.kt, OptimizeApplier.kt, OptimizeRules.kt, OptimizeController.kt, app/src/test/java/app/gamenative/optimize/OptimizeFileAddressingTest.kt
Engine-file levers accept alternative paths. Application filters operations through ConfigFormats.writableOps, selects a usable candidate, and reports missing files in no-op outcomes.
Skipped rungs and next-answer cards
app/src/main/java/app/gamenative/optimize/OptimizeLocalState.kt, OptimizeRules.kt, OptimizeController.kt, app/src/main/java/app/gamenative/ui/component/dialog/OptimizeCardDialog.kt, app/src/test/java/app/gamenative/optimize/OptimizeFileAddressingTest.kt, OptimizeStateTest.kt
Skipped rungs and the no-next-step card flag are persisted. The controller updates waiting cards from next-rung responses, and dialog actions depend on the card flag.
Session judging and exit requests
app/src/main/java/app/gamenative/optimize/OptimizeModels.kt, OptimizeJudge.kt, OptimizeLocalState.kt, OptimizeServer.kt, OptimizeController.kt, app/src/test/java/app/gamenative/optimize/OptimizeJudgeTest.kt, OptimizeServerTest.kt
Session metrics report external-power data when known. Trial judging tracks starts without a game window, and exit requests include eligible throttled sessions.

Estimated code review effort: 4 (Complex) | ~60 minutes

Change: Bug fix

Sequence Diagram(s)

sequenceDiagram
  participant OptimizeController
  participant OptimizeJudge
  participant PendingRung
  participant OutcomeQueue
  OptimizeController->>OptimizeJudge: Judge trial metrics and no-window history
  OptimizeJudge-->>OptimizeController: Return NoWindow decision
  OptimizeController->>PendingRung: Update no-window start count
  OptimizeController->>OutcomeQueue: Queue NOT_COMPARABLE outcome
Loading

Possibly related PRs

Merge Risk: Moderate · up to 0b31e

This change rewrites how game settings files are edited and how optimization steps are judged. Several edge cases can corrupt or incompletely restore XML settings files, or fail an entire optimization step. A step whose game window never appears can stay applied indefinitely. A delayed server answer can keep a setting that should have been undone. These issues should be fixed or explicitly accepted before merging.

- [ ] Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

Utkarsh Dalal added 2 commits November 16, 2026 18:21
…ards from the next answer

- An engine_file lever's path_alternatives are tried in order after its path; the first that
  leads to an existing file is written.
- A settings file that is not there is not a failure: its ops count as skipped, and a rung whose
  files are all missing goes into the tried list as file_missing (outcome no_op with
  apply.missing_files).
- The Unreal project name (from <Project>-Win64-Shipping.exe) goes out as engine_meta.project.
- A helped or no-change card still waiting takes its choices from the next-rung answer at exit:
  exhausted shows the end card, no_rule or not_settings drops "Keep going" (kept or undone only).
  A card already on screen is updated in place.
…r at exit, external power

The next-rung game block carries epic_namespace and epic_app_name for Epic games and amazon_sku for Amazon
games, null when the library row does not have them. A long session in which the device throttled asks the
exit dry-run even when the local rules say it ran fine or this rules build was already asked; the first card
follows the server's answer, and without one the local decision stands. Sessions carry on_external_power,
read from the run's charging state at start and exit.
@utkarshdalal
utkarshdalal marked this pull request as ready for review November 16, 2026 14:40
@utkarshdalal
utkarshdalal merged commit 12c2e29 into master Nov 16, 2026
3 checks passed
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.

1 participant