Skip to content

feat: add --reset to reset a start-only Connect to a clean state - #53

Closed
cgraham-rs wants to merge 3 commits into
mainfrom
cgraham-rs/reset-connect
Closed

feat: add --reset to reset a start-only Connect to a clean state#53
cgraham-rs wants to merge 3 commits into
mainfrom
cgraham-rs/reset-connect

Conversation

@cgraham-rs

@cgraham-rs cgraham-rs commented Jul 17, 2026

Copy link
Copy Markdown

Summary

Adds start-only container management and a fast in-place reset to with-connect,
so a running start-only Connect can be returned to a clean, just-bootstrapped state
on demand without a restart. Useful for test isolation, and more generally whenever
you want a fresh Connect without the cost of a full restart.

  • --reset [CONTAINER_ID] returns a running start-only Connect to its clean
    baseline with the same container, port, and CONNECT_API_KEY still valid.
    A matching reset: GitHub Action input is added.
  • Start-only mode runs Connect under a keep-alive PID 1 so it can be cycled in
    place, with docker-init as PID 1 to reap orphaned processes and forward signals.
  • A healthcheck probes /__ping__ so a crashed Connect reads as unhealthy even
    though the keep-alive keeps the container running.
  • --stop stops Connect gracefully first, then stops the container promptly.

A significant amount of the code change are from tests written during local iterative refinement and code reviews.

How reset works

After bootstrap, with-connect snapshots the clean data dir to a baseline archive,
excluding the license mount. --reset then, without stopping or restarting the
container, stops the Connect process, wipes the data dir while preserving the
license, restores that baseline, relaunches Connect, and polls /__ping__. The API
key survives because it lives in the restored database.

Reset supports only the default SQLite data dir. If a custom Server.DataDir or an
external database is configured, reset fails loudly instead of silently doing nothing.

Returns a running start-only Connect to its clean, just-bootstrapped state with the same container, port, and API key, without restarting the container. Useful for test isolation, and for anyone who wants a clean Connect without a full restart.
@nealrichardson

Copy link
Copy Markdown
Collaborator

We already have the ability to just start a container and not exit, with a followup --stop command. If I start and stop Connect with with-connect, and then start it again, is there data persisting across runs? I'm trying to understand what problem this solves.

@cgraham-rs

Copy link
Copy Markdown
Author

We already have the ability to just start a container and not exit, with a followup --stop command. If I start and stop Connect with with-connect, and then start it again, is there data persisting across runs? I'm trying to understand what problem this solves.

Primarily because it is 10+ seconds faster than a stop-then-start cycle, and that quickly adds up to minutes if you want a clean environment between tests.

@nealrichardson nealrichardson left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

If this works for your use case, fine with me, seems like all existing tests still pass. Just left a couple of notes of things to clean up before we merge.

Comment thread .github/workflows/ci.yml Outdated
Comment thread .github/workflows/ci.yml Outdated
Comment thread main.py Outdated
print(f"Connect reset and ready at http://localhost:{port}", file=sys.stderr)


def cli() -> None:

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

This is confusing. if name in main, call cli, which wraps a function called main.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Agreed, renamed it back so we get.

if __name__ == "__main__":
    main()

@tdstein

tdstein commented Jul 21, 2026

Copy link
Copy Markdown
Contributor

@cgraham-rs do you have any examples of utilizing this within posit-sdk-py to do test isolation?

…aming

Removed two comments added to test-action/test-action-start-only that
described jobs this PR didn't otherwise touch, which the reviewer found
confusing.

Renamed the old main()/cli() pair so the console-script entry point and
the __main__ guard both call a function actually named main(), matching
the Google Python Style Guide and Python Packaging User Guide's own
convention. The former main() (core CLI logic) is now run().
@cgraham-rs

Copy link
Copy Markdown
Author

Closing this PR.

The original research that indicated --reset was "~10s faster" was flawed. --reset looked ~10s faster only because main's --stop is artificially slow. Docker sends SIGTERM and waits 10 seconds before force-killing, but the Connect image's startup script ignores SIGTERM so every stop spends 10 seconds waiting for nothing.

The correct approach is to fix the --stop command

See #56

@cgraham-rs cgraham-rs closed this Jul 23, 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.

3 participants