-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathopenapi.yaml
More file actions
7199 lines (6868 loc) · 236 KB
/
Copy pathopenapi.yaml
File metadata and controls
7199 lines (6868 loc) · 236 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
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
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
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
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
openapi: 3.0.3
info:
title: cix-server API
version: v1
description: |
HTTP API for the `cix-server` semantic code-index daemon.
The wire format is byte-stable across server versions; the `api_version`
field in `/api/v1/status` ticks independently from `server_version` when
a backwards-incompatible change lands.
## Authentication
Two parallel auth paths back the same identity model:
- **Browsers / dashboard**: `POST /api/v1/auth/login` with email +
password issues an HttpOnly cookie `cix_session`. The cookie is sent
automatically on subsequent same-origin requests. Sessions roll
forward 14 days from the last request.
- **CLI / SDK**: `Authorization: Bearer <api_key>` where the key was
issued by `POST /api/v1/api-keys`. Keys are owner-scoped and can be
revoked individually without affecting other clients.
Public endpoints (no auth required): `GET /health`, `GET /docs`,
`GET /openapi.yaml`, `GET /api/v1/auth/bootstrap-status`,
`POST /api/v1/auth/login`. Setting `CIX_AUTH_DISABLED=true` skips the
check on every endpoint (development only — a warning is logged).
When the server starts with an empty users table it requires
`CIX_BOOTSTRAP_ADMIN_EMAIL` + `CIX_BOOTSTRAP_ADMIN_PASSWORD` to seed
the first admin (forced to change password on first login). A legacy
`CIX_API_KEY` set on a fresh database is imported as a single
`env-bootstrap` API key owned by that admin.
## Project addressing
Project `host_path` values contain slashes that cannot be embedded in
URL segments cleanly, so project-scoped endpoints take a `{path}` URL
parameter that is the **first 16 hex chars of `SHA1(host_path)`**.
Compute it with `internal/projects.HashPath`.
## Streaming indexing
`POST /api/v1/projects/{path}/index/files` honours the `Accept` header:
sending `Accept: application/x-ndjson` switches the response to a
newline-delimited stream of `IndexProgressEvent` objects, with a
`heartbeat` event every 10 seconds. Old clients that send no Accept
header (or `application/json`) get the legacy single-JSON response.
## Errors
All error responses use the same body shape: `{"detail": "<message>"}`.
`GET /health` is the only exception — the unhealthy variant additionally
carries `{"reason": "..."}`.
servers:
# Relative URL — Swagger UI's "Try it out" sends requests to whatever
# origin served /openapi.json, so localhost:8001, localhost:21847, and a
# remote deployment all just work without CORS preflight surprises.
- url: /
description: Same-origin (auto-detected from the URL serving this spec)
security:
- bearerAuth: []
tags:
- name: probe
description: Health and status probes
- name: projects
description: Project lifecycle (CRUD)
- name: search
description: Symbol, definition, reference, file, and semantic search
- name: indexing
description: Three-phase indexing protocol
- name: search-stats
description: |
Per-project search counters: how often each project is searched and
which of its files keep coming back in the results. Counters only —
no query text and no per-request log is kept anywhere.
Two tiers are served from the same endpoints. `window=all` reads
cumulative totals that are never pruned; the other windows read a
rolling 7-day series bucketed at 30 minutes. The numbers live in
their own SQLite file so that recording them can never contend with
indexing or with a database compaction — search has to keep serving
through both.
- name: docs
description: API documentation
- name: auth
description: Sessions, login/logout, password change, current user
- name: admin
description: Admin-only user management
- name: api-keys
description: Issue and revoke owner-scoped API keys for CLI/SDK use
- name: workspaces
description: |
Workspaces group GitHub repositories for cross-project semantic search.
Server-wide shared — every authenticated user can list, create, and
modify any workspace. PR1 ships CRUD only; repository attachment,
webhooks, and the two-stage search endpoint land in subsequent
releases of the workspaces feature branch.
- name: groups
description: |
View-groups: admin-managed sets of users. External projects and
workspaces are shared to a group, granting its members read/search
access. Group CRUD and membership are admin-only; GET /groups is
member-scoped for regular users so the share picker can populate.
- name: github-tokens
description: |
GitHub Personal Access Tokens used by the workspaces feature for
cloning private repos and (optionally) registering webhooks. Stored
encrypted-at-rest via AES-GCM; the plaintext is surfaced exactly
once on POST and never returned thereafter.
- name: tunnels
description: |
Managed Tunnels — a server-orchestrated outbound tunnel that gives
the server a public URL while it sits behind NAT. Cloudflare Tunnel
ships now; ngrok is reserved. The live tunnel URL is the preferred
origin for GitHub webhook delivery URLs.
paths:
/health:
get:
operationId: getHealth
tags: [probe]
summary: Liveness probe (public)
description: |
Returns `{"status":"ok"}` when the server can reach SQLite within 1
second. Returns 503 with `{"status":"unhealthy","reason":"..."}` when
the DB ping fails. Public — no `Authorization` header required.
security: []
responses:
"200":
description: Server is healthy
content:
application/json:
schema:
$ref: "#/components/schemas/HealthResponse"
"503":
description: Server is unhealthy (e.g. DB unreachable)
content:
application/json:
schema:
$ref: "#/components/schemas/HealthResponse"
/api/v1/status:
get:
operationId: getStatus
tags: [probe]
summary: Server / sidecar status (authenticated)
description: |
Returns server metadata: version, configured embedding model, whether
the llama-server sidecar is reachable (`model_loaded`), number of
registered projects, and number of currently-running indexing jobs.
responses:
"200":
description: Status payload
content:
application/json:
schema:
$ref: "#/components/schemas/StatusResponse"
"401":
$ref: "#/components/responses/Unauthorized"
/api/v1/auth/bootstrap-status:
get:
operationId: getBootstrapStatus
tags: [auth]
summary: Whether the dashboard needs first-run bootstrap (public)
description: |
Returns `{"needs_bootstrap": true}` when the users table is empty.
The dashboard renders an explanatory screen in that case ("ask the
operator to deploy with CIX_BOOTSTRAP_ADMIN_* env vars and
restart"). No authentication required.
security: []
responses:
"200":
description: Bootstrap status
content:
application/json:
schema:
$ref: "#/components/schemas/BootstrapStatusResponse"
/api/v1/auth/login:
post:
operationId: login
tags: [auth]
summary: Exchange email + password for a session cookie (public)
description: |
On success, sets `Set-Cookie: cix_session=<id>; HttpOnly;
SameSite=Strict; Path=/`. Returns the user payload plus a
`must_change_password` flag — when true, the dashboard forces a
change-password screen before any other action.
security: []
requestBody:
required: true
content:
application/json:
schema:
$ref: "#/components/schemas/LoginRequest"
responses:
"200":
description: Logged in
headers:
Set-Cookie:
schema:
type: string
description: Session cookie (HttpOnly, SameSite=Strict)
content:
application/json:
schema:
$ref: "#/components/schemas/LoginResponse"
"401":
$ref: "#/components/responses/Unauthorized"
"422":
$ref: "#/components/responses/Unprocessable"
/api/v1/auth/logout:
post:
operationId: logout
tags: [auth]
summary: End the current session
description: |
Deletes the server-side session row and instructs the browser to
clear `cix_session` via `Set-Cookie: cix_session=; Max-Age=0`.
responses:
"204":
description: Session ended
"401":
$ref: "#/components/responses/Unauthorized"
/api/v1/auth/me:
get:
operationId: getMe
tags: [auth]
summary: Current authenticated user
description: |
Returns the user attached to the active session OR API key.
Includes `must_change_password` so the dashboard knows whether to
gate further navigation behind a change-password screen.
responses:
"200":
description: Current user
content:
application/json:
schema:
$ref: "#/components/schemas/MeResponse"
"401":
$ref: "#/components/responses/Unauthorized"
/api/v1/auth/change-password:
post:
operationId: changePassword
tags: [auth]
summary: Change the current user's password
description: |
Verifies `current_password`, updates to `new_password`, clears
`must_change_password`, and revokes every other session of this
user (the cookie carrying the change-password request is kept
alive). Does NOT touch API keys — those are revoked individually.
requestBody:
required: true
content:
application/json:
schema:
$ref: "#/components/schemas/ChangePasswordRequest"
responses:
"204":
description: Password updated
"401":
$ref: "#/components/responses/Unauthorized"
"422":
$ref: "#/components/responses/Unprocessable"
/api/v1/auth/sessions:
get:
operationId: listMySessions
tags: [auth]
summary: Active sessions of the current user
description: |
Returns every non-expired session of the caller, newest-first, with
`last_seen_at`, `last_seen_ip`, and `last_seen_ua` so the user can
spot unfamiliar logins. The `is_current` flag marks the session
carrying this request.
responses:
"200":
description: Session list
content:
application/json:
schema:
$ref: "#/components/schemas/SessionListResponse"
"401":
$ref: "#/components/responses/Unauthorized"
/api/v1/auth/sessions/{id}:
delete:
operationId: deleteMySession
tags: [auth]
summary: End one of my sessions (sign out a single device)
parameters:
- name: id
in: path
required: true
schema:
type: string
responses:
"204":
description: Session ended
"401":
$ref: "#/components/responses/Unauthorized"
"404":
$ref: "#/components/responses/NotFound"
/api/v1/admin/users:
get:
operationId: listUsers
tags: [admin]
summary: List all users (admin only)
responses:
"200":
description: User list
content:
application/json:
schema:
$ref: "#/components/schemas/UserListResponse"
"401":
$ref: "#/components/responses/Unauthorized"
"403":
$ref: "#/components/responses/Forbidden"
post:
operationId: createUser
tags: [admin]
summary: Invite a new user (admin only)
description: |
The admin sets an `initial_password` and shares it out-of-band.
The new user is flagged `must_change_password=true` and will be
forced to change it on first login.
requestBody:
required: true
content:
application/json:
schema:
$ref: "#/components/schemas/CreateUserRequest"
responses:
"201":
description: Created
content:
application/json:
schema:
$ref: "#/components/schemas/User"
"401":
$ref: "#/components/responses/Unauthorized"
"403":
$ref: "#/components/responses/Forbidden"
"409":
$ref: "#/components/responses/Conflict"
"422":
$ref: "#/components/responses/Unprocessable"
/api/v1/admin/users/{id}:
parameters:
- name: id
in: path
required: true
schema:
type: string
patch:
operationId: updateUser
tags: [admin]
summary: Change role or disabled flag (admin only)
description: |
Refuses to demote or disable the last enabled admin in the system.
requestBody:
required: true
content:
application/json:
schema:
$ref: "#/components/schemas/UpdateUserRequest"
responses:
"200":
description: Updated
content:
application/json:
schema:
$ref: "#/components/schemas/User"
"401":
$ref: "#/components/responses/Unauthorized"
"403":
$ref: "#/components/responses/Forbidden"
"404":
$ref: "#/components/responses/NotFound"
"422":
$ref: "#/components/responses/Unprocessable"
delete:
operationId: deleteUser
tags: [admin]
summary: Delete a user (admin only)
description: |
Cascades to the user's sessions and API keys. Refuses to delete
the last enabled admin.
responses:
"204":
description: Deleted
"401":
$ref: "#/components/responses/Unauthorized"
"403":
$ref: "#/components/responses/Forbidden"
"404":
$ref: "#/components/responses/NotFound"
/api/v1/admin/users/{id}/reset-password:
parameters:
- name: id
in: path
required: true
schema:
type: string
post:
operationId: resetUserPassword
tags: [admin]
summary: Reset a user's password (admin only)
description: |
Sets a new admin-chosen temporary password and forces the user to
change it on next login (must_change_password=true), mirroring the
invite flow. Any admin may reset any user, including another admin.
The target user's existing sessions are revoked.
requestBody:
required: true
content:
application/json:
schema:
$ref: "#/components/schemas/ResetUserPasswordRequest"
responses:
"200":
description: Password reset
content:
application/json:
schema:
$ref: "#/components/schemas/User"
"401":
$ref: "#/components/responses/Unauthorized"
"403":
$ref: "#/components/responses/Forbidden"
"404":
$ref: "#/components/responses/NotFound"
"422":
$ref: "#/components/responses/Unprocessable"
/api/v1/admin/login-locks:
get:
operationId: listLoginLocks
tags: [admin]
summary: List active login rate-limit locks (admin only)
description: |
Returns the in-memory login-limiter counters that are currently at or
over their threshold — the IPs and (IP, email) pairs a login would be
rejected for right now with 429. State is per-process and self-heals as
the sliding windows expire, so this is a point-in-time snapshot.
responses:
"200":
description: Active locks
content:
application/json:
schema:
$ref: "#/components/schemas/LoginLockListResponse"
"401":
$ref: "#/components/responses/Unauthorized"
"403":
$ref: "#/components/responses/Forbidden"
/api/v1/admin/login-locks/reset:
post:
operationId: resetLoginLock
tags: [admin]
summary: Clear a login rate-limit lock (admin only)
description: |
Lifts a single lock surfaced by `GET /admin/login-locks`. `type` picks
the counter: `ip` clears the per-IP horizontal-sweep counter; `ip_email`
clears the per-(IP, email) counter for one account. The admin selects
the exact row to clear — the server never clears across keys.
Idempotent: clearing a key that is no longer locked returns 204.
requestBody:
required: true
content:
application/json:
schema:
$ref: "#/components/schemas/ResetLoginLockRequest"
responses:
"204":
description: Lock cleared (or already absent)
"401":
$ref: "#/components/responses/Unauthorized"
"403":
$ref: "#/components/responses/Forbidden"
"422":
$ref: "#/components/responses/Unprocessable"
/api/v1/admin/runtime-config:
get:
operationId: getRuntimeConfig
tags: [admin]
summary: Read effective runtime config (admin only)
description: |
Returns the resolved runtime config (DB row → env → recommended) the
sidecar is currently configured against, plus a `source` map labelling
each field's origin so the dashboard can render the "DB" / "Env" /
"Recommended" pill next to every value.
responses:
"200":
description: Effective runtime config
content:
application/json:
schema:
$ref: "#/components/schemas/RuntimeConfig"
"401":
$ref: "#/components/responses/Unauthorized"
"403":
$ref: "#/components/responses/Forbidden"
put:
operationId: putRuntimeConfig
tags: [admin]
summary: Save runtime config overrides (admin only)
description: |
Replaces the runtime_settings row. Fields omitted from the request
clear their override (= fall back to env / recommended on next Get).
Does NOT restart the sidecar — the dashboard issues a separate
POST /admin/sidecar/restart after a successful PUT.
requestBody:
required: true
content:
application/json:
schema:
$ref: "#/components/schemas/RuntimeConfigUpdate"
responses:
"200":
description: Updated config
content:
application/json:
schema:
$ref: "#/components/schemas/RuntimeConfig"
"401":
$ref: "#/components/responses/Unauthorized"
"403":
$ref: "#/components/responses/Forbidden"
"422":
$ref: "#/components/responses/Unprocessable"
/api/v1/admin/sidecar/restart:
post:
operationId: restartSidecar
tags: [admin]
summary: Restart the llama-server sidecar (admin only)
description: |
Drains the embedding queue (30s timeout), terminates the current
child process, and respawns with the latest runtime config.
Returns 202 immediately; poll GET /admin/sidecar/status to observe
the running → restarting → running transition. In-flight indexing
batches at the moment of restart will fail with ErrSupervisor and
must be re-driven by the operator (`cix reindex <project>`).
responses:
"202":
description: Restart accepted
content:
application/json:
schema:
$ref: "#/components/schemas/RestartAccepted"
"401":
$ref: "#/components/responses/Unauthorized"
"403":
$ref: "#/components/responses/Forbidden"
"503":
description: Embeddings disabled at boot — restart is a no-op
content:
application/json:
schema:
$ref: "#/components/schemas/Error"
/api/v1/admin/sidecar/status:
get:
operationId: getSidecarStatus
tags: [admin]
summary: Sidecar process status (admin only)
responses:
"200":
description: Status snapshot
content:
application/json:
schema:
$ref: "#/components/schemas/SidecarStatus"
"401":
$ref: "#/components/responses/Unauthorized"
"403":
$ref: "#/components/responses/Forbidden"
/api/v1/admin/models:
get:
operationId: listModels
tags: [admin]
summary: List GGUF model files cached on disk (admin only)
description: |
Walks `CIX_GGUF_CACHE_DIR` and returns one entry per .gguf file. Used
by the dashboard's embedding-model picker so admins don't have to
type HF repo IDs by hand. Empty list when the cache is empty —
dashboard falls back to a free-text path input in that case.
responses:
"200":
description: Cached model list
content:
application/json:
schema:
$ref: "#/components/schemas/ModelList"
"401":
$ref: "#/components/responses/Unauthorized"
"403":
$ref: "#/components/responses/Forbidden"
/api/v1/admin/resources:
get:
operationId: getResourceUsage
tags: [admin]
summary: Report memory and disk usage (admin only)
description: |
What the server is using right now: Go heap figures, resident set size
where the platform exposes it cheaply, the four storage locations with
their sizes and free space, and the resident vector-store totals.
The vector store is an in-memory database — every document of every
collection is decoded into the heap at startup and never evicted — so
`memory.heap_alloc_bytes` tracks the size of the loaded index almost
one-for-one, and `vector_store.documents` is the number that explains
it. Document counts are read from memory and free; the directory sizes
are real filesystem walks and can take several seconds on a large
index, so render this behind a loading state rather than polling it.
responses:
"200":
description: Current usage
content:
application/json:
schema:
$ref: "#/components/schemas/ResourceUsage"
"401":
$ref: "#/components/responses/Unauthorized"
"403":
$ref: "#/components/responses/Forbidden"
"503":
$ref: "#/components/responses/ResourcesUnavailable"
/api/v1/admin/resources/analyze:
post:
operationId: analyzeReclaimable
tags: [admin]
summary: Find reclaimable garbage (admin only)
description: |
Reconciles what is on disk and in memory against what the database
still knows about, and returns the reclaimable garbage grouped into
categories the admin can select individually.
Synchronous and expensive — it walks the vector store and the clone
directory. Concurrent calls collapse into a single scan.
The returned `analysis_id` is passed back to
`POST /api/v1/admin/resources/clean`. It is an identity for "the
picture the admin was shown", not a safety mechanism: every item is
re-validated against live state immediately before it is deleted, so a
project that comes back between analyze and clean is skipped rather
than wiped.
responses:
"200":
description: Analysis complete
content:
application/json:
schema:
$ref: "#/components/schemas/ReclaimAnalysis"
"401":
$ref: "#/components/responses/Unauthorized"
"403":
$ref: "#/components/responses/Forbidden"
"503":
$ref: "#/components/responses/ResourcesUnavailable"
/api/v1/admin/resources/clean:
post:
operationId: cleanResources
tags: [admin]
summary: Delete the selected reclaimable categories (admin only)
description: |
Deletes the selected categories from a previous analysis.
Returns `200` even when individual items failed or were skipped — the
per-category counts carry that detail, and failing the whole call would
hide the items that were successfully reclaimed. `409` means the
analysis expired or was already spent; re-run analyze.
Deleting orphaned collections releases heap immediately — the server
forces a GC afterwards, so `heap_alloc_bytes` drops right away. How far
`rss_bytes` follows is platform-dependent: on Linux the pages go back to
the OS and resident memory drops with the heap; on macOS they are marked
reclaimable and stay resident until something else needs them.
Everything else is disk only.
requestBody:
required: true
content:
application/json:
schema:
$ref: "#/components/schemas/CleanRequest"
responses:
"200":
description: Clean finished (possibly with per-item failures)
content:
application/json:
schema:
$ref: "#/components/schemas/CleanResult"
"401":
$ref: "#/components/responses/Unauthorized"
"403":
$ref: "#/components/responses/Forbidden"
"409":
$ref: "#/components/responses/Conflict"
"422":
$ref: "#/components/responses/Unprocessable"
"503":
$ref: "#/components/responses/ResourcesUnavailable"
/api/v1/admin/database:
get:
operationId: getDatabaseState
tags: [admin]
summary: Report SQLite size, wasted space and compaction advice (admin only)
description: |
Deleting rows does not shrink a SQLite file. The pages go on the
freelist and are reused by later writes, so a database that has lost
more data than it has since gained stays large and mostly empty. This
endpoint reports how much of the file is waste and whether it is worth
doing anything about it.
Cheap: `page_count` and `freelist_pages` are header reads, not scans,
so this is safe to poll.
`auto_vacuum` is a property of the database file itself, not a stored
setting — it is read live, so it always reflects reality even on a
server that was upgraded into this feature. `none` means the file can
only be shrunk by a full rebuild; `incremental` means free pages can
additionally be returned to the filesystem in small bounded chunks
(see `POST /api/v1/admin/database/reclaim`).
`blocked_reason` is non-null when compaction cannot start right now —
an indexing or clone job is in flight, or the filesystem does not have
room for the copy. Render it instead of enabling the button.
responses:
"200":
description: Current database state
content:
application/json:
schema:
$ref: "#/components/schemas/DatabaseState"
"401":
$ref: "#/components/responses/Unauthorized"
"403":
$ref: "#/components/responses/Forbidden"
"503":
$ref: "#/components/responses/ResourcesUnavailable"
/api/v1/admin/database/compact:
post:
operationId: compactDatabase
tags: [admin]
summary: Rebuild the database to reclaim free pages (admin only)
description: |
Starts a background rebuild and returns immediately with `202`. Poll
`GET /maintenance/status` for progress.
What the admin is agreeing to, and what the confirmation dialog must
say before this is called:
* For the long part the server is **read-only**, not down. Search,
browsing and every read keep working. New logins and every write are
rejected with `503` and a `Retry-After`; indexing and scheduled
polling pause. Existing sessions and API keys keep working — their
last-seen timestamps simply stop being refreshed for the duration,
which is invisible against a 14-day session lifetime.
* Then the server **restarts itself** to adopt the new file, and is
fully unavailable while it comes back up.
* Expect roughly a minute per 8 GB on a warm SSD for the copy, plus
the usual startup time; `estimated_seconds` on `DatabaseState`
carries the current estimate.
The restart is not a fallback, it is the mechanism. Swapping the file
under a live server would leave every service holding an open handle
to the old one, so the swap is performed at boot, before anything
opens the database — no pool, no services, no concurrency. The process
re-executes itself rather than exiting, so a container keeps its PID 1
and no restart policy or supervisor is involved.
The read-only window matters because the rebuild copies a *snapshot*:
anything committed after the copy begins is absent from the new file,
and swapping it in would silently discard those writes. It is enforced
in three layers rather than one, because the obvious single mechanism
is wrong in both available forms.
A route gate refuses the endpoints that write, and is what keeps
latency sane — it is classified per route, never by HTTP method, since
search is a POST and is one of the things that must keep working.
Background work is stopped and drained before the copy starts. Finally
the compactor holds a write transaction on a connection of its own, so
anything that slips past the first two layers is refused by SQLite
itself rather than landing outside the snapshot.
Compaction does not change the database's reclaim mode. It reclaims
space and leaves the mode exactly as it found it — that is a separate
setting, changed through
`PUT /api/v1/admin/database/auto-vacuum`.
Crash safety: progress is journalled to a state file beside the
database, written atomically, and every combination of that state and
the files actually present on disk maps to exactly one recovery
action. An interrupted copy is discarded; an interrupted swap is
carried forward or rolled back. The original is deleted last, so no
interruption leaves the server without a database. Nothing is resumed
— the operation is all-or-nothing and is simply re-run.
The state lives in a file rather than a table precisely because the
database is the thing being replaced: a row describing the operation
could not survive the swap, could not be written during the read-only
window, and could not be read back during the restart.
responses:
"202":
description: Compaction started
content:
application/json:
schema:
$ref: "#/components/schemas/MaintenanceOperation"
"401":
$ref: "#/components/responses/Unauthorized"
"403":
$ref: "#/components/responses/Forbidden"
"409":
description: |
Already running, or held back because clone/index jobs are in
flight. `DatabaseState.blocked_reason` carries the same detail.
content:
application/json:
schema:
$ref: "#/components/schemas/Error"
"507":
$ref: "#/components/responses/InsufficientStorage"
"503":
$ref: "#/components/responses/ResourcesUnavailable"
/api/v1/admin/database/reclaim:
post:
operationId: reclaimFreePages
tags: [admin]
summary: Return free pages to the filesystem in bounded chunks (admin only)
description: |
Runs `PRAGMA incremental_vacuum`, which moves free pages to the end of
the file, followed by a WAL checkpoint. Synchronous, bounded and
cheap: it holds an ordinary write lock for the pages it moves, not an
exclusive lock on the whole database, so it does not need a
maintenance window.
The checkpoint is part of the operation, not an extra. In WAL mode the
page moves and the truncation both land in the log, so the database
file does not shrink until the log is folded back in — without it a
small reclaim reports bytes freed while the file on disk is unchanged.
Requires the file to be in incremental auto-vacuum mode; `409`
otherwise, with compaction as the remedy.
This reclaims space but does not defragment — a full compaction still
rebuilds the file and improves read locality. The point of incremental
reclaim is to make that rare rather than routine.
requestBody:
required: false
content:
application/json:
schema:
$ref: "#/components/schemas/ReclaimRequest"
responses:
"200":
description: Reclaim finished
content:
application/json:
schema:
$ref: "#/components/schemas/ReclaimResult"
"401":
$ref: "#/components/responses/Unauthorized"
"403":
$ref: "#/components/responses/Forbidden"
"409":
description: The database is not in incremental auto-vacuum mode
content:
application/json:
schema:
$ref: "#/components/schemas/Error"
"503":
$ref: "#/components/responses/ResourcesUnavailable"
/api/v1/admin/database/auto-vacuum:
put:
operationId: setAutoVacuumMode
tags: [admin]
summary: Change the database's reclaim mode (admin only)
description: |
Incremental mode lets free pages be returned to the filesystem without
a rebuild — it is what makes
`POST /api/v1/admin/database/reclaim` possible. It is not free: it
maintains pointer-map pages, so every page allocated or freed carries
an extra write, measured at +1.5% on an indexing-shaped workload.
**Asking for the mode the database is already in does nothing** and
answers `200`. Only an actual change costs anything.
A change costs a full rebuild, in either direction, because that is
the only way SQLite can change the mode of a populated database. So a
`202` here means the same interruption as
`POST /api/v1/admin/database/compact`: a read-only window, then a
restart. The space that rebuild happens to reclaim is a side effect,
not the point.
requestBody:
required: true
content:
application/json:
schema:
$ref: "#/components/schemas/AutoVacuumRequest"
responses:
"200":
description: |
The database is already in the requested mode. Nothing was done and
the returned operation is `idle`.
content:
application/json:
schema:
$ref: "#/components/schemas/MaintenanceOperation"
"202":
description: A rebuild has started to apply the change.
content:
application/json:
schema:
$ref: "#/components/schemas/MaintenanceOperation"
"401":
$ref: "#/components/responses/Unauthorized"
"403":
$ref: "#/components/responses/Forbidden"
"409":
description: |
Already running, or held back because clone/index jobs are in
flight.
content:
application/json:
schema:
$ref: "#/components/schemas/Error"
"422":
$ref: "#/components/responses/Unprocessable"
"507":
$ref: "#/components/responses/InsufficientStorage"
"503":
$ref: "#/components/responses/ResourcesUnavailable"
/api/v1/admin/schedules:
get:
operationId: listSchedules
tags: [admin]
summary: List every recurring task and when it next runs (admin only)
description: |
One entry per task the server knows how to run on a schedule. The
timing is a crontab expression, and `next_runs` is computed by the
same parser that will actually fire it — a client must not evaluate
the expression itself, or its preview and the server's behaviour can
disagree.
`configured` is false while a task is still on its built-in or
environment default, which is how an upgraded server reports
automation nobody has opted into.
responses:
"200":
description: Registered tasks
content:
application/json:
schema:
type: object
required: [tasks]
properties:
tasks:
type: array
items:
$ref: "#/components/schemas/ScheduledTask"
"401":
$ref: "#/components/responses/Unauthorized"
"403":
$ref: "#/components/responses/Forbidden"
"503":
$ref: "#/components/responses/ResourcesUnavailable"
/api/v1/admin/schedules/{name}:
put:
operationId: updateSchedule
tags: [admin]
summary: Change when a recurring task runs (admin only)
description: |
Absent fields are left unchanged.