Skip to content

feat(settings): keep-awake on and off on Android - #4290

Merged
thymikee merged 7 commits into
callstack:mainfrom
strzhao:forge/keep-awake
Nov 24, 2026
Merged

thymikee merged 7 commits into
callstack:mainfrom
strzhao:forge/keep-awake

Conversation

@strzhao

@strzhao strzhao commented Nov 6, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Adds settings keep-awake for Android. It lowers to svc power stayon true|false through the global-toggle machinery (writeArgs descriptor), polls the stay_on_while_plugged_in row to a state, and reports typed keep-awake-not-applied / keep-awake-unreadable when the read-back did not move or is not a mask. The write is explicit, so it does not skip a mask that already covers the plugged-in sources.

HarmonyOS keep-awake left this PR per the maintainer's option B: on the tested unit (JDY-AL50, HarmonyOS 7.0.0.111), power-shell timeout -r acks but does not clear an active -o override, so off could report disabled while the hold stayed up. A harmony request now refuses as unsupported through the owner's settings facts. A future PR may bring the half back behind a proven restore route.

Before / after

Base: settings keep-awake on refuses as unsupported on every platform. Head, Android on a physical Redmi (MIUI 14):

$ agent-device settings keep-awake on --platform android --json
{"setting": "keep-awake", "state": "on", "keepAwake": "enabled"}

End to end through the public CLI, device row read back between calls:

$ node bin/agent-device.mjs settings keep-awake on --platform android --serial 5p4hqglvpzxshiuw
Updated setting: keep-awake
$ adb -s 5p4hqglvpzxshiuw shell "settings get global stay_on_while_plugged_in"
7
$ node bin/agent-device.mjs settings keep-awake off --platform android --serial 5p4hqglvpzxshiuw
Updated setting: keep-awake
$ adb -s 5p4hqglvpzxshiuw shell "settings get global stay_on_while_plugged_in"
0

The mask value stays the device's (svc true writes 15 on MIUI); the result names only the state.

Validation

Live runs in docs/evidence/android-keep-awake-2026-11-08.md: raw-adb repro at head 73d04eb4a (0 → 15 → 0), then the shipped lowering with read-back. pnpm vitest run settings command-surface contracts --project unit-core at head abbba3a03: 1566 passed. The body is updated after each push and describes the current head.

@cubic-dev-ai cubic-dev-ai Bot 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.

All reported issues were addressed across 13 files

Tip: cubic used a learning from your PR history. Let your coding agent read cubic learnings directly with the cubic MCP.

View guided diff | Re-trigger cubic

@thymikee

thymikee commented Nov 6, 2026

Copy link
Copy Markdown
Member

I reviewed 14befc1 and the code looks right, but I cannot approve yet because the live device runs the PR body describes are not published.

The PR body says the Redmi and JDY-AL50 runs are recorded in-repo, but no file in the diff holds them. The body has no commands, SHA or output either. Both new write paths (Android svc power stayon, HarmonyOS power-shell timeout -o/-r) are covered only by mocked shell tests, and HarmonyOS has no CI device. So nobody can confirm that power-shell timeout -o 2147483647 is accepted, that timeout -r restores the timeout, or that MIUI applies svc power stayon. Please post a PR comment for 14befc1 with the source SHA and the output of these runs. On the Redmi, run agent-device settings keep-awake on --json, then adb shell settings get global stay_on_while_plugged_in must read non-zero (7 or 15); after off it must read 0. On the JDY-AL50, after on the screen must stay lit past the system screen-off timeout (or hidumper -s 3301 must show the override); after off the system timeout must apply again. Also show one non-supporting target (iOS or web) refusing with the typed unsupported code, and show that the state persists after the session closes.

Not blocking, and fine to take or leave: Android off writes svc power stayon false, so it clears Developer options stay-awake instead of restoring it, while the help at settings-catalog.ts:124 says off restores the system timeout (true only for HarmonyOS); nothing reverts keep-awake on session close, so the help could say it outlives the session and needs an explicit off, which matters on shared remote devices; the PR body says power-shell setmode and 12 files, but the code uses power-shell timeout and the diff touches 13; and unlike mobile-data, Android keep-awake does not read back stay_on_while_plugged_in after the write, so could it fail with a typed reason on mismatch?

