I am a newbie. I installed OpenBSD 4.5 release on a laptop. I want my installation to have the latest patches. So I downloaded the latest sources (from the stable branch) and compiled the kernel. When I rebooted the machine, I expected the uname -v to tell that I have patch six. (ie. GENERIC#6). However, I did not get this. I got GENERIC#0.

The first line of dmesg says:
OpenBSD 4.5-stable (GENERIC) #0: Fri May 15 15:34:00 CDT 2009

NB:
Once I have this squared away, I plan to comment out the checkout lines and just retain update.
I have a companion script, that is run at boot up time. That script, will test the presence of a file "new_kernel_available.000". If one is present, it will re-compile the userland objects, else it will not. If userland is compiled successfully, my script will delete my flag file "new_kernel_avilable.000", so that subsequent reboots, do not force user land re-compile.

In the above script, please tell me where am i going wrong? Why do I not get the latest patches?

That number simply indicates how many times you've recompiled the kernel, if you have recompiled it each time a kernel errata was released... the number would have increased, presuming you never removed the GENERIC folder in the compile directory.

There have only been 3 kernel patches, 2 user land patches.. that's 5 errata entries.

From the looks of it, you're following -STABLE.. and exporting it from the CVS tree.. all the patches on the errata page are in that branch first, some minor things sometimes don't make it that far.

While I can understand that the building the system appears tedious, it is best done manually. The above script will work fine assuming that /usr/src/, /usr/xenocara, & /usr/ports are empty. The problem is when you attempt to update the various components the second, third, etc. times. Instead of doing a CVS checkout, you should be doing a CVS update. You should review the information found in Section 5.3.3 & 5.3.4 of the FAQ which covers this process:

...& you have downloaded the source tree after the date of the last patch & recompiled the portions indicated in the errata, then you can say that all preceding patches have been applied. What file version is pointed to by the CVS tag OPENBSD_4_5 will change as changes are checked into this branch.

As an example, given that you have recompiled the kernel you have some familiarity with the GENERIC configuration file. If you look at the Web page showing the CVS history for this file:

You will see that version 1.651 (at the time of this posting...) has both tags OPENBSD_4_5 & OPENBSD_4_5_BASE. The OPENBSD_4_5_BASE tag indicates the file versions of what became OpenBSD 4.5-release, & after tagging has occurred, no new files are ever checked into this branch. If for some reason, a patch for OpenBSD 4.5-release(or -stable) ever needs to modify GENERIC, it will be checked into the OPENBSD_4_5 branch, & the tag will point to this new version as opposed to 1.651.

Also, because OPENBSD_4_5_BASE & OPENBSD_4_5 both point to the same file version of GENERIC, one can conclude that there have been no changes to the default kernel configuration during the life of OpenBSD 4.5 thus far.