Skip to content

bug: keep an encrypted library encrypted when it is pushed with the project that uses it - #791

Open
quantconnect-kronos[bot] wants to merge 6 commits into
masterfrom
kronos/bug-keep-library-cloud-encryption
Open

quantconnect-kronos[bot] wants to merge 6 commits into
masterfrom
kronos/bug-keep-library-cloud-encryption

Conversation

@quantconnect-kronos

@quantconnect-kronos quantconnect-kronos Bot commented Nov 30, 2026 •

Copy link
Copy Markdown
Contributor

Problem

lean cloud push --project <project> also pushes every library the project uses. Those library pushes never get the command's encryption options, so each one goes out without an encryption key. Take a library whose cloud project is encrypted but whose local files are plain, for example one pulled with lean cloud pull --decrypt --key. Pushing a project that uses it sends the library's plain source with an empty key, and the cloud turns off the library's encryption and stores the plain source. The command never asked to decrypt that library.

Change

  • A push no longer decrypts a library implicitly. Before it pushes anything, push_project checks the libraries it would push along with the project, including nested ones, whose cloud project is encrypted while their local files are not.

    • When the command is --encrypt --key with the key such a library is encrypted with in the cloud, the library is pushed with that key too. Its files go up encrypted and its cloud key stays as it is, so a project and its library pulled with --decrypt --key can be edited and pushed back with --encrypt --key.
    • For any other such library, such as one encrypted with another key, or a push with --decrypt --key or without options, the command fails with this error, and nothing is renamed, created or written:
      Libraries encrypted in the cloud but not locally would lose their cloud encryption if pushed with the project: 'Library/<name>'. Encrypt each of them locally with 'lean encrypt <library> --key' to keep it encrypted, or push it on its own with --decrypt --key to decrypt it

    The cloud also refuses to link an encrypted library to a project or library pushed without encryption, but only after it has written that project's files. So the same check also refuses a push that sends a project or library without encryption when it uses a library this push sends encrypted, whether kept with the command's key or encrypted locally. Again nothing is renamed, created or written:
    The cloud doesn't let projects and libraries pushed without encryption use the encrypted libraries pushed with them: 'Library/<name>'. Encrypt each of them locally with 'lean encrypt <project> --key' to push it encrypted too, or decrypt the encrypted libraries they use

    This applies only to libraries pushed along with a project. Pushing a project explicitly works as before: lean cloud push --project Library/<name> without options still writes the local state, as for any other project, and so does a lean cloud push of all projects.

  • A push no longer sends a key the cloud project already has. projects/update refuses to set a key on a project used as a library or shared with collaborators (A project used as library by other projects can not be encrypted), even the key the project already has. So the CLI couldn't push an encrypted library while keeping it encrypted, for example a library encrypted locally with lean encrypt. When the key the push would send equals the cloud project's key, the key is now left out, and the cloud keeps the project's encryption as it is. Turning encryption on (a new key) or off (an empty key) still sends the key as before. The existing check before the file-by-file push of a too-large project still compares against the cloud key.
    An update that sends a key, even one that fails, can change the cloud project's key. So the push now reads that cloud project again before any later push to it in the same command. This matters when two local copies share one cloud project in one lean cloud push: the second copy now compares against the key the first one left, not the key read before.

Backwards compatible: libraries that aren't encrypted in the cloud, libraries encrypted locally, and projects pushed explicitly are pushed as before.

The --push option of the cloud commands in #725 pushes libraries through this same push_project path, so it gets the check too.

Tests

New, in tests/components/util/test_push_manager.py:

  • a project using a library that is encrypted in the cloud but plain locally, pushed without options, with --decrypt --key, or with --encrypt --key and another key: the push raises and makes no update. Fails without the change.
  • the same project pushed with --encrypt --key and the library's key: the library's files are sent encrypted with that key, and neither update sends the key.
  • the same library nested behind a new local library: neither projects.create nor projects.update is called, and the new library gets no cloud id.
  • a project → new local library → the library encrypted in the cloud with the command's key, or encrypted locally, pushed with --encrypt --key and that key: the push raises, and neither projects.create nor projects.update is called. Fails without the change.
  • the same library in a directory with a trailing period: the directory isn't renamed and the project's reference to it is unchanged.
  • a library encrypted locally with its cloud key, pushed with a project that is encrypted with the same key: both are updated, and neither update resends the key.
  • the same library pushed on its own, without options, is still decrypted in the cloud as before.
  • two local copies of one encrypted cloud project in a bulk push, the plain copy first: the second update sends the key again after the first one removed it. Fails without the re-read.

