mirror of
https://github.com/baserow/baserow.git
synced 2026-12-05 00:38:35 +00:00
develop
4
Commits
| Author | SHA1 | Message | Date | |
|---|---|---|---|---|
|
|
f5bc919473 |
feat(celery): make every task work on a threads worker, and use one in dev (#6926)
* chore(dev): run one threads Celery worker with beat in dev The Docker and native dev stacks start a single Celery worker for every queue, with redbeat embedded, instead of a worker, an export worker and a beat process. It uses a new ThreadsPool that sends worker_process_init, so telemetry and the lazy import check still run under the threads pool. * fix(ws): stop closing every event loop's Redis pools after a broadcast send_messages_to_channel_group called channel_layer.close_pools(), which closes the pools of every event loop, including the ones other worker threads are still sending with. Under the threads pool about a third of broadcasts failed with "attached to a different loop" and some hung. channels_redis now closes a loop's pools itself when that loop closes. * fix(telemetry): keep Celery trace context per thread on threads workers The Celery instrumentation keys a running task's span, context token and start time by the task's id. A task replaced with self.replace(), like every automation node, keeps its id, and on a threads worker the replacement can start in another thread before the original ends. The original then ended the replacement's span and detached its context from the wrong thread, logging "Failed to detach context" and leaving its own context on the thread. That state is now kept per thread. * feat(celery): enforce soft and hard time limits in ThreadsPool Celery's own threads pool ignores soft_time_limit and time_limit, so on a threads worker tasks that rely on them would run on. ThreadsPool now raises the limit in the task's thread, only while that task runs, so a limit never reaches the next task of the thread. EMAIL_TIMEOUT stops a silent SMTP server from blocking a worker thread forever. * fix(chat-runs): cancel a run that keeps going after its deadline The deadline only asks a run to stop. A run whose tools or provider call ignore that request now gets 60 more seconds, is then cancelled, and is saved as timed out. Celery's limit moves after that, so the run's own stop always comes first. On a threads worker this is the only way to end it, because a time limit can't reach a thread waiting inside async_to_sync. * fix(premium): share one capped thread pool across AI field generations Each generation started its own pool of BASEROW_AI_FIELD_MAX_CONCURRENT_GENERATIONS threads, so a threads worker running several jobs multiplied the threads and model calls. All generations in a process now share one pool of that size. A prefork process runs one job at a time, so nothing changes there. * feat(celery): cancel queries at the hard limit and report overdue tasks ThreadsPool checks every running task's time limits from one watchdog thread, like the prefork pool's timeout handler, instead of starting timer threads for each task. At the hard limit it also cancels the query the task's thread is running, which the limit's exception can't interrupt. A thread can't be killed, so a task still running 60 seconds after its hard limit is reported to Sentry instead. Every limit reached is counted in baserow.celery.task.time_limit, per task and limit. * fix(airtable): time out requests to Airtable Two Airtable import requests had no timeout, so a server that stopped answering held the import, and on a threads worker its thread, forever. All Airtable requests now use the same 3 minute read timeout. * fix(celery): load sentry_sdk only when reporting an overdue task The overdue report imported sentry_sdk at the top of baserow.config.celery, which every process imports, so it was loaded even with Sentry off. * chore: add a changelog entry for the Celery task timeouts * fix(celery): raise threads pool time limits at the task's next query An exception raised into a thread from outside can land right after a lock is taken and before the code that releases it, leaving the lock held for every thread of the worker. The pool now marks a reached limit and the task's own next query raises it, once, through a connection execute wrapper. The hard limit still cancels the running query, and raises TimeLimitExceeded whatever the soft limit is. Limits end before Celery's success callback runs. Savepoint queries are never interrupted, through a helper shared with the periodic field update deadline. * fix(celery): apply the worker default time limits on the threads pool Celery passes CELERY_TASK_SOFT_TIME_LIMIT and CELERY_TASK_TIME_LIMIT to the pool and None per task when a task sets no limit. The prefork pool falls back to the pool's values; the threads pool now does too. * fix(celery): keep threads pool time limits until running tasks end The watchdog stopped before on_stop waited for the running tasks, so a task passing its limit during a warm shutdown was never stopped or reported. * chore: name the emails the SMTP timeout covers in the changelog EMAIL_TIMEOUT applies to the instance's own emails only. Automation and builder SMTP steps already time out after 30 seconds. * chore(dev): drop dev.sh tabs for the removed Celery workers The export and beat services are disabled, so attaching to them made the script exit before opening the remaining tabs. * test(celery): cover thread time limits and savepoint rollback * fix(ai): use one generation slot for nonpositive limits * fix(chat): warn that an action may finish after a reply times out * docs(celery): explain which timeout guarantees require prefork * docs(celery): record the threads pool decision and task contract * fix(chat): keep the worker slot until started tools finish * fix(chat): warn visitors about repeating a timed-out request * docs(chat): clarify when the stop grace period begins |
||
|
|
b587de3dba |
feat(agent): configure per-user active-run limits (#6458)
* feat(agent): configure per-user active-run limits BASEROW_AGENT_MAX_ACTIVE_RUNS_PER_USER caps the Agent replies one user can have queued or running across workspaces. Unset means no limit, so self-hosted installs are unaffected. The run-type hook receives the user so a plugin can set the limit per user. * fix(agent): address review of the per-user run limit - Negative Agent run limits mean no limit, like the trigger limits, so no configured value can refuse every send. - Docs keep plan wording for the workspace hook only; the user hook sets one user's cap across workspaces. - ChatRunLimitReached docstrings say "a reply limit" instead of listing which limits exist. - Drop Agent tests that repeated core checks; core now checks that a finished run frees its slot. |
||
|
|
362f690b9e |
feat(chat-runs): per-run-type limits and a core run stream (#6454)
* feat(chat-runs): limit active runs per run type, per user or workspace Each run type now counts only its own runs. The per-user limit keeps its default of 2, and a run type can add a per-workspace limit. * feat(chat-runs): follow any run over one core streaming endpoint GET /api/chat-runs/<run_id>/stream/ relays the output of any run type behind its read check. Helm and the install guides route /api/chat-runs/ to the ASGI service; the guides also gain Kuma's /assistant/ route. * feat(chat-runs): read the core run stream by default in the frontend The base ChatRunType reads the core stream, applies the resume baseline and retries once after a token refresh. * refactor(chat-runs): expose the output fold for lost runs Run types rebuild a lost run's partial text from the buffered output with fold_output. * perf(chat-runs): send heartbeat records and skip repeated run reads While no output arrives, an open stream sends run.heartbeat as a JSON record, so a follower can tell a quiet stream from a stalled one. The stream view hands follow_run the run state it read for its permission check, finish_run returns the ended run instead of letting callers read it again, and a lease renewal takes one statement while the run goes on. The per-workspace limit hook receives the workspace, so a run type can set the limit per plan. * perf(chat-runs): follow runs from their open stream in the frontend The store reads a run's status only while it has no stream or the stream lost its output, and restarts a stream that stays silent for 15 seconds, also after the computer slept. Following a run opens its stream directly, and Stop doesn't read a run whose stream is open. Each run type keeps one chat subscription, released with unsubscribeFromChat; refreshChat runs only when a subscription is confirmed on a new websocket, and window focus or a regained network only re-attach followers. The developer guide documents the subscription and heartbeat contract. * perf(chat-runs): write a reply's first words at once - The journal writes output after a quiet moment at once and batches what follows, so the first words no longer wait for the 250 ms timer. - The stream adapter settles when aborted. Chrome can fire the last progress event after the request is done, where aborting fires no event. - A stream refused with 503 is retried with the next status check instead of spending every reconnect attempt at once. * refactor(chat-runs): register the stream route by URL name |
||
|
|
9eabe6b06b |
feat(core): add Redis-backed background chat runs (#6382)
* feat(core): add Redis-backed background chat runs Run AI work once in Celery and follow bounded Redis Streams over HTTP. Keep lifecycle, Stop, leases and final outcomes in Postgres without per-token writes. Include the shared frontend follower, adapter registry, recovery API, migration, queue/deployment wiring and adapter guide. No product uses it yet. Part of #6346 * Remove unused chat run response header exposure * Extract shared async streaming HTTP router * Simplify chat run follower and group engine constants - Check read access once when a stream opens; read run state from Postgres only after 5 s without output or on run.finished. - Split follow_run into small steps around _OutputReader. - Turn event kinds, error codes and stop reasons into StrEnums; the Kuma-only model_unavailable code moves to Kuma. - Document ChatRunType hooks with param, return and raises fields. - Add BASEROW_ASGI_HTTP_MAX_CONCURRENT_STREAMS and size the follower Redis pool by it. - Give handler publish/recover calls their own event loop, so cleanup cannot close pools shared by HTTP followers. - Update ADR 010 and the background chat runs docs. * Clean up chat run interfaces and test setup * Prune chat runs once after 7 days and skip overdue claims - Delete each expired page with one statement. Incomplete runs get one more ensure_interruption_warning call first, and are deleted even if it fails, so run metadata never accumulates. The hook now returns None. - Keep runs for 7 days instead of 30. - Never claim a queued run older than NOT_STARTED_AFTER; the sweeper ends it. * Retry brief Redis failures in chat run followers - A connection error, or a buffer that does not exist yet, is retried with the same cursor, sending heartbeats meanwhile. - run.replay_unavailable is only sent once the follower stops reading, so the browser can treat it as final. * Let finished chat run output expire with the active TTL Nothing reads a buffer once its run has finished: followers return the saved outcome first and recovery only reads running runs. Drop finish() and the 24 h TTL, so a finished buffer expires an hour after its last append. _publish_terminal now reuses _publish. * Run the chat run scale tests on fakeredis Build the buffer's real read and write pools on fakeredis connections, so these tests always run and backend CI needs no Redis service. The Kuma e2e tests cover a real Redis. * Address the remaining chat run review comments - Serialize the saved outcome after the transaction, so only a failed save is logged as one. - Make the primary-pin test transactional; inside the test transaction the router always used the primary, so it could not fail. - Cover the race past the per-user lock, a lost run after Stop and an old writer appending to a recreated buffer. - End the admission test's request with a disconnect, so a regression fails instead of looping. - Document that one worker process runs AI replies one at a time. * Move the chat run migration after develop's core 0130 * Log only the class of an outcome serialization error * Test that the run deadline asks a run to stop * Keep a run's status when a resumed follower rebuilds its output * Note that slow DNS lookups turn off a run's live output |