Job application tracker and AI-powered job search assistant. Helps job seekers manage their search journey with AI resume review, job matching, task logging, and application analytics, all while keeping your data private.
TypeScript ai-agentai-resume-analyzerapplication-trackerapplication-tracking-systematscareerjob-applicationjob-automationjob-huntingjob-searchjob-seeker-toolsjob-trackerjob-trackingjobsearchjobseekersmcpollamaresumeresume-reviewself-hosted
fix(ai-usage): record chat provider errors as Error and disconnects as Stopped, group rows without copying; docs(wiki): describe Settings → AI Usage
Khuram Niazaf9456617757
diff --git a/__tests__/agentChatRoute.spec.ts b/__tests__/agentChatRoute.spec.tsindex d4fc295..9002d4d 100644--- a/__tests__/agentChatRoute.spec.ts+++ b/__tests__/agentChatRoute.spec.ts@@ -58,6 +58,7 @@ import { getModel } from "@/lib/ai/providers";import { getUserSettings } from "@/actions/userSettings.actions";import { saveChatConversation } from "@/actions/agentChat.actions";import { buildAgentTools } from "@/lib/agent/tools";+import { statusOf } from "@/lib/aiUsage/tracker";import { buildPageContextMessage } from "@/lib/agent/prompt";import { APP_CONSTANTS } from "@/lib/constants";import {@@ -445,11 +446,13 @@ describe("POST /api/ai/chat", () => {await POST(req({ messages: [pasteMessage("posting")] }));streamArgs().onFinish({ totalUsage: { inputTokens: 5000, outputTokens: 200 }, finishReason: "stop" });await finishTurn();- expect(finish).toHaveBeenCalledWith({+ const arg = finish.mock.calls[0][0];+ expect(arg).toMatchObject({usage: { inputTokens: 5000, outputTokens: 200 },finishReason: "stop",excludeMs: 0,});+ expect(statusOf(arg)).toBe("ok");});it("records a stopped turn with finished-step usage", async () => {@@ -472,5 +475,36 @@ describe("POST /api/ai/chat", () => {await finishTurn();expect(finish.mock.calls[0][0].excludeMs).toBe(90_000);});++ // A doStream throw (Ollama down, bad key) skips streamText's onFinish and+ // reaches the route only as an error part through toUIMessageStream.+ const streamError = (error: unknown) =>+ (toUIMessageStream.mock.calls as any)[0][0].onError(error);++ it("records a provider error before any step as error", async () => {+ await POST(req({ messages: [pasteMessage("posting")] }));+ streamError(new Error("connect ECONNREFUSED 127.0.0.1:11434"));+ await finishTurn();+ expect(statusOf(finish.mock.calls[0][0])).toBe("error");+ });++ it("records an error after a finished tool step as error, not ok", async () => {+ await POST(req({ messages: [pasteMessage("posting")] }));+ streamArgs().onFinish({ totalUsage: { inputTokens: 900, outputTokens: 30 }, finishReason: "tool-calls" });+ streamError(new Error("connect ECONNREFUSED 127.0.0.1:11434"));+ await finishTurn();+ expect(statusOf(finish.mock.calls[0][0])).toBe("error");+ });++ it("records a disconnect as stopped before isAborted is set", async () => {+ const controller = new AbortController();+ await POST({ json: async () => ({ messages: [pasteMessage("posting")] }), signal: controller.signal } as any);+ streamArgs().onAbort({ steps: [{ usage: { inputTokens: 4000, outputTokens: 50 } }] });+ controller.abort();+ await finishTurn(false);+ const arg = finish.mock.calls[0][0];+ expect(statusOf(arg)).toBe("stopped");+ expect(arg.usage).toEqual({ inputTokens: 4000, outputTokens: 50 });+ });});});diff --git a/src/app/api/ai/chat/route.ts b/src/app/api/ai/chat/route.tsindex b29f2ed..903f8bf 100644--- a/src/app/api/ai/chat/route.ts+++ b/src/app/api/ai/chat/route.ts@@ -243,8 +243,12 @@ export const POST = async (req: NextRequest) => {// onError, which would map and log the same failure a second time. Passing// an already-mapped string straight back keeps it to one line per failure.const alreadyMapped = new Set<string>();+ // A doStream throw (Ollama down, bad key) never reaches streamText's+ // onFinish; this is the only place the turn learns it failed.+ let turnError: unknown;const mapTurnError = (error: unknown): string =>runInSpan(turnSpan, () => {+ turnError ??= error;const message = error instanceof Error ? error.message : "";if (alreadyMapped.has(message)) return message;const mapped = mapAgentError(error, errorContext);@@ -371,11 +375,16 @@ export const POST = async (req: NextRequest) => {"jobsync.message_chars": fields.messageChars,"jobsync.prefix_changed": fields.prefixChanged,});- void turnUsageTracker.finish(- isAborted- ? { usage: turnAbortUsage, abortedBy: turnSignal, excludeMs: nestedGuard.elapsedMs }- : { usage: turnUsage, finishReason: turnFinishReason, excludeMs: nestedGuard.elapsedMs },- );+ // The stream's cancel path can run this before isAborted is set, so the+ // signal decides too; statusOf ignores abortedBy unless it fired.+ const aborted = isAborted || turnSignal.aborted;+ void turnUsageTracker.finish({+ usage: aborted ? turnAbortUsage : turnUsage,+ finishReason: turnFinishReason,+ error: turnError,+ abortedBy: turnSignal,+ excludeMs: nestedGuard.elapsedMs,+ });// A cancelled turn never writes back. Clear deletes the conversation and// this fires afterwards on the stream's cancel path, so saving here would// restore exactly what the user just deleted. The write-on-receipt abovediff --git a/src/lib/aiUsage/summarize.ts b/src/lib/aiUsage/summarize.tsindex 8d7bc23..c8e9f28 100644--- a/src/lib/aiUsage/summarize.ts+++ b/src/lib/aiUsage/summarize.ts@@ -76,7 +76,9 @@ function groupBy<T>(rows: T[], key: (row: T) => string): Map<string, T[]> {const groups = new Map<string, T[]>();for (const row of rows) {const k = key(row);- groups.set(k, [...(groups.get(k) ?? []), row]);+ const group = groups.get(k);+ if (group) group.push(row);+ else groups.set(k, [row]);}return groups;}diff --git a/wiki/getting-started.md b/wiki/getting-started.mdindex 5907710..907c992 100644--- a/wiki/getting-started.md+++ b/wiki/getting-started.md@@ -3,8 +3,8 @@ type: tutorialtitle: Getting Starteddescription: The first run through JobSync — creating an account, connecting an AI provider, adding a job, and what each sidebar area is for.feature: setup-tags: [setup, first run, sign in, account, ai provider, ollama, sidebar, navigation, dashboard, quick add, shortcuts]-aliases: [new user, onboarding, first steps, how do I start, set up jobsync]+tags: [setup, first run, sign in, account, ai provider, ollama, sidebar, navigation, dashboard, quick add, shortcuts, ai usage, tokens]+aliases: [new user, onboarding, first steps, how do I start, set up jobsync, how much ai am i using]status: stablestale_after: 2027-08-31---@@ -23,6 +23,10 @@ If you run Ollama somewhere other than the default address, add that address undNothing AI-powered works until a provider *and* a model are both set — resume review, job matching, cover letters and the chat panel all refuse to start rather than silently picking a model for you. If you selected Ollama and the model list is empty, JobSync could not reach the Ollama server; check that it is running and reachable from wherever JobSync is running.+## How do I see how much AI I'm using?++Open **Settings → AI Usage**. It shows the last 7 or 30 days: total tokens, how many AI calls were made, typical response time and time to the first visible word, and how many calls failed — broken down by provider, model and feature (Agent chat, Job match, Automations, Resume review, Cover letter, Resume import), with the last 50 calls at the bottom. A chat message counts as one call; a review, match or cover letter it starts is counted separately under its own feature, and its time is not added to the chat's. Failures are split into provider errors, timeouts, truncated answers and interrupted streams; calls you stopped yourself are shown but never counted as failures. An amber "near context limit" badge on an Ollama model means those calls filled at least 90% of the model's context window, where Ollama silently drops the oldest text. History is kept for 90 days and is not part of the data backup.+## How do I add my first job?Click **Jobs** in the sidebar, then the **Add Job** button in the top-right of the Jobs card. Job Title, Company, Job Location and Job Source are the fields you have to fill in yourself. Job Type, Workplace Type, Status, Due Date and Job Description are also required, but the form arrives with them already filled — Due Date three days out and Job Description the placeholder `N/A` — so you can change them but not leave them empty. Job URL, Salary Range, Date Applied, a resume, a cover letter and skills are the genuinely optional ones, and you can add them later.@@ -47,7 +51,7 @@ Five of them take you to the matching page with the form already open, so you la- **Profile** — your resumes, contact information and the profile the AI features read from.- **Library** — the shared reference lists behind the dropdowns: Companies, Job Titles, Locations, Sources, Skills and Activity Types.-**Settings is not one of the entries above.** Open the avatar menu at the bottom of the sidebar instead, below the navigation list, and choose **Settings**. It holds AI Provider, API Keys, Appearance, MCP Access and Data (backup, export and import). That same menu also has Support and Logout.+**Settings is not one of the entries above.** Open the avatar menu at the bottom of the sidebar instead, below the navigation list, and choose **Settings**. It holds AI Provider, AI Usage, API Keys, Appearance, MCP Access and Data (backup, export and import). That same menu also has Support and Logout.## Where do I find installation and Docker instructions?