Updated: test_cloud_push_pushes_files_one_by_one_when_a_too_large_project_keeps_its_encryption_key and test_cloud_push_keeps_cloud_project_encrypted_when_project_pulled_encrypted_without_key_and_encrypted_flag_given now assert that the unchanged key isn't sent.

  • python -m pytest -s -rs: 2947 passed, 81 skipped, 0 failed
  • python static_analysis.py: BUILD PASSED (the 5 unused-import warnings are the same as on master)

End to end

Tested end to end against the cloud API. In each case a library is encrypted in the cloud and plain locally, for example after a push of the library on its own with --encrypt --key, or a lean cloud pull --project <project> --decrypt --key.

Case master this branch
library pushed on its own with --encrypt --key, then a project using it pushed with --encrypt --key and the same key library decrypted in the cloud both pushed, encrypted with the key and linked
project and library pulled with --decrypt --key, both edited, the project pushed with --encrypt --key and the same key library decrypted in the cloud, its plain source stored exit code 0; both still encrypted with the key and linked; a fresh lean cloud pull --decrypt --key shows both edits
the same project pushed with --encrypt --key and another registered key, with --decrypt --key, or without options library decrypted in the cloud error, exit code 1; both still encrypted with the key
project → new local library → that library, pushed without options all three pushed unencrypted, the library decrypted error; library still encrypted; neither the new library nor the project created
project → new local library → the library, pushed with --encrypt --key and the library's key, the library plain locally or encrypted locally with lean encrypt new library created and its files written, its link to the library refused; project created, encrypted and linked to the new library; exit code 0 error, exit code 1; library still encrypted with the key; neither the new library nor the project created
the same, after lean encrypt Library/<new library> --key all three pushed, encrypted with the key and linked
lean encrypt Library/<name> --key, then the project pushed with --encrypt --key both pushed, encrypted with the same key and linked; a fresh lean cloud pull --project <project> --decrypt --key restores the library's local change
lean cloud push --project Library/<name> --decrypt --key, then the project without options library decrypted; new library and project created and linked

A library directory renamed to end with a period, in a project pushed without options, is refused before the directory is renamed; a unit test covers it.

A bulk lean cloud push of two local copies of one cloud project encrypted with a key, the plain copy first and the copy encrypted locally with the same key second:

master this branch
cloud project encrypted with its key, ciphertext stored encrypted with its key, ciphertext stored

A library encrypted locally with a different key from the project's, pushed with the project using --encrypt --key, behaves the same on master and on this branch. Both projects are pushed and linked, each with its own key, and lean cloud pull --decrypt --key with the project's key can't decrypt the library.

The case of a project shared with collaborators, which the second change also covers, wasn't run end to end. It goes through the same check in projects/update.

This change was prepared with the help of an AI assistant (Claude).

…roject that uses it

`lean cloud push --project <project>` pushes the project's libraries too, without an encryption key. A library whose
cloud project is encrypted and whose local files are plain, such as one pulled with --decrypt --key, was pushed with
an empty key, which turned its cloud encryption off and stored its plain source. Such a library now isn't pushed: the
push warns with how to push it on its own and goes on with the project, as for any library that can't be pushed.

A push no longer sends an encryption key the cloud project already has. The cloud refuses to set a key on a project
used as a library or shared with collaborators, even its current key, so an encrypted library could not be pushed
while staying encrypted.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@quantconnect-kronos quantconnect-kronos Bot added the kronos:develop:working develop: in progress label Nov 30, 2026
@quantconnect-kronos

