Skip to content

fix(app): re-read background jobs after reconnect - #65053

Closed
jlongster wants to merge 2 commits into
devfrom
job-list-resync
Closed

jlongster wants to merge 2 commits into
devfrom
job-list-resync

Conversation

@jlongster

@jlongster jlongster commented Nov 20, 2026 •

Copy link
Copy Markdown
Contributor

Issue for this PR

Closes #

Type of change

  • Bug fix
  • New feature
  • Refactor / code improvement
  • Documentation

What does this PR do?

Moves the composer activity pill's job list/event merge from model.ts into createJobList (background.ts) so it can be unit tested. Behavior is unchanged. The list is still re-read when connection.status() returns to connected, which already happens on every stream reconnect, watchdog abort and forced resync (packages/client/src/solid/connection.ts). Each load replaces the job state, and events that arrive while a list request is in flight still win over its response (#64966).

How did you verify your code works?

Added tests in job-list.test.ts: a job whose settled event was missed disappears after a reload, and an event during the reload wins over the stale list. I also ran tsc -b for app.

Screenshots / recordings

n/a

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

User decisions:
- Re-read the job list after a reconnect so missed events don't leave stale rows

@opencodejr opencodejr Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I couldn't run the web app here (no Playwright browsers), so I checked the reconnect path at the client level. It looks like the base already does what this PR adds.

The base job-list effect in model.ts reads serverSDK.connection.status(), and createClientConnection moves that status to reconnecting and back to connected on every stream reconnect, including after a server restart and the forced resync after sleep. I ran a quick check with a fake stream that drops twice. An effect gated on status() === "connected" ran on all three connects, each time before the batched server.connected (about 16 ms later). The base therefore already reloads the full list after a reconnect, and mergeJobList replaces the state, so a missed settle should already be cleared. With this change, every reconnect (and the first connect with a session open) sends two job.list requests, and the second cancels the first. If you've seen a stuck row that the status effect misses, could you describe the case? Otherwise the new server.connected handler can probably be dropped.

The bun.lock diff only removes libc fields from platform packages, which looks like output from a different Bun version (the repo pins bun@1.4.4). It's unrelated to this change and is probably best reverted.

The job-list tests pass and tsc -b for packages/app is clean. Public API: unchanged.

const next = new Map(previous)
next.delete(info.id)
const stopJobs = serverSDK.event.on("experimental.job.updated", (event) => jobList.update(event.data.info))
const stopJobsResync = serverSDK.event.on("server.connected", () => {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks redundant with the effect below. createClientConnection sets connection.status() to reconnecting and then connected on every stream reconnect, so that effect already calls loadJobs then. server.connected reaches listeners about 16 ms later (the event flush), so each reconnect, and the first connect, now sends two job.list requests, and the second cancels the first. Is there a case where server.connected arrives without a status change? If not, this handler can go.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right, thanks. createClientConnection (packages/client/src/solid/connection.ts) sets status to connecting/reconnecting at the top of each connect attempt (L150) and after each drop (L163), then back to connected once server.connected is read (L115). The idle watchdog (L91) and resync() (L212-217, foreground/online) both just abort the live request, so they go through that same loop, and stop()/start() sets connecting (L208). I couldn't find a path where the stream reopens while staying connected, so the status-gated effect already re-lists on every reconnect.

Removed the server.connected handler in c9b5808. What's left is createJobList, which moves the existing list/event merge out of the effect, plus tests for the missed-settle and in-flight-event cases. That's a refactor with tests, not a behavior fix. The stray bun.lock change was already dropped (8846d18), and the diff only touches packages/app/src/session/requests/.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I checked c9b5808 and it looks right. The server.connected handler is gone, and the effect is once again the only thing that re-lists jobs. In connection.ts, status goes to connecting or reconnecting at L150, L163 and L208, and back to connected at L115. That means every reconnect, including the ones triggered by the idle watchdog and resync(), re-lists jobs once.

What I verified:

  • git diff pr/base...pr/head changes only background.ts, job-list.test.ts and model.ts, all under packages/app/src/session/requests/. There is no bun.lock change.
  • bun test src/session/requests/job-list.test.ts passes (4 tests).
  • In model.ts, the effect's behavior is the same as before. The in-flight merge and the params.id === sessionID check are just moved into createJobList.

One thing left: the PR title (fix(app): re-read background jobs after reconnect) and the description still say it adds a server.connected re-read, and that's no longer true. Since this is now a refactor with tests, retitle it refactor(app): … and cut the server.connected paragraph from the description.

I didn't change anything in the checkout.

User decisions:
- Re-read the job list after a reconnect so missed events don't leave stale rows

@opencodejr opencodejr Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The new commit reverts the unrelated bun.lock changes, so the lockfile is no longer in this PR. Its only other change is a blank line in model.ts, so the inline question about the server.connected handler duplicating the status effect is still open. job-list.test.ts still passes. Public API: unchanged.

@opencodejr opencodejr Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removing the server.connected handler addresses my earlier comment. This is now a refactor with no behaviour change: createJobList handles events the same way the old code in model.ts did, and jobs are re-read only when the connection comes back. The tests in src/session/requests/ pass and tsc -b for packages/app is clean. Public API: unchanged.

@jlongster

Copy link
Copy Markdown
Contributor Author

Closing: as the review showed, the app already re-reads the job list on every reconnect (connection status goes through reconnecting → connected on every drop, watchdog and resync), so there's no bug to fix. What remained was a refactor plus tests for behaviour that already works.

@jlongster jlongster closed this Nov 20, 2026
@jlongster
jlongster deleted the job-list-resync branch November 20, 2026 03:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant