Skip to content

fix(revyl): bind uploads to admitted job destinations - #5337

Open
thymikee wants to merge 7 commits into
0.22from
t3/revyl-upload-admission
Open

thymikee wants to merge 7 commits into
0.22from
t3/revyl-upload-admission

Conversation

@thymikee

@thymikee thymikee commented Dec 2, 2026 •

Copy link
Copy Markdown
Member

Summary

The build uploads only to an HTTPS URL from the Revyl API that resolves to a public address, over a connection to that approved address. Private, loopback and link-local hosts are refused, redirects are refused, and the Revyl bearer token is never attached. website/docs/docs/revyl.md notes that a backend returning private storage URLs cannot install local builds.

Before / after

Before: the upload URL went straight to fetch, so an internal host could receive the build.
After: uploadRevylArtifact requires https: and approves the URL with approveDownloadSourceUrl. It sends a PUT with https.request and agent: false, using a lookup pinned to the approved address. The URL host still sets SNI, certificate checks and Host. No pooled socket or proxy agent can skip the pin.
A request error at any time fails the upload. The body is exactly the stat'ed size. An empty or shortened file fails with revyl_upload_unreachable.
Reasons: revyl_upload_destination_refused, revyl_upload_rejected (with status), revyl_upload_unreachable.

Validation

Tested at 4835963: artifact-upload.test.ts 15 passed, provider-revyl tests 46 passed, hosted CI green. Removing the late error listener or the byte check fails its test.
Production delta versus 0.22: about +82 lines.
Risk: no live Revyl run yet; connect returns HTTP 401 "Invalid API key" with the available key. A live install receipt follows once a working key is available.

@apex-sentinel-staging

This comment has been minimized.

@apex-sentinel-staging apex-sentinel-staging Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Apex Sentinel: 2 new findings on 0996eea. The verdict and the full list are in the summary comment.

@github-actions

github-actions Bot commented Dec 2, 2026 •

Copy link
Copy Markdown
Contributor

Size Report

Metric Base Current Diff
Installed (including dependencies) 5.29 MB 5.29 MB 0 B
Package (unpacked) 5.28 MB 5.28 MB 0 B
Package (download) 1.62 MB 1.62 MB -1 B

Startup median (7 runs, lower is better):

Scenario Base Current Diff
CLI --version 14.7 ms 15.0 ms +0.3 ms
CLI --help 25.7 ms 27.2 ms +1.5 ms

Affected plugins

Plugin Installed (including dependencies) Unpacked Download
@agent-device/revyl 187.7 kB → 203.8 kB (+16.1 kB) 187.3 kB → 203.4 kB (+16.1 kB) 60.7 kB → 65.4 kB (+4.7 kB)

@blacksmith-sh

This comment has been minimized.

@apex-sentinel-staging

This comment has been minimized.

@apex-sentinel-staging apex-sentinel-staging Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Apex Sentinel: 1 new finding on 9fee0bd. The verdict and the full list are in the summary comment.

@blacksmith-sh

This comment has been minimized.

@apex-sentinel-staging

This comment has been minimized.

@apex-sentinel-staging

This comment has been minimized.

@apex-sentinel-staging

This comment has been minimized.

@thymikee

thymikee commented Dec 3, 2026

Copy link
Copy Markdown
Member Author

The code at 6140203 has one gap: the Revyl install path has no live run yet. CI is green, with 18 checks passing at this head, and no conflicts are known.

The Revyl install route (deployRevylApp, then uploadSessionArtifact) now sends the build through a hand-rolled pinned http.request PUT in artifact-upload.ts:36. The request uses connection: close, an explicit host header and Content-Length over a streamed pipeline. The tests mock requestApprovedUrl or use local servers, and the PR body says no live provider ran. App install on a rented device is an app-lifecycle path, so a rejected presigned request would break installs. For example, the signature may cover the host header, or storage may reject the unchunked body or the early close. Before merge, please run one live agent-device install <app> <local build> against a Revyl session at this head or later. Use one Android .apk or one iOS .app. Post the SHA, the platform and the command output that shows the upload finished and the installed identity came back. One blocked-destination refusal would help too, if it is practical.

Not blocking, and fine to take or leave: when storage answers a large PUT early with 403 and closes the connection, the pipeline in install-source-network-transport.ts:87 can reject with EPIPE or ECONNRESET, so users see revyl_upload_unreachable without the HTTP status that fetch gave on base, and a non-2xx status that already arrived could win over the pipe error; the daemon-harness diagnostics in daemon-harness.ts:48 duplicate #5335 and could land once there; the plugin now pulls in ipaddr.js, socks and the proxy and TLS transport, so a size receipt for this head would help, and could the host supply the pinned transport through an existing runtime capability instead of bundling it; and the module mocks in revyl-client.test.ts apply to the whole file, so the upload tests could move to an artifact-upload.test.ts.

