Skip to content

Port upstream 0.66.0: iterate Manus browser sessions with env fallback - #635

Closed
Finesssee wants to merge 1 commit into
port/upstream-0.66.0from
port/micro-0.66.0-manus-session-iteration
Closed

Finesssee wants to merge 1 commit into
port/upstream-0.66.0from
port/micro-0.66.0-manus-session-iteration

Conversation

@Finesssee

Copy link
Copy Markdown
Collaborator

Summary

Manus now tries every browser session instead of one merged header, and falls back to environment credentials. A rejected session (HTTP 401/403) moves on to the next candidate rather than ending the refresh.

  • Per-candidate retry over providers::browser_cookie_headers_for_domain("manus.im"), modeled on replicate/mod.rs fetch_browser_cookie. Tokens already tried are skipped. A non-auth failure (5xx, bad JSON, missing credit fields) is final, as upstream.
  • Environment fallback after the browser candidates: MANUS_SESSION_TOKEN, then MANUS_SESSION_ID, then a MANUS_COOKIE header. It is never used when a manual/token-account header is supplied, and a Manual cookie source with nothing stored fails closed (ManualEmptyCookiePolicy::FailClosedWeb, owns_browser_cookie_resolution, the Replicate shape) instead of importing a browser account or reading the environment.
  • Tolerant session_id extraction: session_token() used split_once('=')? inside the loop, so one chunk without = aborted the whole scan. It now skips such chunks. Candidates that cannot form a bearer header value are skipped so they cannot abort the scan at request-build time.
  • Required credit-key presence: the payload (first non-null of data/result/response/availableCredits, else the root) must be an object with at least one of the eight credit keys, else a parse failure.
  • Lenient numbers as upstream (number or numeric string, else 0, non-finite is 0).
  • Legacy numeric nextRefreshTime adds 978307200 (2001 reference epoch); ISO-8601 strings are used as is. Before this change a numeric value failed deserialization of the whole payload.

Upstream reference

Ported / Deferred

Ported: all cases of ManusCookieHeaderTests (4) and ManusPluginTests (rejected candidates advance before env fallback with the duplicate skipped, manual never uses env after rejection, off never sends a request, sparse credits with numeric date), plus local cases for malformed chunks, env precedence and cleaning, non-auth failure stopping iteration, and browser read failure still reaching env.

Deferred (no behavior change, cosmetic or outside the requested scope): lane mapping stays as is (extra add-on and event windows, a credits available primary when proMonthlyCredits is 0 where upstream omits the primary, the reset text format); upstream's Chrome User-Agent request header is not sent. off needs no code: the shell maps it to SourceMode::Cli, which Manus rejects before any request or env read (covered by a test).

Validation

Run on Rust 1.98.0 with a process-local target dir (pwsh was refused in this worktree, so CARGO_TARGET_DIR was set outside every worktree).

  • cargo +1.98.0 fmt --all: clean
  • cargo +1.98.0 clippy --workspace --all-targets -- -D warnings: pass
  • cargo +1.98.0 test -p codexbar manus: 23 passed, 0 failed
  • cargo +1.98.0 test -p codexbar-desktop-tauri fetch_context: 28 passed, 0 failed (shell context building, unchanged code)

The full cargo test -p codexbar was not run: no shared code changed (core, settings, spend).

Affected areas

  • Provider-specific behavior
  • Tray panel / Settings UI / CLI / packaging (not touched)

UI proof

Not applicable. No frontend, tray, settings, or float-bar change.

Retry each browser session on rejection, fall back to MANUS_SESSION_TOKEN / MANUS_SESSION_ID / MANUS_COOKIE unless the cookie source is Manual, tolerate malformed cookie chunks, require a credit key, and apply the 2001 reference-epoch offset to numeric reset dates.
@coderabbitai

coderabbitai Bot commented Sep 29, 2026

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Advanced

Run ID: cbb44e91-bb13-422b-8c7d-d850172b256f

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review

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

Comment @coderabbitai help to get the list of available commands.

@Finesssee

Copy link
Copy Markdown
Collaborator Author

Port review: Manus browser-session iteration with env fallback (#635, GAP row 28e)

Reviewed the branch diff 08170519 vs port/upstream-0.66.0 against the 0.66.0 manifest spec for row 28e (upstream manus.js + ManusSettingsReader), plus the PR body.

What I checked:

  • Per-candidate iteration: tokens from providers::browser_cookie_headers_for_domain("manus.im") are tried one at a time via try_candidate; a 401/403 (AuthRequired) marks the attempt rejected and moves to the next candidate; a non-auth failure (5xx, bad JSON, missing credit fields) is final, as upstream. Tokens already tried are skipped via a HashSet, and chunks without = no longer abort the whole session_token scan (the split_once early-exit bug is fixed).
  • Environment fallback: after the browser candidates, in upstream ManusSettingsReader order — MANUS_SESSION_TOKEN, then MANUS_SESSION_ID, then a full header from MANUS_COOKIE. Never used when a manual/token-account header is supplied; a Manual cookie source with nothing stored fails closed (ManualEmptyCookiePolicy::FailClosedWeb + owns_browser_cookie_resolution, the Replicate shape) instead of importing a browser account or reading the environment.
  • Request shape: POST https://api.manus.im/user.v1.UserService/GetAvailableCredits, body {}, Authorization: Bearer <session_id>, Accept: application/json, Content-Type: application/json — matches upstream. Tokens that cannot form a bearer header value are skipped rather than aborting at request-build time.
  • Payload gate: the credits payload (first non-null of data/result/response/availableCredits, else the root) must be an object carrying at least one of the eight credit keys, else a parse failure — the spec's required-credit-key-presence rule.
  • Lenient fields: numbers may be JSON numbers or numeric strings (non-finite → 0); next_refresh_time accepts a legacy numeric Foundation reference-date offset (2001 epoch, 978307200 s) or an ISO-8601 string; any other shape means no reset — matching the upstream number()/legacy-date behavior in the manifest.
  • Tests: tests.rs (449 new lines) covers candidate ordering, rejection-continues, env-fallback ordering and manual exclusivity, the credit-key gate, lenient number/date parsing and the dedup/skip behavior.

Result: no findings. Fail-open iteration, terminal non-auth failures, env-fallback order and fail-closed manual policy all match the spec. Files under the cap (mod.rs ~301 delta, tests 449). No dependency, locale, bridge or frontend change.

@Finesssee

Copy link
Copy Markdown
Collaborator Author

Shipped in v0.70.0: this PR's head is included in main via #735 (merge commit 9d0a37a). Closing as integrated.

@Finesssee Finesssee closed this Oct 3, 2026
junglesub-bot Bot pushed a commit to junglesub/Win-CodexBar that referenced this pull request Oct 4, 2026
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