Copy link
Copy Markdown
Contributor Author

The test (windows-latest, 3.14) failures, in both Build runs and again on their re-run, happen before any test runs. pip installs lxml>=4.9.0, the requirement in setup.py, and now resolves it to lxml 6.2.1, which it downloads as source only (lxml-6.2.1.tar.gz, no cp314-win_amd64 wheel). Building that source fails with Cannot open include file: 'libxml/xmlversion.h'. The last master Build (run 46072048529, Nov 27) installed the lxml-6.2.0-cp314-cp314-win_amd64.whl wheel and passed. The same failure hit run 46314900881 on another branch on Nov 29. GitHub then cancelled the other test jobs. This PR doesn't change dependencies, so the job should pass once lxml publishes the Windows wheel for 3.14, or with lxml pinned below 6.2.1.

@quantconnect-kronos-reviewer quantconnect-kronos-reviewer 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.

Requesting changes: in a common workflow, the library guard now leaves the project that uses the library broken in the cloud.

1. A project pushed without encryption, still linked to a library the push kept encrypted, gets half-written and stops compiling. Setup: a project and its library, both encrypted in the cloud with the same key and linked. Run lean cloud pull --project P --decrypt --key key.txt, which pulls the library decrypted too. Make a local change, then run lean cloud push --project P. I tested this end to end:

master this branch
library pushed, cloud encryption removed Cannot push 'Library/…' warning, stays encrypted
project pushed, decrypted Cannot push 'P': Encrypted libraries can not be added to a unencrypted project, yet its encryption is already removed and its plain source written
cloud compile of the project BuildSuccess BuildError: SyntaxError in the library's Library.py (its ciphertext is compiled as source)

projects/update removes the key and writes the files before it validates the library list, so the request fails only after it has written the project. The user is told nothing was pushed, but the project no longer compiles, and every retry fails the same way. On master this flow worked, but it removed the library's encryption.

What a fix must achieve: when the push would leave the project unencrypted (an empty key sent, or no key on the cloud project) while it references a library this push kept encrypted, the project's push writes nothing. Its warning says how to go on: push the project with --encrypt --key, or decrypt the library on its own first. For example, record the cloud ids the new guard skips and check them against update_args["libraries"] before projects.update. That is about 5 lines, plus a test for this flow. Don't use the cached encrypted flag of every library cloud project for this check: under lean cloud push with no --project, a library pushed earlier in the same run may already have been decrypted. Please also add this flow to the end-to-end table in the description.

Everything else checks out. The cloud reports encryptionKey.id as the key hash, and setting a key the project already has only re-validates it and upserts the same row. Leaving that key out therefore changes nothing in the cloud and avoids the library/collaborator refusal. I also ran the push tests locally: 215 passed.

CI: no test ran on this commit. test (windows-latest, 3.14) fails while installing lxml 6.2.1, which has no Windows wheel for Python 3.14, and GitHub then cancelled the rest of the matrix. This change didn't cause that failure (#792). The Regression Testing run is still in progress.

Label: risk:high. The change alters what pushes send for encrypted projects, it breaks the flow above, and it has no green CI yet.

Comment thread lean/components/cloud/push_manager.py Resolved
@quantconnect-kronos-reviewer quantconnect-kronos-reviewer Bot added risk:high High risk and removed kronos:review:working review: in progress labels Nov 30, 2026
…ept encrypted

The cloud removes the project's key and writes its files before it refuses an encrypted library in an unencrypted
project, so the push left the project half-written and failing to compile.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@quantconnect-kronos quantconnect-kronos Bot added the kronos:review Request review label Nov 30, 2026
@quantconnect-kronos-reviewer quantconnect-kronos-reviewer Bot added kronos:review:queued review: queued kronos:review:working review: in progress and removed kronos:review Request review kronos:review:queued review: queued labels Nov 30, 2026
@quantconnect-kronos-reviewer
quantconnect-kronos-reviewer Bot marked this pull request as ready for review November 30, 2026 03:05

@quantconnect-kronos-reviewer quantconnect-kronos-reviewer 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.

