Skip to content

fix: clean up the client scripts and tests - #2

Draft
Ho1yShif wants to merge 5 commits into
mainfrom
cleanup/client-code
Draft

Ho1yShif wants to merge 5 commits into
mainfrom
cleanup/client-code

Conversation

@Ho1yShif

Copy link
Copy Markdown

Summary

Clean up the Python and TypeScript clients and their tests. See testing.md for test steps.

 cleanup
-  loop 12 times: delete, sleep 3 s on 409
+  delete with SDK retries (max 5; the SDK retries 409 with backoff)
   404 counts as deleted

 run_task
+  exit "Set SANDBOX_ID first." before the stream opens (first run only)
+  make one idempotency key per run
-  maxRetries: 0, so the key never protected a retry
+  SDK default retries, each sending the same key

 create_session (Python)
+  fail if the environment is not self_hosted
-  write_text (mode follows umask)
+  os.open(O_EXCL, 0o600)

 wait_for_sandbox (Python)
+  exit "Set SANDBOX_ID first." in place of a KeyError
-  while ... else
+  ready flag

Decisions:

  • create_session keeps max_retries=0, because session creation has no idempotency key and a retry could make a second session.
  • TypeScript create_session now uses flag: "wx" to match the Python O_EXCL check.
  • The TypeScript missing-ID error is still a thrown Error, so Node prints a stack trace. Python exits with only the message.
  • The tests copy each client to tmp_path/<lang>/ and prompt.txt to tmp_path/, so no test writes to the shared parent directory.

I checked the retry behavior in the installed SDKs (Python openai 3.24.0, TypeScript openai 7.30.0). Both retry 409 with backoff from 0.5 s to 8 s. Both send the caller's Idempotency-Key again on each retry.

Evidence

  • Before: 24 tests pass. Without SANDBOX_ID, Python fails with KeyError: 'SANDBOX_ID'.
  • After: 28 tests pass. The new tests are:
    • test_missing_sandbox_id[run_task|wait_for_sandbox], for both languages: exits non-zero with Set SANDBOX_ID first., makes no API or CLI call, and Python prints no traceback.
    • test_create_and_no_overwrite: also checks that session.json has mode 600.
    • test_cleanup[conflict]: still sees two DELETE requests, now from SDK retries.
  • npm run typecheck --prefix typescript passes.

Merge Danger

Door: two-way

Blast Radius: clients

The cleanup retry window is shorter than before, about 15 s in place of 36 s. A session that rejects deletion for longer keeps session.json, and you can run cleanup again.

🤖 Generated with Claude Code

Ho1yShif and others added 5 commits October 16, 2026 16:31
Remove the manual retry loop. The SDK retries 409 with backoff up to 8 seconds. Five retries wait about 15 seconds in total.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Make the key one time for each script run. The SDK sends the same key on each retry, so OpenAI ignores duplicate submissions.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Both clients now write session.json with mode 600 and fail if the file exists. TypeScript gets the "wx" flag so that it matches the Python O_EXCL behavior.

Both clients check SANDBOX_ID before they open the event stream.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
@Ho1yShif Ho1yShif changed the title Clean up the client scripts and tests fix: clean up the client scripts and tests Oct 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

1 participant