mirror of
https://github.com/Ark0N/Codeman.git
synced 2026-11-17 11:49:33 +01:00
fix(git): the interval fetches one run per folder, and the rest of the review (review)
The scheduler is the part that runs with nobody watching, so it is decided per folder rather than per session: sessions sharing a folder are the same clone and share one run that both see, `inFlight`/`lastRunAt` are keyed by the resolved folder, the schedule is stamped when a folder is picked instead of when its run starts, and a tick is skipped while the previous one is still going. The click route joins a run already going for the same folder rather than starting a second fetch in one clone. The tick keeps ONE bound for the git processes of the whole run and hands it to every folder, and bounds its folders with a bound of its own: the same semaphore cannot serve both levels, because a folder holding a slot would then wait for a slot its own fetch needs. Both bounds are `FETCH_CONCURRENCY`, so the ceiling is unchanged. The bound claim in CLAUDE.md, the `Limiter` jsdoc and docs/api-reference.md now describes it as it is. Before anything is fetched the folder is probed with the bounded path probe, so a case on a mount that stopped answering is skipped and never touched. The rest of the review: the hooks are named as they really are (`reference-transaction`, `pre-auto-gc` through the maintenance a fetch triggers, config commands such as `credential.helper`) and `FETCH_CONFIG_ARGS` turns maintenance and gc off for an unattended run; the claim that an agent in the same repository is not disturbed is replaced by the ref-lock collision it actually is; the click route publishes its own run as `trigger: 'click'`; `autoSaveGitFetch` uses `_apiJson` so a 400 shows the error toast and applies the returned settings; and the two wording fixes. Tests: the scheduler pins one run per folder, the two bounds, the probe before anything runs, and that closing the session holding the override keeps the folder while another session is still open on it; the route test pins the click publish and the join, asserting the join before the held run is released — releasing first lets the run finish and clears the lane, so the joiner would be entitled to its own fetch and the test would pass for the wrong reason.
This commit is contained in:
1 parent
9432d9f9e2
commit
ea4318947b
20 files changed
+774
-209
No files matched your search
@@ -16,10 +16,10 @@
|
||||
import type { FastifyInstance } from 'fastify';
|
||||
import { ApiErrorCode, createErrorResponse, getErrorMessage, type ApiResponse } from '../../types.js';
|
||||
import { redactGitCredentials } from '../../git-clone.js';
|
||||
import { emptyReport, fetchGitWorkspaceOverview, type GitFetchReport } from '../../git-fetch.js';
|
||||
import { emptyReport, fetchWorkspaceOnce, gitFetchStatusFrom, type GitFetchReport } from '../../git-fetch.js';
|
||||
import { readDockerCases } from '../../docker-hosts.js';
|
||||
import { getDataDir } from '../../config/instance.js';
|
||||
import { findSessionOrFail } from '../route-helpers.js';
|
||||
import { findSessionOrFail, persistAndBroadcastSession } from '../route-helpers.js';
|
||||
import {
|
||||
emptyOverview,
|
||||
findWorkspaceRepo,
|
||||
@@ -32,7 +32,7 @@ import {
|
||||
type GitRunner,
|
||||
type GitWorkspaceOverview,
|
||||
} from '../../git-workspace-status.js';
|
||||
import type { SessionPort } from '../ports/index.js';
|
||||
import type { EventPort, SessionPort } from '../ports/index.js';
|
||||
|
||||
/**
|
||||
* Host paths of every Docker case workspace: repositories at or inside these are never inspected.
|
||||
@@ -58,7 +58,9 @@ function limitsFrom(query: { maxRepos?: unknown; timeout?: unknown }) {
|
||||
|
||||
export function registerGitStatusRoutes(
|
||||
app: FastifyInstance,
|
||||
ctx: SessionPort,
|
||||
// EventPort as well as SessionPort: the fetch route publishes the run it did, and a route that broadcasts
|
||||
// has to say so in its own signature.
|
||||
ctx: SessionPort & EventPort,
|
||||
git?: GitRunner,
|
||||
dockerWorkspaces: () => Promise<string[]> = defaultDockerWorkspaces
|
||||
): void {
|
||||
@@ -131,9 +133,14 @@ export function registerGitStatusRoutes(
|
||||
// Fetch, and only because the user clicked Fetch in the panel (src/git-fetch.ts): one
|
||||
// `git fetch --quiet` per repository the panel would show, through the same resolver so the two cannot
|
||||
// disagree about which repositories belong to the workspace. This is the only git command Codeman runs
|
||||
// that writes, and it writes remote-tracking refs only — nothing commits, checks out or merges, so an
|
||||
// agent working in the same repository is not disturbed. Remote and Docker sessions answer `unsupported`
|
||||
// like the status route, and a repository a container can write to is refused before any git runs.
|
||||
// that writes, and it writes remote-tracking refs only — nothing commits, checks out or merges. It is not
|
||||
// as harmless as a read though: a fetch holds git's ref lock, so an agent's own `git pull` in the same
|
||||
// clone can collide with it, which is why the run goes through `fetchWorkspaceOnce` — a click while a tick
|
||||
// is already fetching this folder joins that run instead of starting a second one. It can also run a
|
||||
// repository's own hooks (`reference-transaction`, `pre-auto-gc` through the maintenance git runs after a
|
||||
// fetch) and its config commands such as `credential.helper`, so the `FETCH_CONFIG_ARGS` overrides turn
|
||||
// maintenance and gc off, and a repository a container can write to is refused before any git runs. Remote
|
||||
// and Docker sessions answer `unsupported` like the status route.
|
||||
app.post('/api/sessions/:id/git-fetch', async (req): Promise<ApiResponse<GitFetchReport>> => {
|
||||
const { id } = req.params as { id: string };
|
||||
const query = req.query as { maxRepos?: unknown; timeout?: unknown };
|
||||
@@ -141,13 +148,16 @@ export function registerGitStatusRoutes(
|
||||
const session = findSessionOrFail(ctx, id, req);
|
||||
if (session.remote) return { success: true, data: emptyReport('unsupported', { reason: 'remote' }) };
|
||||
if (session.docker) return { success: true, data: emptyReport('unsupported', { reason: 'docker' }) };
|
||||
return {
|
||||
success: true,
|
||||
data: await fetchGitWorkspaceOverview(session.workingDir, {
|
||||
git,
|
||||
...limits,
|
||||
dockerWorkspaces: await dockerWorkspaces(),
|
||||
}),
|
||||
};
|
||||
const report = await fetchWorkspaceOnce(session.workingDir, {
|
||||
git,
|
||||
...limits,
|
||||
dockerWorkspaces: await dockerWorkspaces(),
|
||||
});
|
||||
// The response answers the click, and the run is also the session's current truth: what the panel's
|
||||
// "behind" number is based on. Publishing it is what the api docs say a click does, and what makes a
|
||||
// second tab open on the same folder see the same run — including a click that joined a tick already
|
||||
// going, where the row has to say who last fetched.
|
||||
if (session.setGitFetchStatus(gitFetchStatusFrom(report, 'click'))) persistAndBroadcastSession(ctx, session);
|
||||
return { success: true, data: report };
|
||||
});
|
||||
}
|
||||
@@ -3611,11 +3611,13 @@ export function registerSessionRoutes(
|
||||
|
||||
// ========== Git fetch on an interval ==========
|
||||
|
||||
// Per-case override for the fetch interval (src/git-fetch-scheduler.ts). `null` on either field clears
|
||||
// the case's choice so the app-wide setting applies again, and a field left out of the body leaves the
|
||||
// other half as it was: the Session Options rows save on their own. Refused for a remote or Docker
|
||||
// session, exactly as the Git panel excludes them — a container can write to the repository it mounts,
|
||||
// so git there would run that repository's own configuration on the host.
|
||||
// Per-session override for the fetch interval (src/git-fetch-scheduler.ts), which is what the Session
|
||||
// Options rows say it is: two sessions on one folder can hold different choices, and that folder is
|
||||
// fetched when the first of them is due. `null` on either field clears this session's choice so the
|
||||
// app-wide setting applies again, and a field left out of the body leaves the other half as it was: the
|
||||
// Session Options rows save on their own. Refused for a remote or Docker session, exactly as the Git
|
||||
// panel excludes them — a container can write to the repository it mounts, so git there would run that
|
||||
// repository's own configuration on the host.
|
||||
app.post('/api/sessions/:id/git-fetch-settings', async (req) => {
|
||||
const { id } = req.params as { id: string };
|
||||
const body = parseBody(GitFetchSettingsSchema, req.body, 'Invalid request body');
|
||||
|
||||
Reference in new issue
Block a user