The session report should remain correct when a user's events arrive out of order. Finish the grouping logic so the inactivity threshold is applied to the event times, including its exact boundary.
Build the implementation in Python under /app, with /app/run.sh as its entry point. Read one JSON request from standard input and write one JSON result to standard output. Input has nonnegative integer gap and events with user string and integer time. Deduplicate identical user/time pairs. For each user, start a new session only when the next timestamp difference exceeds gap. Return records user, start, end and events count sorted by user and start. Negative times are valid. Reject invalid gap.
Reject inputs that violate an explicit validation rule with exit status 2, no standard output, and {"error":"invalid_input"} on standard error. For valid input, exit with status 0. Keep the implementation reusable for new inputs; it must work offline and must not depend on the example data being the only data it receives.
Repair or replace the unfinished /app/run.sh and add source files under /app. Malformed JSON must use the same invalid-input response. Do not read /tests or /oracle from the application.