mostlyright-data 0.31.49__tar.gz → 0.31.50__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (132) hide show
  1. {mostlyright_data-0.31.49 → mostlyright_data-0.31.50}/PKG-INFO +1 -1
  2. {mostlyright_data-0.31.49 → mostlyright_data-0.31.50}/src/mostlyright/data_harness/thin/transport.py +52 -12
  3. {mostlyright_data-0.31.49 → mostlyright_data-0.31.50}/src/mostlyright/data_harness/thin/v4_query.py +49 -7
  4. {mostlyright_data-0.31.49 → mostlyright_data-0.31.50}/src/mostlyright/data_harness/ux/remediation.py +15 -1
  5. {mostlyright_data-0.31.49 → mostlyright_data-0.31.50}/.gitignore +0 -0
  6. {mostlyright_data-0.31.49 → mostlyright_data-0.31.50}/README.md +0 -0
  7. {mostlyright_data-0.31.49 → mostlyright_data-0.31.50}/pyproject.toml +0 -0
  8. {mostlyright_data-0.31.49 → mostlyright_data-0.31.50}/scripts/hatch_build.py +0 -0
  9. {mostlyright_data-0.31.49 → mostlyright_data-0.31.50}/skills/mr-data-build/SKILL.md +0 -0
  10. {mostlyright_data-0.31.49 → mostlyright_data-0.31.50}/skills/mr-data-build/agents/openai.yaml +0 -0
  11. {mostlyright_data-0.31.49 → mostlyright_data-0.31.50}/skills/mr-data-build/references/1-open-the-page-and-the-link-to-it-in-the-first-message.md +0 -0
  12. {mostlyright_data-0.31.49 → mostlyright_data-0.31.50}/skills/mr-data-build/references/2-brief-two-to-four-questions-each-with-a-recommended-answer.md +0 -0
  13. {mostlyright_data-0.31.49 → mostlyright_data-0.31.50}/skills/mr-data-build/references/3-probe-read-a-source-before-committing-to-it.md +0 -0
  14. {mostlyright_data-0.31.49 → mostlyright_data-0.31.50}/skills/mr-data-build/references/4-decide-say-what-you-chose-what-you-refused-and-ask-one-question.md +0 -0
  15. {mostlyright_data-0.31.49 → mostlyright_data-0.31.50}/skills/mr-data-build/references/5-draft-one-recipe-document-one-call.md +0 -0
  16. {mostlyright_data-0.31.49 → mostlyright_data-0.31.50}/skills/mr-data-build/references/6-build-one-run-sized-to-acquire-every-measured-source-whole.md +0 -0
  17. {mostlyright_data-0.31.49 → mostlyright_data-0.31.50}/skills/mr-data-build/references/7-interrogate-ask-the-run-what-it-actually-delivered.md +0 -0
  18. {mostlyright_data-0.31.49 → mostlyright_data-0.31.50}/skills/mr-data-build/references/8-fix-revise-the-document-and-register-it-again.md +0 -0
  19. {mostlyright_data-0.31.49 → mostlyright_data-0.31.50}/skills/mr-data-build/references/9-present-only-what-survived-inspection-with-caveats.md +0 -0
  20. {mostlyright_data-0.31.49 → mostlyright_data-0.31.50}/skills/mr-data-build/references/agent-protocol.md +0 -0
  21. {mostlyright_data-0.31.49 → mostlyright_data-0.31.50}/skills/mr-data-build/references/autonomous-delivery.md +0 -0
  22. {mostlyright_data-0.31.49 → mostlyright_data-0.31.50}/skills/mr-data-build/references/before-the-first-tool-call.md +0 -0
  23. {mostlyright_data-0.31.49 → mostlyright_data-0.31.50}/skills/mr-data-build/references/boundaries.md +0 -0
  24. {mostlyright_data-0.31.49 → mostlyright_data-0.31.50}/skills/mr-data-build/references/cloud-authentication-preflight.md +0 -0
  25. {mostlyright_data-0.31.49 → mostlyright_data-0.31.50}/skills/mr-data-build/references/commands.md +0 -0
  26. {mostlyright_data-0.31.49 → mostlyright_data-0.31.50}/skills/mr-data-build/references/enriching-with-small-models.md +0 -0
  27. {mostlyright_data-0.31.49 → mostlyright_data-0.31.50}/skills/mr-data-build/references/live-run.md +0 -0
  28. {mostlyright_data-0.31.49 → mostlyright_data-0.31.50}/skills/mr-data-build/references/making-a-table-incremental.md +0 -0
  29. {mostlyright_data-0.31.49 → mostlyright_data-0.31.50}/skills/mr-data-build/references/narrating-the-run.md +0 -0
  30. {mostlyright_data-0.31.49 → mostlyright_data-0.31.50}/skills/mr-data-build/references/not-hosted-yet.md +0 -0
  31. {mostlyright_data-0.31.49 → mostlyright_data-0.31.50}/skills/mr-data-build/references/one-install.md +0 -0
  32. {mostlyright_data-0.31.49 → mostlyright_data-0.31.50}/skills/mr-data-build/references/patterns.md +0 -0
  33. {mostlyright_data-0.31.49 → mostlyright_data-0.31.50}/skills/mr-data-build/references/predicting-with-tabular-models.md +0 -0
  34. {mostlyright_data-0.31.49 → mostlyright_data-0.31.50}/skills/mr-data-build/references/prediction-labels.md +0 -0
  35. {mostlyright_data-0.31.49 → mostlyright_data-0.31.50}/skills/mr-data-build/references/preparing-table-search.md +0 -0
  36. {mostlyright_data-0.31.49 → mostlyright_data-0.31.50}/skills/mr-data-build/references/promote.md +0 -0
  37. {mostlyright_data-0.31.49 → mostlyright_data-0.31.50}/skills/mr-data-build/references/readers.md +0 -0
  38. {mostlyright_data-0.31.49 → mostlyright_data-0.31.50}/skills/mr-data-build/references/receipts.md +0 -0
  39. {mostlyright_data-0.31.49 → mostlyright_data-0.31.50}/skills/mr-data-build/references/recipe-test.md +0 -0
  40. {mostlyright_data-0.31.49 → mostlyright_data-0.31.50}/skills/mr-data-build/references/recording-a-stream-venue.md +0 -0
  41. {mostlyright_data-0.31.49 → mostlyright_data-0.31.50}/skills/mr-data-build/references/recovering-an-import-failure.md +0 -0
  42. {mostlyright_data-0.31.49 → mostlyright_data-0.31.50}/skills/mr-data-build/references/reference-pages.md +0 -0
  43. {mostlyright_data-0.31.49 → mostlyright_data-0.31.50}/skills/mr-data-build/references/required-protocol.md +0 -0
  44. {mostlyright_data-0.31.49 → mostlyright_data-0.31.50}/skills/mr-data-build/references/satellite-signals.md +0 -0
  45. {mostlyright_data-0.31.49 → mostlyright_data-0.31.50}/skills/mr-data-build/references/source-credentials.md +0 -0
  46. {mostlyright_data-0.31.49 → mostlyright_data-0.31.50}/skills/mr-data-build/references/sources.md +0 -0
  47. {mostlyright_data-0.31.49 → mostlyright_data-0.31.50}/skills/mr-data-build/references/the-one-thing-to-say-about-the-skill-itself.md +0 -0
  48. {mostlyright_data-0.31.49 → mostlyright_data-0.31.50}/skills/mr-data-build/references/transforms.md +0 -0
  49. {mostlyright_data-0.31.49 → mostlyright_data-0.31.50}/skills/mr-data-build/references/user-communication-contract.md +0 -0
  50. {mostlyright_data-0.31.49 → mostlyright_data-0.31.50}/skills/mr-data-build/references/writing-a-decision-record.md +0 -0
  51. {mostlyright_data-0.31.49 → mostlyright_data-0.31.50}/skills/mr-data-build/scripts/write_research_notebook.py +0 -0
  52. {mostlyright_data-0.31.49 → mostlyright_data-0.31.50}/src/mostlyright/data_harness/__init__.py +0 -0
  53. {mostlyright_data-0.31.49 → mostlyright_data-0.31.50}/src/mostlyright/data_harness/agent_protocol.py +0 -0
  54. {mostlyright_data-0.31.49 → mostlyright_data-0.31.50}/src/mostlyright/data_harness/canonical.py +0 -0
  55. {mostlyright_data-0.31.49 → mostlyright_data-0.31.50}/src/mostlyright/data_harness/key_seam.py +0 -0
  56. {mostlyright_data-0.31.49 → mostlyright_data-0.31.50}/src/mostlyright/data_harness/page_coverage.py +0 -0
  57. {mostlyright_data-0.31.49 → mostlyright_data-0.31.50}/src/mostlyright/data_harness/part_check_evidence.py +0 -0
  58. {mostlyright_data-0.31.49 → mostlyright_data-0.31.50}/src/mostlyright/data_harness/session_probes.py +0 -0
  59. {mostlyright_data-0.31.49 → mostlyright_data-0.31.50}/src/mostlyright/data_harness/skill_assets.py +0 -0
  60. {mostlyright_data-0.31.49 → mostlyright_data-0.31.50}/src/mostlyright/data_harness/table_manifest.py +0 -0
  61. {mostlyright_data-0.31.49 → mostlyright_data-0.31.50}/src/mostlyright/data_harness/thin/__init__.py +0 -0
  62. {mostlyright_data-0.31.49 → mostlyright_data-0.31.50}/src/mostlyright/data_harness/thin/activity.py +0 -0
  63. {mostlyright_data-0.31.49 → mostlyright_data-0.31.50}/src/mostlyright/data_harness/thin/backoff.py +0 -0
  64. {mostlyright_data-0.31.49 → mostlyright_data-0.31.50}/src/mostlyright/data_harness/thin/categories.py +0 -0
  65. {mostlyright_data-0.31.49 → mostlyright_data-0.31.50}/src/mostlyright/data_harness/thin/dataset-categories-v1.json +0 -0
  66. {mostlyright_data-0.31.49 → mostlyright_data-0.31.50}/src/mostlyright/data_harness/thin/dataset_layout.py +0 -0
  67. {mostlyright_data-0.31.49 → mostlyright_data-0.31.50}/src/mostlyright/data_harness/thin/delivery.py +0 -0
  68. {mostlyright_data-0.31.49 → mostlyright_data-0.31.50}/src/mostlyright/data_harness/thin/description_shape.py +0 -0
  69. {mostlyright_data-0.31.49 → mostlyright_data-0.31.50}/src/mostlyright/data_harness/thin/download.py +0 -0
  70. {mostlyright_data-0.31.49 → mostlyright_data-0.31.50}/src/mostlyright/data_harness/thin/enrichment.py +0 -0
  71. {mostlyright_data-0.31.49 → mostlyright_data-0.31.50}/src/mostlyright/data_harness/thin/fast_features.py +0 -0
  72. {mostlyright_data-0.31.49 → mostlyright_data-0.31.50}/src/mostlyright/data_harness/thin/matching_benchmark.py +0 -0
  73. {mostlyright_data-0.31.49 → mostlyright_data-0.31.50}/src/mostlyright/data_harness/thin/probe.py +0 -0
  74. {mostlyright_data-0.31.49 → mostlyright_data-0.31.50}/src/mostlyright/data_harness/thin/progress_rate.py +0 -0
  75. {mostlyright_data-0.31.49 → mostlyright_data-0.31.50}/src/mostlyright/data_harness/thin/progress_vocabulary.py +0 -0
  76. {mostlyright_data-0.31.49 → mostlyright_data-0.31.50}/src/mostlyright/data_harness/thin/recipe.py +0 -0
  77. {mostlyright_data-0.31.49 → mostlyright_data-0.31.50}/src/mostlyright/data_harness/thin/recipe_brief.py +0 -0
  78. {mostlyright_data-0.31.49 → mostlyright_data-0.31.50}/src/mostlyright/data_harness/thin/recipe_explain.py +0 -0
  79. {mostlyright_data-0.31.49 → mostlyright_data-0.31.50}/src/mostlyright/data_harness/thin/recipe_forecast.py +0 -0
  80. {mostlyright_data-0.31.49 → mostlyright_data-0.31.50}/src/mostlyright/data_harness/thin/recipe_lint.py +0 -0
  81. {mostlyright_data-0.31.49 → mostlyright_data-0.31.50}/src/mostlyright/data_harness/thin/recipe_test.py +0 -0
  82. {mostlyright_data-0.31.49 → mostlyright_data-0.31.50}/src/mostlyright/data_harness/thin/refresh_rehearsal.py +0 -0
  83. {mostlyright_data-0.31.49 → mostlyright_data-0.31.50}/src/mostlyright/data_harness/thin/release_check.py +0 -0
  84. {mostlyright_data-0.31.49 → mostlyright_data-0.31.50}/src/mostlyright/data_harness/thin/research.py +0 -0
  85. {mostlyright_data-0.31.49 → mostlyright_data-0.31.50}/src/mostlyright/data_harness/thin/router.py +0 -0
  86. {mostlyright_data-0.31.49 → mostlyright_data-0.31.50}/src/mostlyright/data_harness/thin/run_diagnose.py +0 -0
  87. {mostlyright_data-0.31.49 → mostlyright_data-0.31.50}/src/mostlyright/data_harness/thin/run_prefix.py +0 -0
  88. {mostlyright_data-0.31.49 → mostlyright_data-0.31.50}/src/mostlyright/data_harness/thin/runs.py +0 -0
  89. {mostlyright_data-0.31.49 → mostlyright_data-0.31.50}/src/mostlyright/data_harness/thin/session.py +0 -0
  90. {mostlyright_data-0.31.49 → mostlyright_data-0.31.50}/src/mostlyright/data_harness/thin/stream.py +0 -0
  91. {mostlyright_data-0.31.49 → mostlyright_data-0.31.50}/src/mostlyright/data_harness/thin/stream_venue.py +0 -0
  92. {mostlyright_data-0.31.49 → mostlyright_data-0.31.50}/src/mostlyright/data_harness/thin/studio_capabilities.py +0 -0
  93. {mostlyright_data-0.31.49 → mostlyright_data-0.31.50}/src/mostlyright/data_harness/thin/support.py +0 -0
  94. {mostlyright_data-0.31.49 → mostlyright_data-0.31.50}/src/mostlyright/data_harness/thin/table_search_contract.json +0 -0
  95. {mostlyright_data-0.31.49 → mostlyright_data-0.31.50}/src/mostlyright/data_harness/thin/table_view.py +0 -0
  96. {mostlyright_data-0.31.49 → mostlyright_data-0.31.50}/src/mostlyright/data_harness/thin/user_agent.py +0 -0
  97. {mostlyright_data-0.31.49 → mostlyright_data-0.31.50}/src/mostlyright/data_harness/thin/v4.py +0 -0
  98. {mostlyright_data-0.31.49 → mostlyright_data-0.31.50}/src/mostlyright/data_harness/thin/v4_artifacts.py +0 -0
  99. {mostlyright_data-0.31.49 → mostlyright_data-0.31.50}/src/mostlyright/data_harness/thin/v4_catalog.py +0 -0
  100. {mostlyright_data-0.31.49 → mostlyright_data-0.31.50}/src/mostlyright/data_harness/thin/v4_connected.py +0 -0
  101. {mostlyright_data-0.31.49 → mostlyright_data-0.31.50}/src/mostlyright/data_harness/thin/v4_connections.py +0 -0
  102. {mostlyright_data-0.31.49 → mostlyright_data-0.31.50}/src/mostlyright/data_harness/thin/v4_dataset_covers.py +0 -0
  103. {mostlyright_data-0.31.49 → mostlyright_data-0.31.50}/src/mostlyright/data_harness/thin/v4_datasets.py +0 -0
  104. {mostlyright_data-0.31.49 → mostlyright_data-0.31.50}/src/mostlyright/data_harness/thin/v4_handoff.py +0 -0
  105. {mostlyright_data-0.31.49 → mostlyright_data-0.31.50}/src/mostlyright/data_harness/thin/v4_matching.py +0 -0
  106. {mostlyright_data-0.31.49 → mostlyright_data-0.31.50}/src/mostlyright/data_harness/thin/v4_narrative.py +0 -0
  107. {mostlyright_data-0.31.49 → mostlyright_data-0.31.50}/src/mostlyright/data_harness/thin/v4_public.py +0 -0
  108. {mostlyright_data-0.31.49 → mostlyright_data-0.31.50}/src/mostlyright/data_harness/thin/v4_public_pull.py +0 -0
  109. {mostlyright_data-0.31.49 → mostlyright_data-0.31.50}/src/mostlyright/data_harness/thin/v4_reader.py +0 -0
  110. {mostlyright_data-0.31.49 → mostlyright_data-0.31.50}/src/mostlyright/data_harness/thin/v4_runs.py +0 -0
  111. {mostlyright_data-0.31.49 → mostlyright_data-0.31.50}/src/mostlyright/data_harness/thin/v4_search.py +0 -0
  112. {mostlyright_data-0.31.49 → mostlyright_data-0.31.50}/src/mostlyright/data_harness/thin/v4_search_contract.py +0 -0
  113. {mostlyright_data-0.31.49 → mostlyright_data-0.31.50}/src/mostlyright/data_harness/thin/v4_secrets.py +0 -0
  114. {mostlyright_data-0.31.49 → mostlyright_data-0.31.50}/src/mostlyright/data_harness/thin/v4_stream.py +0 -0
  115. {mostlyright_data-0.31.49 → mostlyright_data-0.31.50}/src/mostlyright/data_harness/thin/v4_tables.py +0 -0
  116. {mostlyright_data-0.31.49 → mostlyright_data-0.31.50}/src/mostlyright/data_harness/thin/vocabulary.py +0 -0
  117. {mostlyright_data-0.31.49 → mostlyright_data-0.31.50}/src/mostlyright/data_harness/ux/__init__.py +0 -0
  118. {mostlyright_data-0.31.49 → mostlyright_data-0.31.50}/src/mostlyright/data_harness/ux/attendance.py +0 -0
  119. {mostlyright_data-0.31.49 → mostlyright_data-0.31.50}/src/mostlyright/data_harness/ux/clarification.py +0 -0
  120. {mostlyright_data-0.31.49 → mostlyright_data-0.31.50}/src/mostlyright/data_harness/ux/cloud_auth.py +0 -0
  121. {mostlyright_data-0.31.49 → mostlyright_data-0.31.50}/src/mostlyright/data_harness/ux/commands/__init__.py +0 -0
  122. {mostlyright_data-0.31.49 → mostlyright_data-0.31.50}/src/mostlyright/data_harness/ux/commands/auth.py +0 -0
  123. {mostlyright_data-0.31.49 → mostlyright_data-0.31.50}/src/mostlyright/data_harness/ux/commands/clarify.py +0 -0
  124. {mostlyright_data-0.31.49 → mostlyright_data-0.31.50}/src/mostlyright/data_harness/ux/commands/login.py +0 -0
  125. {mostlyright_data-0.31.49 → mostlyright_data-0.31.50}/src/mostlyright/data_harness/ux/commands/whoami.py +0 -0
  126. {mostlyright_data-0.31.49 → mostlyright_data-0.31.50}/src/mostlyright/data_harness/ux/credential_native.py +0 -0
  127. {mostlyright_data-0.31.49 → mostlyright_data-0.31.50}/src/mostlyright/data_harness/ux/credential_store.py +0 -0
  128. {mostlyright_data-0.31.49 → mostlyright_data-0.31.50}/src/mostlyright/data_harness/ux/credentials.py +0 -0
  129. {mostlyright_data-0.31.49 → mostlyright_data-0.31.50}/src/mostlyright/data_harness/ux/login.py +0 -0
  130. {mostlyright_data-0.31.49 → mostlyright_data-0.31.50}/src/mostlyright/data_harness/ux/path_kind.py +0 -0
  131. {mostlyright_data-0.31.49 → mostlyright_data-0.31.50}/src/mostlyright/data_harness/ux/plain_file.py +0 -0
  132. {mostlyright_data-0.31.49 → mostlyright_data-0.31.50}/src/mostlyright/data_harness/ux/render.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: mostlyright-data
