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

Merged
UT
5d ago
+1678-417

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.

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.