Approving. The finding about a project pushed unencrypted that uses a library the push kept encrypted is resolved. That push now stops before projects/update, so it writes nothing.

I tested c730588 end to end. Setup: a project and its library, both encrypted in the cloud with the same key, pulled with --decrypt --key and given a local change. Running lean cloud push --project P with no options gives a Cannot push warning for both. The cloud state of both is the same before and after: encryption, key, library link and file contents. Pushing the project with --encrypt --key after that updates it, and it keeps its key and its library link. The library is warned about and left unchanged. The full test suite passes locally: 2940 passed, 81 skipped.

CI: test (windows-latest, 3.14) fails in both Build and Regression Testing while installing lxml 6.2.1, which has no Windows wheel for Python 3.14 (#792). This change didn't cause that. In Build, GitHub cancelled the rest of the matrix after that failure. Regression Testing passed on Ubuntu and macOS.

Label: stays risk:high. The change alters what every push of an encrypted project sends, and it refuses pushes of a decrypted project that go through on master. Also, the Build test matrix hasn't run on this commit.

@quantconnect-kronos-reviewer quantconnect-kronos-reviewer Bot removed the kronos:review:working review: in progress label Nov 30, 2026
@quantconnect-kronos quantconnect-kronos Bot added the kronos:review Request review label Nov 30, 2026
@quantconnect-kronos-reviewer quantconnect-kronos-reviewer Bot added kronos:review:queued review: queued and removed kronos:review Request review labels Nov 30, 2026
@quantconnect-kronos-reviewer-2 quantconnect-kronos-reviewer-2 Bot added kronos:review:working review: in progress and removed kronos:review:queued review: queued labels Nov 30, 2026

@quantconnect-kronos-reviewer-2 quantconnect-kronos-reviewer-2 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.

Requesting changes. The same-key path now leaves both cloud projects untouched when a push would decrypt the parent, and the encrypted retry works. I verified four other outcomes end to end:

  1. A bulk push can report success while storing ciphertext as unencrypted source. Two local copies share one cloud ID. The plain copy pushes first and clears the key; the encrypted copy pushes second. Master restores the key with the second upload. This branch omits it based on the cached read, so the cloud ends up with the encrypted copy's files and no key.
  2. A differently keyed library can make the parent impossible to pull with its own key. A push with --encrypt --key succeeded and linked the retained library even though the two keys differed. The next lean cloud pull --decrypt --key could not decrypt the project. Check for the same key, not just for a nonempty parent key, before updating the parent.
  3. Skipping a library can break its local reference. On Linux, a library directory with a trailing period was renamed before the skip. Master repaired the reference; this branch left it pointing to the old directory, and the same-key parent push failed.
  4. A nested refusal can publish a reference to a library whose files never uploaded. With App → new local library → retained encrypted library, the new library was created but its update was refused. The app still pushed and linked to the cloud template, without the module it imports. Continue with existing compatible cloud copies, but not with a newly created placeholder whose first upload was blocked.

Please cover these paths with regression tests and add their end-to-end outcomes to the description. The current full suite passed locally (2,940 passed, 81 skipped). CI's Windows Python 3.14 job fails during dependency installation (#792); I verified the same lxml build error on an unrelated branch. risk:high remains warranted because a reported successful push can leave unusable cloud code.

Comment thread lean/components/cloud/push_manager.py Resolved
Comment thread lean/components/cloud/push_manager.py Resolved
Comment thread lean/components/cloud/push_manager.py Resolved
Comment thread lean/components/cloud/push_manager.py Resolved
@quantconnect-kronos-reviewer-2 quantconnect-kronos-reviewer-2 Bot removed the kronos:review:working review: in progress label Nov 30, 2026
…f skipping the library

Skipping a library whose cloud project is encrypted and whose local files are not, while pushing the rest, could
leave projects the cloud can't use: an unencrypted or differently keyed project linked to the encrypted library, a new
intermediate library created but never uploaded, or a renamed library's reference left stale. push_project now checks
the libraries it would push before it renames, creates or writes anything, and fails with how to keep or remove the
library's encryption.

An update that sends an encryption key can change the cloud project's key even when it fails, so the cached cloud
project is read again before a later push to it: a second local copy of the same cloud project pushed in the same
command no longer leaves out a key the first copy removed.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@quantconnect-kronos

Copy link
Copy Markdown
Contributor Author

Thanks for the review. 941baf1 changes the approach instead of patching each case. Three of the four findings came from skipping the library and pushing the rest. Now a project push that would decrypt any of its libraries, nested ones included, fails before anything is renamed, created or written. The error says how to keep the library encrypted (lean encrypt <library> --key) or decrypt it (--decrypt --key on its own). The stale key comparison is fixed by reading the cloud project again after an update that sends a key. Each finding has a regression test, and the description now has the end-to-end outcomes on master and on this branch (and on c730588 for the bulk case). Full suite: 2943 passed, 81 skipped.

@quantconnect-kronos-reviewer quantconnect-kronos-reviewer Bot added kronos:review:working review: in progress and removed kronos:review Request review kronos:review:queued review: queued labels Nov 30, 2026

@quantconnect-kronos-reviewer quantconnect-kronos-reviewer 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.

Requesting changes. The round trip from my last review now works. I tested it end to end: a project and its library pulled with --decrypt --key, edited, and pushed with --encrypt --key both stay encrypted with the key and linked, and a fresh lean cloud pull --decrypt --key shows the library's edit. The push tests pass locally (117 passed, 3 skipped). One new finding comes from the same-key path.

1. A plain library that uses a library pushed with the command's key is left unlinked in the cloud, and the command exits 0. Setup: library A is encrypted in the cloud with key k and plain locally (pushed on its own with --encrypt --key k). A new library B uses A, and project P uses B. I ran lean cloud push --project P --encrypt --key k end to end:

master this branch
A decrypted in the cloud (the bug this PR fixes) stays encrypted with k
B created and linked to A created and its files written, then Cannot push 'Library/B': Encrypted libraries can not be added to a unencrypted project; not linked to A
P encrypted with k, linked to B encrypted with k, linked to B
exit code 0 0

So P now uses a cloud library whose code imports a module the cloud doesn't link to it. On the previous commit this push failed before writing anything. The cause is the one fixed earlier for the project itself: something pushed without a key references a library pushed encrypted, and the cloud writes before it refuses the link. Master leaves the same state when A is encrypted locally with lean encrypt instead. I ran that too: B created but not linked to A, P linked to B, exit 0. So one check covers both.

What a fix must achieve: before anything is renamed, created or written, refuse a project or library this push sends without a key when its libraries include one the push sends encrypted, either kept with the command's key or encrypted locally. The error should say how to go on, such as encrypting the referencing library too, or decrypting the referenced one on its own. That is about 5 to 8 lines next to the check at line 92. Please add a test for this nested case pushed with the library's own key, asserting that nothing is created or updated, and add the case to the end-to-end table.

CI: in both Build runs, test (windows-latest, 3.14) fails while installing lxml 6.2.1 (#792), and GitHub cancelled the rest of the matrix, so no unit test ran in CI on this commit. This change didn't cause that failure. Regression Testing is still queued.

Comment thread lean/components/cloud/push_manager.py Resolved
@quantconnect-kronos-reviewer quantconnect-kronos-reviewer Bot removed the kronos:review:working review: in progress label Nov 30, 2026
…pushed without encryption

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@quantconnect-kronos

Copy link
Copy Markdown
Contributor Author

Addressed the review in 514b20e.

1. A plain library using a library pushed encrypted. Before anything is renamed, created or written, the push now refuses any project or library it would send without encryption that uses a library it sends encrypted. That covers a library kept with the command's key and one encrypted locally with lean encrypt. The error names the referencing projects and libraries, and suggests encrypting them with lean encrypt <project> --key or decrypting the libraries they use. A lean cloud push of all projects is left as it was: refusing there would stop every unrelated project too.

New test: test_push_project_creates_nothing_when_an_unencrypted_library_uses_a_library_pushed_encrypted, parametrized on whether the nested library is plain locally (kept with the command's key) or encrypted locally. It asserts that neither projects.create nor projects.update is called and that the new library gets no cloud id. Both cases fail without the change.

Tested end to end, project → new library → library, pushed with --encrypt --key and the library's key:

  • library plain locally, encrypted in the cloud with the key: error, exit code 1; library still encrypted; neither the new library nor the project created.
  • library encrypted locally with lean encrypt: the same.
  • after lean encrypt of the new library: exit code 0; all three encrypted with the key and linked.
  • a project that uses the library directly, pushed with the same key: exit code 0; both encrypted and linked, as before.

The end-to-end table in the description has the new rows. Its master column for the nested case is from your run.

python -m pytest -s -rs: 2947 passed, 81 skipped. python static_analysis.py: passed.

@quantconnect-kronos quantconnect-kronos Bot added the kronos:review Request review label Nov 30, 2026
@quantconnect-kronos-reviewer quantconnect-kronos-reviewer Bot added kronos:review:queued review: queued kronos:review:working review: in progress and removed kronos:review Request review kronos:review:queued review: queued labels Nov 30, 2026
@quantconnect-kronos-reviewer
quantconnect-kronos-reviewer Bot marked this pull request as ready for review November 30, 2026 04:17

@quantconnect-kronos-reviewer quantconnect-kronos-reviewer 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.

Approving. My last finding is resolved: a plain library that uses a library pushed encrypted is no longer created and left unlinked. The push now stops before anything is renamed, created or written.

I tested 514b20e end to end. Setup: library A is encrypted in the cloud with key k and plain locally, a new library B uses A, and project P uses B.

Push Outcome
lean cloud push --project P --encrypt --key k exit 1 with the new error naming Library/B; neither B nor P created
the same, after lean encrypt Library/B --key k exit 0; A, B and P all encrypted with k, P linked to B and B linked to A
a project that uses A directly, pushed with --encrypt --key k exit 0; encrypted with k and linked to A (no false refusal)

The new test fails on the previous commit in both of its cases and passes now. The full suite passes locally: 2947 passed, 81 skipped.

CI: in both Build runs, test (windows-latest, 3.14) fails while installing lxml 6.2.1 (#792), and GitHub cancelled every other test job, so no unit test ran in CI on this commit. This change didn't cause that failure. Regression Testing is still queued.

@quantconnect-kronos-reviewer quantconnect-kronos-reviewer Bot removed the kronos:review:working review: in progress label Nov 30, 2026
@quantconnect-kronos quantconnect-kronos Bot added the kronos:review Request review label Nov 30, 2026
@quantconnect-kronos-reviewer quantconnect-kronos-reviewer Bot added kronos:review:queued review: queued and removed kronos:review Request review labels Nov 30, 2026
@quantconnect-kronos-reviewer-2 quantconnect-kronos-reviewer-2 Bot added kronos:review:working review: in progress and removed kronos:review:queued review: queued labels Nov 30, 2026
@quantconnect-kronos-reviewer-2

Copy link
Copy Markdown

The review of 514b20e failed. It's requested again.

@quantconnect-kronos-reviewer-2 quantconnect-kronos-reviewer-2 Bot added kronos:review Request review and removed kronos:review:working review: in progress labels Nov 30, 2026
@quantconnect-kronos-reviewer quantconnect-kronos-reviewer Bot added kronos:review:queued review: queued and removed kronos:review Request review labels Nov 30, 2026
@quantconnect-kronos-reviewer-2 quantconnect-kronos-reviewer-2 Bot added kronos:review:working review: in progress and removed kronos:review:queued review: queued labels Nov 30, 2026

@quantconnect-kronos-reviewer-2 quantconnect-kronos-reviewer-2 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.

Requesting changes: the library encryption check must stop the push if it cannot verify an associated library’s cloud state. It also needs to stay out of bulk pushes that have no implicit libraries to validate.

I verified end to end that a bulk push with one unrelated config.json containing "libraries": null uploads the valid project on master, but exits 1 before uploading it on this branch. The same-key pull/decrypt → edit → push/encrypt round trip worked: both projects stayed encrypted and linked, and a fresh pull included both edits. The full suite passed locally (2,947 passed, 81 skipped).

CI: Windows Python 3.14 still fails installing lxml before tests (#792), which is unrelated to this change. The remaining Build jobs were cancelled; Regression Testing passed on Ubuntu and macOS.

cloud_project = self._get_cloud_project(cloud_id, organization_id)
except RequestFailedError:
# the push of the project reports the cloud project it can't read
return None

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

A failed lookup does not establish that the library is unencrypted. Returning None lets the push proceed without having verified that it will preserve encryption. Stop before any changes if this lookup fails, and add a regression test asserting no writes when the encryption check cannot complete.

encrypted = {path for path in all_projects_to_push if associated_libraries_to_push and is_pushed_encrypted(path)}
unencrypted_users = "', '".join(
path.relative_to(Path.cwd()).as_posix() for path in all_projects_to_push
if path not in encrypted and any(LeanLibraryReference(**library).path.expanduser().resolve() in encrypted

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

When there are no associated libraries, encrypted is empty but this still parses every project’s references outside the per-project error handler. That turns one bad config into a failure for the whole workspace. Skip this scan when there are no encrypted targets to check, and test that a bulk push still uploads unrelated valid projects.

@quantconnect-kronos-reviewer-2 quantconnect-kronos-reviewer-2 Bot removed the kronos:review:working review: in progress label Nov 30, 2026
@quantconnect-kronos

Copy link
Copy Markdown
Contributor Author

@Martin-Molinero Decision needed: should this PR keep checking the cloud's encryption rules before a push and fix the two latest findings, or shrink to a smaller change?

The PR stops lean cloud push --project from removing the cloud encryption of a library that is encrypted in the cloud but plain locally. It does this by refusing such a library, or pushing it with the command's key when that key matches. The common round trip now works end to end: lean cloud pull --decrypt --key, edit, lean cloud push --encrypt --key. Five reviews in a row have asked for changes, for one reason: the cloud's projects/update writes a project's files before it refuses its key or its links to libraries. So the CLI has to predict those refusals up front, for every layout of projects and libraries, and each check added for one layout has exposed another: a half-written project, stale keys in a bulk push, a nested library left unlinked, and now the two findings below.

The two latest findings, on 514b20e:

  1. A lean cloud push of all projects stops before pushing anything when one unrelated config.json has "libraries": null. On master the valid projects are still pushed. The cause is that the new check reads every project's libraries even when there are none to check.
  2. When the CLI can't read a library's cloud project, the check treats that library as unencrypted and lets the push go on.
  • A. Fix the two findings and keep the approach (recommended): run the new check only when this push sends a library encrypted, and stop before writing anything when a library's cloud project can't be read. That's about 5 lines plus two tests. Users keep every flow tested so far, the round trip included. The cost is that a layout no review has tried yet can still fail the same way. I recommend it because both fixes are small and stay inside the existing check.
  • B. Shrink to the core fix: keep leaving out a key the cloud project already has, and refuse any library that is encrypted only in the cloud, whatever the key. Drop pushing such a library with the command's key, and drop the nested check. That's about 40 fewer lines. No push ever decrypts a library. But the round trip of a project with a library now fails, with an error asking the user to run lean encrypt on the library first. On master that push succeeds, though it decrypts the library.
  • C. Have the cloud API check a project's key and library links before it writes any file, so a refused push changes nothing. This PR would then drop the nested check and keep the rest. Users get A's behaviour, and the CLI no longer predicts the cloud's rules. It needs a separate change to the cloud API first, and this PR waits for it.

Reply with the option you choose, or another way to go.

Reviews asked for changes 5 times since a person last commented, so the developer stopped: a comment, or adding kronos:develop or kronos:review, has it go on.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

kronos:develop:working develop: in progress risk:high High risk

Projects

None yet

Development

Successfully merging this pull request may close these issues.

0 participants