3
- Version: 0.31.49
3
+ Version: 0.31.50
4
4
  Summary: Mostly Right hosted CLI for reviewed datasets
5
5
  Project-URL: Homepage, https://mostlyright.md/
6
6
  Project-URL: Documentation, https://mostlyright.md/docs/guides/cli/
@@ -35,6 +35,12 @@ from mostlyright.data_harness.thin.user_agent import with_user_agent
35
35
  #: passes its own, much larger, timeout.
36
36
  REQUEST_TIMEOUT_SECONDS = 30.0
37
37
 
38
+ #: Drop a pooled socket that has been idle longer than this, instead of reusing it. The sandbox
39
+ #: forwarder is a Node server whose default ``keepAliveTimeout`` is five seconds; a request written
40
+ #: on a socket the server has already closed fails before any response byte. Four seconds leaves a
41
+ #: margin between this check and that close.
42
+ POOLED_CONNECTION_IDLE_SECONDS = 4.0
43
+
38
44
  #: A JSON answer from Cloud or Studio that exceeds this is refused unread. Every response this
39
45
  #: lane parses is a small object; a signed download session is the largest of them.
40
46
  MAX_JSON_RESPONSE_BYTES = 1024 * 1024
@@ -361,7 +367,12 @@ class ReusableHttpsTransport(UrlLibTransport):
361
367
  urllib deliberately sends Connection: close. A query client reuses its
362
368
  own connection instead, never a global credential-bearing pool. Changing
363
369
  origin closes the old socket. Responses are bounded and fully framed;
364
- any failure discards the socket and is raised without replaying a POST.
370
+ a failure discards the socket. A POST is replayed only when
371
+ ``idempotent_post`` is set. Query submit sets it: Studio derives the query
372
+ id from the canonical command, so a second identical POST is the same query.
373
+ A reused connection that then fails before any response byte is sent again
374
+ once, on a new connection. A pooled socket idle longer than
375
+ :data:`POOLED_CONNECTION_IDLE_SECONDS` is closed instead of reused.
365
376
  Only the host-only root GAESA routing cookie is retained in memory, bound
366
377
  to this client's exact origin and authorization context, never login cookies.
367
378
  """
@@ -371,12 +382,15 @@ class ReusableHttpsTransport(UrlLibTransport):
371
382
  *,
372
383
  timeout: float | Callable[[], float] = REQUEST_TIMEOUT_SECONDS,
373
384
  context: ssl.SSLContext | None = None,
385
+ idempotent_post: bool = False,
374
386
  ) -> None:
375
387
  self._timeout = timeout if callable(timeout) else float(timeout)
376
388
  self._context = context if context is not None else ssl.create_default_context()
389
+ self._idempotent_post = bool(idempotent_post)
377
390
  self._lock = threading.Lock()
378
391
  self._connection: http.client.HTTPConnection | None = None
379
392
  self._connection_origin: tuple[str, str, int] | None = None
393
+ self._connection_idle_at: float | None = None
380
394
  self._routing = CookieJar(policy=_RoutingCookiePolicy())
381
395
  self._routing_context: tuple[tuple[str, str, int], bytes] | None = None
382
396
  self._stream_lock = threading.Lock()
@@ -387,6 +401,7 @@ class ReusableHttpsTransport(UrlLibTransport):
387
401
  def _discard(self) -> None:
388
402
  connection, self._connection = self._connection, None
389
403
  self._connection_origin = None
404
+ self._connection_idle_at = None
390
405
  if connection is not None:
391
406
  connection.close()
392
407
 
@@ -597,10 +612,23 @@ class ReusableHttpsTransport(UrlLibTransport):
597
612
  if parts.query:
598
613
  path += "?" + parts.query
599
614
  outgoing_headers = dict(cookie_request.header_items())
600
- idempotent = method.upper() in {"GET", "HEAD"}
615
+ # GET and HEAD are safe to send again. A POST is safe only when the caller has said
616
+ # this transport's posts are idempotent. Query submit is: the id is a digest of the
617
+ # command. A session open or a metered mint is not, and stays one send.
618
+ idempotent = method.upper() in {"GET", "HEAD"} or (
619
+ self._idempotent_post and method.upper() == "POST"
620
+ )
601
621
  response: http.client.HTTPResponse | None = None
602
622
  for attempt in range(2):
603
623
  reused = self._connection is not None and self._connection.sock is not None
624
+ if (
625
+ reused
626
+ and self._connection_idle_at is not None
627
+ and time.monotonic() - self._connection_idle_at
628
+ > POOLED_CONNECTION_IDLE_SECONDS
629
+ ):
630
+ self._discard()
631
+ reused = False
604
632
  if self._connection is None:
605
633
  self._connection = self._open_connection(origin, remaining())
606
634
  self._connection_origin = origin
@@ -609,20 +637,30 @@ class ReusableHttpsTransport(UrlLibTransport):
609
637
  if connection.sock is not None:
610
638
  connection.sock.settimeout(remaining())
611
639
  try:
640
+ # A reset or a broken pipe here is the write, before any response byte.
641
+ # RemoteDisconnected is a ConnectionResetError, so it is included.
612
642
  connection.request(method, path, body=body, headers=outgoing_headers)
613
- if connection.sock is not None:
614
- connection.sock.settimeout(remaining())
643
+ except (ConnectionResetError, BrokenPipeError):
644
+ self._discard()
645
+ if not (idempotent and reused and attempt == 0):
646
+ raise
647
+ continue
648
+ if connection.sock is not None:
649
+ connection.sock.settimeout(remaining())
650
+ try:
615
651
  response = connection.getresponse()
616
- break
617
- except (
618
- http.client.RemoteDisconnected,
619
- http.client.BadStatusLine,
620
- ConnectionResetError,
621
- BrokenPipeError,
622
- ):
652
+ except http.client.RemoteDisconnected:
653
+ # An empty status line: the server closed before sending a response.
654
+ # A BadStatusLine is bytes that are not a status, and a ConnectionResetError
655
+ # while reading may follow bytes already delivered. Neither is sent again.
623
656
  self._discard()
624
- if not (idempotent and reused) or attempt == 1:
657
+ if not (idempotent and reused and attempt == 0):
625
658
  raise
659
+ continue
660
+ except (ConnectionResetError, BrokenPipeError):
661
+ self._discard()
662
+ raise
663
+ break
626
664
  assert response is not None
627
665
  expected = response.length
628
666
  chunks: list[bytes] = []
@@ -650,6 +688,8 @@ class ReusableHttpsTransport(UrlLibTransport):
650
688
  response.close()
651
689
  if response.will_close or connection.sock is None or status < 200:
652
690
  self._discard()
691
+ else:
692
+ self._connection_idle_at = time.monotonic()
653
693
  return status, raw, response_headers
654
694
  except BaseException:
655
695
  self._discard()
@@ -39,6 +39,7 @@ from __future__ import annotations
39
39
 
40
40
  import argparse
41
41
  import hashlib
42
+ import http.client
42
43
  import os
43
44
  import re
44
45
  import time
@@ -305,6 +306,40 @@ def _cloud_asked_for_a_moment(refusal: ThinLaneError) -> bool:
305
306
  return getattr(refusal, "studio_code", None) is None
306
307
 
307
308
 
309
+ def _cloud_transport_refusal(error: BaseException, *, act: str) -> ThinLaneError:
310
+ """The refusal for one transport failure, named by which kind it was.
311
+
312
+ A timeout waited out its clock. A dropped connection, including one the transport already
313
+ replayed once, closed before a full answer. A refused connection or a name that did not
314
+ resolve never opened. Anything else that still cannot be classified is unreachable too:
315
+ the host was not a party to an exchange.
316
+ """
317
+
318
+ if isinstance(error, TimeoutError):
319
+ return ThinLaneError(
320
+ "THIN_CLOUD_TIMEOUT", f"Cloud did not answer in time the request to {act}"
321
+ )
322
+ # RemoteDisconnected is a ConnectionResetError for an empty status line. A reset, a broken
323
+ # pipe, a status line that is not HTTP, or a body cut short are a connection that closed.
324
+ # A refusal, a DNS failure, and anything else that never exchanged bytes stay unreachable.
325
+ if isinstance(
326
+ error,
327
+ (
328
+ ConnectionResetError,
329
+ BrokenPipeError,
330
+ http.client.BadStatusLine,
331
+ http.client.IncompleteRead,
332
+ ),
333
+ ):
334
+ return ThinLaneError(
335
+ "THIN_CLOUD_CONNECTION_DROPPED",
336
+ f"Cloud dropped the connection on the request to {act}",
337
+ )
338
+ return ThinLaneError(
339
+ "THIN_CLOUD_UNREACHABLE", f"Cloud could not be reached for the request to {act}"
340
+ )
341
+
342
+
308
343
  class CloudRunQueryClient(CloudClient):
309
344
  """Cloud's two metered query routes, behind the device key.
310
345
 
@@ -319,9 +354,12 @@ class CloudRunQueryClient(CloudClient):
319
354
  :data:`QUERY_REQUEST_TIMEOUT_SECONDS` is longer than that, so Cloud's own answer always lands.
320
355
 
321
356
  ⚠ AND THE SAME BOUNDED RETRIES AS THE METERED MINTS, on Cloud's own 429 and 503 only. A
322
- transport failure is ``THIN_CLOUD_UNREACHABLE`` at once. A resubmit after a 503 is safe as well
323
- as bounded: Studio derives the query's identifier from the command, so a submit that was queued
324
- before Cloud failed is answered again as the same query.
357
+ resubmit after a 503 is safe as well as bounded: Studio derives the query's identifier from the
358
+ command, so a submit that was queued before Cloud failed is answered again as the same query.
359
+ That is also why the transport this client constructs may replay one POST when a reused
360
+ connection dies before any response byte. A timeout is ``THIN_CLOUD_TIMEOUT``. A connection
361
+ dropped, including after that one replay, is ``THIN_CLOUD_CONNECTION_DROPPED``. A connection
362
+ that never opened — refused, or a name that did not resolve — stays ``THIN_CLOUD_UNREACHABLE``.
325
363
  """
326
364
 
327
365
  def __init__(
@@ -331,9 +369,15 @@ class CloudRunQueryClient(CloudClient):
331
369
  transport: Transport | None = None,
332
370
  sleep: Callable[[float], None] = time.sleep,
333
371
  ) -> None:
372
+ # Query submit is the only POST this client sends, and it is idempotent: Studio derives
373
+ # the query id from the canonical command. The flag is not the default, because the same
374
+ # transport class also carries posts that must not be sent twice.
334
375
  super().__init__(
335
376
  credentials,
336
- transport=transport or ReusableHttpsTransport(timeout=QUERY_REQUEST_TIMEOUT_SECONDS),
377
+ transport=transport
378
+ or ReusableHttpsTransport(
379
+ timeout=QUERY_REQUEST_TIMEOUT_SECONDS, idempotent_post=True
380
+ ),
337
381
  )
338
382
  self._sleep = sleep
339
383
 
@@ -364,9 +408,7 @@ class CloudRunQueryClient(CloudClient):
364
408
  method, f"{self._origin}{path}", headers, encoded, MAX_JSON_RESPONSE_BYTES
365
409
  )
366
410
  except (OSError, HTTPException) as error:
367
- raise ThinLaneError(
368
- "THIN_CLOUD_UNREACHABLE", f"Cloud did not answer the request to {act}"
369
- ) from error
411
+ raise _cloud_transport_refusal(error, act=act) from error
370
412
  if response_headers is not None:
371
413
  response_headers.clear()
372
414
  response_headers.update(answered)
@@ -11,7 +11,7 @@ neither affordable nor honest:
11
11
  * **Families.** Every code prefix is assigned to a family -- 224 of them, plus 20 compound
12
12
  prefixes, across 40 families. A family is one paragraph: what this class of failure is about,
13
13
  where to look, and what to do. Every prefix has one, so no code can fail to say something useful.
14
- * **Curated codes.** The 130 failures a person actually meets get their own exact sentences, and
14
+ * **Curated codes.** The 132 failures a person actually meets get their own exact sentences, and
15
15
  where one command is the whole answer, the command itself.
16
16
 
17
17
  Those four counts are not a note somebody remembered to update:
@@ -2435,6 +2435,20 @@ CODES: dict[str, Remediation] = {
2435
2435
  "files it already verified.",
2436
2436
  ),
2437
2437
  ),
2438
+ "THIN_CLOUD_TIMEOUT": Remediation(
2439
+ lines=(
2440
+ "Mostly Right Cloud did not answer before the deadline.",
2441
+ "Run the command again. For a bounded query, a repeat is the same question and "
2442
+ "reads that query back rather than starting another.",
2443
+ ),
2444
+ ),
2445
+ "THIN_CLOUD_CONNECTION_DROPPED": Remediation(
2446
+ lines=(
2447
+ "Mostly Right Cloud closed the connection before a full answer arrived.",
2448
+ "Run the command again. For a bounded query, a repeat is the same question and "
2449
+ "reads that query back rather than starting another.",
2450
+ ),
2451
+ ),
2438
2452
  "THIN_RATE_LIMITED": Remediation(
2439
2453
  lines=(
2440
2454
  "Mostly Right Cloud asked this command to slow down. Nothing was changed.",