Conversation
fix(skills): keep HAR capture usable after a bad action — flushes a partial HAR on action failure, extracts shared action parsing to
|
Author
|
I rechecked this PR after the refactor. The remaining failed check is the amd64 Docker build in run 31674658945. I attempted to rerun the failed job, but GitHub returned HTTP 403: repository admin rights are required. Could a maintainer rerun that failed job? I have left the code unchanged because the reviewed failure is in CI infrastructure. |
Failed --action specs IndexError and skip context.close(), so the HAR never lands. CDP attach drives pages[0] (and --goto navigates it), and derivation drops form params and base64 response bodies. Share a validated run_action helper (bad specs fail with a clear ValueError, including empty selectors), flush the Playwright HAR in finally, listen on every CDP context, and open a new tab for --goto so it cannot wipe the tab Hermes is driving. In-flight requests left after --wait are flushed as entries with a null response, after detaching the listeners. Calling the waiting request.response() there could hang the capture (no timeout) or record a late response twice. har_to_client now reads params-only postData and decodes base64 content. Does not change header redaction, scheme printing, or CDP queryString (NousResearch#85053). Null postData is handled by the new body helper, which supersedes NousResearch#84977.
Adolanium
force-pushed
the
fix/har-derived-capture-and-derive
branch
from
October 1, 2026 11:51
f371e8c to
c6b4bcd
Compare
Author
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What does this PR do?
Fixes the capture and derivation bugs in the
har-derived-api-clientskill described in #85099:--actionno longer costs you the capture. Both capture scripts share one validatedrun_action(newscripts/har_actions.py). Malformed specs (fill:onlysel, bareclick,sleep:, empty selectors) fail with aValueErrornaming the expected shape instead ofIndexError. Local capture closes the context in afinally, so Playwright flushes the HAR even when an action fails, and the error still propagates, so there's no false "HAR written" on a run that produced nothing.contexts[0].pages[0],--gotoopens a new tab, and actions run on that same tab.--wait. Leftovers are written as entries with a null response, after the listeners detach. The flush deliberately never calls Playwright'srequest.response(): it blocks with no timeout until a response arrives (long-poll or a stuck XHR would hang the capture), and a response arriving mid-flush would be recorded twice since the response event also appends an entry.request_body_sample()handles params-only urlencoded postData, andresponse_body_text()decodesencoding: "base64"content so{"ok":true}prints as JSON, noteyJvayI6dHJ1ZX0=. The same helper treatspostData: nullas empty (it has to, to reachparamsat all), which supersedes fix(har-derived-api-client): handle postData: null in HAR entries #84977.read_text()the scripts and regexed for call sites are replaced with behavioral ones: real HAR fixtures throughhar_to_client.main(), and fake page/context/request objects for the action and CDP helpers. The flush test assertsresponse()is never called so the hang can't quietly come back.Deliberately untouched: header redaction, the printed scheme, and CDP
queryString. Those belong to #85053, which edits the same grouping loop, so whichever of the two lands second gets a small rebase.Related Issue
Fixes #85099
Type of Change
Changes Made
optional-skills/web-development/har-derived-api-client/scripts/har_actions.py: new shared helper withparse_action/run_action(validated specs),choose_drive_page(new-tab policy for CDP--goto), andflush_pending(null-response entries, no waiting calls)optional-skills/web-development/har-derived-api-client/scripts/har_capture.py:context.close()in afinallyso a failed action still flushes the HARoptional-skills/web-development/har-derived-api-client/scripts/har_capture_cdp.py: context-level listeners on every context,--gotoopens a new tab, detach-then-flush in afinally, the drive error re-raised after the HAR is writtenoptional-skills/web-development/har-derived-api-client/scripts/har_to_client.py:request_body_sample()(params + null postData) andresponse_body_text()(base64 decode)optional-skills/web-development/har-derived-api-client/SKILL.md: pitfalls now say a failed action writes a partial HAR and that CDP--gotoopens a new tabtests/skills/test_har_derived_api_client_skill.py: behavioral tests replacing the source-text assertionsHow to Test
scripts/run_tests.sh tests/skills/test_har_derived_api_client_skill.py -q(11 pass, stdlib + pytest only, no network, no playwright needed)python3 optional-skills/web-development/har-derived-api-client/scripts/har_capture.py https://example.com out.har --action "fill:#q"fails withValueError: fill needs fill:SELECTOR:TEXTandout.harstill contains the page-load traffic (before this PR:IndexErrorand no file)--remote-debugging-port=9222, open a page in the existing tab, thenpython3 .../har_capture_cdp.py http://127.0.0.1:9222 out.har --goto https://example.com. The original tab is untouched and the HAR contains the new tab's requestsChecklist
Code
fix(scope):,feat(scope):, etc.)pytest tests/ -qand all tests passDocumentation & Housekeeping
docs/, docstrings) — or N/Acli-config.yaml.exampleif I added/changed config keys — or N/ACONTRIBUTING.mdorAGENTS.mdif I changed architecture or workflows — or N/AScreenshots / Logs
Ruff is clean on the changed files. Overlap notes: #84977's null-postData case is covered here by
request_body_sample(), and #85053's redaction/scheme/queryString lines are untouched.