-
Notifications
You must be signed in to change notification settings - Fork 4.3k
[v2] Add session id to user agent string #9498
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Conversation
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
42ded3a
to
82bdf95
Compare
ashovlin
previously requested changes
Jun 17, 2025
aemous
requested changes
Jun 25, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good overall, some questions about potential edge cases and non-blocking nits
aemous
approved these changes
Jun 27, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
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.
This PR generates and appends a session id to the user agent string.
Description
A session id is an identifier that represents an AWS CLI usage session (ie a specific task or logical grouping of tasks). It has the following properties:
Session ids are cached in a SQLite database stored in the
session
table. An entry in the database consists of:key
: Primary key that represents a cache key, which is a hash of the host id + TTY pathsession_id
: The session id associated with a host id + TTY pathtimestamp
: Most recent timestamp of the session id's usageA single host id is generated using uuid4 and persisted in the
host_id
table. The primary key is always hardcoded to0
to ensure there's only ever 1 host id that doesn't change.A cached session id is considered to be expired if it has been at least 30 minutes since the associated timestamp. On every AWS CLI invocation, the cache is cleared by deleting all entries with timestamps < current timestamp - (60*30) seconds. The cleanup job is processed in a daemon thread that terminates as soon as the main CLI process terminates to prevent blocking on cleanup tasks.
When determining the session id, it first checks the cache.
The session id is appended to the user agent string under the
sid
prefix. eg:Caveats
Why SQLite over files?
Caching session data in files can lead to race conditions when multiple processes are writing/reading to/from the same files. We can work around this by either implementing cross-file locks or writing to temporary files and moving them, but both approaches add complexity to implementation.
SQLite offers atomic primitives off the shelf, along with a few useful features:
INSERT OR REPLACEINTO
for simpler writesDELETE .. WHERE
for bulk deletes