Uh oh!
There was an error while loading. Please reload this page.
fix(cli): avoid panic on multi-byte UTF-8 in --since duration - #2446
Conversation
parse_duration_to_ms was moved to commands/common.rs since the original PR was opened, but it still split the last byte of the input with split_at(s.len() - 1), which panics when the final character is multi-byte UTF-8 (e.g. 'openshell logs my-sandbox --since 5€'). Split off the last character using its UTF-8 length instead, so invalid units surface the intended 'unknown duration unit' error. Add regression tests in commands/common.rs. Signed-off-by: Andrew White <andrewh@cdw.com>
All contributors have signed the DCO ✍️ ✅ |
andrewwhitecdw
commented
Jul 23, 2026
I have read the DCO document and I hereby sign the DCO. |
johntmyers
left a comment
There was a problem hiding this comment.
gator-agent
PR Review Status
Validation: This is a project-valid, concentrated CLI bug fix that prevents openshell logs --since from panicking on a multi-byte UTF-8 unit. It supersedes #2406, which was closed only by the earlier vouch gate.
Head SHA: 5b038779924ad59313f71d6cfafe1f7d40ee1c1f
Review findings:
- No blocking or actionable findings remain. The UTF-8 boundary calculation is correct and the regression tests cover both
5€and a multi-byte-only input.
Docs: Not needed because this preserves the documented CLI contract and replaces a crash with the intended validation error.
E2E: Not required for this isolated duration-parser fix; no sandbox lifecycle, gateway, policy, network, credential, driver, GPU, Kubernetes, or packaging behavior changes.
Next state: gator:watch-pipeline
johntmyers
commented
Jul 24, 2026
/ok to test 5b03877 |
elezar
left a comment
There was a problem hiding this comment.
As a general question, instead of fixing this here, would replacing the parsing with an exernal crate that explicitly parses to std::time::Duration here be better?
andrewwhitecdw
commented
Jul 28, 2026
Good question. The current parser intentionally accepts a small, |
andrewwhitecdw
commented
Jul 29, 2026
@elezar thanks for the question — I replied above. The current change keeps the existing kubectl-compatible unit set and only fixes the multi-byte panic, so switching crates is probably best left to a follow-up if you want to widen the accepted syntax. Could a maintainer re-trigger the cancelled CI gate when convenient? The code itself should be ready for another /ok-to-test pass. |
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
johntmyers
commented
Jul 29, 2026
Monitoring CompleteMonitoring is complete because this PR has merged. Final status: The concentrated CLI panic fix was reviewed with no blocking findings at head I removed the active |
Summary
openshell logs <name> --since <duration>panics when the duration's last character is multi-byte UTF-8 (e.g.--since 5€).parse_duration_to_mssplit the input withsplit_at(s.len() - 1), indexing by byte length, which is not a char boundary for multi-byte characters. The CLI now returns the intended "unknown duration unit" error instead of crashing.This PR supersedes #2406, which was auto-closed by the vouch-check workflow before I was vouched.
Related Issue
N/A — small fix found during code review (panic verified with a standalone repro:
"5€".split_at(3)→byte index 3 is not a char boundary).Changes
parse_duration_to_ms(now incommands/common.rs) splits off the last character using its UTF-8 length (char::len_utf8) instead of assuming a single bytecommands/common.rsfor valid units and multi-byte inputTesting
mise run pre-commitpasses (mise unavailable in this environment; ran equivalentcargo fmt+cargo clippy -p openshell-cli --all-targets— clean)cargo test -p openshell-cli parse_duration_to_ms— 2 passed)Checklist