-
Notifications
You must be signed in to change notification settings - Fork 0
Define runtime workspace selection contract #2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
6068b56
Define a canonical workspace selection contract.
eddietejeda 618f3c3
Handle cancelled persisted results as terminal failures.
eddietejeda 26acad1
Align runtime contract with adapter usage and ambiguity safeguards.
eddietejeda 632b689
Add normalized runtime adapters and shared result helpers.
eddietejeda 631e57e
Align run-history helper pagination with result listings.
eddietejeda d3a7823
Add runtime usage example and README reference.
eddietejeda 161a142
Drop HOTDATA_TOKEN fallback from runtime auth resolution.
eddietejeda 3e5d531
refactor: read workspace id from HOTDATA_WORKSPACE_ID only
eddietejeda ba06915
feat: add HTTP retries and resilient execute_sql
eddietejeda 747ca1c
refactor: use HOTDATA_WORKSPACE env var
eddietejeda 78f8541
fix: remove unsupported run history offset from example
eddietejeda 466d697
docs: add runtime feature overview
eddietejeda 9beb00a
docs: match run history contract to helper signature
eddietejeda File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,92 @@ | ||
| # hotdata-runtime Contract | ||
|
|
||
| `hotdata-runtime` is the framework-agnostic runtime contract for Hotdata integrations. | ||
|
|
||
| ## Scope | ||
|
|
||
| This package provides shared primitives for: | ||
|
|
||
| - Environment and workspace resolution | ||
| - Query execution and polling | ||
| - Normalized tabular result handling | ||
| - Basic workspace health checks | ||
|
|
||
| ## Public Runtime Contract | ||
|
|
||
| The supported import surface is: | ||
|
|
||
| - `HotdataClient` | ||
| - `QueryResult` | ||
| - `from_env` | ||
| - `workspace_health_lines` | ||
| - `default_api_key` | ||
| - `default_host` | ||
| - `default_session_id` | ||
| - `explicit_workspace_id` | ||
| - `list_workspaces` | ||
| - `normalize_host` | ||
| - `pick_workspace` | ||
| - `resolve_workspace_selection` | ||
| - `ResultSummary` | ||
| - `RunHistoryItem` | ||
| - `WorkspaceSelection` | ||
|
|
||
| Adapters should import from `hotdata_runtime` and treat this surface as the stable API. | ||
|
|
||
| ## Semantic Guarantees | ||
|
|
||
| ### `HotdataClient` | ||
|
|
||
| - Represents runtime context: API key, host, workspace, optional session. | ||
| - `from_env()` resolves runtime context from env vars and selected workspace. | ||
| - `execute_sql(sql)` returns `QueryResult` or raises `RuntimeError`/`TimeoutError`. | ||
| - `get_result(result_id)` returns a ready `QueryResult` and waits for readiness when needed. | ||
| - `connections()` returns the connections API wrapper for adapter UI/status features. | ||
| - `query_runs()` returns the query-runs API wrapper for adapter history views. | ||
| - `results()` returns the results API wrapper for adapter result pickers. | ||
| - `list_recent_results(...)` returns normalized `ResultSummary` entries. | ||
| - `list_run_history(limit=...)` returns normalized `RunHistoryItem` entries. | ||
| - `list_qualified_table_names(...)` returns sorted fully qualified table names. | ||
| - `columns_for_qualified(qualified, connection_id=...)` resolves table columns, and | ||
| adapters should pass `connection_id` when known. | ||
|
|
||
| ### `QueryResult` | ||
|
|
||
| - Canonical tabular result model with `columns`, `rows`, and `row_count`. | ||
| - Carries server identifiers and execution metadata when available. | ||
| - `to_pandas()` converts to a DataFrame with stable column ordering. | ||
| - `to_records(max_rows=...)` returns row dicts keyed by column names. | ||
| - `metadata_dict()` returns normalized result metadata for adapter rendering. | ||
|
|
||
| ### Env Resolution | ||
|
|
||
| - `default_api_key()` reads `HOTDATA_API_KEY`. | ||
| - `default_host()` reads `HOTDATA_API_URL` (default: `https://api.hotdata.dev`) and normalizes it. | ||
| - `default_session_id()` reads `HOTDATA_SANDBOX`. | ||
| - `explicit_workspace_id()` reads `HOTDATA_WORKSPACE` (workspace public id). | ||
| - `pick_workspace()` prefers explicit env workspace, then active workspace, then first workspace. | ||
| - `resolve_workspace_selection()` is the canonical workspace selection algorithm. It returns `WorkspaceSelection` with selected workspace id, selection source, and discovered workspaces when auto-selected. | ||
|
|
||
| ## Adapter Responsibilities | ||
|
|
||
| Framework packages (Jupyter, Marimo, LangChain, LangGraph, LlamaIndex, Streamlit) own: | ||
|
|
||
| - Framework-native lifecycle and state management | ||
| - Rendering/UI concerns | ||
| - Tool/agent wrappers and callback integration | ||
|
|
||
| They should not duplicate runtime env/workspace/query semantics. | ||
|
|
||
| ## Runtime Non-Goals | ||
|
|
||
| `hotdata-runtime` does not define framework UI primitives and does not require framework dependencies. | ||
|
|
||
| ## Versioning Policy | ||
|
|
||
| - Backward-incompatible contract changes require a major version bump. | ||
| - Additive contract changes are minor versions. | ||
| - Bug fixes that preserve contract semantics are patch versions. | ||
|
|
||
| ## Enforcement | ||
|
|
||
| Contract stability is enforced by tests that verify the public export surface and key behavioral invariants. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| """Basic hotdata-runtime usage.""" | ||
|
|
||
| from hotdata_runtime import from_env | ||
|
|
||
|
|
||
| def main() -> None: | ||
| client = from_env() | ||
| result = client.execute_sql("SELECT 1 AS ok") | ||
|
|
||
| print("result metadata:", result.metadata_dict()) | ||
| print("records:", result.to_records(max_rows=5)) | ||
|
|
||
| print("recent results:") | ||
| for item in client.list_recent_results(limit=5, offset=0): | ||
| print(item.to_dict()) | ||
|
|
||
| print("run history:") | ||
| for item in client.list_run_history(limit=5): | ||
| print(item.to_dict()) | ||
|
|
||
| client.close() | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| main() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
super nit: (not blocking)
list_recent_resultsacceptsoffsetbutlist_run_historydoes not, and their defaultlimits differ (50 vs 20). Both wrap paginated server endpoints and adapters will likely want to page through both. Adding a matchingoffset: int = 0tolist_run_history(and considering aligning default limits) would make these helpers consistent and avoid surprise when adapters reuse pagination code across the two.