witan-code 0.26.0__tar.gz → 0.27.0__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 (111) hide show
  1. {witan_code-0.26.0 → witan_code-0.27.0}/.gitignore +3 -0
  2. {witan_code-0.26.0 → witan_code-0.27.0}/CHANGELOG.md +12 -0
  3. {witan_code-0.26.0 → witan_code-0.27.0}/PKG-INFO +4 -4
  4. {witan_code-0.26.0 → witan_code-0.27.0}/README.md +3 -3
  5. witan_code-0.27.0/changelog.d/20261021_142050_blarghmatey_witan_code_drop_bridge_repo_file.md +14 -0
  6. witan_code-0.27.0/changelog.d/20261021_143525_blarghmatey_witan_coalesce_hot_writes.md +6 -0
  7. {witan_code-0.26.0 → witan_code-0.27.0}/pyproject.toml +2 -2
  8. {witan_code-0.26.0 → witan_code-0.27.0}/tests/test_bridge.py +83 -0
  9. {witan_code-0.26.0 → witan_code-0.27.0}/tests/test_store.py +93 -0
  10. {witan_code-0.26.0 → witan_code-0.27.0}/witan_code/bridge.py +12 -4
  11. {witan_code-0.26.0 → witan_code-0.27.0}/witan_code/cli.py +1 -1
  12. {witan_code-0.26.0 → witan_code-0.27.0}/witan_code/ingest.py +1 -1
  13. {witan_code-0.26.0 → witan_code-0.27.0}/witan_code/maintenance.py +10 -8
  14. {witan_code-0.26.0 → witan_code-0.27.0}/witan_code/queries/bridge.gq +3 -5
  15. {witan_code-0.26.0 → witan_code-0.27.0}/witan_code/schema/bridge-schema.pg +0 -2
  16. {witan_code-0.26.0 → witan_code-0.27.0}/witan_code/store.py +74 -12
  17. {witan_code-0.26.0 → witan_code-0.27.0}/changelog.d/README.md +0 -0
  18. {witan_code-0.26.0 → witan_code-0.27.0}/config/claude.json +0 -0
  19. {witan_code-0.26.0 → witan_code-0.27.0}/config/copilot.json +0 -0
  20. {witan_code-0.26.0 → witan_code-0.27.0}/config/pi.json +0 -0
  21. {witan_code-0.26.0 → witan_code-0.27.0}/conftest.py +0 -0
  22. {witan_code-0.26.0 → witan_code-0.27.0}/docs/BRANCH_INDEXING.md +0 -0
  23. {witan_code-0.26.0 → witan_code-0.27.0}/docs/CLI_REFERENCE.md +0 -0
  24. {witan_code-0.26.0 → witan_code-0.27.0}/docs/EDGE_PRECISION_TIERS.md +0 -0
  25. {witan_code-0.26.0 → witan_code-0.27.0}/docs/PACKAGE_MAP.md +0 -0
  26. {witan_code-0.26.0 → witan_code-0.27.0}/docs/STAGE2_STITCHING.md +0 -0
  27. {witan_code-0.26.0 → witan_code-0.27.0}/docs/SYMBOL_FORMAT.md +0 -0
  28. {witan_code-0.26.0 → witan_code-0.27.0}/docs/SYMBOL_TABLE.md +0 -0
  29. {witan_code-0.26.0 → witan_code-0.27.0}/docs/USER_GUIDE.md +0 -0
  30. {witan_code-0.26.0 → witan_code-0.27.0}/install.sh +0 -0
  31. {witan_code-0.26.0 → witan_code-0.27.0}/tests/__init__.py +0 -0
  32. {witan_code-0.26.0 → witan_code-0.27.0}/tests/conftest.py +0 -0
  33. {witan_code-0.26.0 → witan_code-0.27.0}/tests/test_batched_deletes.py +0 -0
  34. {witan_code-0.26.0 → witan_code-0.27.0}/tests/test_branches.py +0 -0
  35. {witan_code-0.26.0 → witan_code-0.27.0}/tests/test_chunked_load.py +0 -0
  36. {witan_code-0.26.0 → witan_code-0.27.0}/tests/test_cli_dispatch.py +0 -0
  37. {witan_code-0.26.0 → witan_code-0.27.0}/tests/test_cli_hooks.py +0 -0
  38. {witan_code-0.26.0 → witan_code-0.27.0}/tests/test_cli_output_format.py +0 -0
  39. {witan_code-0.26.0 → witan_code-0.27.0}/tests/test_cli_selected_target.py +0 -0
  40. {witan_code-0.26.0 → witan_code-0.27.0}/tests/test_config.py +0 -0
  41. {witan_code-0.26.0 → witan_code-0.27.0}/tests/test_config_targets.py +0 -0
  42. {witan_code-0.26.0 → witan_code-0.27.0}/tests/test_context.py +0 -0
  43. {witan_code-0.26.0 → witan_code-0.27.0}/tests/test_crossrepo.py +0 -0
  44. {witan_code-0.26.0 → witan_code-0.27.0}/tests/test_edges.py +0 -0
  45. {witan_code-0.26.0 → witan_code-0.27.0}/tests/test_elicit.py +0 -0
  46. {witan_code-0.26.0 → witan_code-0.27.0}/tests/test_enrichment.py +0 -0
  47. {witan_code-0.26.0 → witan_code-0.27.0}/tests/test_github_app.py +0 -0
  48. {witan_code-0.26.0 → witan_code-0.27.0}/tests/test_graph.py +0 -0
  49. {witan_code-0.26.0 → witan_code-0.27.0}/tests/test_hooks.py +0 -0
  50. {witan_code-0.26.0 → witan_code-0.27.0}/tests/test_identity.py +0 -0
  51. {witan_code-0.26.0 → witan_code-0.27.0}/tests/test_index_failure_diagnostics.py +0 -0
  52. {witan_code-0.26.0 → witan_code-0.27.0}/tests/test_index_reports_its_store.py +0 -0
  53. {witan_code-0.26.0 → witan_code-0.27.0}/tests/test_index_requires_a_repo_key.py +0 -0
  54. {witan_code-0.26.0 → witan_code-0.27.0}/tests/test_indexer.py +0 -0
  55. {witan_code-0.26.0 → witan_code-0.27.0}/tests/test_indexer_scope.py +0 -0
  56. {witan_code-0.26.0 → witan_code-0.27.0}/tests/test_ingest.py +0 -0
  57. {witan_code-0.26.0 → witan_code-0.27.0}/tests/test_languages.py +0 -0
  58. {witan_code-0.26.0 → witan_code-0.27.0}/tests/test_maintenance.py +0 -0
  59. {witan_code-0.26.0 → witan_code-0.27.0}/tests/test_package_map.py +0 -0
  60. {witan_code-0.26.0 → witan_code-0.27.0}/tests/test_reaper.py +0 -0
  61. {witan_code-0.26.0 → witan_code-0.27.0}/tests/test_rebuild_honours_the_repo_key.py +0 -0
  62. {witan_code-0.26.0 → witan_code-0.27.0}/tests/test_refusal_audit.py +0 -0
  63. {witan_code-0.26.0 → witan_code-0.27.0}/tests/test_remote_proxy.py +0 -0
  64. {witan_code-0.26.0 → witan_code-0.27.0}/tests/test_remote_store.py +0 -0
  65. {witan_code-0.26.0 → witan_code-0.27.0}/tests/test_repo.py +0 -0
  66. {witan_code-0.26.0 → witan_code-0.27.0}/tests/test_server.py +0 -0
  67. {witan_code-0.26.0 → witan_code-0.27.0}/tests/test_setup.py +0 -0
  68. {witan_code-0.26.0 → witan_code-0.27.0}/tests/test_stitch.py +0 -0
  69. {witan_code-0.26.0 → witan_code-0.27.0}/tests/test_symbol_table.py +0 -0
  70. {witan_code-0.26.0 → witan_code-0.27.0}/tests/test_tasks.py +0 -0
  71. {witan_code-0.26.0 → witan_code-0.27.0}/tests/test_tool_schema.py +0 -0
  72. {witan_code-0.26.0 → witan_code-0.27.0}/tests/test_views.py +0 -0
  73. {witan_code-0.26.0 → witan_code-0.27.0}/tests/test_visualize.py +0 -0
  74. {witan_code-0.26.0 → witan_code-0.27.0}/witan_code/__init__.py +0 -0
  75. {witan_code-0.26.0 → witan_code-0.27.0}/witan_code/__main__.py +0 -0
  76. {witan_code-0.26.0 → witan_code-0.27.0}/witan_code/bridge_extractors.py +0 -0
  77. {witan_code-0.26.0 → witan_code-0.27.0}/witan_code/config.py +0 -0
  78. {witan_code-0.26.0 → witan_code-0.27.0}/witan_code/context.py +0 -0
  79. {witan_code-0.26.0 → witan_code-0.27.0}/witan_code/edges.py +0 -0
  80. {witan_code-0.26.0 → witan_code-0.27.0}/witan_code/elicit.py +0 -0
  81. {witan_code-0.26.0 → witan_code-0.27.0}/witan_code/extensions/pi/codegraph.ts +0 -0
  82. {witan_code-0.26.0 → witan_code-0.27.0}/witan_code/github_app.py +0 -0
  83. {witan_code-0.26.0 → witan_code-0.27.0}/witan_code/graph.py +0 -0
  84. {witan_code-0.26.0 → witan_code-0.27.0}/witan_code/hooks.py +0 -0
  85. {witan_code-0.26.0 → witan_code-0.27.0}/witan_code/identity.py +0 -0
  86. {witan_code-0.26.0 → witan_code-0.27.0}/witan_code/indexer.py +0 -0
  87. {witan_code-0.26.0 → witan_code-0.27.0}/witan_code/output.py +0 -0
  88. {witan_code-0.26.0 → witan_code-0.27.0}/witan_code/package_map.py +0 -0
  89. {witan_code-0.26.0 → witan_code-0.27.0}/witan_code/queries/code_mutations.gq +0 -0
  90. {witan_code-0.26.0 → witan_code-0.27.0}/witan_code/queries/code_read.gq +0 -0
  91. {witan_code-0.26.0 → witan_code-0.27.0}/witan_code/queries/delete.gq +0 -0
  92. {witan_code-0.26.0 → witan_code-0.27.0}/witan_code/queries_ts/bash.scm +0 -0
  93. {witan_code-0.26.0 → witan_code-0.27.0}/witan_code/queries_ts/hcl.scm +0 -0
  94. {witan_code-0.26.0 → witan_code-0.27.0}/witan_code/queries_ts/python.scm +0 -0
  95. {witan_code-0.26.0 → witan_code-0.27.0}/witan_code/queries_ts/sql.scm +0 -0
  96. {witan_code-0.26.0 → witan_code-0.27.0}/witan_code/queries_ts/typescript.scm +0 -0
  97. {witan_code-0.26.0 → witan_code-0.27.0}/witan_code/queries_ts/yaml.scm +0 -0
  98. {witan_code-0.26.0 → witan_code-0.27.0}/witan_code/reaper.py +0 -0
  99. {witan_code-0.26.0 → witan_code-0.27.0}/witan_code/remote/__init__.py +0 -0
  100. {witan_code-0.26.0 → witan_code-0.27.0}/witan_code/remote/oidc.py +0 -0
  101. {witan_code-0.26.0 → witan_code-0.27.0}/witan_code/remote/proxy.py +0 -0
  102. {witan_code-0.26.0 → witan_code-0.27.0}/witan_code/remote/store.py +0 -0
  103. {witan_code-0.26.0 → witan_code-0.27.0}/witan_code/repo.py +0 -0
  104. {witan_code-0.26.0 → witan_code-0.27.0}/witan_code/schema/code-schema.pg +0 -0
  105. {witan_code-0.26.0 → witan_code-0.27.0}/witan_code/selected_target.py +0 -0
  106. {witan_code-0.26.0 → witan_code-0.27.0}/witan_code/server.py +0 -0
  107. {witan_code-0.26.0 → witan_code-0.27.0}/witan_code/setup.py +0 -0
  108. {witan_code-0.26.0 → witan_code-0.27.0}/witan_code/skills/witan-code/SKILL.md +0 -0
  109. {witan_code-0.26.0 → witan_code-0.27.0}/witan_code/stitch.py +0 -0
  110. {witan_code-0.26.0 → witan_code-0.27.0}/witan_code/views.py +0 -0
  111. {witan_code-0.26.0 → witan_code-0.27.0}/witan_code/visualize.py +0 -0
