Commit 7ff1a81
authored
aitools: extract pollStatement helper and pin OnWaitTimeout (#5092)
## Stack
This PR is part of a 4-PR stack making `aitools` data exploration faster
for ai-dev-kit. Each PR is independently reviewable; merge in order.
1. **#5092 — aitools: extract pollStatement helper and pin
OnWaitTimeout** *(base: `main`)* — **this PR**
2. #5093 — aitools: run multiple SQL queries in parallel from one query
invocation *(base: #5092)*
3. #5095 — aitools: add 'tools statement' lifecycle commands *(base:
#5093)*
4. #5097 — aitools: parallelize discover-schema across tables and probes
*(base: #5095)*
Use `git diff <base>...HEAD` or set the comparison base in the GitHub UI
to see only this PR's changes; the default "Files changed" diff against
`main` includes ancestor PRs.
---
## Why
The query command in `experimental/aitools/cmd/query.go` works today,
but two things make it fragile and hard to reuse:
1. The polling loop, signal handling, spinner, and server-side
cancellation are entangled in one ~100-line function. Upcoming features
(parallel batch queries, a statement lifecycle command tree) need pure
polling without the signal-handler side effects, so the helper has to
come out cleanly.
2. The `ExecuteStatement` request sets `WaitTimeout: 0s` but does not
set `OnWaitTimeout`. That relies on the SDK's default being `CONTINUE`.
It is today, but a flip would silently break the command: the statement
would be cancelled before our first GET and we'd never see the result.
This PR is a pure refactor + one explicit-default fix. No user-visible
behavior change.
## Changes
- Extract `pollStatement(ctx, api, resp)` from `executeAndPoll`. The
helper polls until the statement reaches a terminal state and returns
the response. It does not call `CancelExecution` on context
cancellation, that's the caller's job (and a deliberate design choice
for the upcoming `statement get` command, where Ctrl+C should stop
polling without killing the server-side statement).
- Pin `OnWaitTimeout: CONTINUE` explicitly on the `ExecuteStatement`
call.
- Update `executeAndPoll` to delegate to `pollStatement` and keep the
existing signal-handling, spinner, and server-side cancel-on-Ctrl+C
semantics intact.
- Add five unit tests covering the new helper:
- Immediate terminal short-circuit (no Get calls)
- Failed terminal returned without error (caller decides)
- Eventual success across multiple polls
- Context cancellation returns ctx error and does NOT call
CancelExecution
- GetStatement transport error is wrapped and propagated
- Update the existing `TestExecuteAndPollImmediateSuccess` matcher to
assert `OnWaitTimeout == CONTINUE` so a future SDK default flip cannot
regress us.
## Test plan
- [x] `go test ./experimental/aitools/...` passes (10 polling-related
cases including the 5 new ones).
- [x] `make checks` clean (tidy, whitespace, dead code).
- [x] `make fmt` no drift.
- [x] `make lint` 0 issues.
- [x] Existing `executeAndPoll` tests (immediate success, immediate
failure, polling, fail-during-poll,
ctx-cancellation-calls-cancel-execution) all still pass without
modification beyond the matcher tweak.1 parent 30e21b5 commit 7ff1a81
2 files changed
Lines changed: 146 additions & 22 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
262 | 262 | | |
263 | 263 | | |
264 | 264 | | |
265 | | - | |
266 | | - | |
267 | | - | |
| 265 | + | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
268 | 269 | | |
269 | 270 | | |
270 | 271 | | |
271 | 272 | | |
272 | 273 | | |
273 | 274 | | |
274 | 275 | | |
275 | | - | |
276 | | - | |
277 | | - | |
278 | | - | |
279 | | - | |
280 | 276 | | |
281 | 277 | | |
282 | 278 | | |
| |||
327 | 323 | | |
328 | 324 | | |
329 | 325 | | |
| 326 | + | |
| 327 | + | |
| 328 | + | |
| 329 | + | |
| 330 | + | |
| 331 | + | |
| 332 | + | |
| 333 | + | |
| 334 | + | |
| 335 | + | |
| 336 | + | |
| 337 | + | |
| 338 | + | |
| 339 | + | |
| 340 | + | |
| 341 | + | |
| 342 | + | |
| 343 | + | |
| 344 | + | |
| 345 | + | |
| 346 | + | |
| 347 | + | |
| 348 | + | |
| 349 | + | |
| 350 | + | |
| 351 | + | |
| 352 | + | |
| 353 | + | |
| 354 | + | |
| 355 | + | |
| 356 | + | |
| 357 | + | |
| 358 | + | |
330 | 359 | | |
331 | 360 | | |
332 | 361 | | |
333 | 362 | | |
334 | | - | |
335 | | - | |
336 | | - | |
337 | | - | |
| 363 | + | |
| 364 | + | |
338 | 365 | | |
339 | 366 | | |
340 | 367 | | |
341 | 368 | | |
342 | 369 | | |
343 | | - | |
| 370 | + | |
344 | 371 | | |
345 | | - | |
346 | | - | |
347 | | - | |
348 | | - | |
| 372 | + | |
| 373 | + | |
349 | 374 | | |
350 | 375 | | |
351 | 376 | | |
352 | 377 | | |
353 | 378 | | |
354 | | - | |
355 | | - | |
356 | | - | |
357 | | - | |
358 | 379 | | |
359 | 380 | | |
360 | 381 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2 | 2 | | |
3 | 3 | | |
4 | 4 | | |
| 5 | + | |
5 | 6 | | |
6 | 7 | | |
7 | 8 | | |
| |||
48 | 49 | | |
49 | 50 | | |
50 | 51 | | |
51 | | - | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
52 | 55 | | |
53 | 56 | | |
54 | 57 | | |
| |||
154 | 157 | | |
155 | 158 | | |
156 | 159 | | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
| 258 | + | |
| 259 | + | |
157 | 260 | | |
158 | 261 | | |
159 | 262 | | |
| |||
0 commit comments