Repository navigation
feat(api): add GET /api/0/devices endpoint (bucket identity phase 2.2) - #183
TimeToBuildBob wants to merge 2 commits into
Conversation
Mirror aw-server-rust's /api/0/devices endpoint in Python aw-server. Returns the local device id (UUID, stable across restarts) and hostname. Paired with aw-core#177 which adds device_id to the SQLite schema. Part of ActivityWatch/activitywatch#302 (bucket identity unification). Git-Session-Id: 02ce
|
…stability Git-Session-Id: aa774620-bec5-581f-adf4-2c8cc3cf4eb6
|
@greptileai review |
|
Status update: all checks green except macOS-latest which has been stuck in QUEUED for ~1h (infrastructure queue issue, not a code failure — Ubuntu and Windows builds both pass). Greptile re-reviewed at 5/5 confidence: "No new actionable issues were found." The P2 "Device endpoint lacks tests" thread is now resolved (tests were added in a prior commit covering list response, repeated ID, and hostname agreement with Ready to merge once macOS CI clears or a maintainer overrides the pending check. |
|
CI-green and mergeable (Greptile 5/5) — waiting only on a maintainer click. This PR is ready to merge, but the bot has pull-only access to this repo and can't self-merge — surfacing it here so it isn't lost. The monitoring loop will stop re-flagging it now that this note is posted. |
🤖 AI code reviewAdds a GET /api/0/devices endpoint to the Python aw-server, mirroring the Rust server. ServerAPI.get_devices() returns a list with one device object containing the stable device_id and current hostname. rest.py adds a Device model and DevicesResource with marshal_list_with. tests/test_server.py adds test_devices verifying the response shape, id stability, and id matching /api/0/info. Safe to merge — no P0/P1 findingsConfidence 5/5 ✅ No thread-worthy findings. Advisory notes follow; they are retained without opening review threads. 1 advisory finding (summary-only, not scored)These P2 guard, heuristic, trade-off, or documentation claims are retained for judgment without opening review threads.
The get_devices() method in ServerAPI is not decorated with @_serialized or any lock, but it only reads the device_id file and hostname. The get_device_id() function has a race condition: if two processes or threads call it concurrently when the device_id file does not exist, both may generate different UUIDs and write to the same path, resulting in the file containing one UUID while the other caller returns a different UUID. This could cause the /api/0/devices endpoint to return a different id on concurrent first calls, breaking the stability contract. However, in practice the server initializes the device_id early, and the file is written once. The race is unlikely but possible if the server is started with multiple workers. The existing get_info() has the same race, so this is not new. The PR does not introduce a new race; it reuses the existing helper. The test only checks stability across sequential calls, not concurrent. This is a pre-existing issue, not introduced by this PR. How this was verified: Checked get_device_id() in aw_server/api.py lines 35-44; the file is written with f.write(uuid) without a newline, but if the file already exists from any source, its content is returned as-is. The new endpoint and test both call get_device_id(), so the test does not catch a trailing newline. Consensus: 2/3 passes agreed — pass 3 looked and disagreed Files changed (3) — the diff as I read it
Reviewed Maintainer commands
|
Summary
Mirror the
GET /api/0/devicesendpoint from aw-server-rust into Python aw-server. This is phase 2.2 of the bucket identity unification effort (ActivityWatch/activitywatch#302).aw_server/api.py: AddServerAPI.get_devices()— returns[{"id": <stable_uuid>, "hostname": <hostname>}]using the existingget_device_id()helper.aw_server/rest.py: AddDevicesResourceat/api/0/deviceswith flask-restx marshalling, and theDevicemodel schema.Relationship to other PRs
Paired with ActivityWatch/aw-core#177 which adds the
device_idcolumn to the SQLite storage and v1→v2 migration. Together these two PRs bring the Python stack to parity with the Rust server for phase 2 of ActivityWatch/activitywatch#302.Testing
test_server.pyunit tests pass (incl. the 3 benchmark tests after installingpytest-benchmark)test_extension_cors.pyordering-dependent failures are pre-existing on upstreammaster(confirmed bygit stash+ re-run) — not introduced by this PR