@@ -43,3 +43,6 @@ mcp-server.log
43
43
 
44
44
  # Zensical build output for the witan-context docs site.
45
45
  site/
46
+
47
+ # You get this with every apply run.
48
+ agent-config.toml.applied.json
@@ -8,6 +8,18 @@ a MINOR bump may include breaking changes).
8
8
 
9
9
  <!-- scriv-insert-here -->
10
10
 
11
+ ## [0.27.0] - 2026-10-21
12
+
13
+ ### Changed
14
+
15
+ - The cleanup that rides a background optimize now keeps 2 days of versions
16
+ instead of 30, matching the deployed nightly cleanup. Nothing reads older
17
+ history, and on omnigraph 0.13 a cleanup's cost grows with every version
18
+ still present ([ModernRelay/omnigraph#1095](https://github.com/ModernRelay/omnigraph/issues/1095)).
19
+ - `witan-code cleanup --yes` with neither `--keep` nor `--older-than` now keeps 2 days
20
+ as well, since it shares the default. Pass `--older-than 30d` to keep the
21
+ old window.
22
+
11
23
  ## [0.26.0] - 2026-10-16
12
24
 
13
25
  ### Fixed
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.5
2
2
  Name: witan-code
3
- Version: 0.26.0
3
+ Version: 0.27.0
4
4
  Summary: witan-code — tree-sitter code graph + cross-repo bridge (mounts under `witan code`)
5
5
  Project-URL: Homepage, https://github.com/mitodl/agent-kit/tree/main/mcp/servers/witan-code
6
6
  Project-URL: Repository, https://github.com/mitodl/agent-kit
@@ -355,7 +355,7 @@ symlink alternative:
355
355
  | `WITAN_AUTHOR` / `USER` | `unknown` | attribution string |
356
356
  | `WITAN_REPO` | — | override the detected repo slug |
357
357
  | `WITAN_CODE_OPTIMIZE_INTERVAL` | `86400` (daily) | throttle window (seconds) for `checkpoint`'s opportunistic store compaction; `0` disables it |
358
- | `WITAN_CODE_CLEANUP_INTERVAL` | `604800` (weekly) | throttle window (seconds) for the `cleanup --older-than 30d` that rides a `checkpoint` compaction; `0` disables it |
358
+ | `WITAN_CODE_CLEANUP_INTERVAL` | `604800` (weekly) | throttle window (seconds) for the `cleanup --older-than 2d` that rides a `checkpoint` compaction; `0` disables it |
359
359
  | `WITAN_CODE_INDEX_ROLE` | `client` | `ci` designates this process the writer of a shared graph's default-branch view. Only meaningful against a shared cluster graph; local stores are unaffected. See [Branch indexing](docs/BRANCH_INDEXING.md#who-may-write-the-shared-default-branch-view) |
360
360
  | `WITAN_ACTOR` | derived from the `witan login` session | the identity that owns the branch views this process writes; an `act-…` id or a raw OIDC `sub`. For a non-interactive writer (CI, a maintenance job). See [Branch indexing](docs/BRANCH_INDEXING.md#per-writer-branch-views) |
361
361
  | `WITAN_CONFIG` | `~/.config/witan/config.toml` | config file path (see below) |
@@ -586,7 +586,7 @@ graph):
586
586
  reclaim disk by GC'ing old Lance versions (**destructive**; requires
587
587
  `--yes`). `--keep N` retains the newest N graph commits of every live
588
588
  branch (omnigraph 0.12+; versions per table on 0.11); with neither bound it
589
- keeps the last 30 days.
589
+ keeps the last 2 days.
590
590
  - `checkpoint` — opportunistically compact the current repo's store and the
591
591
  bridge store if due (see [Hooks](#hooks)); registered as the `Stop` hook,
592
592
  not usually run by hand.
@@ -646,7 +646,7 @@ mechanisms keep this in check, mirroring that module (deliberately duplicated
646
646
  the shared bridge store, at most once per `WITAN_CODE_OPTIMIZE_INTERVAL`
647
647
  (default daily; `0` disables) each — see [Hooks](#hooks). At most once per
648
648
  `WITAN_CODE_CLEANUP_INTERVAL` (default weekly) the run also cleans up
649
- versions older than 30 days. On omnigraph 0.11 that is the only thing that
649
+ versions older than 2 days. On omnigraph 0.11 that is the only thing that
650
650
  reclaims the storage of branches deleted by `branches --prune` or
651
651
  `reap-views --apply`; `optimize` no longer does.
652
652
  - **Scheduled**: `witan-code optimize [--store PATH | --bridge]
@@ -322,7 +322,7 @@ symlink alternative:
322
322
  | `WITAN_AUTHOR` / `USER` | `unknown` | attribution string |
323
323
  | `WITAN_REPO` | — | override the detected repo slug |
324
324
  | `WITAN_CODE_OPTIMIZE_INTERVAL` | `86400` (daily) | throttle window (seconds) for `checkpoint`'s opportunistic store compaction; `0` disables it |
325
- | `WITAN_CODE_CLEANUP_INTERVAL` | `604800` (weekly) | throttle window (seconds) for the `cleanup --older-than 30d` that rides a `checkpoint` compaction; `0` disables it |
325
+ | `WITAN_CODE_CLEANUP_INTERVAL` | `604800` (weekly) | throttle window (seconds) for the `cleanup --older-than 2d` that rides a `checkpoint` compaction; `0` disables it |
326
326
  | `WITAN_CODE_INDEX_ROLE` | `client` | `ci` designates this process the writer of a shared graph's default-branch view. Only meaningful against a shared cluster graph; local stores are unaffected. See [Branch indexing](docs/BRANCH_INDEXING.md#who-may-write-the-shared-default-branch-view) |
327
327
  | `WITAN_ACTOR` | derived from the `witan login` session | the identity that owns the branch views this process writes; an `act-…` id or a raw OIDC `sub`. For a non-interactive writer (CI, a maintenance job). See [Branch indexing](docs/BRANCH_INDEXING.md#per-writer-branch-views) |
328
328
  | `WITAN_CONFIG` | `~/.config/witan/config.toml` | config file path (see below) |
@@ -553,7 +553,7 @@ graph):
553
553
  reclaim disk by GC'ing old Lance versions (**destructive**; requires
554
554
  `--yes`). `--keep N` retains the newest N graph commits of every live
555
555
  branch (omnigraph 0.12+; versions per table on 0.11); with neither bound it
556
- keeps the last 30 days.
556
+ keeps the last 2 days.
557
557
  - `checkpoint` — opportunistically compact the current repo's store and the
558
558
  bridge store if due (see [Hooks](#hooks)); registered as the `Stop` hook,
559
559
  not usually run by hand.
@@ -613,7 +613,7 @@ mechanisms keep this in check, mirroring that module (deliberately duplicated
613
613
  the shared bridge store, at most once per `WITAN_CODE_OPTIMIZE_INTERVAL`
614
614
  (default daily; `0` disables) each — see [Hooks](#hooks). At most once per
615
615
  `WITAN_CODE_CLEANUP_INTERVAL` (default weekly) the run also cleans up
616
- versions older than 30 days. On omnigraph 0.11 that is the only thing that
616
+ versions older than 2 days. On omnigraph 0.11 that is the only thing that
617
617
  reclaims the storage of branches deleted by `branches --prune` or
618
618
  `reap-views --apply`; `optimize` no longer does.
619
619
  - **Scheduled**: `witan-code optimize [--store PATH | --bridge]
@@ -0,0 +1,14 @@
1
+ ### Removed
2
+
3
+ - `InterfaceBinding.repo_file` is gone from the bridge schema. The per-file
4
+ purge deletes on `repo` and `file` directly, which GQ 2.1 allows. omnigraph
5
+ 0.13 cannot drop the column in place, so the deployed `code-bridge` graph has
6
+ to be recreated and every repo reindexed when this ships.
7
+
8
+ ### Changed
9
+
10
+ - A local `_bridge.omni` whose schema omnigraph reports it cannot migrate in
11
+ place (`schema plan` answers `supported: false`) is now deleted and recreated
12
+ instead of failing every apply. It comes back empty. Run
13
+ `witan-code reindex <repo root>` in each indexed repo to restore its
14
+ cross-repo bindings.
@@ -0,0 +1,6 @@
1
+ ### Changed
2
+
3
+ - A bridge write clears the repo's symbol table in the same commit as its
4
+ per-file bindings purge, instead of a separate one. Every index that writes
5
+ bindings now costs the bridge one commit fewer, on a graph whose main branch
6
+ every repo shares and whose commits serialize.
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "witan-code"
3
- version = "0.26.0"
3
+ version = "0.27.0"
4
4
  description = "witan-code — tree-sitter code graph + cross-repo bridge (mounts under `witan code`)"
5
5
  readme = "README.md"
6
6
  license = "BSD-3-Clause"
@@ -266,7 +266,7 @@ testpaths = ["tests"]
266
266
  packages = ["witan_code"]
267
267
 
268
268
  [tool.bumpversion]
269
- current_version = "0.26.0"
269
+ current_version = "0.27.0"
270
270
  allow_dirty = true
271
271
 
272
272
  [[tool.bumpversion.files]]
@@ -737,3 +737,86 @@ def test_incremental_index_preserves_unchanged_file_bindings(tmp_path, monkeypat
737
737
  (base / "b.ts").unlink()
738
738
  indexer.index_path(base, config=cfg)
739
739
  assert binding_files() == {"a.ts"}
740
+
741
+
742
+ @requires_stack
743
+ def test_bridge_purge_and_symbol_reset_are_one_commit(tmp_path, monkeypatch):
744
+ """The bindings purge and the repo's symbol-table reset used to be two
745
+ bridge commits on every index. Bridge main is one serialized commit lane
746
+ shared by every repo, so they now land as one; the load is the other."""
747
+ from witan_code import config as cfg_mod
748
+ from witan_code import indexer
749
+ from witan_code.graph import OmnigraphClient
750
+
751
+ monkeypatch.setenv("WITAN_REPO", "https://github.com/test/commits")
752
+ monkeypatch.setenv("WITAN_CODE_DIR", str(tmp_path / "code"))
753
+ cfg = cfg_mod.load()
754
+ base = tmp_path / "repo"
755
+ base.mkdir()
756
+ (base / "a.ts").write_text('const a = fetch("/api/v0/aaa/");\n')
757
+ indexer.index_path(base, config=cfg)
758
+
759
+ commits: list[str] = []
760
+ inside = {"batch": 0}
761
+ real_change = OmnigraphClient.change
762
+ real_change_many = OmnigraphClient.change_many
763
+
764
+ # Depth-guarded like witan's `commits` fixture: a one-step `change_many`
765
+ # delegates to `change`, which must not count twice.
766
+ def change(self, query_file, query_name, *args, **kwargs):
767
+ if query_file == "bridge.gq" and not inside["batch"]:
768
+ commits.append(query_name)
769
+ return real_change(self, query_file, query_name, *args, **kwargs)
770
+
771
+ def change_many(self, steps, *args, **kwargs):
772
+ if steps and steps[0][0] == "bridge.gq" and not inside["batch"]:
773
+ commits.append("+".join(sorted({name for _f, name, _p in steps})))
774
+ inside["batch"] += 1
775
+ try:
776
+ return real_change_many(self, steps, *args, **kwargs)
777
+ finally:
778
+ inside["batch"] -= 1
779
+
780
+ monkeypatch.setattr(OmnigraphClient, "change", change)
781
+ monkeypatch.setattr(OmnigraphClient, "change_many", change_many)
782
+
783
+ (base / "a.ts").write_text('const a = fetch("/api/v0/aaa2/");\n')
784
+ indexer.index_path(base, config=cfg)
785
+
786
+ assert commits == ["delete_bindings_in_file+delete_repo_symbols"], commits
787
+
788
+
789
+ @requires_stack
790
+ def test_the_per_file_purge_is_scoped_to_its_repo(tmp_path, monkeypatch):
791
+ """The purge deletes on repo AND file. Two repos share a path here, so a
792
+ delete on the file alone would take the other repo's binding with it."""
793
+ from witan_code import config as cfg_mod
794
+ from witan_code import indexer
795
+ from witan_code.graph import OmnigraphClient
796
+
797
+ monkeypatch.setenv("WITAN_CODE_DIR", str(tmp_path / "code"))
798
+ cfg = cfg_mod.load()
799
+ repo_a = "https://github.com/test/repo-a"
800
+ repos = {repo_a: tmp_path / "a", "https://github.com/test/repo-b": tmp_path / "b"}
801
+ for uri, base in repos.items():
802
+ base.mkdir()
803
+ (base / "client.ts").write_text('const a = fetch("/api/v0/shared/");\n')
804
+ (base / "other.ts").write_text('const b = fetch("/api/v0/other/");\n')
805
+ indexer.index_path(base, repo_override=uri, config=cfg)
806
+
807
+ def client_ts_repos():
808
+ client = OmnigraphClient(
809
+ str(cfg_mod.bridge_store_path(cfg.code_dir)), cfg.queries_dir
810
+ )
811
+ return {
812
+ r["repo"]
813
+ for r in client.read("bridge.gq", "all_bindings", {})
814
+ if r["file"] == "client.ts"
815
+ }
816
+
817
+ assert client_ts_repos() == set(repos)
818
+
819
+ (repos[repo_a] / "client.ts").unlink()
820
+ indexer.index_path(repos[repo_a], repo_override=repo_a, config=cfg)
821
+
822
+ assert client_ts_repos() == {"https://github.com/test/repo-b"}
@@ -7,8 +7,10 @@ store, an unreadable one, a dangling symlink) worth pinning explicitly.
7
7
 
8
8
  import json
9
9
  import os
10
+ import subprocess
10
11
  import threading
11
12
  import time
13
+ from concurrent.futures import ThreadPoolExecutor
12
14
  from pathlib import Path
13
15
  from typing import ClassVar
14
16
 
@@ -245,6 +247,97 @@ def test_discard_store_takes_the_schema_stamp_with_it(tmp_path):
245
247
  assert freed >= len("payload")
246
248
 
247
249
 
250
+ def _plan(cfg, store) -> dict:
251
+ res = subprocess.run(
252
+ [
253
+ store_module._binary(),
254
+ "schema",
255
+ "plan",
256
+ "--schema",
257
+ str(cfg.bridge_schema_file),
258
+ "--json",
259
+ str(store),
260
+ ],
261
+ capture_output=True,
262
+ text=True,
263
+ check=True,
264
+ )
265
+ return json.loads(res.stdout)
266
+
267
+
268
+ @requires_stack
269
+ @pytest.mark.parametrize("callers", [1, 4])
270
+ def test_a_bridge_the_shipped_schema_cannot_migrate_is_recreated(
271
+ tmp_path, monkeypatch, callers
272
+ ):
273
+ """omnigraph 0.13 refuses to drop InterfaceBinding.repo_file in place, so
274
+ a local bridge created before the drop fails every apply. Recreating it is
275
+ the recovery, since the bridge is derived from the indexed checkouts.
276
+
277
+ Several callers at once is the state right after an upgrade, when every
278
+ reindex hook finds the old store. Without the write lock one of them
279
+ deletes the store another is initialising, or inits over one that exists.
280
+ """
281
+ from witan_code import config as cfg_mod
282
+
283
+ monkeypatch.setenv("WITAN_CODE_DIR", str(tmp_path / "code"))
284
+ cfg = cfg_mod.load()
285
+ current = cfg.bridge_schema_file.read_text()
286
+ field = " file: String @index"
287
+ assert field in current
288
+ old_schema = tmp_path / "bridge-with-repo-file.pg"
289
+ old_schema.write_text(
290
+ current.replace(field, f"{field}\n repo_file: String @index", 1)
291
+ )
292
+ store = cfg_mod.bridge_store_path(cfg.code_dir)
293
+ store.parent.mkdir(parents=True)
294
+ subprocess.run(
295
+ [store_module._binary(), "init", "--schema", str(old_schema), str(store)],
296
+ check=True,
297
+ capture_output=True,
298
+ )
299
+ assert _plan(cfg, store)["supported"] is False
300
+
301
+ with ThreadPoolExecutor(callers) as pool:
302
+ for future in [
303
+ pool.submit(store_module.ensure_bridge_store, cfg) for _ in range(callers)
304
+ ]:
305
+ future.result()
306
+
307
+ assert _plan(cfg, store) == {
308
+ "uri": str(store),
309
+ "supported": True,
310
+ "step_count": 0,
311
+ "steps": [],
312
+ }
313
+
314
+
315
+ @requires_stack
316
+ def test_a_bridge_whose_apply_fails_for_another_reason_is_kept(tmp_path, monkeypatch):
317
+ """Only a plan that says the change is unsupported deletes the bridge. It
318
+ holds every repo's bindings, so a failure a retry can fix must not."""
319
+ from witan_code import config as cfg_mod
320
+
321
+ monkeypatch.setenv("WITAN_CODE_DIR", str(tmp_path / "code"))
322
+ cfg = cfg_mod.load()
323
+ store = cfg_mod.bridge_store_path(cfg.code_dir)
324
+ store_module.ensure_bridge_store(cfg)
325
+ marker = store / "kept"
326
+ marker.write_text("")
327
+ monkeypatch.setattr(store_module, "schema_apply_if_changed", lambda *_: False)
328
+
329
+ store_module.ensure_bridge_store(cfg)
330
+
331
+ assert marker.exists()
332
+
333
+
334
+ @pytest.mark.parametrize("binary", ["/nonexistent/omnigraph", "false"])
335
+ def test_an_unanswered_plan_is_not_a_reason_to_recreate(tmp_path, binary):
336
+ assert not store_module._schema_change_unsupported(
337
+ binary, tmp_path / "bridge-schema.pg", tmp_path / "_bridge.omni"
338
+ )
339
+
340
+
248
341
  def test_discard_store_refuses_a_cluster_graph():
249
342
  """The client cannot create a cluster graph, so it may not delete one."""
250
343
  ref = store_module.StoreRef("https://omnigraph.test", graph_id="code-cg")
@@ -157,10 +157,20 @@ def write_bindings(
157
157
  # uncapped batch runs past the client's 120s timeout — see
158
158
  # `_PURGE_BATCH_SIZE` for the measurements and for why the argv reasoning
159
159
  # this comment used to give no longer applies.
160
+ #
161
+ # The repo's symbol table is cleared in the same batch, because it is
162
+ # rebuilt below from `all_rows` and the fresh bindings, both already read.
163
+ # Nothing read between here and the load depends on this repo's
164
+ # RepoSymbol rows (`repo_symbol_rows` was read above, and the package-map
165
+ # read excludes this repo). As its own commit it cost one more slot in the
166
+ # bridge's serialized commit lane on every index.
160
167
  client.change_many(
161
168
  [
162
- ("bridge.gq", "delete_bindings_in_file", {"repo_file": f"{repo}|{rel}"})
163
- for rel in sorted(purge_files)
169
+ *(
170
+ ("bridge.gq", "delete_bindings_in_file", {"repo": repo, "file": rel})
171
+ for rel in sorted(purge_files)
172
+ ),
173
+ ("bridge.gq", "delete_repo_symbols", {"repo": repo}),
164
174
  ],
165
175
  chunk_size=_PURGE_BATCH_SIZE,
166
176
  )
@@ -238,7 +248,6 @@ def write_bindings(
238
248
  for r in all_rows
239
249
  if r.get("repo") == repo and r.get("file") not in purge_files
240
250
  ]
241
- client.change("bridge.gq", "delete_repo_symbols", {"repo": repo})
242
251
 
243
252
  records = _dedupe([_record(b, repo) for b in adjusted])
244
253
  n_bindings = len(records)
@@ -438,7 +447,6 @@ def _record(b: ParsedBinding, repo: str) -> dict:
438
447
  "role": b.role,
439
448
  "repo": repo,
440
449
  "file": b.file,
441
- "repo_file": f"{repo}|{b.file}",
442
450
  "symbol_id": b.symbol_id or None,
443
451
  "line": b.line,
444
452
  "language": b.language,
@@ -759,7 +759,7 @@ def cleanup(
759
759
  reclaims the storage of deleted branches (``branches --prune``,
760
760
  ``reap-views --apply``). Irreversible, so it requires ``--yes``.
761
761
 
762
- With neither bound given it keeps the last 30 days, the same policy the
762
+ With neither bound given it keeps the last 2 days, the same policy the
763
763
  Stop hook and the deployed maintenance job use.
764
764
 
765
765
  Parameters
@@ -349,7 +349,7 @@ def _step_params(step: dict) -> dict:
349
349
  """A step's params, refusing anything that is not a mapping.
350
350
 
351
351
  Omitted and null both mean "no params". Anything else has to be a dict: the
352
- value is handed to ``change_many`` and ends up as the ``--params`` JSON of a
352
+ value is handed to ``change_many`` and ends up as the params JSON of a
353
353
  composed mutation, so a string or a list would surface as an opaque omnigraph
354
354
  CLI failure several layers below the caller that sent it.
355
355
  """
@@ -23,11 +23,10 @@ From omnigraph 0.11 ``optimize`` no longer reclaims the storage of deleted
23
23
  branches (``branches --prune``, ``reap-views --apply``); only ``cleanup`` does.
24
24
  So on a slower cadence the same detached run also cleans up
25
25
  (``--cleanup-older-than``), after optimize and in the same process so the two
26
- never race. Retention matches the deployed weekly ``omnigraph-cleanup`` CronJob: age only,
27
- never a version count. The window applies to a deleted branch too: on omnigraph
28
- 0.11.0 a freshly deleted fork survives ``cleanup --older-than 30d`` and is
29
- reclaimed by ``--older-than 1s``, so its storage goes at the first cleanup
30
- after its versions age past 30 days.
26
+ never race. Retention follows the deployed stop-window cleanup (nightly,
27
+ ``--older-than 2d``): age only, never a version count. The window applies to a
28
+ deleted branch too: its storage goes at the first cleanup after its versions
29
+ age past :data:`CLEANUP_OLDER_THAN`.
31
30
 
32
31
  The throttle window, atomic last-run stamp, and due-check live in
33
32
  ``witan_core.maintenance``; this module supplies witan-code's own env var,
@@ -56,9 +55,12 @@ _OPTIMIZE_INTERVAL = _throttle.DEFAULT_OPTIMIZE_INTERVAL
56
55
  # store. Override with WITAN_CODE_CLEANUP_INTERVAL (seconds; 0 disables).
57
56
  _CLEANUP_INTERVAL = 7 * 24 * 3600.0
58
57
 
59
- # Versions younger than this survive a cleanup, so time-travel reads over the
60
- # recent past keep working.
61
- CLEANUP_OLDER_THAN = "30d"
58
+ # Versions younger than this survive a cleanup. Nothing in witan reads history
59
+ # (no time-travel reads); the window only leaves an operator time to undelete
60
+ # with ``omnigraph query --snapshot``. Kept short because on omnigraph 0.13 a
61
+ # cleanup opens every version still present before it deletes any, so its cost
62
+ # grows with the window (https://github.com/ModernRelay/omnigraph/issues/1095).
63
+ CLEANUP_OLDER_THAN = "2d"
62
64
 
63
65
 
64
66
  def optimize_interval() -> float:
@@ -8,12 +8,10 @@
8
8
  // ── Deletes (reindex cleanup) ─────────────────────────────────────
9
9
  // Per-file purge: drop one source file's bindings so a reindex only replaces
10
10
  // what it re-extracted (an incremental full-repo index skips unchanged files,
11
- // so a repo-wide purge would orphan their bindings). Keyed on the composite
12
- // repo_file ("repo|file") because delete `where` takes a single condition
13
- // (no compound `and`).
11
+ // so a repo-wide purge would orphan their bindings).
14
12
 
15
- query delete_bindings_in_file($repo_file: String) {
16
- delete InterfaceBinding where repo_file = $repo_file
13
+ query delete_bindings_in_file($repo: String, $file: String) {
14
+ delete InterfaceBinding where repo = $repo and file = $file
17
15
  }
18
16
 
19
17
  // The readiness probe (`store.store_health`). The bridge's per-repo sibling
@@ -27,8 +27,6 @@ node InterfaceBinding {
27
27
  role: enum(provider, consumer, shared) @index
28
28
  repo: String @index // canonical HTTPS repo URI (join key to Layer 2)
29
29
  file: String @index // repo-relative source path of the binding
30
- repo_file: String @index // "repo|file" — single-field key for per-file delete
31
- // (delete `where` takes one condition, no compound `and`)
32
30
  sub_kind: String? // service anchor variant: repo | image | name
33
31
  symbol_id: String? // enclosing Symbol id (repo#path::Qn) when applicable
34
32
  line: I32?
@@ -37,6 +37,7 @@ from witan_core.omnigraph import (
37
37
  schema_apply_if_changed,
38
38
  schema_stamp_path,
39
39
  shared_transport,
40
+ store_write_lock,
40
41
  )
41
42
  from witan_core.refusal import Refusal
42
43
 
@@ -470,6 +471,39 @@ def ensure_store(slug: str, config: cfg_module.Config | None = None) -> StoreRef
470
471
  return StoreRef(str(store))
471
472
 
472
473
 
474
+ def _schema_change_unsupported(binary: str, schema_file: Path, store: Path) -> bool:
475
+ """Whether ``omnigraph schema plan`` says ``store`` cannot take ``schema_file``.
476
+
477
+ Only a plan that answers ``supported: false`` counts. A missing binary, a
478
+ held lock or output this does not recognise is no evidence that the store
479
+ needs recreating, and a wrong yes deletes every repo's bindings, so each of
480
+ those is ``False`` and the next call retries the apply.
481
+ """
482
+ try:
483
+ res = subprocess.run(
484
+ [
485
+ binary,
486
+ "schema",
487
+ "plan",
488
+ "--schema",
489
+ str(schema_file),
490
+ "--json",
491
+ str(store),
492
+ ],
493
+ capture_output=True,
494
+ text=True,
495
+ check=False,
496
+ )
497
+ except OSError:
498
+ return False
499
+ if res.returncode != 0:
500
+ return False
501
+ try:
502
+ return json.loads(res.stdout)["supported"] is False
503
+ except (ValueError, KeyError, TypeError):
504
+ return False
505
+
506
+
473
507
  def ensure_bridge_store(config: cfg_module.Config | None = None) -> StoreRef:
474
508
  """Resolve the shared bridge graph, initialising it from bridge-schema.pg.
475
509
 
@@ -477,6 +511,13 @@ def ensure_bridge_store(config: cfg_module.Config | None = None) -> StoreRef:
477
511
  bridge graph is declared by provisioning under the fixed
478
512
  :data:`config.BRIDGE_GRAPH_ID` and this only verifies it. ``schema apply``
479
513
  builds the FTS index on ``key_norm`` that ``search_bindings`` needs.
514
+
515
+ A local store whose schema omnigraph cannot migrate in place (e.g. the drop
516
+ of ``InterfaceBinding.repo_file``) is deleted and recreated, because the
517
+ writer no longer matches it and the bridge is derived from the indexed
518
+ checkouts. The check cannot tell an older store from a newer one, so two
519
+ witan-code versions on either side of such a change, sharing one
520
+ ``code_dir``, recreate each other's bridge on every write.
480
521
  """
481
522
  cfg = config or cfg_module.load()
482
523
  if _via_mcp(cfg) or cfg.code_server:
@@ -484,20 +525,41 @@ def ensure_bridge_store(config: cfg_module.Config | None = None) -> StoreRef:
484
525
 
485
526
  store = cfg_module.bridge_store_path(cfg.code_dir)
486
527
  binary = _binary()
487
- if store.exists():
488
- # Pick up additive schema changes (new nodes/fields) on existing
489
- # stores; the mtime stamp keeps hot reindex paths subprocess-free.
490
- schema_apply_if_changed(binary, cfg.bridge_schema_file, store)
528
+ # Pick up additive schema changes (new nodes/fields) on existing stores;
529
+ # the mtime stamp keeps hot reindex paths subprocess-free.
530
+ if store.exists() and schema_apply_if_changed(
531
+ binary, cfg.bridge_schema_file, store
532
+ ):
491
533
  return StoreRef(str(store))
534
+ # Creating or recreating runs under the write lock every local write to
535
+ # the store takes, so a concurrent writer waits for a finished store
536
+ # rather than writing into a deleted or half-built one. Every check is
537
+ # repeated once the lock is held, since another process may have done
538
+ # the work while this one waited.
539
+ with store_write_lock(str(store)):
540
+ if store.exists():
541
+ if schema_apply_if_changed(binary, cfg.bridge_schema_file, store):
542
+ return StoreRef(str(store))
543
+ if not _schema_change_unsupported(binary, cfg.bridge_schema_file, store):
544
+ return StoreRef(str(store))
545
+ # Unchanged files keep no bindings on an incremental index, so each
546
+ # repo needs a forced reindex to put its own back.
547
+ logger.warning(
548
+ "witan.code.store.bridge_recreated",
549
+ store=str(store),
550
+ reason="schema change omnigraph cannot apply in place",
551
+ recovery="run `witan-code reindex <repo root>` in each indexed repo",
552
+ )
553
+ discard_store(StoreRef(str(store)))
492
554
 
493
- store.parent.mkdir(parents=True, exist_ok=True)
494
- subprocess.run(
495
- [binary, "init", "--schema", str(cfg.bridge_schema_file), str(store)],
496
- check=True,
497
- capture_output=True,
498
- text=True,
499
- )
500
- schema_apply(binary, cfg.bridge_schema_file, store)
555
+ store.parent.mkdir(parents=True, exist_ok=True)
556
+ subprocess.run(
557
+ [binary, "init", "--schema", str(cfg.bridge_schema_file), str(store)],
558
+ check=True,
559
+ capture_output=True,
560
+ text=True,
561
+ )
562
+ schema_apply(binary, cfg.bridge_schema_file, store)
501
563
  return StoreRef(str(store))
502
564
 
503
565
 
File without changes
File without changes
File without changes