The open P3 thread on the HarmonyOS settings test still applies: the test matches only the message text, and parseSettingState throws INVALID_ARGS, so it should assert the code like the Android sibling does. #4290 (comment)

All 11 checks pass at 14befc1 and there are no conflicts. I had no device access and ran no local tests. The leaf tests would fail without the new cases, judged from the diff. Before merge, please post the Android and HarmonyOS keep-awake on/off evidence for this head.

@thymikee

thymikee commented Nov 7, 2026

Copy link
Copy Markdown
Member

Tracked in #4318, group B (HarmonyOS). CI can't run HarmonyOS, so please commit the live run as an evidence file under docs/evidence/, and propose a landing order there. HarmonyOS moves to a plugin in 0.22 (#4317).

@strzhao

strzhao commented Nov 8, 2026

Copy link
Copy Markdown
Contributor Author

Evidence committed to the branch: docs/evidence/android-keep-awake-2026-11-08.md, and the evidence run forced a real fix. The draft's svc power stayon true lowering is a live no-op when the stored mask already covers the plugged-in sources (Redmi K60, Android 14: stored 15 stayed 15 through the command). The backend now writes stay_on_while_plugged_in explicitly (7 / 0) and returns the read-back value, so an ack cannot claim a write the device did not store. End-to-end through the public CLI on hardware: 15 → 7 → 0, user's mask restored after. Head is now 124a99e.

🤖 Generated with Claude Code

@cubic-dev-ai cubic-dev-ai Bot 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.

1 issue found across 3 files (changes from recent commits).

Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="docs/evidence/android-keep-awake-2026-11-08.md">

<violation number="1" location="docs/evidence/android-keep-awake-2026-11-08.md:48">
P2: The transcript ends at `0` but only asserts that the user’s mask was later restored to `15`. Include the restoration command and its `settings get` output so reviewers can verify the device was left unchanged.</violation>
</file>

Reply with feedback, questions, or to request a fix.

View guided diff | Re-trigger cubic

@thymikee

thymikee commented Nov 8, 2026

Copy link
Copy Markdown
Member

Thanks for the update. At 124a99e the Android evidence now includes a shipped-backend section with CLI runs, and the new leaf test would fail against the old lowering. The HarmonyOS half still has no live proof, so the code needs one more round. All 11 checks pass and there are no conflicts. I read the diff and the device transcripts; I did not reproduce them on a device.

The issue asks for evidence first on the HarmonyOS contribution: device, OS, build, commands and raw output. The HarmonyOS section is still prose that quotes two ack lines. It shows no settings keep-awake on|off run on the device, no read of the effective override, no build or SHA, and no off confirmation. The new power-shell timeout -o/-r path is covered only by mocked shell tests, and HarmonyOS has no CI device. Please add a HarmonyOS section with the device, OS and build. Show settings keep-awake on --platform harmonyos --json with raw output, then proof the override is active (hidumper -s 3301 output, or the screen staying lit past the system timeout). Show off and the same read after it, proving the system timeout applies again. Record the PR head SHA the run used.

Not blocking, and fine to take or leave: Android on now writes 7 while the evidence device stored 15, so a device that holds 15 loses the dock source. off writes 0, and nothing saves or restores the stored mask, so the 'restored to 15' line in the evidence was a manual step. The write also skips signal and discloseDispatch handling and a typed not-applied failure on read-back mismatch, which setAndroidGlobalToggle gives mobile-data. The catalog help still says Android lowers to svc power stayon and that off restores the system timeout. The PR body still says svc power stayon, power-shell setmode and '12 files'. Both should match the shipped lowering, including that Android off does not restore a prior mask.

Could the original svc power stayon true|false lowering stay, confirmed through the existing global-toggle read-back? That would be a keep-awake descriptor whose parseRow maps non-zero to enabled and '0' to disabled, with a typed keep-awake-not-applied reason. The result would be { keepAwake } only, matching HarmonyOS, with no platform mask key in the shared result. If a direct write is still wanted, could setAndroidGlobalToggle take its write argv from the toggle descriptor instead of a hand-rolled put plus get in the switch case? What would have to change first is a live repro on a device where svc power stayon true leaves the row at 0 or at a value that does not keep the screen on. The 15 -> 15 run in the transcript is not that repro.

Seven threads from the earlier review still apply, and none can be resolved yet: the HarmonyOS evidence, the missing commit SHA, the unbacked restore claim, the CLI-less svc-true section, the read-back never compared and the fake settings get echo. A lower-priority one covers the HarmonyOS error-code assertion.

Before merge, please publish the HarmonyOS live run in docs/evidence/, with the CLI on/off output, a read of the effective override after each, the build and the head SHA. Please also either show a device where svc power stayon true fails, or drop the hand-written mask for the existing toggle read-back.

@thymikee

Copy link
Copy Markdown
Member

Head 124a99e now conflicts with main. Please rebase onto current main and push; the open findings from the earlier review still apply to the rebased head.

strzhao and others added 4 commits November 23, 2026 22:10
…onyOS

`settings keep-awake on|off` covers the screen-hold workaround automation had
to reach for through raw device shells. Android runs `svc power stayon
true|false`, which holds the screen while the device charges. HarmonyOS runs
`power-shell timeout -o 2147483647`, the largest screen-off timeout the tool
accepts, and `off` restores the system timeout with `power-shell timeout -r`.

The setting joins the catalog as a device-level mobile toggle, so a named app
is refused daemon-side with `setting_app_not_consumed`. The Android and
HarmonyOS owners declare the write fact, and so does the Limrun Android leg.

Co-Authored-By: Claude Code <noreply@anthropic.com>
…on refusal

Review follow-up on the keep-awake slice. The help sentence now discloses
persistence: the Android stay-on write survives a reboot, a reboot clears the
HarmonyOS override, and `off` restores the timeout the system setting holds.

`power-shell setmode` spells only the 600-series power modes, so `timeout -o`
is the route that takes the raw 2147483647 millisecond value; the HarmonyOS
comment now records that choice for the next reader.

`keep-awake` joins the daemon `setting_app_not_consumed` parameterized cases,
so the device-level app refusal is pinned at the daemon entry too.

Co-Authored-By: Claude Code <noreply@anthropic.com>
…ack state

svc power stayon true leaves a stored 15 untouched while acking, which a
live Redmi K60 run exposed. The backend writes
stay_on_while_plugged_in directly (7 for on, 0 for off) and returns the
read-back value so the result cannot claim a write the device did not
store. Evidence recorded in docs/evidence/.

Co-Authored-By: Claude Code <noreply@anthropic.com>
…-back

Co-Authored-By: Claude Code <noreply@anthropic.com>
Co-Authored-By: Claude Code <noreply@anthropic.com>
@strzhao

strzhao commented Nov 23, 2026

Copy link
Copy Markdown
Contributor Author

Rebased onto current main (one conflict: the R-series ReasonTable refactor in harmonyos runtime.ts — the PR's keep-awake message kept on the typed reason member). Live runs for both halves are recorded in docs/evidence/android-keep-awake-2026-11-08.md:

Android (head 73d04eb, Redmi 2312DRAABC, Android 14/MIUI) — the repro ask answered from the other side: svc power stayon true on a 0 mask writes 15, and false returns it to 0, so the original lowering works here and the shipped 7 would clobber a 15 a dock had set. Took your suggested redesign: the lowering now rides setAndroidGlobalToggle via a writeArgs descriptor (stayon true|false), the row polls to a state (0 disabled, positive mask enabled), typed keep-awake-not-applied/keep-awake-unreadable reasons on a read-back that did not move or is not a mask, and the result is { keepAwake } only. 281 platform-android tests pass; the catalog help now says off clears the mask and does not restore a user's own.

HarmonyOS (JDY-AL50, 7.0.0.111) — live with the screen state read from hidumper -s DisplayPowerManagerService:

  • baseline: screen off at 198s
  • keep-awake on (timeout -o 2147483647): no screen off through 360s (display dimmed, never 0); a 10s control override off'd at 12s, so -o is honored
  • keep-awake off (timeout -r) does not restore on this unit: after the ack, no screen off in 260s across isolated cycles. The 198s baseline was the untouched system timer — the first -r was a no-op, not a restore.

So the PR's off contract ("off restores the timeout the system setting holds") does not hold after a hold was raised on 7.0.0.111. The unit now sits at an explicit timeout -o 180000 (verified off at 185s). The restore route (a stored pre-override value, or another tool path) is an owner decision — the CLI cannot read the current timeout to snapshot it.

Co-Authored-By: Claude Code noreply@anthropic.com

@thymikee

Copy link
Copy Markdown
Member

Thanks for the update.

Since the earlier review, the Android path is fixed. It now runs svc power stayon and compares the read-back with the request, and the new tests cover keep-awake-not-applied and keep-awake-unreadable. At b2f9bec, HarmonyOS off and the live evidence still need work.

settings keep-awake off --platform harmonyos runs power-shell timeout -r and returns { keepAwake: 'disabled' } with no read-back (settings.ts:22). The live run on the JDY-AL50 (7.0.0.111) in the evidence doc shows -r acks without clearing an active -o 2147483647 override. The screen stayed up past 260s in an isolated cycle and again after a fresh suspend. So on then off leaves the override in place while the CLI says disabled, and a device left on a bench can drain the battery and burn in the screen. The rule is: after off, the system screen-off timeout applies again, and the result states only what a live check showed. Either find a restore route that works on a device (for example an explicit timeout -o <value> the tool can read or snapshot) and prove on, off, then the timer firing at the system value with raw output, or remove HarmonyOS keep-awake from this PR and land Android alone.

The keep-awake help says HarmonyOS "off restores the timeout the system setting holds" (settings-catalog.ts:124). The PR's own evidence shows that is false on the tested unit. The code comment at platform-harmonyos/src/settings.ts:8-9 and the test title at settings.test.ts:46 repeat it. An agent that follows this help trusts off after a hold. Keep the sentence only if a working restore route lands with evidence behind it. Otherwise delete the HarmonyOS clauses from the help, the comment and the test.

The earlier review asked for a HarmonyOS section with device, OS and build, raw settings keep-awake on --platform harmonyos --json output, proof the override is active, the same after off, and the PR head SHA (evidence doc:84). The section is still prose. It has no raw output, no --json transcript, no hidumper transcript and no build string, and it names "head 8643981-era build". 8643981 is not an ancestor of this PR head or of main, so it identifies no build of this PR. The run also predates the last Android commit (73d04eb). Once the restore question is settled, publish a transcript for the final head: device, OS and build, the PR head SHA, raw output of on and off with --json, and an effective-override read after each (hidumper -s 3301 output, or the measured screen-off time against the baseline).

Before merge, the HarmonyOS live run on the final head is required, showing that off returns to the system timeout, or the HarmonyOS half must be removed. The existing run shows off does not restore. Android is proven only through raw adb at 73d04eb, so one CLI run on Android is also welcome.

Of the other open inline threads, this one on the HarmonyOS evidence and this one on the restored mask still stand. The thread on the 73d04eb4a repro and the 86439819-era run also still applies, and one lower-priority thread on the HarmonyOS test assertion still applies. These no longer apply and can be resolved: the echoed-mask fixture (outdated, it belonged to the replaced hand-written put/get), the CLI invocation section (the CLI acks are shown, although for the replaced backend), and the read-back comparison (now compared with the request in awaitAndroidGlobalToggle).

CI shows 15 checks passing and Body rules failing in pnpm gate pr-body with "Add a '## Before / after' section". That gate reads only the PR description, so the failure looks unrelated to the code. The fix is a body edit.

Not blocking, and these can be taken or left: the evidence doc still carries sections of the replaced Android backend (the 15 -> 7 -> 0 run and the read-back stayOnWhilePluggedIn result), and its first section says a svc no-op is why svc was dropped while the newest section says the opposite; the Android run at 73d04eb is raw adb shell, so one settings keep-awake on|off --platform android --json run on the final head would help; the new KEEP_AWAKE_TOGGLE docblock in platform-android/src/settings.ts:327 sits between the mobile-data docblock and MOBILE_DATA_TOGGLE; and the PR body still describes the first head (svc power stayon, power-shell setmode, 12 files, head 14befc1), so it needs a rewrite to the final head with a ## Before / after section of up to 3 calls at base and head.

Not verified here: any device run, the unit tests locally, and the reboot persistence claims in the help. The Android and HarmonyOS transcripts and the claim that timeout -r fails were read from the evidence doc as the author wrote it.

Before merge, HarmonyOS off must restore the system timeout with a raw on/off transcript for the final head, or the HarmonyOS half must go, and the PR body must gain its ## Before / after section so Body rules passes.

…out per review

The maintainer's live review on JDY-AL50 (HarmonyOS 7.0.0.111) proved
power-shell timeout -r acks but does not clear an active -o override, so
harmony off reported disabled while the hold stayed up. No proven restore
route exists and no device is reachable to prove one, so the HarmonyOS half
leaves this PR behind the maintainer's option B; Android lands alone.

settings keep-awake now serves Android only: the harmony owner drops the
keep-awake fact, so a harmony request refuses as unsupported-platform-leaf
through the owner's settings facts before dispatch, and the catalog help
loses its harmony clauses. A future PR may bring the half back behind a
proven restore route recorded in the PR thread.
@strzhao

strzhao commented Nov 23, 2026

Copy link
Copy Markdown
Contributor Author

Taking the review's option B: HarmonyOS keep-awake leaves this PR and Android lands alone. Head abbba3a03 (pushed to forge/keep-awake).

The -r restore defect, for the record (JDY-AL50, HarmonyOS 7.0.0.111, run live at head 86439819-era build, screen state read from hidumper -s DisplayPowerManagerService, State=0 is screen off):

  • Baseline, keep-awake off: wake, then screen off at 198s — the untouched system timer.
  • keep-awake on (timeout -o 2147483647): wake, then no screen off through 360s (the display sits dimmed, State=2, and never reaches 0).
  • A 10-second override confirms -o is honored: screen off at 12s.
  • keep-awake off (timeout -r): the restore fails on this unit. After the ack ("Restore screen off time"), the screen stayed up past 260s in an isolated cycle, and again after a fresh suspend/wake. The 198s baseline was the system timer with no override active — the first -r was a no-op, not a restore.

So timeout -r acks but does not clear an active -o override on 7.0.0.111: off reports disabled while the hold stays up. The unit was left at an explicit timeout -o 180000 (verified: screen off at 185s). The CLI cannot read the current timeout to snapshot it, and no proven restore route exists, so the half moves out here rather than shipping a command that cannot undo itself.

A future PR may bring the HarmonyOS half back behind a proven restore route. The removed evidence section lives on in this thread and in the updated docs/evidence/android-keep-awake-2026-11-08.md note.

@thymikee

Copy link
Copy Markdown
Member

Thanks for the update.

At abbba3a the code looks good. The HarmonyOS keep-awake half and its evidence section are removed, and the Android path now uses the svc power stayon write with a read-back check, so the earlier findings from #4290 (comment) are fixed. The checks show 17 of 17 passing at this commit, and there are no conflicts. Nothing in the code blocks merge.

Not blocking: the PR title and the evidence doc intro at docs/evidence/android-keep-awake-2026-11-08.md:3 still say "Android and HarmonyOS", and the squash subject would carry that. They can be taken or left, but retitling to "feat(settings): keep-awake on and off on Android" and saying "Android" in the doc intro would match the code.

Of the open inline threads, the one on the restored mask value in the evidence doc (#4290 (comment)) still stands as hygiene only. These threads no longer apply and can be resolved: the HarmonyOS invalid-state test, because the test was deleted with the branch (#4290 (comment)); the HarmonyOS live-transcript ask, because that half is removed (#4290 (comment)); the repro head pin (#4290 (comment)) and the CLI acks (#4290 (comment)), because the Android on/off proof is pinned and the older section documents the replaced backend; the echoed-mask fixture (#4290 (comment)), because the new svc tests cover write, read-back, not-applied and unreadable; and the read-back comparison (#4290 (comment)), because it is unchanged and was already confirmed.

Not verified here: no HarmonyOS or Android device was used, and the device timings and runs were read from the evidence doc and the author comment. The 1566-test claim was not re-run locally. The Android live proof at the final lowering is raw adb at 73d04eb (0 -> 15 -> 0); the CLI run in the doc is from the replaced backend, which was already called welcome but not required.

@strzhao

strzhao commented Nov 23, 2026

Copy link
Copy Markdown
Contributor Author

Route-hunt closure on the live unit (JDY-AL50, HarmonyOS 7.0.0.111), for the record: no shell-readable timeout source and no working restore primitive exist on this build.

  • settings is not present in the shell (/bin/sh: settings: inaccessible or not found), so the "explicit timeout -o <value> the tool can read" route has no read source.
  • power-shell timeout offers only -o / -r, no query form; -r is the already-recorded no-op against an active override (measured: hold persisted, screen up past 260 s in the earlier runs, re-confirmed State=2 in today's controlled cycle).
  • hidumper -s PowerManagerService advertises -f: restore screen off time in its dump help, but the shell parser rejects every invocation (hidumper: option pid missed. f — tried bare, with the powermgr pid, with pid 0). The debug hook is unreachable from the shell surface.

So the HarmonyOS half stays out of this PR until one of those surfaces changes (an OS update fixing -r, or a system-level restore path). The unit is left as found, at an explicit timeout -o 180000 (verified applied).

@thymikee

Copy link
Copy Markdown
Member

Thanks for closing the HarmonyOS route hunt. With no readable timeout source and no restore primitive on that build, dropping HarmonyOS keep-awake from this PR is the right scope, and the review at abbba3a found no blocking issue in the Android path. The remaining note is optional: a title that says Android only would match what ships.

@strzhao strzhao changed the title feat(settings): keep-awake on and off across android and harmonyos feat(settings): keep-awake on and off on android Nov 23, 2026
@strzhao strzhao changed the title feat(settings): keep-awake on and off on android feat(settings): keep-awake on and off on Android Nov 24, 2026
…ce intro

The PR title and the shipped backend are Android-only after the HarmonyOS
half moved out; the evidence intro still said "across Android and
HarmonyOS". The HarmonyOS note stays as the recorded restore-route finding.
@thymikee

Copy link
Copy Markdown
Member

Thanks for the update. At dd45e0f the delta is a one-line docs change, and the code still has no blocking issue from the earlier review (#4290 (comment)).

The live evidence is satisfied. The shipped svc-toggle lowering is covered live only by the raw-adb 0/15/0 repro, and the CLI read-back run comes from an earlier backend. Not verified here: the unit and integration tests were not run locally, no Android device was run, and svc power stayon on Limrun Android was not checked (it shares the mobile-data facts path, which was accepted at abbba3a).

Of the other open threads, none is a high-priority one that still applies, and none of the lower-priority ones apply. Please resolve these. The Harmony test thread targets a file no longer in the diff (#4290 (comment)). The restore-transcript thread asks about a backend that no longer ships, so it does not affect the shipped behavior (#4290 (comment)). The next four are fixed or moot: the not-applied and unreadable tests (#4290 (comment)), the pinned head SHA in the evidence file (#4290 (comment)), the HarmonyOS transcript, which moved out (#4290 (comment)), the CLI invocation shown in the evidence file (#4290 (comment)), and the read-back that now settles before reporting (#4290 (comment)).

The Smoke Tests (ios) and Smoke Tests (macos) jobs passed, and they do not overlap with this Android-only diff. One Smoke Tests job was still pending at review time. No conflicts are known, and the PR is ready once that job finishes.

@thymikee thymikee added the ready-for-human Valid work that needs human implementation, judgment, or maintainer merge label Nov 24, 2026
@thymikee
thymikee merged commit 63fe1b6 into callstack:main Nov 24, 2026
16 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ready-for-human Valid work that needs human implementation, judgment, or maintainer merge

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants