Skip to content

service-knowledge: split knowledge-service.ts (5,411 lines, one class) into concern modules, move-only, so knowledge cards stop queueing on one file #38660

Description

@objectstack-fleet

repo:objectstack#2 · os-warren · session_01JQwxbXyLoBzNYY1U8SNPFu

2026-11-30T01:19Z · Body amended: the split registers in the existing facade gate (see Amendment at the end).

Filing gate: ③ maintainer-directed. Source: maintainer, os-warren's fleet project thread, 2026-11-30T00:57:27Z, decision card 「立一张拆分 knowledge-service.ts 的卡,排在两个 PR 合并后第一个做吗?」 answered 「立卡并优先做」 (after the seat's advice: split along the concerns, move-only, one PR, land when no open PR touches the file).
Grading: area:ai · Task (engineering throughput, no product behaviour change) · Suggested-grade: p2 (the knowledge topic's next three cards queue on this file) · reach: every knowledge-topic card · evidence: measured on origin/main f5da514.
Blocked-by: #38599, #38606

维护者速读

What (measured at f5da514)

packages/services/service-knowledge/src/knowledge-service.ts holds class KnowledgeService (line 263) and about 150 members. Its concerns, by method:

  • Build and index state: planIndex, reindexSource, walkObjectSource, completeBuild, readIndexState*, rebuildSource, buildUnderLease, recordBuildStart, closeStaleBuild, closeInterruptedBuilds, buildSourcesAtBoot, buildIfDue, reconcilePass, reconcileOf (~L731–2236).
  • Search and answer: search, searchWithRefusals, searchByKey, answerByRecord, checkFreshness, dropUnverifiedHits, planSearches, searchRound, sourcesNarrowedToVisible, readVisibleIds (~L2476–3272).
  • Record sync and backlog: processRecordSync*, syncRecordGroup, recordSyncWaiting, considerBacklogReconcile, syncRows, handleRecordUpsert/Delete, syncRecord, syncRow, writeSynced, sync state and dead letters (~L1864–2074, L3431–4079).
  • Save admission and scoping: admitSources, admitAuthoredSource, readTenancyPosture, scopeByOrganization, applyPermissionFilter (~L4079–4465+).

Ask

  1. Split the class's bodies into concern modules beside it (the dev proposes the cut and names, e.g. knowledge-build.ts, knowledge-search.ts, knowledge-record-sync.ts, knowledge-admission.ts); KnowledgeService keeps its public surface and delegates. Move-only: no rename of a public member, no behaviour change, no new export from the package entry.
  2. Tests move only when a test imports a moved private helper; the existing suites pass unchanged.
  3. One PR. Start from main after feat(service-knowledge)!: an author's knowledge source save is refused while the knowledge service is not enabled #38599 and feat(knowledge): a knowledge source orders its hits for the person asking (source.affinity) #38606 merge, and land before any other card opens a PR on the file.

Acceptance

  • git diff --stat shows the class body moved, not rewritten; the PR body maps each moved member to its new file.
  • Every service-knowledge test and the knowledge pins elsewhere pass unchanged; the package's public declaration (api-surface) is unchanged.
  • knowledge-service.ts falls well below 2,000 lines.
  • The PR registers the split in the existing facade gate: a facades row for KnowledgeService and a ceilings row for knowledge-service.ts in scripts/facade-delegation-registry.json (post-split line count as baseLines, the existing CEILING_MARGIN of 100), so scripts/check-facade-delegation-only.mjs keeps the file a facade. Every moved body lives in a concern module; a member that must stay in the facade (state-owning) gets an exceptions row with its reason.

Not here

Related: topic #37000, #38346, #38536.

Amendment 2026-11-30T01:19Z: maintainer (Warren, os-warren), os-warren's fleet project thread, 2026-11-30T01:18:13Z 「同意,立卡」 and 2026-11-30T01:18:26Z 「按照 fable的方案」, approving the large-file plan (isolated fable analysis; prior rulings 6624258595 on #29465 and 6897467376 on #33949: split files carry a ceiling, unsplit files none). Its step 1 is this card's registry rows above.

Activity

  1. added
    priority:p2
    area:ai
    on Nov 30, 2026
  2. objectstack-fleet commented on Nov 30, 2026

    @objectstack-fleet
    ContributorAuthor

    triage@os-warren · os-warren · session_01JQwxbZzZ2f5mzcvJbRrRNZ

    Triage: lands in packages/services/service-knowledge/src/knowledge-service.ts and new concern modules beside it · area:ai · domain:server · Task · p2 · pm:blocked · size M.
    Rationale: a maintainer-directed, move-only split (decision answered 2026-11-30T00:57Z, quoted in the body). A refactor is a Task. It takes p2 under the blocker rule because the knowledge topic's next cards (#38591 and #38471 at p2) queue on this one file. It waits on the body's Blocked-by: line, PRs #38599 and #38606. Grade and area are kept as filed. Answers knock 7265756280.

  3. added
    domain:server
    pm:blocked
    on Nov 30, 2026
  4. objectstack-fleet commented on Nov 30, 2026

    @objectstack-fleet
    ContributorAuthor

    repo:objectstack#2 · os-warren · session_01JQwxbXyLoBzNYY1U8SNPFu

    2026-11-30T03:18Z · Claim · #38599 and #38606 merged (the body's Blocked-by: line is clear); the maintainer's 「立卡并优先做」 puts this split first in the knowledge topic.

    Claim: PM loop round 1
    Session: session_01JQwxbXyLoBzNYY1U8SNPFu
    Account: os-warren
    Branch: new, from origin/main at c35318c25d; the card thread's branch is named by a claim amendment on its first report
    Worktree: objectstack-issue-38660
    Domain: domain:server
    Seat: repo:objectstack#2
    Area: o2-A (area:ai)
    File surface: packages/services/service-knowledge/src/knowledge-service.ts, new concern modules beside it under packages/services/service-knowledge/src/, tests under packages/services/service-knowledge/src/__tests__/ only where a test imports a moved private helper, scripts/facade-delegation-registry.json (the facades, ceilings and any exceptions rows for KnowledgeService), one changeset if the dev finds a published byte moves (expected: none, skip-changeset otherwise) (stop on breach; explain in the report)
    Container & model: L, mode:thread, model: default (dispatch-gates --tier: no path-derived mandate), effort: high
    Clause-②: no
    Metadata-protocol: none
    Responsibility: n/a — not a defect card (maintainer-directed Task)
    Thread-read: none
    Premise: holds at c35318c25d — knowledge-service.ts is 5,571 lines, one class KnowledgeService; #38599 and #38606 are on main; no open PR touches the file at this read except the knowledge cards queued behind this one (#38591, #38471, #38504, #38369 PR 3), none started.
    Serial constraints cleared: lands before any other card opens a PR on knowledge-service.ts; overlap-check.mjs runs before every push.
    Pre-claim lane: packages/services/service-knowledge/** ⇒ domain:server (file ownership only); area:ai, zone o2-A.
    Pre-claim deps: Blocked-by: #38599, #38606 — both merged.
    Prior rulings read: the maintainer's 「立卡并优先做」 (2026-11-30T00:57:27Z) and 「同意,立卡」「按照 fable的方案」 (2026-11-30T01:18:26Z); facade rulings 6624258595 (#29465) and 6897467376 (#33949).

  5. added
    pm:dispatched
    and removed
    pm:blocked
    on Nov 30, 2026
  6. objectstack-fleet commented on Nov 30, 2026

    @objectstack-fleet
    ContributorAuthor

    repo:objectstack#2 · os-warren · session_01JQwxbXyLoBzNYY1U8SNPFu

    2026-11-30T03:22Z · Claim amendment to 7267792242: names the card thread's branch.

    Claim: PM loop round 1 (amendment of 7267792242)
    Session: session_01JQwxbXyLoBzNYY1U8SNPFu
    Thread session: session_01JQwxbZLuMpo8YX4ACmyoNd
    Account: os-warren
    Branch: claude/project-thread-e6npb2 (from origin/main at 39064f62)
    Worktree: objectstack-issue-38660
    Domain: domain:server
    Seat: repo:objectstack#2
    Area: o2-A (area:ai)
    File surface: unchanged from 7267792242; concern-module names must not collide with the existing knowledge-* modules (e.g. knowledge-build.ts already exists)
    Container & model: L, mode:thread, model: default (dispatch-gates --tier: no path-derived mandate), effort: high
    Clause-②: no
    Metadata-protocol: none
    Thread-read: none

  7. objectstack-fleet commented on Nov 30, 2026

    @objectstack-fleet
    ContributorAuthor

    repo:objectstack#2 · os-warren · session_01JQwxbZLuMpo8YX4ACmyoNd
    os-dev-report

    {
     "issue": 38660,
     "status": "done",
     "branch": "claude/project-thread-e6npb2",
     "pr": "https://github.com/objectstack-ai/objectstack/pull/38700",
     "pr_number": 38700,
     "head_sha": "ad4f458a7cee52716072fa5581efa57f89d6d4e3",
     "session": "session_01JQwxbZLuMpo8YX4ACmyoNd",
     "premise_still_valid": true,
     "summary": "KnowledgeService (5,571 lines at 39064f62, confirmed) is now a 1,658-line facade: 114 members forward in one call to bodies in five concern modules (sources, indexing, record-sync, search, admission) plus knowledge-service-top-level.ts (every non-class top-level declaration, moved whole) and knowledge-service-host.ts (per-service host, SqlDriver/engine.ts precedent shape). Move-only: no member renamed, index.ts untouched, a throwaway token-identity verifier proved all 114 bodies and 68 top-level declarations identical (negative control reds), and the built index.d.ts is unchanged where public (KnowledgeService differs only by 70 private-member comments). Registered in the facade gate (facades row, ceilings row baseLines 1658 / maxLines 1758 at baseCommit 4c4a984345 ruling 6897467376, exceptions for constructor and knowledgeTools). PR body maps every moved member to its file and itemises net growth.",
     "tests": "At ad4f458a7c: os-verify-lock 'pnpm --filter @objectstack/service-knowledge test && ... typecheck' -> Test Files 25 passed (25), Tests 836 passed (836), typecheck clean, VERDICT command-exit 0. Knowledge pins elsewhere at 5fffac643b (package source differs from final head by 7 comment lines only): core 3/34, knowledge-memory 2/56, knowledge-turso 3/267, mcp 1/22, runtime 4/198, service-settings 4/192, objectql 1/7, rest 1/82, spec token-estimate 1/29, cli pin 1/2, all pass, VERDICT command-exit 0. NOT MEASURED: service-knowledge-pgvector live tests, reason: no Postgres in container. No ablation: no tested behaviour changed (move-only); move proven by token-identity verifier with negative control.",
     "gates": "Local, at ad4f458a7c: dispatch-gates --commands (repo objectstack-ai/objectstack, commit ad4f458a7c) derived 121; all run, exit codes captured before pipes; --ran: '121 derived famil(ies) accounted for - 118 run, 3 NOT-MEASURED (3 DERIVED from a recorded exit 3)'. Exit 0 includes check-facade-delegation-only (KnowledgeService 150 members, 123 delegations, 25 fields, 2 named exceptions; knowledge-service.ts 1658 lines, ceiling 1758) + self-test, tenant-audit-census + self-test, check:system-context-census, spec check:liveness, check:empty-state, changeset gates, check-plugin-teardown-shape --self-test, check:platform-checklist, check:pm-dispatch-gates. NOT MEASURED (exit 3, prerequisite: whole-workspace dist not built): spec check:skill-examples, check:dual-build-cjs-loads, check:published-readme-exports. check-platform-checklist --changed-from origin/main exit 0 (no anchored file). overlap-check before final push: VERDICT clean exit 0 (origin/main and #38497 merge cleanly). CI: PR check-runs on ad4f458a7c at report time 25 total: 1 success, 5 skipped, 19 in_progress -> NOT MEASURED: CI families, reason: not concluded when the report was written (convergence is the seat's).",
     "dogfood_battery": "n/a - no ! in the PR title and no (narrowing) arm (Clause-2: no)",
     "line_budget": "knowledge-service.ts 5,571 -> 1,658 (ceiling 1,758). New: knowledge-service-sources.ts 415, -indexing.ts 1,483, -record-sync.ts 944, -search.ts 1,147, -admission.ts 580, -top-level.ts 1,067, -host.ts 62. The eight knowledge-service*.ts class files together 5,571 -> 7,356 (+1,785: 114 stubs, 120-line static host block, 220 lines of host interfaces, 44 one-line facet docblocks, module headers/imports, re-export block, host module). Diff vs merge-base 25ac5dfa9: 14 files, +6,162 / -4,333 (10,495 changed lines, over 3,000: approval is the seat's/maintainer's).",
     "files_changed": [
      ".changeset/38660-knowledge-service-split.md",
      "content/docs/permissions/system-context.mdx",
      "packages/services/service-knowledge/src/knowledge-service.ts",
      "packages/services/service-knowledge/src/knowledge-service-admission.ts",
      "packages/services/service-knowledge/src/knowledge-service-host.ts",
      "packages/services/service-knowledge/src/knowledge-service-indexing.ts",
      "packages/services/service-knowledge/src/knowledge-service-record-sync.ts",
      "packages/services/service-knowledge/src/knowledge-service-search.ts",
      "packages/services/service-knowledge/src/knowledge-service-sources.ts",
      "packages/services/service-knowledge/src/knowledge-service-top-level.ts",
      "packages/spec/liveness/knowledge_source.json",
      "scripts/check-facade-delegation-only.mjs",
      "scripts/facade-delegation-registry.json",
      "scripts/tenant-audit-census.mjs"
     ],
     "deviations": [
      "Commit trailer: the dispatch's Co-Authored-By line names a model, which AGENTS.md and the pre-push hook refuse (and the dispatch itself says never put a model identifier in commits); commits carry the model-free pair Co-authored-by: Claude + Claude-Session instead.",
      "Changeset instead of skip-changeset: dist code moves between chunks (published bytes change), so one patch changeset; it names @objectstack/spec too because the liveness ledger ships there. No skip-changeset label sent.",
      "File-surface additions beyond the package, each forced by a gate reading moved code: check-facade-delegation-only.mjs (one DECLARED_WATCH_HINTS path, self-test N7), tenant-audit-census.mjs (one UNTYPED_RECEIVERS row for record-sync adapter receiver), system-context.mdx (generated register via --write, 4 anchors), packages/spec/liveness/knowledge_source.json (10 path#symbol citations repointed; check:liveness was red on documentKeyOf).",
      "One earlier push (1b7a98c75 or before) went out in the same command chain as an overlap-check that answered cannot-answer on a shallow clone; deepened, reran clean; the final push was preceded by a clean overlap-check.",
      "Pins in other packages were read at 5fffac643b, not the final head; the package source differs by comment lines only.",
      "PR body carries a plain 'Signed: repo:objectstack#2 · os-warren · session_...' line before the mandated tail (no HTML comment signature), so the body still ends with the required lines.",
      "Local-only reading: 3 gates and pgvector live tests NOT MEASURED (see gates/tests)."
     ],
     "mcp_calls": "0",
     "api_writes": "3 - fleet-write relay dispatch fw-20261130T053515Z-8e9c6d (run 46360583423) for pr_create: POST /repos/objectstack-ai/objectstack/pulls (#38700, draft, body read back byte-identical) + POST /repos/objectstack-ai/objectstack/issues/38700/assignees (os-warren); post-stamped.mjs: POST /repos/objectstack-ai/objectstack/issues/38660/comments (this os-dev-report). git push to claude/project-thread-e6npb2 is not a REST write.",
     "open_questions": [],
     "security_findings": "none",
     "out_of_scope_findings": []
    }
  8. objectstack-fleet commented on Nov 30, 2026

    @objectstack-fleet
    ContributorAuthor

    repo:objectstack#2 · os-warren · session_01JQwxbXyLoBzNYY1U8SNPFu

    2026-11-30T05:39Z · Claim amendment to 7267842463: names the PR and admits four gate-fed files and a patch changeset.

    Claim: PM loop round 1 (amendment of 7267842463)
    Session: session_01JQwxbXyLoBzNYY1U8SNPFu
    Thread session: session_01JQwxbZLuMpo8YX4ACmyoNd
    Account: os-warren
    Branch: claude/project-thread-e6npb2, PR #38700
    Worktree: objectstack-issue-38660
    Domain: domain:server
    Seat: repo:objectstack#2
    Area: o2-A (area:ai)
    File surface: 7267842463's, plus four files whose gates read the moved code, each admitted: scripts/check-facade-delegation-only.mjs (watch hint), scripts/tenant-audit-census.mjs (one receiver row), the generated system-context.mdx (--write), and packages/spec/liveness/knowledge_source.json (10 citations repointed). Also one patch changeset for @objectstack/service-knowledge and @objectstack/spec, because dist chunks move; it replaces the expected skip-changeset.
    Container & model: L, mode:thread, model: default (dispatch-gates --tier: no path-derived mandate), effort: high
    Clause-②: no
    Metadata-protocol: none
    Thread-read: none

    Size note: the diff is 14 files, +6,162/−4,333, over the 3,000-line human-merge threshold, so a person merges it after the seat's L1. The seat checks the move-only claim independently (token identity of the 114 delegated bodies and 68 moved declarations) before ACCEPT.

  9. objectstack-fleet commented on Nov 30, 2026

    @objectstack-fleet
    ContributorAuthor

    repo:objectstack#2 · os-warren · session_01JQwxbXyLoBzNYY1U8SNPFu

    2026-11-30T08:04Z · Landed — card closed by the merge; seat label cleared.

    PR #38700 (the move-only split of the knowledge service) merged at 2026-11-30T08:03Z as e6b424b719. The cards that waited on the split (#38591, #38471, #38504) stay undispatched under the maintainer's hold on new objectstack-side knowledge cards.

  10. removed
    pm:dispatched
    on Nov 30, 2026
  11. added 2 commits that reference this issue on Dec 1, 2026
    e6b424b
    80ddfb5
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

area:aidomain:serverpriority:p2

Type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions