Skip to content

Post-D1 SDK fixes, integrated (0.4.0) - #17

Merged
sahiljagtap08 merged 30 commits into
mainfrom
integrate/post-d1
Nov 18, 2026
Merged

sahiljagtap08 merged 30 commits into
mainfrom
integrate/post-d1

Conversation

@sahiljagtap08

@sahiljagtap08 sahiljagtap08 commented Nov 18, 2026 •

Copy link
Copy Markdown
Contributor

What

One branch with every post-D1 SDK pull request merged into it, the conflicts between them resolved, and the follow-ups the console and gateway side asked for. It proposes 0.4.0. Nothing is published: no tag, nothing on PyPI.

Merged from origin/main, with merge commits, in this order:

  1. ci: pip-audit gate and a weekly dependency audit (A-40) #10 fix/w7-dependency-audit: pip-audit gate, weekly audit, test matrix on ubuntu-24.04 (A-40)
  2. Retry 429s on every call with Retry-After and jitter; certifi fallback for macOS certificates #11 fix/w4-retry-after-certs: Retry-After on every call, certifi fallback (A-29, A-07)
  3. SDK: exchange the API key for a desktop token when the gateway asks for it #14 fix/w2-token-exchange: API key to desktop token exchange (A-30)
  4. Run object: open a training run, buffer its steps, close it, label its desktops #12 fix/w4-run-object: run object client (A-36)
  5. drums preflight: check a run can start before any GPU is paid for #13 fix/w4-preflight: drums preflight
  6. drums mcp: custom tasks by task set, list/get task sets, verify without a task says so #15 fix/w4-mcp-custom-tasks: MCP custom tasks (A-08, A-09)
  7. CHANGELOG for the post-D1 SDK fixes; propose 0.4.0 (not published) #16 fix/w4-release-0.4.0: CHANGELOG and version 0.4.0

Conflicts resolved

Follow-ups added here

Run object, to match the gateway's trainer runs (Drums-Labs/drums#41):

  • scripted_test is no longer a run kind. The kinds are training, rl, evaluation and eval (eval is the gateway's own name).
  • desktops_provisioned is sent on open (client.run(..., desktops_provisioned=N)) and per step (run.step(..., desktops_provisioned=N)).
  • Labels come from the open reply's label. When another running run already holds the name, the gateway answers <label>-<4 of id>, and desktops created later get that label.
  • A 409 on PATCH or close means the run has ended on the gateway (closed, or marked lost). The SDK drops what is buffered and stops sending, with one warning; run.ended says why. A 409 on close is quiet. Before this, a 409 on PATCH put the points back in the buffer, and they were sent again on every flush.
  • The 403 message says computers:write also suffices.

Token exchange (#14) with #11:

  • The exchange builds its own connection, so it now goes through Client._build_opener. That gives it the same redirect policy plus certifi's bundle once the client uses it. A certificate failure at the console switches the client to certifi once, with one stderr line naming the console. Without certifi it raises CertificateError naming the console.
  • Discovery (GET /auth) also switches to certifi on a certificate failure, so discovery, exchange and calls agree.
  • The exchange and every renewal (including the one after a 401) use the client's RetryPolicy. A 429 waits at least its Retry-After, and max_wait_s=0 turns this off. In token mode with no valid token there is nothing to fall back to, so a 5xx or a dropped connection is retried within the same budget too. In both mode, or while the old token is still valid, these are not retried, and the client falls back at once as before.
  • A key sent before the gateway's mode was known gets one rediscovery and resend after a 401. This happens when the discovery request got no answer, and a token-mode gateway then refuses the key.

Preflight (#13):

  • Works in token mode. The exchange runs before /v1/health, so a console that cannot issue a token shows as an auth failure, not "gateway down". A refused key at the console is an auth failure. A both-mode gateway running on the key alone is a warning. The auth row says when a desktop token was used.
  • The console row defaults to the token URL's origin.
  • _limits_view was checked against the reply in Drums-Labs/drums#49. Every field it reads is there with the same name, and a test replays that exact document. It now also reads host.admission (down fails the admission row), host.max_desktops / live / free (host capacity when /v1/health has none), and workspace.rate_limit_profile (shown on the rate row).
  • A 403 on /v1/limits says the key lacks usage:read.
  • runs:write is no longer a wanted scope, because computers:write opens runs (#41).

Docs: the CHANGELOG describes the combined 0.4.0. The README gets a desktop tokens note, the preflight table update, the run object changes, and an "Upgrading from 0.3" section (nothing breaks, what is new, the 429 off switch).

How it was tested

  • python -m unittest discover -s tests: 158 tests, OK locally on 3.12, 3.9 and 3.13 (uv). CI runs 3.9 to 3.13 on ubuntu-24.04, plus pip-audit.
  • New tests:
    • test_tokens.py: 429 Retry-After on the exchange; 5xx retried in token mode; the off switch; both mode does not wait; renewal after a 401 retries a 429; resend after an unanswered discovery; certifi fallback at the console, with and without certifi; a client already on certifi uses it for the exchange.
    • test_runs.py: kinds; desktops_provisioned; the label from the reply on creates; a 409 heartbeat stops the retries; a quiet 409 on close; the 403 text.
    • test_preflight.py: token mode end to end, where the gateway never sees the key; console down in token mode; refused key; both fallback warning; console origin default; the exact #49 document; capacity from the limits; 403 on limits.

Not done here

Nothing is merged into main, and nothing is released. The individual PRs stay open; close them once this one lands.

…s, and a weekly audit that opens an issue on failure (A-40)
…ittered backoff (RetryPolicy, DRUMS_RETRY_MAX_WAIT_S); fall back to certifi when the system certificate store fails, else CertificateError with the fix
… has no Python 3.9 (main fails the same way)
…s a run, buffers step() points and flushes at most once per 30 s, closes on exit, labels the desktops created inside; a no-op with one warning on a gateway without the run routes
…admission, rate limit, quota, spend cap and task set before a run; drums.preflight() in Python
…oken mode; renew before expiry and after a 401; no secret in reprs or errors
…sk_set, a task document sent as a JSON string, and verify with no task says so (same tool list and messages as the gateway)
# Conflicts:
#	drums/__init__.py
# Conflicts:
#	drums/mcp.py
# Conflicts:
#	CHANGELOG.md
…ack and RetryPolicy (429 with Retry-After; 5xx and dropped connections too in token mode); a key sent before the auth mode was known is retried once after a 401
…ipted_test kind (eval accepted), desktops_provisioned on open and steps, the label from the open reply, a 409 on heartbeat or close ends the run with one warning and no retries, a 403 says computers:write also suffices
…nsole that cannot issue a token is an auth failure, both mode on the key is a warning; the console row defaults to the token URL's origin) and reads GET /v1/limits as Drums-Labs/drums#49 serves it (admission down fails, host capacity from the limits, rate profile, a 403 names usage:read); runs:write is no longer wanted
…s hash and a summary of its scalar top-level values, with one warning; a 400 on open warns with the gateway's message and leaves run.id None (only 404/405 mean no run routes)
@sahiljagtap08
sahiljagtap08 merged commit 043f850 into main Nov 18, 2026
6 checks passed
@sahiljagtap08
sahiljagtap08 deleted the integrate/post-d1 branch November 18, 2026 04:13
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.

1 participant