The three earlier inline threads are fixed at this head and can be resolved: the upload now goes through admission and the pinned transport (#5337 (comment)), admission now comes before the source open (#5337 (comment)), and the early-response race is fixed in fe48b74 (#5337 (comment)).

Not verified here: tests were not run, the early-response behavior against real S3 or GCS presigned storage, and the plugin size at this head.

@thymikee
thymikee force-pushed the t3/revyl-upload-admission branch from 6140203 to f6b02b1 Compare December 3, 2026 07:30
@blacksmith-sh

This comment has been minimized.

@apex-sentinel-staging

This comment has been minimized.

@apex-sentinel-staging apex-sentinel-staging Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Apex Sentinel: 1 new finding on f6b02b1. The verdict and the full list are in the summary comment.

@apex-sentinel-staging

This comment has been minimized.

@apex-sentinel-staging apex-sentinel-staging Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Apex Sentinel: 1 new finding and 1 moved to a new line on c5463c2. The verdict and the full list are in the summary comment.

@apex-sentinel-staging

This comment has been minimized.

@blacksmith-sh

This comment has been minimized.

@apex-sentinel-staging

This comment has been minimized.

@apex-sentinel-staging apex-sentinel-staging Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Apex Sentinel: 2 new findings on c24a114. The verdict and the full list are in the summary comment.

@apex-sentinel-staging

This comment has been minimized.

@thymikee
thymikee marked this pull request as ready for review December 3, 2026 10:58

@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 8 files

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

View guided diff | Turn on auto-fix | Re-trigger cubic

@thymikee

thymikee commented Dec 3, 2026

Copy link
Copy Markdown
Member Author

At 8ca32a6 the earlier findings (#5337 (comment)) are fixed in code: the reason comments, the early-200 settle rule and the non-2xx status handling now match, and a redirect is rejected. The new PUT transport still has five problems, and the live install it needs is still missing. All 27 checks pass at this head. No conflicts.

The install route (deployRevylApp -> uploadSessionArtifact -> uploadRevylArtifact) now sends a hand-built https.request PUT with a pinned lookup and a streamed Content-Length body (artifact-upload.ts:44). Every test stubs https.request or redirects it to a plain-HTTP fixture, so no real presigned storage has accepted this request shape. If S3 or GCS rejects it, every local-build install on a rented Revyl device fails, and CI cannot show that. Before merge, please post one live agent-device install <app> <local build> against a Revyl session at 8ca32a6 or later (one Android .apk or one iOS simulator .app). Include the SHA, the platform, and output showing the upload finished and the installed identity came back. Not verified here: behavior against real presigned storage (Host-signed headers, Content-Length streaming, early close).

A second independent pass found that the default HTTPS agent can bypass the pinned lookup when Node environment proxying is on (artifact-upload.ts:44). The proxy receives a CONNECT for the hostname and picks the destination itself. If it resolves the name to private storage with a valid certificate, that storage gets the build and the signed upload query. The previous transport sent CONNECT to the approved numeric address. Please use a fresh direct HTTPS connection for this request, such as agent: false, with the existing pinned lookup. If the upload must go through a proxy, tunnel to the approved numeric address and keep the hostname for TLS and Host.

A second independent pass found a related gap at artifact-upload.ts:50. Two jobs can receive URLs on the same storage origin. The default agent pools by origin, so the second upload can reuse the first job's socket and skip the second lookup. The build then goes to the previous job's address, not the one admitted for this job. Disabling shared-agent reuse for the upload, for example with agent: false, makes every request dial its own admitted address.

A second independent pass found that a request error after the body finishes is lost (artifact-upload.ts:72). If storage closes the connection, or the caller cancels, after the PUT is written and before response headers arrive, the ClientRequest error comes after the pipeline callback. Nothing passes it to fail, so the promise never settles. The previous transport and base fetch both rejected here. On the install route the 420 s budget in deployment.ts:96 eventually aborts it, so the user waits about seven minutes. Please register an error listener on the ClientRequest that calls fail for its whole lifetime, including after the body pipeline ends.

A second independent pass found that the upload can stream more bytes than the ticket issued (artifact-upload.ts:72). Deployment sizes the file at deployment.ts:89 and uses that size in the ticket request. If a build process appends to the file while the ticket request waits, the new transport streams to EOF under the old Content-Length with no length check, and a 2xx can advance the worker install. Base fetch enforced the declared length. Please make the source stream enforce the ticket's exact byte count, including zero bytes and early EOF, and fail before sending anything beyond it.

The open inline thread on the lost request error at artifact-upload.ts:72 still stands (#5337 (comment)), and it is the same fix as above. Two lower-priority threads still apply, both on test strength: the fixture dropping url.search and the upload test never asserting the forwarded signal. The threads on the reason comments (#5337 (comment)), the early-200 settle (#5337 (comment)), the non-2xx status (#5337 (comment)) and the file-size race (#5337 (comment)) no longer apply and can be resolved. The first three are fixed at this head. The last is a benign race, since deployment.ts:89 stats the packed build right before the upload and keeps the fs error as the cause.

Tests were not run here. CI is green at this head. Before merge, the live Revyl install above is still required, and the five transport fixes above need to land.

@thymikee

thymikee commented Dec 3, 2026

Copy link
Copy Markdown
Member Author

Live Revyl install attempt at 76541ff (Android, branch CLI after pnpm build, plugin packed from packages/provider-revyl and added with plugins add <tgz> into a clean AGENT_DEVICE_HOME and state dir).

Result: not verified. connect fails authentication, so no device was rented and the upload path did not run. I ran it twice with the same result.

$ agent-device connect revyl --platform android
Error (UNAUTHORIZED): Revyl request GET /api/v1/entity/users/get_user_uuid failed with HTTP 401: Invalid API key. Next: Refresh daemon metadata and retry the command.

$ agent-device install com.callstack.agentdevice.snapshothelper android/snapshot-helper/dist/agent-device-android-snapshot-helper-0.21.24.apk
Error (INVALID_ARGS): install requires an active session or an explicit device selector (e.g. --platform ios). Not dispatched.

$ agent-device disconnect
No remote connection for "pr5337-live".

The key was REVYL_PARTNER_API_KEY from the maintainer .env, exported as REVYL_API_KEY, with no REVYL_API_URL override. The live install needs a valid Revyl key before it can run.

@thymikee
thymikee force-pushed the t3/revyl-upload-admission branch from 76541ff to 4835963 Compare December 3, 2026 11:30
@apex-sentinel-staging

Copy link
Copy Markdown

Apex Sentinel · ✅ Approve · review of 4835963

Since the review of 8ca32a6: 2 new · 0 still open · 0 no longer raised

2 finding(s): 2 minor.

🟡 Minor (2)

Where Finding
packages/provider-revyl/src/revyl-client.ts:364 🆕 Injected fetch no longer covers the artifact upload path
packages/provider-revyl/src/artifact-upload.ts:41 🆕 An empty build is reported as storage refusing an upload that was never sent

Reviewed with this repository's own Sentinel configuration (64dd30eae755).

💬 Talking to Sentinel

In a finding's thread, reply with:

Command What it does
@apex-sentinel-staging note <context> Adds context; Sentinel re-checks the cited code
@apex-sentinel-staging pivot <why> Says the finding is wrong; Sentinel re-checks the cited code
@apex-sentinel-staging like Marks the finding as useful
@apex-sentinel-staging dislike <why> Marks it as not useful, so it is not raised again

On this conversation, comment @apex-sentinel-staging review to run a full review once again.

@apex-sentinel-staging apex-sentinel-staging Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Apex Sentinel: 2 new findings on 4835963. The verdict and the full list are in the summary comment.

@thymikee

thymikee commented Dec 3, 2026

Copy link
Copy Markdown
Member Author

The upload path is still unproven against real storage at 4835963, so this needs one live run before merge. The late request error handling from the earlier review (#5337 (comment)) is now fixed, and the code diff has no other open problem.

The install route (deployRevylApp to uploadAndInstall to RevylClient.uploadSessionArtifact to uploadRevylArtifact) now sends a hand-built https.request PUT at artifact-upload.ts:45. It uses agent: false, a pinned lookup and a streamed Content-Length body. Every test stubs https.request or reroutes it to a plain-HTTP fixture, so no real presigned storage has accepted this request shape. If Revyl storage rejects or stalls on it, every local-build install on a rented Revyl device fails, and CI cannot show that. The PR body says no live run happened because connect returned 401 with the available key. Please post one live agent-device install <app> <local build> against a Revyl session at 4835963 or later, with one Android .apk or one iOS simulator .app. Include the SHA, the platform, and output that shows the upload finished with no revyl_upload_* reason and that the installed app identity came back from installAndWait. A connect or verify run does not reach this route.

The inline thread on late request errors is fixed at this head, so it can be resolved: #5337 (comment). The other four threads do not apply and can be resolved. The fixture dropping url.search is test strength only, because production passes the full signed URL (#5337 (comment)). The abort signal is forwarded at artifact-upload.ts:55 and rethrown at :32 and :101, so the thread asks only for a stronger assertion (#5337 (comment)). No production caller injects fetch, so only tests lose the stub (#5337 (comment)). An empty build is refused before any request with the typed reason revyl_upload_unreachable, and only the message wording is broad (#5337 (comment)).

The only failing check is Body rules. It grades the PR title and body against docs/agents/pull-requests.md, not code, so it is likely unrelated to the diff. The body lacks a tested SHA and receipt in Validation, and its Before / after section is prose instead of base and head calls with output. The other 19 checks pass. No conflicts are known.

No tests were run here. The new tests were traced by reading them against the code. Not verified here: that agent: false bypasses NODE_USE_ENV_PROXY, and that the lookup option reaches tls.connect; both come from reading Node http/https semantics, not from a run. Not verified here: any behavior of real presigned storage.

Before merge, the live install above is required. After that, fix the PR body so Body rules passes.

This branch has not been deployed

No deployments
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