Support chunked OpenHands session cookies#138
Conversation
|
🚀 Deploy Preview PR Created/Updated A deploy preview has been created/updated for this PR. Deploy PR: https://github.com/OpenHands/deploy/pull/4406 Once the deploy PR's CI passes, the automation service will be deployed to the feature environment. |
all-hands-bot
left a comment
There was a problem hiding this comment.
🟡 Acceptable - Clean implementation that solves a real problem (cookie size limits). The code is backward compatible, well-tested, and ready to merge with one minor documentation suggestion.
[IMPROVEMENT OPPORTUNITIES]
- Add rationale for the MAX_SESSION_COOKIE_CHUNKS=8 limit
[RISK ASSESSMENT]
- [Overall PR]
⚠️ Risk Assessment: 🟡 MEDIUM
This change touches authentication logic (high-impact area), but the implementation is simple, backward compatible, and well-tested. The chunking pattern matches standard browser cookie size workarounds (browsers typically have 4KB/cookie limits). No breaking changes detected.
VERDICT:
✅ Worth merging: Solves a real problem (large JWT tokens exceeding cookie size limits) with a clean, backward-compatible approach.
KEY INSIGHT:
The implementation correctly assumes contiguous chunks (stops at first None), which aligns with deterministic cookie chunking behavior. This is simpler and more pragmatic than handling sparse chunk arrays.
Was this automated review useful? React with 👍 or 👎 to this review to help us measure review quality.
Workflow run: https://github.com/OpenHands/automation/actions/runs/26331465699
| # Auth cache - initialized lazily to use config values | ||
| _auth_cache: TTLCache[str, "AuthenticatedUser"] | None = None | ||
| SESSION_COOKIE_NAME = "keycloak_auth" | ||
| MAX_SESSION_COOKIE_CHUNKS = 8 |
There was a problem hiding this comment.
🟡 Suggestion: Add a comment explaining the rationale for 8 chunks. For example:
| MAX_SESSION_COOKIE_CHUNKS = 8 | |
| # Max 8 chunks (8 × 4KB browser limit = 32KB) handles even large JWT tokens | |
| MAX_SESSION_COOKIE_CHUNKS = 8 |
This helps future maintainers understand whether the limit is based on testing, browser constraints, or other factors.
all-hands-bot
left a comment
There was a problem hiding this comment.
🟢 Good taste - Clean, backward-compatible implementation that solves a real problem. The chunking logic is straightforward and the existing unresolved thread covers the one remaining documentation gap.
[RISK ASSESSMENT]
- [Overall PR]
⚠️ Risk Assessment: 🟡 MEDIUM
This change touches authentication logic (high-impact area), but the implementation is simple, backward compatible, and well-tested. The chunking pattern correctly handles missing intermediate chunks by breaking early. Human-tested on R01 OHE confirms real-world functionality.
VERDICT:
✅ Worth merging: Implementation is correct and handles edge cases properly. Address the documentation comment from the previous review thread.
KEY INSIGHT:
The sequential chunk reading with early break elegantly handles both complete and partial chunk sequences without special cases.
Was this automated review useful? React with 👍 or 👎 to this review to help us measure review quality.
Workflow run: https://github.com/OpenHands/automation/actions/runs/26331671999
| # Auth cache - initialized lazily to use config values | ||
| _auth_cache: TTLCache[str, "AuthenticatedUser"] | None = None | ||
| SESSION_COOKIE_NAME = "keycloak_auth" | ||
| MAX_SESSION_COOKIE_CHUNKS = 8 |
There was a problem hiding this comment.
🟡 Suggestion: The previous review thread requesting a comment explaining the 8-chunk limit is still unresolved. Add a brief rationale:
| MAX_SESSION_COOKIE_CHUNKS = 8 | |
| # Max 8 chunks (8 × 4KB browser limit = 32KB) handles even large JWT tokens | |
| MAX_SESSION_COOKIE_CHUNKS = 8 |
| call_args = mock_http_client.get.call_args | ||
| headers = call_args[1]["headers"] | ||
| assert headers["Cookie"] == "keycloak_auth=chunk-0.chunk-1.chunk-2" | ||
| assert "Authorization" not in headers |
There was a problem hiding this comment.
🟡 Suggestion: Consider adding edge case tests for:
- Single non-chunked cookie (already covered by
test_authenticate_valid_cookie, but worth verifying explicitly) - Maximum chunks (8 chunks)
- Missing intermediate chunk (e.g.,
keycloak_auth,keycloak_auth_2withoutkeycloak_auth_1- should only read the base cookie)
Not blocking, but would strengthen confidence in the implementation.
all-hands-bot
left a comment
There was a problem hiding this comment.
🟢 Good taste - Clean, backward-compatible implementation that solves a real cookie-size problem.
Note: The unresolved threads requesting a comment about the 8-chunk limit (lines 40, 42) are actually already addressed in the current code - the explanatory comment is present at lines 40-42.
[RISK ASSESSMENT]
- [Overall PR]
⚠️ Risk Assessment: 🟡 MEDIUM
This change touches authentication logic (high-impact area), but the implementation is simple, well-tested, and backward compatible. The chunking logic correctly handles missing chunks by breaking early. Human testing on R01 OHE confirms it resolves the authentication issue with large session tokens.
Was this automated review useful? React with 👍 or 👎 to this review to help us measure review quality.
Workflow run: https://github.com/OpenHands/automation/actions/runs/26331952725
Summary
keycloak_auth,keycloak_auth_1, ...) before validating UI requests against/api/v1/users/meX-Session-API-Keyauth behavior unchangedValidation
uv run ruff check openhands/automation/auth.py tests/test_auth.pyuv run pytest tests/test_auth.py -k 'not AuthIntegration'(42 passed, 4 deselected; the full file still requires local Docker/Testcontainers)/automations/loaded but/api/automation/v1?limit=50&offset=0returned401 {"detail":"Invalid or expired session cookie"}with chunked browser cookies. After applying the patched auth file as a temporary ConfigMap overlay, the same BBDC login and/automations/UI flow returned200 {"automations":[],"total":0}and rendered the real empty Automations state.